D&D in Emacs: Dice Rolls

I've started running a D&D campaign, and I have been using Emacs and org-mode for taking notes, which I will use to guide players through the adventure. This lets me do a few things:

I found decide-mode for doing dice rolls, but what if I came across the sentence "Hit dice: 1d4" during play? Wouldn't it be nice to be able to hover the cursor over "1d4" and tell Emacs to roll a 4 sided die?

I've included a new minor mode in my .emacs: dnd-mode. This will turn XdY into buttons (using button-lock) that can be clicked, or invoked with C-c C-r.

(require 'button-lock)
(require 'decide)

  (defvar *dnd-mode-buttons* '()))

(defvar *dnd-mode-max-ndice* 10)
(defvar *dnd-mode-nsides* '(2 3 4 6 8 10 20))

(define-minor-mode dnd-mode
  "A minor mode for D&D"
  :lighter " D&D"
  :keymap (let ((map (make-sparse-keymap)))
            (define-key map (kbd "C-c C-r") 'dnd-mode-roll-at-point)
  (if dnd-mode

(defun dnd-mode-highlight-dice-rolls ()
  (dolist (ndice (number-sequence 1 *dnd-mode-max-ndice*))
    (dolist (nsides *dnd-mode-nsides*)
      (lexical-let ((spec-string (format "%dd%d" ndice nsides)))
        (add-to-list '*dnd-mode-buttons*
                      (lambda ()
                        (dnd-mode-roll-dice spec-string))
                      :face 'link :face-policy 'prepend))))))

(defun dnd-mode-unhighlight-dice-rolls ()
  (dolist (button *dnd-mode-buttons*)
    (button-lock-unset-button button))
  (setq *dnd-buttons* '()))

(defun dnd-mode-roll-dice (spec-string)
  (let ((buffer-read-only t))
    (decide-roll-dice spec-string)))

(defun dnd-mode-roll-at-point ()
  (dnd-mode-roll-dice (thing-at-point 'word)))

(provide 'dnd-mode)


Here's an example from some notes I took on Hollow's Last Hope:


The Future

I expect to extend and improve "dnd-mode" as my adventure progresses. A few ideas off the top of my head:

TODO Insert org links to relevant rulebook pages automatically

d20srd.org could be used as the reference material instead of PDF's. For example, "gelatinous cube" might become an external link to http://www.d20srd.org/srd/monsters/ooze.htm#gelatinousCube.

TODO Org-mode spreadsheet for character sheets

TODO NPC generation