branch: externals/leaf commit 800fc718767e5300b75271fe948c76840effa695 Author: Valeriy Litkovskyy <vlr.ltk...@protonmail.com> Commit: Valeriy Litkovskyy <vlr.ltk...@protonmail.com>
leaf-key-bindlist is no longer required to be defined --- leaf-tests.el | 12 ++++++------ leaf.el | 10 +++++++++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/leaf-tests.el b/leaf-tests.el index f786db0..3a8e607 100644 --- a/leaf-tests.el +++ b/leaf-tests.el @@ -2409,37 +2409,37 @@ Example: '(((leaf-key "C-M-i" 'flyspell-correct-wrapper) (let* ((old (lookup-key global-map (kbd "C-M-i"))) (value `(global-map "C-M-i" flyspell-correct-wrapper ,(and old (not (numberp old)) old) nil))) - (push value leaf-key-bindlist) + (leaf-safe-push value leaf-key-bindlist) (define-key global-map (kbd "C-M-i") 'flyspell-correct-wrapper))) ((leaf-key [remap backward-sentence] 'sh-beginning-of-command) (let* ((old (lookup-key global-map [remap backward-sentence])) (value `(global-map "<remap> <backward-sentence>" sh-beginning-of-command ,(and old (not (numberp old)) old) nil))) - (push value leaf-key-bindlist) + (leaf-safe-push value leaf-key-bindlist) (define-key global-map [remap backward-sentence] 'sh-beginning-of-command))) ((leaf-key "C-M-i" 'flyspell-correct-wrapper 'c-mode-map) (let* ((old (lookup-key c-mode-map (kbd "C-M-i"))) (value `(c-mode-map "C-M-i" flyspell-correct-wrapper ,(and old (not (numberp old)) old) nil))) - (push value leaf-key-bindlist) + (leaf-safe-push value leaf-key-bindlist) (define-key c-mode-map (kbd "C-M-i") 'flyspell-correct-wrapper))) ((leaf-key [remap backward-sentence] 'sh-beginning-of-command 'shell-mode-map) (let* ((old (lookup-key shell-mode-map [remap backward-sentence])) (value `(shell-mode-map "<remap> <backward-sentence>" sh-beginning-of-command ,(and old (not (numberp old)) old) nil))) - (push value leaf-key-bindlist) + (leaf-safe-push value leaf-key-bindlist) (define-key shell-mode-map [remap backward-sentence] 'sh-beginning-of-command))) ((leaf-key (vector 'key-chord ?i ?j) 'undo nil) (let* ((old (lookup-key global-map [key-chord 105 106])) (value `(global-map "<key-chord> i j" undo ,(and old (not (numberp old)) old) nil))) - (push value leaf-key-bindlist) + (leaf-safe-push value leaf-key-bindlist) (define-key global-map [key-chord 105 106] 'undo))) ((leaf-key [(control ?x) (control ?f)] 'undo) (let* ((old (lookup-key global-map [(control 120) (control 102)])) (value `(global-map "C-x C-f" undo ,(and old (not (numberp old)) old) nil))) - (push value leaf-key-bindlist) + (leaf-safe-push value leaf-key-bindlist) (define-key global-map [(control 120) (control 102)] 'undo)))))) (when (version< "24.0" emacs-version) diff --git a/leaf.el b/leaf.el index 3ef15dd..bc0271d 100644 --- a/leaf.el +++ b/leaf.el @@ -766,6 +766,14 @@ see `alist-get'." (indent-region (point-min) (point-max)) (display-buffer buf)))) +(defmacro leaf-safe-push (newelt place) + "Safely add NEWELT to the list stored in the generalized variable PLACE. +This is equivalent to `push' if PLACE is bound, otherwise, `setq' +is used to define a new list." + `(if (boundp ',place) + (push ,newelt ,place) + (setq ,place (list ,newelt)))) + ;;;; find-function @@ -838,7 +846,7 @@ For example: (mstr (if (stringp key*) key* (key-description key*)))) `(let* ((old (lookup-key ,mmap ,(if vecp key* `(kbd ,key*)))) (value ,(list '\` `(,mmap ,mstr ,command* ,',(and old (not (numberp old)) old) ,path)))) - (push value leaf-key-bindlist) + (leaf-safe-push value leaf-key-bindlist) (define-key ,mmap ,(if vecp key* `(kbd ,key*)) ',command*)))) (defmacro leaf-key* (key command)