branch: externals/leaf commit 4d485016df283710c851132c16145186b0bc4cbd Merge: 75914b5 d695f24 Author: Naoya Yamashita <con...@gmail.com> Commit: Naoya Yamashita <con...@gmail.com>
Merge remote-tracking branch 'origin/master' into refactor/typing-leaf-defaults --- leaf-tests.el | 12 ++++++------ leaf.el | 12 ++++++++++-- 2 files changed, 16 insertions(+), 8 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 69177f8..aa09aa5 100644 --- a/leaf.el +++ b/leaf.el @@ -5,7 +5,7 @@ ;; Author: Naoya Yamashita <con...@gmail.com> ;; Maintainer: Naoya Yamashita <con...@gmail.com> ;; Keywords: lisp settings -;; Version: 4.4.4 +;; Version: 4.4.5 ;; URL: https://github.com/conao3/leaf.el ;; Package-Requires: ((emacs "24.1")) @@ -772,6 +772,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 @@ -844,7 +852,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)