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

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

[elpa] externals/leaf e4343f1 04/13: Merge pull request #483 from conao3


From: Stefan Monnier
Subject: [elpa] externals/leaf e4343f1 04/13: Merge pull request #483 from conao3/feature#266
Date: Wed, 17 Mar 2021 18:45:35 -0400 (EDT)

branch: externals/leaf
commit e4343f153dcdb9d7bbd56a5736bdb3a5d377105f
Merge: b1fe4f2 de55bed
Author: Naoya Yamashita <conao3@gmail.com>
Commit: GitHub <noreply@github.com>

    Merge pull request #483 from conao3/feature#266
    
    Add :bind-keymap, :bind-keymap* keywords
---
 README.md     | 119 +++++++++++++++++++++++++++++++++-
 README.org    | 205 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 leaf-tests.el | 130 +++++++++++++++++++++++++++++++++++++
 leaf.el       |  79 ++++++++++++++++++++--
 4 files changed, 525 insertions(+), 8 deletions(-)

diff --git a/README.md b/README.md
index 8280cf7..f6ea083 100644
--- a/README.md
+++ b/README.md
@@ -14,6 +14,7 @@
   - [:commands keyword](#commands-keyword)
   - [:after keyword](#after-keyword)
   - [:bind, :bind* keywords](#bind-bind-keywords)
+  - [:bind-keymap, :bind-keymap* keywords](#bind-keymap-bind-keymap-keywords)
 - [Configure variables keywords](#configure-variables-keywords)
   - [:custom, :custom*, :custom-face 
keywords](#custom-custom-custom-face-keywords)
   - [:pre-setq, :setq, :setq-default 
keywords](#pre-setq-setq-setq-default-keywords)
@@ -643,7 +644,7 @@ When defined globally, key bindings and their corresponding 
functions are specif
 
 To set it to a specific map, **place the map name as a keyword or symbol** at 
the top of the list.
 
-If you omit `:package`, use leaf&#x2013;name as `:package` to lazy load.
+If you omit `:package`, use leaf--name as `:package` to lazy load.
 
 ```emacs-lisp
 (cort-deftest-with-macroexpand leaf/bind
@@ -845,6 +846,122 @@ If you omit `:package`, use leaf&#x2013;name as 
`:package` to lazy load.
 
 
 
+## :bind-keymap, :bind-keymap\* keywords
+
+`:bind-keymap` and `:bind-keymap*` provide frontend for keybind manager for 
binding keymap.
+
+Basic usage is same as `:bind` and `:bind*`
+
+```emacs-lisp
+(cort-deftest-with-macroexpand leaf/bind-keymap
+  '(
+    ;; cons-cell will be accepted
+    ((leaf projectile
+       :ensure t
+       :bind-keymap ("C-c p" . projectile-command-map))
+     (prog1 'projectile
+       (leaf-handler-package projectile projectile nil)
+       (leaf-keys-bind-keymap (("C-c p" . projectile-command-map))
+                              nil 'projectile)))
+
+    ;; multi cons-cell will be accepted
+    ((leaf projectile
+       :bind-keymap
+       ("C-c p" . projectile-command-map)
+       ("C-%" . ctl-x-5-map))
+     (prog1 'projectile
+       (leaf-keys-bind-keymap (("C-c p" . projectile-command-map)
+                               ("C-%" . ctl-x-5-map))
+                              nil 'projectile)))
+
+    ;; multi cons-cell in list will be accepted
+    ((leaf projectile
+       :bind-keymap (("C-c p" . projectile-command-map)
+                     ("C-%" . ctl-x-5-map)))
+     (prog1 'projectile
+       (leaf-keys-bind-keymap (("C-c p" . projectile-command-map)
+                               ("C-%" . ctl-x-5-map))
+                              nil 'projectile)))
+
+    ;; nested cons-cell list will be accepted
+    ((leaf projectile
+       :bind-keymap (("C-c p" . projectile-command-map)
+                     (("C-^" . ctl-x-4-map)
+                      ("C-%" . ctl-x-5-map))))
+     (prog1 'projectile
+       (leaf-keys-bind-keymap (("C-c p" . projectile-command-map)
+                               ("C-^" . ctl-x-4-map)
+                               ("C-%" . ctl-x-5-map))
+                              nil 'projectile)))
+
+    ;; use keyword at first element to bind specific map
+    ((leaf projectile
+       :bind-keymap (("C-c p" . projectile-command-map)
+                     (:projectile-mode-map
+                      ("C-^" . ctl-x-4-map)
+                      ("C-%" . ctl-x-5-map))))
+     (prog1 'projectile
+       (leaf-keys-bind-keymap (("C-c p" . projectile-command-map)
+                               (projectile-mode-map
+                                :package projectile
+                               ("C-^" . ctl-x-4-map)
+                               ("C-%" . ctl-x-5-map)))
+                              nil 'projectile)))
+
+    ;; specific map at top-level will be accepted
+    ((leaf projectile
+       :bind-keymap
+       ("C-c p" . projectile-command-map)
+       (:projectile-mode-map
+        ("C-^" . ctl-x-4-map)
+        ("C-%" . ctl-x-5-map)))
+     (prog1 'projectile
+       (leaf-keys-bind-keymap (("C-c p" . projectile-command-map)
+                               (projectile-mode-map :package projectile
+                                                   ("C-^" . ctl-x-4-map)
+                                                   ("C-%" . ctl-x-5-map)))
+                              nil 'projectile)))
+
+    ;; use :package to deffering :iserch-mode-map declared
+    ((leaf projectile
+       :bind-keymap (("C-c p" . projectile-command-map)
+                     (:isearch-mode-map
+                      :package isearch
+                      ("C-^" . ctl-x-4-map)
+                      ("C-%" . ctl-x-5-map))))
+     (prog1 'projectile
+       (leaf-keys-bind-keymap (("C-c p" . projectile-command-map)
+                               (isearch-mode-map :package isearch
+                                                ("C-^" . ctl-x-4-map)
+                                                ("C-%" . ctl-x-5-map)))
+                              nil 'projectile)))
+
+    ;; you can use symbol instead of keyword to specify map
+    ((leaf projectile
+       :bind-keymap (("C-c p" . projectile-command-map)
+                     (isearch-mode-map
+                      :package isearch
+                      ("C-^" . ctl-x-4-map)
+                      ("C-%" . ctl-x-5-map))))
+     (prog1 'projectile
+       (leaf-keys-bind-keymap (("C-c p" . projectile-command-map)
+                               (isearch-mode-map :package isearch
+                                                ("C-^" . ctl-x-4-map)
+                                                ("C-%" . ctl-x-5-map)))
+                              nil 'projectile)))
+
+    ;; you can use vectors to remap etc
+    ((leaf projectile
+       :ensure t
+       :bind-keymap (([remap isearch-forward] . projectile-command-map)))
+     (prog1 'projectile
+       (leaf-handler-package projectile projectile nil)
+       (leaf-keys-bind-keymap (([remap isearch-forward] . 
projectile-command-map))
+                              nil 'projectile)))))
+```
+
+
+
 # Configure variables keywords
 
 
diff --git a/README.org b/README.org
index 2803084..1e265bb 100644
--- a/README.org
+++ b/README.org
@@ -32,6 +32,7 @@
   - [[:commands keyword]]
   - [[:after keyword]]
   - [[:bind, :bind* keywords]]
+  - [[:bind-keymap, :bind-keymap* keywords]]
 - [[Configure variables keywords]]
   - [[:custom, :custom*, :custom-face keywords]]
   - [[:pre-setq, :setq, :setq-default keywords]]
@@ -855,6 +856,210 @@ If you omit ~:package~, use leaf--name as ~:package~ to 
lazy load.
                       ("M-O" . isearch-moccur-all)))))))
 #+end_src
 
+** :bind-keymap, :bind-keymap* keywords
+
+~:bind-keymap~ and ~:bind-keymap*~ provide frontend for keybind manager for 
binding keymap.
+
+Basic usage is same as ~:bind~ and ~:bind*~
+
+#+begin_src emacs-lisp
+  (cort-deftest-with-macroexpand leaf/bind
+    '(
+      ;; cons-cell will be accepted
+      ((leaf macrostep
+         :ensure t
+         :bind ("C-c e" . macrostep-expand))
+       (prog1 'macrostep
+         (unless (fboundp 'macrostep-expand) (autoload #'macrostep-expand 
"macrostep" nil t))
+         (declare-function macrostep-expand "macrostep")
+         (leaf-handler-package macrostep macrostep nil)
+         (leaf-keys (("C-c e" . macrostep-expand)))))
+
+      ;; multi cons-cell will be accepted
+      ((leaf color-moccur
+         :bind
+         ("M-s O" . moccur)
+         ("M-o" . isearch-moccur)
+         ("M-O" . isearch-moccur-all))
+       (prog1 'color-moccur
+         (unless (fboundp 'moccur) (autoload #'moccur "color-moccur" nil t))
+         (unless (fboundp 'isearch-moccur) (autoload #'isearch-moccur 
"color-moccur" nil t))
+         (unless (fboundp 'isearch-moccur-all) (autoload #'isearch-moccur-all 
"color-moccur" nil t))
+         (declare-function moccur "color-moccur")
+         (declare-function isearch-moccur "color-moccur")
+         (declare-function isearch-moccur-all "color-moccur")
+         (leaf-keys (("M-s O" . moccur)
+                     ("M-o" . isearch-moccur)
+                     ("M-O" . isearch-moccur-all)))))
+
+      ;; multi cons-cell in list will be accepted
+      ((leaf color-moccur
+         :bind (("M-s O" . moccur)
+                ("M-o" . isearch-moccur)
+                ("M-O" . isearch-moccur-all)))
+       (prog1 'color-moccur
+         (unless (fboundp 'moccur) (autoload #'moccur "color-moccur" nil t))
+         (unless (fboundp 'isearch-moccur) (autoload #'isearch-moccur 
"color-moccur" nil t))
+         (unless (fboundp 'isearch-moccur-all) (autoload #'isearch-moccur-all 
"color-moccur" nil t))
+         (declare-function moccur "color-moccur")
+         (declare-function isearch-moccur "color-moccur")
+         (declare-function isearch-moccur-all "color-moccur")
+         (leaf-keys (("M-s O" . moccur)
+                     ("M-o" . isearch-moccur)
+                     ("M-O" . isearch-moccur-all)))))
+
+      ;; bind to nil to unbind shortcut
+      ((leaf color-moccur
+         :bind (("M-s" . nil)
+                ("M-s o" . isearch-moccur)
+                ("M-s i" . isearch-moccur-all)))
+       (prog1 'color-moccur
+         (unless (fboundp 'isearch-moccur) (autoload #'isearch-moccur 
"color-moccur" nil t))
+         (unless (fboundp 'isearch-moccur-all) (autoload #'isearch-moccur-all 
"color-moccur" nil t))
+         (declare-function isearch-moccur "color-moccur")
+         (declare-function isearch-moccur-all "color-moccur")
+         (leaf-keys (("M-s")
+                     ("M-s o" . isearch-moccur)
+                     ("M-s i" . isearch-moccur-all)))))
+
+      ;; nested cons-cell list will be accepted
+      ((leaf color-moccur
+         :bind (("M-s O" . moccur)
+                (("M-o" . isearch-moccur)
+                 (("M-O" . isearch-moccur-all))
+                 ("M-s" . isearch-moccur-some))))
+       (prog1 'color-moccur
+         (unless (fboundp 'moccur) (autoload #'moccur "color-moccur" nil t))
+         (unless (fboundp 'isearch-moccur) (autoload #'isearch-moccur 
"color-moccur" nil t))
+         (unless (fboundp 'isearch-moccur-all) (autoload #'isearch-moccur-all 
"color-moccur" nil t))
+         (unless (fboundp 'isearch-moccur-some) (autoload 
#'isearch-moccur-some "color-moccur" nil t))
+         (declare-function moccur "color-moccur")
+         (declare-function isearch-moccur "color-moccur")
+         (declare-function isearch-moccur-all "color-moccur")
+         (declare-function isearch-moccur-some "color-moccur")
+         (leaf-keys (("M-s O" . moccur)
+                     ("M-o" . isearch-moccur)
+                     ("M-O" . isearch-moccur-all)
+                     ("M-s" . isearch-moccur-some)))))
+
+      ;; use keyword at first element to bind specific map
+      ((leaf color-moccur
+         :bind (("M-s O" . moccur)
+                (:isearch-mode-map
+                 ("M-o" . isearch-moccur)
+                 ("M-O" . isearch-moccur-all))))
+       (prog1 'color-moccur
+         (unless (fboundp 'moccur) (autoload #'moccur "color-moccur" nil t))
+         (unless (fboundp 'isearch-moccur) (autoload #'isearch-moccur 
"color-moccur" nil t))
+         (unless (fboundp 'isearch-moccur-all) (autoload #'isearch-moccur-all 
"color-moccur" nil t))
+         (declare-function moccur "color-moccur")
+         (declare-function isearch-moccur "color-moccur")
+         (declare-function isearch-moccur-all "color-moccur")
+         (defvar isearch-mode-map)
+         (leaf-keys (("M-s O" . moccur)
+                     (:isearch-mode-map
+                      :package color-moccur
+                      ("M-o" . isearch-moccur)
+                      ("M-O" . isearch-moccur-all))))))
+
+      ;; specific map at top-level will be accepted
+      ((leaf color-moccur
+         :bind
+         ("M-s O" . moccur)
+         (:isearch-mode-map
+          ("M-o" . isearch-moccur)
+          ("M-O" . isearch-moccur-all)))
+       (prog1 'color-moccur
+         (unless (fboundp 'moccur) (autoload #'moccur "color-moccur" nil t))
+         (unless (fboundp 'isearch-moccur) (autoload #'isearch-moccur 
"color-moccur" nil t))
+         (unless (fboundp 'isearch-moccur-all) (autoload #'isearch-moccur-all 
"color-moccur" nil t))
+         (declare-function moccur "color-moccur")
+         (declare-function isearch-moccur "color-moccur")
+         (declare-function isearch-moccur-all "color-moccur")
+         (defvar isearch-mode-map)
+         (leaf-keys (("M-s O" . moccur)
+                     (:isearch-mode-map
+                      :package color-moccur
+                      ("M-o" . isearch-moccur)
+                      ("M-O" . isearch-moccur-all))))))
+
+      ;; use :package to deffering :iserch-mode-map declared
+      ((leaf color-moccur
+         :bind (("M-s O" . moccur)
+                (:isearch-mode-map
+                 :package isearch
+                 ("M-o" . isearch-moccur)
+                 ("M-O" . isearch-moccur-all))))
+       (prog1 'color-moccur
+         (unless (fboundp 'moccur) (autoload #'moccur "color-moccur" nil t))
+         (unless (fboundp 'isearch-moccur) (autoload #'isearch-moccur 
"color-moccur" nil t))
+         (unless (fboundp 'isearch-moccur-all) (autoload #'isearch-moccur-all 
"color-moccur" nil t))
+         (declare-function moccur "color-moccur")
+         (declare-function isearch-moccur "color-moccur")
+         (declare-function isearch-moccur-all "color-moccur")
+         (defvar isearch-mode-map)
+         (leaf-keys (("M-s O" . moccur)
+                     (:isearch-mode-map
+                      :package isearch
+                      ("M-o" . isearch-moccur)
+                      ("M-O" . isearch-moccur-all))))))
+
+      ;; you can use symbol instead of keyword to specify map
+      ((leaf color-moccur
+         :bind (("M-s O" . moccur)
+                (isearch-mode-map
+                 :package isearch
+                 ("M-o" . isearch-moccur)
+                 ("M-O" . isearch-moccur-all))))
+       (prog1 'color-moccur
+         (unless (fboundp 'moccur) (autoload #'moccur "color-moccur" nil t))
+         (unless (fboundp 'isearch-moccur) (autoload #'isearch-moccur 
"color-moccur" nil t))
+         (unless (fboundp 'isearch-moccur-all) (autoload #'isearch-moccur-all 
"color-moccur" nil t))
+         (declare-function moccur "color-moccur")
+         (declare-function isearch-moccur "color-moccur")
+         (declare-function isearch-moccur-all "color-moccur")
+         (defvar isearch-mode-map)
+         (leaf-keys (("M-s O" . moccur)
+                     (isearch-mode-map
+                      :package isearch
+                      ("M-o" . isearch-moccur)
+                      ("M-O" . isearch-moccur-all))))))
+
+      ;; you can use vectors to remap etc
+      ((leaf swiper
+          :ensure t
+          :bind (([remap isearch-forward] . swiper)))
+       (prog1 'swiper
+         (unless (fboundp 'swiper) (autoload #'swiper "swiper" nil t))
+         (declare-function swiper "swiper")
+
+         (leaf-handler-package swiper swiper nil)
+         (leaf-keys (([remap isearch-forward] . swiper)))))
+
+      ((leaf files
+          :bind (([(control ?x) (control ?f)] . find-file)))
+       (prog1 'files
+         (unless (fboundp 'find-file) (autoload #'find-file "files" nil t))
+         (declare-function find-file "files")
+         (leaf-keys (([(control ?x) (control ?f)] . find-file)))))))
+
+  (cort-deftest-with-macroexpand leaf/bind*
+    '(
+      ;; bind* to bind override any key-bind map
+      ((leaf color-moccur
+         :bind*
+         ("M-s O" . moccur)
+         ("M-o" . isearch-moccur)
+         ("M-O" . isearch-moccur-all))
+       (prog1 'color-moccur
+         (autoload #'moccur "color-moccur" nil t)
+         (autoload #'isearch-moccur "color-moccur" nil t)
+         (autoload #'isearch-moccur-all "color-moccur" nil t)
+         (leaf-keys* (("M-s O" . moccur)
+                      ("M-o" . isearch-moccur)
+                      ("M-O" . isearch-moccur-all)))))))
+#+end_src
+
 ** COMMENT :defaults keyword
 
 ~:defalts~ provide to download recommended settings for specified package.
diff --git a/leaf-tests.el b/leaf-tests.el
index 998694a..aa28961 100644
--- a/leaf-tests.el
+++ b/leaf-tests.el
@@ -1218,6 +1218,112 @@ Example:
                     ("M-O" . isearch-moccur-all)
                     ("M-s" . isearch-moccur-some)))))))
 
+(cort-deftest-with-macroexpand leaf/bind-keymap
+  '(
+    ;; cons-cell will be accepted
+    ((leaf projectile
+       :ensure t
+       :bind-keymap ("C-c p" . projectile-command-map))
+     (prog1 'projectile
+       (leaf-handler-package projectile projectile nil)
+       (leaf-keys-bind-keymap (("C-c p" . projectile-command-map))
+                              nil 'projectile)))
+
+    ;; multi cons-cell will be accepted
+    ((leaf projectile
+       :bind-keymap
+       ("C-c p" . projectile-command-map)
+       ("C-%" . ctl-x-5-map))
+     (prog1 'projectile
+       (leaf-keys-bind-keymap (("C-c p" . projectile-command-map)
+                               ("C-%" . ctl-x-5-map))
+                              nil 'projectile)))
+
+    ;; multi cons-cell in list will be accepted
+    ((leaf projectile
+       :bind-keymap (("C-c p" . projectile-command-map)
+                     ("C-%" . ctl-x-5-map)))
+     (prog1 'projectile
+       (leaf-keys-bind-keymap (("C-c p" . projectile-command-map)
+                               ("C-%" . ctl-x-5-map))
+                              nil 'projectile)))
+
+    ;; nested cons-cell list will be accepted
+    ((leaf projectile
+       :bind-keymap (("C-c p" . projectile-command-map)
+                     (("C-^" . ctl-x-4-map)
+                      ("C-%" . ctl-x-5-map))))
+     (prog1 'projectile
+       (leaf-keys-bind-keymap (("C-c p" . projectile-command-map)
+                               ("C-^" . ctl-x-4-map)
+                               ("C-%" . ctl-x-5-map))
+                              nil 'projectile)))
+
+    ;; use keyword at first element to bind specific map
+    ((leaf projectile
+       :bind-keymap (("C-c p" . projectile-command-map)
+                     (:projectile-mode-map
+                      ("C-^" . ctl-x-4-map)
+                      ("C-%" . ctl-x-5-map))))
+     (prog1 'projectile
+       (leaf-keys-bind-keymap (("C-c p" . projectile-command-map)
+                               (projectile-mode-map
+                                :package projectile
+                               ("C-^" . ctl-x-4-map)
+                               ("C-%" . ctl-x-5-map)))
+                              nil 'projectile)))
+
+    ;; specific map at top-level will be accepted
+    ((leaf projectile
+       :bind-keymap
+       ("C-c p" . projectile-command-map)
+       (:projectile-mode-map
+        ("C-^" . ctl-x-4-map)
+        ("C-%" . ctl-x-5-map)))
+     (prog1 'projectile
+       (leaf-keys-bind-keymap (("C-c p" . projectile-command-map)
+                               (projectile-mode-map :package projectile
+                                                   ("C-^" . ctl-x-4-map)
+                                                   ("C-%" . ctl-x-5-map)))
+                              nil 'projectile)))
+
+    ;; use :package to deffering :iserch-mode-map declared
+    ((leaf projectile
+       :bind-keymap (("C-c p" . projectile-command-map)
+                     (:isearch-mode-map
+                      :package isearch
+                      ("C-^" . ctl-x-4-map)
+                      ("C-%" . ctl-x-5-map))))
+     (prog1 'projectile
+       (leaf-keys-bind-keymap (("C-c p" . projectile-command-map)
+                               (isearch-mode-map :package isearch
+                                                ("C-^" . ctl-x-4-map)
+                                                ("C-%" . ctl-x-5-map)))
+                              nil 'projectile)))
+
+    ;; you can use symbol instead of keyword to specify map
+    ((leaf projectile
+       :bind-keymap (("C-c p" . projectile-command-map)
+                     (isearch-mode-map
+                      :package isearch
+                      ("C-^" . ctl-x-4-map)
+                      ("C-%" . ctl-x-5-map))))
+     (prog1 'projectile
+       (leaf-keys-bind-keymap (("C-c p" . projectile-command-map)
+                               (isearch-mode-map :package isearch
+                                                ("C-^" . ctl-x-4-map)
+                                                ("C-%" . ctl-x-5-map)))
+                              nil 'projectile)))
+
+    ;; you can use vectors to remap etc
+    ((leaf projectile
+       :ensure t
+       :bind-keymap (([remap isearch-forward] . projectile-command-map)))
+     (prog1 'projectile
+       (leaf-handler-package projectile projectile nil)
+       (leaf-keys-bind-keymap (([remap isearch-forward] . 
projectile-command-map))
+                              nil 'projectile)))))
+
 (cort-deftest-with-macroexpand leaf/global-minor-mode
   '(
     ;; symbol will be accepted
@@ -2304,6 +2410,30 @@ Example:
          (push value leaf-key-bindlist)
          (define-key global-map [(control 120) (control 102)] 'undo))))))
 
+(when (version< "24.0" emacs-version)
+  (cort-deftest-with-macroexpand leaf/leaf-key-bind-keymap
+    '(((leaf-key-bind-keymap "C-c p" projectile-command-map)
+       (progn
+         nil
+         (leaf-key "C-c p" projectile-command-map nil)))
+
+      ((leaf-key-bind-keymap "C-c p" projectile-command-map 'c-mode-map)
+       (progn
+         nil
+         (leaf-key "C-c p" projectile-command-map 'c-mode-map)))
+
+      ((leaf-key-bind-keymap "C-c p" projectile-command-map 'c-mode-map 
'projectile)
+       (progn
+         (require 'projectile)
+         (leaf-key "C-c p" projectile-command-map 'c-mode-map)))
+
+      ((leaf-key-bind-keymap [remap backward-sentence] projectile-command-map 
'shell-mode-map)
+       (progn
+         nil
+         (leaf-key
+         [remap backward-sentence]
+         projectile-command-map 'shell-mode-map))))))
+
 ;; required `tabulated-list'
 ;; there are only tested running (leaf-key-describe-bindings) with no error
 (when (version<= "24.4" emacs-version)
diff --git a/leaf.el b/leaf.el
index f8a23d6..d88dbb8 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.0
+;; Version: 4.4.1
 ;; URL: https://github.com/conao3/leaf.el
 ;; Package-Requires: ((emacs "24.1"))
 
@@ -109,6 +109,8 @@ Same as `list' but this macro does not evaluate any 
arguments."
    :bind*             (progn
                         (leaf-register-autoload (cadr leaf--value) leaf--name)
                         `((leaf-keys* ,(car leaf--value)) ,@leaf--body))
+   :bind-keymap       `((leaf-keys-bind-keymap ,(car leaf--value) nil 
',leaf--name) ,@leaf--body)
+   :bind-keymap*      `((leaf-keys-bind-keymap* ,(car leaf--value) nil 
',leaf--name) ,@leaf--body)
 
    :mode              (progn
                         (leaf-register-autoload (mapcar #'cdr leaf--value) 
leaf--name)
@@ -247,7 +249,7 @@ Sort by `leaf-sort-leaf--values-plist' in this order.")
                (cons (car elm) (cadr elm)))
              (mapcan 'identity leaf--value)))
 
-    ((memq leaf--key '(:bind :bind*))
+    ((memq leaf--key '(:bind :bind* :bind-keymap :bind-keymap*))
      ;; Accept: `leaf-keys' accept form
      ;; Return: a pair like (leaf--value . (fn fn ...))
      (eval `(leaf-keys ,leaf--value ,leaf--name)))
@@ -836,9 +838,11 @@ For example:
 Bind COMMAND at KEY."
   `(leaf-key ,key ,command 'leaf-key-override-global-map))
 
-(defmacro leaf-keys (bind &optional dryrun-name)
+(defmacro leaf-keys (bind &optional dryrun-name bind-keymap bind-keymap-pkg)
   "Bind multiple BIND for KEYMAP defined in PKG.
 BIND is (KEY . COMMAND) or (KEY . nil) to unbind KEY.
+If BIND-KEYMAP is non-nil generate `leaf-key-bind-keymap' instead of 
`leaf-key'.
+If BIND-KEYMAP-PKG is passed, require it before binding.
 
 OPTIONAL:
   BIND also accept below form.
@@ -865,7 +869,10 @@ NOTE: BIND can also accept list of these."
           (lambda (bind)
             (cond
              ((funcall pairp bind)
-              (push `(leaf-key ,(car bind) #',(cdr bind)) forms)
+              (push (if bind-keymap
+                        `(leaf-key-bind-keymap ,(car bind) ,(cdr bind) nil 
,bind-keymap-pkg)
+                      `(leaf-key ,(car bind) #',(cdr bind)))
+                    forms)
               (push bind bds)
               (push (cdr bind) fns))
              ((and (listp (car bind))
@@ -873,7 +880,10 @@ NOTE: BIND can also accept list of these."
               (mapcar (lambda (elm)
                         (if (funcall pairp elm)
                             (progn
-                              (push `(leaf-key ,(car elm) #',(cdr elm)) forms)
+                              (push (if bind-keymap
+                                        `(leaf-key-bind-keymap ,(car elm) 
,(cdr elm) nil ,bind-keymap-pkg)
+                                      `(leaf-key ,(car elm) #',(cdr elm)))
+                                    forms)
                               (push elm bds)
                               (push (cdr elm) fns))
                           (funcall recurfn elm)))
@@ -888,7 +898,9 @@ NOTE: BIND can also accept list of these."
                               ,@(mapcar
                                  (lambda (elm)
                                    (push (cdr elm) fns)
-                                   `(leaf-key ,(car elm) #',(cdr elm) ',map))
+                                   (if bind-keymap
+                                       `(leaf-key-bind-keymap ,(car elm) ,(cdr 
elm) ',map ',pkg)
+                                     `(leaf-key ,(car elm) #',(cdr elm) 
',map)))
                                  elmbinds))))
                 (push (if pkg
                           `(,map :package ,pkg ,@elmbinds)
@@ -896,7 +908,8 @@ NOTE: BIND can also accept list of these."
                       bds)
                 (when pkg
                   (dolist (elmpkg (if (atom pkg) `(,pkg) pkg))
-                    (setq form `(eval-after-load ',elmpkg ',form))))
+                    (unless bind-keymap
+                      (setq form `(eval-after-load ',elmpkg ',form)))))
                 (push form forms)))
              (t
               (mapcar (lambda (elm) (funcall recurfn elm)) bind)))))
@@ -911,6 +924,48 @@ BIND must not contain :{{map}}."
   (let ((binds (if (and (atom (car bind)) (atom (cdr bind))) `(,bind) bind)))
     `(leaf-keys (:leaf-key-override-global-map ,@binds))))
 
+;;; leaf-keys-bind-keymap
+
+(defmacro leaf-key-bind-keymap (key kmap &optional keymap pkg)
+  "Bind KEY to KMAP in KEYMAP (`global-map' if not passed).
+If PKG passed, require PKG before binding."
+  `(progn
+     ,(when pkg `(require ,pkg))
+     (leaf-key ,key ,kmap ,keymap)))
+
+(defmacro leaf-key-bind-keymap* (key keymap &optional pkg)
+  "Similar to `leaf-keys-bind-keymap', but overrides any mode-specific 
bindings.
+Bind KEYMAP at KEY.
+If PKG passed, require PKG before binding."
+  `(leaf-keys-bind-keymap ,key ,keymap 'leaf-key-override-global-map ,pkg))
+
+(defmacro leaf-keys-bind-keymap (bind &optional dryrun-name pkg)
+  "Bind multiple BIND for KEYMAP defined in PKG.
+BIND is (KEY . KEYMAP) or (KEY . nil) to unbind KEY.
+If PKG passed, require PKG before binding.
+
+OPTIONAL:
+  BIND also accept below form.
+    (:{{map}} :package {{pkg}} (KEY . KEYMAP) (KEY . KEYMAP))
+  KEYMAP is quoted keymap name.
+  PKG is quoted package name which define KEYMAP.
+  (wrap `eval-after-load' PKG)
+
+  If DRYRUN-NAME is non-nil, return list like
+  (LEAF_KEYS-FORMS (FN FN ...))
+
+  If omit :package of BIND, fill it in LEAF_KEYS-FORM.
+
+NOTE: BIND can also accept list of these."
+  `(leaf-keys ,bind ,dryrun-name 'bind-keymap ,pkg))
+
+(defmacro leaf-keys-bind-keymap* (bind &optional pkg)
+  "Similar to `leaf-keys-bind-keymap' but overrides any mode-specific bindings.
+BIND must not contain :{{map}}.
+If PKG passed, require PKG before binding."
+  (let ((binds (if (and (atom (car bind)) (atom (cdr bind))) `(,bind) bind)))
+    `(leaf-keys (:leaf-key-override-global-map ,@binds) ,pkg)))
+
 (define-derived-mode leaf-key-list-mode tabulated-list-mode "Leaf-key Bindings"
   "Major mode for listing bindings configured via `leaf-key'."
   (setq tabulated-list-format [("Map"     20 t)
@@ -961,6 +1016,16 @@ FN also accept list of FN."
          (push target leaf--autoload))))
    (if (listp fn) fn `(,fn))))
 
+(defun leaf-register-bind-keymap-autoload (fn pkg)
+  "Registor FN as autoload for PKG.
+FN also accept list of FN."
+  (mapc
+   (lambda (elm)
+     (let ((target `(,(intern (format "leaf-key--bind-keymap--%s--%s" pkg 
elm)) . ,(symbol-name pkg))))
+       (when (and elm (symbolp elm) (not (member target leaf--autoload)))
+         (push target leaf--autoload))))
+   (if (listp fn) fn `(,fn))))
+
 (defmacro leaf-handler-leaf-protect (name &rest body)
   "Meta handler for :leaf-protect in NAME for BODY `leaf' block."
   (declare (indent 1))



reply via email to

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