emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/leaf d695f24 06/18: Merge pull request #493 from xFA25E


From: Stefan Monnier
Subject: [elpa] externals/leaf d695f24 06/18: Merge pull request #493 from xFA25E/master
Date: Wed, 2 Jun 2021 18:28:01 -0400 (EDT)

branch: externals/leaf
commit d695f24369d7abacbef57648ae596cee0cd62108
Merge: ab5cc26 1263f8a
Author: Naoya Yamashita <conao3@gmail.com>
Commit: GitHub <noreply@github.com>

    Merge pull request #493 from xFA25E/master
    
    Implemented optional leaf-key-bindlist
---
 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 3ef15dd..64baac2 100644
--- a/leaf.el
+++ b/leaf.el
@@ -5,7 +5,7 @@
 ;; Author: Naoya Yamashita <conao3@gmail.com>
 ;; Maintainer: Naoya Yamashita <conao3@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"))
 
@@ -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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]