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