Compare commits
6 Commits
b12f781155
...
578c540e12
Author | SHA1 | Date | |
---|---|---|---|
|
578c540e12 | ||
|
782d8c8c78 | ||
|
db53b9008f | ||
|
f50f0d84e0 | ||
|
ad22b9a7e8 | ||
|
5cbc08b864 |
|
@ -90,7 +90,7 @@ installation method.
|
||||||
I use `straight.el`:
|
I use `straight.el`:
|
||||||
|
|
||||||
```lisp
|
```lisp
|
||||||
(straight-get-package
|
(straight-use-package
|
||||||
'(define-repeat-map
|
'(define-repeat-map
|
||||||
:host nil
|
:host nil
|
||||||
:repo "https://tildegit.org/acdw/define-repeat-map.el"))
|
:repo "https://tildegit.org/acdw/define-repeat-map.el"))
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
;; Author: Case Duckworth <acdw@acdw.net>
|
;; Author: Case Duckworth <acdw@acdw.net>
|
||||||
;; Keywords: convenience
|
;; Keywords: convenience
|
||||||
;; URL:
|
;; URL: https://tildegit.org/acdw/define-repeat-map.el/
|
||||||
|
|
||||||
;;; License:
|
;;; License:
|
||||||
|
|
||||||
|
@ -24,11 +24,11 @@
|
||||||
;;; 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."
|
"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 (fn args)
|
||||||
"Internal. Map FN over ARGS, whch are commands in MAP."
|
"Internal. Map FN over ARGS, whch are commands in MAP."
|
||||||
(let (res)
|
(let (res)
|
||||||
(dolist (arg args)
|
(dolist (arg args)
|
||||||
|
@ -37,9 +37,9 @@
|
||||||
(reverse res)))
|
(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."
|
"Internal. Map `define-key' in MAP over ARGS, transorming them with FN."
|
||||||
(unless (zerop (mod (length args) 2))
|
(unless (zerop (mod (length args) 2))
|
||||||
(error "Wrong number of args"))
|
(signal 'wrong-number-of-arguments (length args)))
|
||||||
(let (res)
|
(let (res)
|
||||||
(while args
|
(while args
|
||||||
(let ((key (pop args))
|
(let ((key (pop args))
|
||||||
|
@ -49,24 +49,24 @@
|
||||||
(reverse res)))
|
(reverse res)))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defmacro define-repeat-map (name &rest args)
|
(defmacro define-repeat-map (name &rest keys)
|
||||||
"Define a repeat-map, NAME-repeat-map, and bind keys to it.
|
"Define a `repeat-map', NAME -repeat-map, and bind KEYS to it.
|
||||||
Each ARG is a list of lists containing keybind definitions of
|
Each ARG is a list of lists containing keybind definitions of
|
||||||
the form (KEY DEFINITION) KEY is anything `kbd' can recognize,
|
the form (KEY DEFINITION) KEY is anything `kbd' can recognize,
|
||||||
and DEFINITION is passed directly to `define-key'.
|
and DEFINITION is passed directly to `define-key'.
|
||||||
|
|
||||||
Optionally, the car of an arglist can contain the following
|
Optionally, the car of an arglist can contain the following
|
||||||
symbols, which changes the behavior of the key definitions in the
|
symbols, which changes the behavior of the key definitions in the
|
||||||
rest of the list:
|
rest of the list:
|
||||||
|
|
||||||
:enter - Provided commands can enter the repeat-map, but aren't
|
:enter - Provided commands can enter the `repeat-map', but aren't
|
||||||
bound in the map. They need to be bound elsewhere, however.
|
bound in the map. They need to be bound elsewhere, however.
|
||||||
|
|
||||||
:exit - Keys are bound in the repeat-map, but can't enter the
|
:exit - Keys are bound in the `repeat-map', but can't enter the
|
||||||
map. Their invocation exits the repeat-map.
|
map. Their invocation exits the `repeat-map'.
|
||||||
|
|
||||||
: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 ((define-repeat-map--result)
|
(let ((define-repeat-map--result)
|
||||||
(map (intern (concat (symbol-name name) "-repeat-map"))))
|
(map (intern (concat (symbol-name name) "-repeat-map"))))
|
||||||
|
@ -75,14 +75,13 @@
|
||||||
"Defined by `define-repeat-map'.")
|
"Defined by `define-repeat-map'.")
|
||||||
define-repeat-map--result)
|
define-repeat-map--result)
|
||||||
|
|
||||||
;; Iterate through ARGS
|
;; Iterate through KEYS
|
||||||
(dolist (arg args)
|
(dolist (arg keys)
|
||||||
(pcase (car arg)
|
(pcase (car arg)
|
||||||
(:enter
|
(:enter
|
||||||
;; Add the map to the commands' repeat-map property.
|
;; Add the map to the commands' repeat-map property.
|
||||||
(push `(progn
|
(push `(progn
|
||||||
,@(define-repeat-map--map-commands
|
,@(define-repeat-map--map-commands
|
||||||
`,map
|
|
||||||
(lambda (cmd) `(put ',cmd 'repeat-map ',map))
|
(lambda (cmd) `(put ',cmd 'repeat-map ',map))
|
||||||
(cdr arg)))
|
(cdr arg)))
|
||||||
define-repeat-map--result))
|
define-repeat-map--result))
|
||||||
|
@ -103,7 +102,6 @@
|
||||||
(lambda (cmd) (define-repeat-map--make-alias cmd map))
|
(lambda (cmd) (define-repeat-map--make-alias cmd map))
|
||||||
(cdr arg))
|
(cdr arg))
|
||||||
,@(define-repeat-map--map-commands
|
,@(define-repeat-map--map-commands
|
||||||
`,map
|
|
||||||
(lambda (cmd)
|
(lambda (cmd)
|
||||||
(let ((alias (define-repeat-map--make-alias cmd map)))
|
(let ((alias (define-repeat-map--make-alias cmd map)))
|
||||||
`(progn
|
`(progn
|
||||||
|
@ -120,7 +118,6 @@
|
||||||
(push `(progn
|
(push `(progn
|
||||||
,@(define-repeat-map--define-keys `,map #'identity arg)
|
,@(define-repeat-map--define-keys `,map #'identity arg)
|
||||||
,@(define-repeat-map--map-commands
|
,@(define-repeat-map--map-commands
|
||||||
`,map
|
|
||||||
(lambda (cmd) `(put ',cmd 'repeat-map ',map))
|
(lambda (cmd) `(put ',cmd 'repeat-map ',map))
|
||||||
arg))
|
arg))
|
||||||
define-repeat-map--result))))
|
define-repeat-map--result))))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user