♻️ Extract `rpgdm-core.el'
Prior to this commit, I experienced the following use case: Given I have the following code: ```emacs-lisp (require 'rpgdm-dice "~/git/emacs-rpgdm/rpgdm-dice.el") (require 'rpgdm-tables "~/git/emacs-rpgdm/rpgdm-tables.el") (require 'rpgdm-tables-dice "~/git/emacs-rpgdm/rpgdm-tables-dice.el") (require 'rpgdm-tables-freq "~/git/emacs-rpgdm/rpgdm-tables-freq.el") (setq rpgdm-base "~/git/emacs-rpgdm/") ``` And I call `rpgdm-tables-load` And load all the tables. When I then call `rpgdm-tables-choose` Then I get the following error: ``` let*: Symbol’s function definition is void: rpgdm-message ``` With this commit I'm able to skip requiring `rpgdm` and thus only use a segment of the `rpgdm` package ecosystem.
This commit is contained in:
parent
25c282c094
commit
cf24af20b6
6 changed files with 86 additions and 69 deletions
65
rpgdm.el
65
rpgdm.el
|
|
@ -25,15 +25,11 @@
|
|||
|
||||
(require 'ert)
|
||||
|
||||
(require 'rpgdm-core)
|
||||
(require 'rpgdm-dice)
|
||||
(require 'rpgdm-screen)
|
||||
(require 'rpgdm-tables)
|
||||
|
||||
|
||||
(defvar rpgdm-base
|
||||
(seq-find (lambda (elt) (string-match "rpgdm" elt)) load-path (getenv "HOME"))
|
||||
"Default directory to look for supporting data, like tables and charts.")
|
||||
|
||||
(define-minor-mode rpgdm-mode
|
||||
"Minor mode for layering role-playing game master functions over your notes."
|
||||
:lighter " D&D"
|
||||
|
|
@ -73,65 +69,6 @@
|
|||
|
||||
("q" nil "quit") ("<f12>" nil))
|
||||
|
||||
|
||||
(defvar rpgdm-last-results (make-ring 10)
|
||||
"The results from calls to `rpgdm-screen-' functions are stored here.")
|
||||
|
||||
(defvar rpgdm-last-results-ptr 0
|
||||
"Keeps track of where we are in the message display ring.
|
||||
Each call to `rpgdm-last-results' resets this to 0.")
|
||||
|
||||
(defun rpgdm-message (format-string &rest args)
|
||||
"Replace `messasge' function allowing it to be re-displayed.
|
||||
The FORMAT-STRING is a standard string for the `format' function,
|
||||
and ARGS are substitued values."
|
||||
(let ((message (apply 'format format-string args)))
|
||||
(ring-insert rpgdm-last-results message)
|
||||
(kill-new message)
|
||||
(rpgdm-last-results)))
|
||||
|
||||
(defun rpgdm-last-results ()
|
||||
"Display results from the last call to a `rpgdm-message' function."
|
||||
(interactive)
|
||||
(setq rpgdm-last-results-ptr 0)
|
||||
(message (ring-ref rpgdm-last-results rpgdm-last-results-ptr)))
|
||||
|
||||
(defun rpgdm-last-results-previous ()
|
||||
"Display results from an earlier call to `rpgdm-message'."
|
||||
(interactive)
|
||||
(incf rpgdm-last-results-ptr)
|
||||
(when (>= rpgdm-last-results-ptr (ring-length rpgdm-last-results))
|
||||
(setq rpgdm-last-results-ptr 0))
|
||||
(message "%d> %s" rpgdm-last-results-ptr (ring-ref rpgdm-last-results rpgdm-last-results-ptr)))
|
||||
|
||||
(defun rpgdm-last-results-next ()
|
||||
"Display results from an later call to `rpgdm-message'.
|
||||
Meant to be used with `rpgdm-last-results-previous'."
|
||||
(interactive)
|
||||
(when (> rpgdm-last-results-ptr 0)
|
||||
(cl-decf rpgdm-last-results-ptr))
|
||||
(message "%d> %s" rpgdm-last-results-ptr (ring-ref rpgdm-last-results rpgdm-last-results-ptr)))
|
||||
|
||||
(defun rpgdm-paste-last-message ()
|
||||
"Yank, e.g. paste, the last displayed message."
|
||||
(interactive)
|
||||
(insert (rpgdm-last-results)))
|
||||
|
||||
(ert-deftest rpgdm-last-results-test ()
|
||||
(progn
|
||||
(setq rpgdm-last-results (make-ring 10))
|
||||
(rpgdm-message "First in, so this is the oldest")
|
||||
(rpgdm-message "Something or other")
|
||||
(rpgdm-message "Almost the newest")
|
||||
(rpgdm-message "Newest"))
|
||||
|
||||
(should (equal "Newest" (rpgdm-last-results)))
|
||||
(should (equal "1> Almost the newest" (rpgdm-last-results-previous)))
|
||||
(should (equal "2> Something other" (rpgdm-last-results-previous)))
|
||||
(should (equal "1> Almost the newest" (rpgdm-last-results-next)))
|
||||
(should (equal "0> Almost the newest" (rpgdm-last-results-next)))
|
||||
(should (equal "0> Almost the newest" (rpgdm-last-results-next))))
|
||||
|
||||
(defvar rpgdm-oracle-mod 0 "Cummulative skew to create more tension.")
|
||||
|
||||
(defun rpgdm-oracle ()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue