 ;;
 ;; [1]: http://ergoemacs.org/emacs/elisp_defvar_problem.html
 
-(defvar radian-dotfiles nil
-  "Association list from a keybinding suffix to be used after
-M-RET to the file opened by the resulting keybinding.")
-(setq radian-dotfiles
-      '(("e i"   ".emacs.d/init.el")
-        ("e b"   ".emacs.d/init.before.local.el")
-        ("e p r" ".emacs.d/init.pre.local.el")
-        ("e p o" ".emacs.d/init.post.local.el")
-        ("e l"   ".emacs.d/init.local.el")
-        ("g c"   ".gitconfig")
-        ("g e"   ".gitexclude")
-        ("g l"   ".gitconfig.local")
-        ("l p"   ".lein/profiles.clj")
-        ("t c"   ".tmux.conf")
-        ("t l"   ".tmux.local.conf")
-        ("z r"   ".zshrc")
-        ("z a"   ".zshrc.antigen.local")
-        ("z b"   ".zshrc.before.local")
-        ("z l"   ".zshrc.local")))
-
-(dolist (item radian-dotfiles)
-  (global-set-key (kbd (concat "M-RET " (car item)))
-                  `(lambda ()
-                     ,(concat "Open ~/" (cadr item) " in the current buffer.")
-                     (interactive)
-                     (find-file ,(concat "~/" (cadr item))))))
+(defmacro radian-register-dotfile (filename &optional keybinding)
+  "Tell Radian about a dotfile.
+
+This is best demonstrated by example. If NAME is
+\".emacs.d/init.el\" then `radian-register-dotfile' will create
+the interactive function `radian-find-init-el'. Calling that
+function will invoke `find-file' on ~/.emacs.d/init.el.
+
+If additionally KEYBINDING is \"e i\" then
+`radian-register-dotfile' will use `global-set-key' to bind
+`radian-find-init-el' to (kbd \"M-RET e i\")."
+  (let* ((bare-filename (replace-regexp-in-string ".*/" "" filename))
+         (defun-name (make-symbol
+                      (concat
+                       "radian-find-"
+                       (replace-regexp-in-string "[^a-z0-9]" "-" bare-filename))))
+         (full-filename (concat "~/" filename))
+         (docstring (format "Open %s in the current buffer."
+                            full-filename))
+         (defun-form `(defun ,defun-name ()
+                        ,docstring
+                        (interactive)
+                        (find-file ,full-filename))))
+    (if keybinding
+        (let* ((full-keybinding (concat "M-RET " keybinding))
+               (set-key-form `(global-set-key (kbd ,full-keybinding)
+                                              #',defun-name)))
+          `(progn
+             ,defun-form
+             ,set-key-form))
+      defun-form)))
+
+;; Emacs
+(radian-register-dotfile ".emacs.d/init.el" "e i")
+(radian-register-dotfile ".emacs.d/init.before.local.el" "e b")
+(radian-register-dotfile ".emacs.d/init.pre.local.el" "e p r") ; deprecated
+(radian-register-dotfile ".emacs.d/init.post.local.el" "e p o") ; deprecated
+(radian-register-dotfile ".emacs.d/init.local.el" "e l")
+
+;; Git
+(radian-register-dotfile ".gitconfig" "g c")
+(radian-register-dotfile ".gitexclude" "g e")
+(radian-register-dotfile ".gitconfig.local" "g l")
+
+;; Leiningen
+(radian-register-dotfile ".lein/profiles.clj" "l p")
+
+;; Tmux
+(radian-register-dotfile ".tmux.conf" "t c")
+(radian-register-dotfile ".tmux.local.conf" "t l")
+
+;; Zsh
+(radian-register-dotfile ".zshrc" "z r")
+(radian-register-dotfile ".zshrc.antigen.local" "z a")
+(radian-register-dotfile ".zshrc.before.local" "z b")
+(radian-register-dotfile ".zshrc.local" "z l")
 
 (when (equal radian-customize-completion-mechanism 'helm-ido)
   ;; Use IDO ("interactive do") for C-x C-f and other file-finding

(when (radian-package-disabled-p 'helm)
  (autoload 'dired-jump "dired-x")
  (autoload 'dired-jump-other-window "dired-x")
  (global-set-key (kbd "C-x C-j") 'dired-jump)
  (global-set-key (kbd "C-x 4 C-j") 'dired-jump-other-window))

;; Suppress the 'ls does not support --dired' warning. Doing this instead
;; of installing a dired-compatibile ls is much easier, although it may


  (xterm-mouse-mode t)

  (defun radian-scroll-down ()
    "Scroll down one line."
    (interactive)
    (scroll-down 1))

  (defun radian-scroll-up ()
    "Scroll up one line."
    (interactive)
    (scroll-up 1))

  (global-set-key (kbd "<mouse-4>") #'radian-scroll-down)
  (global-set-key (kbd "<mouse-5>") #'radian-scroll-up))

;;; Clipboard
;; Based on https://gist.github.com/the-kenny/267162
