Add docstrings, etc.

This commit is contained in:
Case Duckworth 2021-09-06 23:56:25 -05:00
parent dc88071462
commit 647605457b
1 changed files with 19 additions and 15 deletions

View File

@ -24,25 +24,29 @@
;;; Code:
(defun define-repeat-map--make-alias (cmd map)
"Internal. Make an alias for CMD in repeat-map MAP."
(intern (concat (symbol-name cmd) "|"
(symbol-name map))))
(defun define-repeat-map--map-commands (map fn args)
(let (result)
"Internal. Map FN over ARGS, whch are commands in MAP."
(let (res)
(dolist (arg args)
(unless (stringp arg)
(push (funcall fn arg) result)))
(nreverse result)))
(push (funcall fn arg) res)))
(reverse res)))
(defun define-repeat-map--define-keys (map fn args)
"Internal. Map `define-key' over ARGS, transorming them with FN."
(unless (zerop (mod (length args) 2))
(error "Wrong number of args"))
(let (result)
(let (res)
(while args
(let ((key (pop args))
(cmd (funcall fn (pop args))))
(push `(define-key ,map (kbd ,key) #',cmd) result)))
(nreverse result)))
(push `(define-key ,map `(kbd ,key) #',cmd)
res)))
(reverse res)))
;;;###autoload
(defmacro define-repeat-map (name &rest args)
@ -64,12 +68,12 @@
:continue - Keys are bound in the repeat-map, but can't enter the
map. However, their invocations keep the repeat-map active."
(declare (indent 1))
(let ((result)
(let ((define-repeat-map--result)
(map (intern (concat (symbol-name name) "-repeat-map"))))
;; Create the keymap
(push `(defvar ,map (make-sparse-keymap)
"Defined by `define-repeat-map'.")
result)
define-repeat-map--result)
;; Iterate through ARGS
(dolist (arg args)
@ -81,14 +85,14 @@
`,map
(lambda (cmd) `(put ',cmd 'repeat-map ',map))
(cdr arg)))
result))
define-repeat-map--result))
(:exit
;; Bind the commands in the map.
(push `(progn
,@(define-repeat-map--define-keys
`,map #'identity (cdr arg)))
result))
define-repeat-map--result))
(:continue
;; Make an alias for each command, and process that alias like the
@ -108,7 +112,7 @@
(put ',alias
'repeat-map ',map))))
(cdr arg)))
result))
define-repeat-map--result))
(_
;; Default: bind the commands in the map, and add the map to the
@ -119,11 +123,11 @@
`,map
(lambda (cmd) `(put ',cmd 'repeat-map ',map))
arg))
result))))
define-repeat-map--result))))
`(with-eval-after-load 'repeat
,@(nreverse result))))
`(add-hook repeat-mode-hook
(lambda nil
,@(reverse define-repeat-map--result)))))
(provide 'define-repeat-map)
;;; define-repeat-map.el ends here