Skip to content

Commit ccb7e3a

Browse files
authored
Merge pull request #587 from minad/keymap-fixes
Keymap fixes
2 parents 5d9fc9c + 40c4991 commit ccb7e3a

File tree

5 files changed

+189
-190
lines changed

5 files changed

+189
-190
lines changed

README.org

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -388,23 +388,23 @@ Embark comes with the following indicators:
388388
- =embark-minimal-indicator=: shows a messages in the echo area or
389389
minibuffer prompt showing the current target and the types of all
390390
targets starting with the current one; this one is on by default.
391-
391+
392392
- =embark-highlight-indicator=: highlights the target at point;
393393
also on by default.
394-
394+
395395
- =embark-verbose-indicator=: displays a table of actions and their key
396396
bindings in a buffer; this is not on by default, in favor of the
397397
mixed indicator described next.
398-
398+
399399
- =embark-mixed-indicator=: starts out by behaving as the minimal
400400
indicator but after a short delay acts as the verbose indicator;
401401
this is on by default.
402-
402+
403403
- =embark-isearch-highlight-indicator=: this only does something when
404404
the current target is the symbol at point, in which case it
405405
lazily highlights all occurrences of that symbol in the current
406406
buffer, like isearch; also on by default.
407-
407+
408408
Users of the popular [[https://github.com/justbur/emacs-which-key][which-key]] package may prefer to use the
409409
=embark-which-key-indicator= from the [[https://github.com/oantolin/embark/wiki/Additional-Configuration#use-which-key-like-a-key-menu-prompt][Embark wiki]]. Just copy its
410410
definition from the wiki into your configuration and customize the
@@ -633,24 +633,23 @@ For around-action hooks:
633633

634634
** Creating your own keymaps
635635

636-
All internal keymaps are defined with a helper macro
637-
=embark-define-keymap= that you can use to define your own keymaps,
638-
whether they are for new categories in =embark-keymap-alist= or for any
639-
other purpose! For example a simple version of the file action keymap
636+
All internal keymaps are defined with the standard helper macro
637+
=defvar-keymap=. For example a simple version of the file action keymap
640638
could be defined as follows:
641639

642640
#+BEGIN_SRC emacs-lisp
643-
(embark-define-keymap embark-file-map
644-
"Example keymap with a few file actions"
645-
("d" delete-file)
646-
("r" rename-file)
647-
("c" copy-file))
641+
(defvar-keymap embark-file-map
642+
:doc "Example keymap with a few file actions"
643+
:parent embark-general-map
644+
"d" #'delete-file
645+
"r" #'rename-file
646+
"c" #'copy-file)
648647
#+END_SRC
649648

650-
Remember also that these action keymaps are perfectly normal Emacs
651-
keymaps, and do not need to be created with this helper macro. You
652-
can use the built-in =define-key=, or your favorite external package
653-
such as =bind-key= or =general.el= to manage them.
649+
These action keymaps are perfectly normal Emacs
650+
keymaps. You may want to inherit from the =embark-general-map= if you
651+
want to access the default Embark actions. Note that =embark-collect=
652+
and =embark-export= are also made available via =embark-general-map=.
654653

655654
** Defining actions for new categories of targets
656655

@@ -743,11 +742,12 @@ commands, instead of defining new ones.
743742
the kill-ring, which you get for free). Then this will do:
744743

745744
#+begin_src emacs-lisp
746-
(embark-define-keymap embark-tab-actions
747-
"Keymap for actions for tab-bar tabs (when mentioned by name)."
748-
("s" tab-bar-select-tab-by-name)
749-
("r" tab-bar-rename-tab-by-name)
750-
("k" tab-bar-close-tab-by-name))
745+
(defvar-keymap embark-tab-actions
746+
:doc "Keymap for actions for tab-bar tabs (when mentioned by name)."
747+
:parent embark-general-map
748+
"s" #'tab-bar-select-tab-by-name
749+
"r" #'tab-bar-rename-tab-by-name
750+
"k" #'tab-bar-close-tab-by-name)
751751

752752
(add-to-list 'embark-keymap-alist '(tab . embark-tab-actions))
753753
#+end_src
@@ -805,7 +805,7 @@ included in the list =embark-indicators=).
805805
(str (buffer-substring-no-properties beg end)))
806806
(save-match-data
807807
(when (string-match "wikipedia:\\([[:alnum:]_]+\\)" str)
808-
`(url
808+
`(url
809809
,(format "https://en.wikipedia.org/wiki/%s"
810810
(match-string 1 str))
811811
,beg . ,end))))))
@@ -853,7 +853,7 @@ included in the list =embark-indicators=).
853853
prompt, which would almost never be sensible. Also consider this as
854854
a warning to structure your own action commands so that if they use
855855
=y-or-n-p=, they do so only after the prompting for the target.
856-
856+
857857
Here is a simple example illustrating the various ways of reading
858858
input from the user mentioned above. Bind the following commands to
859859
the =embark-symbol-map= to be used as actions, then put the point on
@@ -863,27 +863,27 @@ included in the list =embark-indicators=).
863863
(defun example-action-command1 ()
864864
(interactive)
865865
(message "The input was `%s'." (read-from-minibuffer "Input: ")))
866-
866+
867867
(defun example-action-command2 (arg input1 input2)
868868
(interactive "P\nsInput 1: \nsInput 2: ")
869869
(message "The first input %swas `%s', and the second was `%s'."
870870
(if arg "truly " "")
871871
input1
872872
input2))
873-
873+
874874
(defun example-action-command3 ()
875875
(interactive)
876876
(message "Your selection was `%s'."
877877
(completing-read "Select: " '("E" "M" "B" "A" "R" "K"))))
878-
878+
879879
(defun example-action-command4 ()
880880
(interactive)
881881
(message "I don't prompt you for input and thus ignore the target!"))
882-
883-
(define-key embark-symbol-map "X1" #'example-action-command1)
884-
(define-key embark-symbol-map "X2" #'example-action-command2)
885-
(define-key embark-symbol-map "X3" #'example-action-command3)
886-
(define-key embark-symbol-map "X4" #'example-action-command4)
882+
883+
(keymap-set embark-symbol-map "X 1" #'example-action-command1)
884+
(keymap-set embark-symbol-map "X 2" #'example-action-command2)
885+
(keymap-set embark-symbol-map "X 3" #'example-action-command3)
886+
(keymap-set embark-symbol-map "X 4" #'example-action-command4)
887887
#+end_src
888888

889889
Also note that if you are using the key bindings to call actions,
@@ -893,9 +893,9 @@ included in the list =embark-indicators=).
893893
This ability to pass prefix arguments to actions is useful for some
894894
actions in the default configuration, such as
895895
=embark-shell-command-on-buffer=.
896-
896+
897897
** Non-interactive functions as actions
898-
898+
899899
Alternatively, Embark does support one other type of action: a
900900
non-interactive function of a single argument. The target is passed
901901
as argument to the function. For example:
@@ -904,7 +904,7 @@ included in the list =embark-indicators=).
904904
(defun example-action-function (target)
905905
(message "The target was `%s'." target))
906906

907-
(define-key embark-symbol-map "X4" #'example-action-function)
907+
(keymap-set embark-symbol-map "X 4" #'example-action-function)
908908
#+end_src
909909

910910
Note that normally binding non-interactive functions in a keymap is
@@ -923,7 +923,7 @@ included in the list =embark-indicators=).
923923
no text properties. For certain advanced uses you may want the
924924
action to receive a string /with/ some text properties, or even a
925925
non-string target.
926-
926+
927927
* Embark, Marginalia and Consult
928928

929929
Embark cooperates well with the [[https://github.com/minad/marginalia][Marginalia]] and [[https://github.com/minad/consult][Consult]] packages.
@@ -1043,7 +1043,7 @@ behavior of Consult commands when used as Embark actions are:
10431043
- =consult-imenu= will search for the target and take you directly to
10441044
the location if it matches a unique imenu entry, otherwise it will
10451045
leave the minibuffer open so you can navigate among the matches.
1046-
1046+
10471047
* Resources
10481048

10491049
If you want to learn more about how others have used Embark here are

embark-consult.el

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
;; Keywords: convenience
88
;; Version: 0.6
99
;; Homepage: https://github.com/oantolin/embark
10-
;; Package-Requires: ((emacs "27.1") (embark "0.17") (consult "0.17"))
10+
;; Package-Requires: ((emacs "27.1") (embark "0.20") (consult "0.17"))
1111

1212
;; This program is free software; you can redistribute it and/or modify
1313
;; it under the terms of the GNU General Public License as published by
@@ -24,7 +24,7 @@
2424

2525
;;; Commentary:
2626

27-
;; This package provides integration between Embark and Consult. The package
27+
;; This package provides integration between Embark and Consult. The package
2828
;; will be loaded automatically by Embark.
2929

3030
;; Some of the functionality here was previously contained in Embark
@@ -45,7 +45,7 @@
4545
;; Additionally this package contains some functionality that has
4646
;; never been in Embark: access to Consult preview from auto-updating
4747
;; Embark Collect buffer that is associated to an active minibuffer
48-
;; for a Consult command. For information on Consult preview, see
48+
;; for a Consult command. For information on Consult preview, see
4949
;; Consult's info manual or its readme on GitHub.
5050

5151
;; If you always want the minor mode enabled whenever it possible use:
@@ -55,7 +55,7 @@
5555
;; If you don't want the minor mode automatically on and prefer to
5656
;; trigger the consult previews manually use this instead:
5757

58-
;; (define-key embark-collect-mode-map (kbd "C-j")
58+
;; (keymap-set embark-collect-mode-map "C-j"
5959
;; #'consult-preview-at-point)
6060

6161
;;; Code:
@@ -160,10 +160,10 @@ This function is meant to be added to `embark-collect-mode-hook'."
160160
(defvar wgrep-header/footer-parser)
161161
(declare-function wgrep-setup "ext:wgrep")
162162

163-
(embark-define-keymap embark-consult-revert-map
164-
"A keymap with a binding for revert-buffer."
163+
(defvar-keymap embark-consult-revert-map
164+
:doc "A keymap with a binding for revert-buffer."
165165
:parent nil
166-
("g" revert-buffer))
166+
"g" #'revert-buffer)
167167

168168
(defun embark-consult-export-grep (lines)
169169
"Create a grep mode buffer listing LINES."
@@ -276,6 +276,7 @@ This function is meant to be added to `embark-collect-mode-hook'."
276276
;;; Support for consult-man and consult-info
277277

278278
(defun embark-consult-man (cand)
279+
"Default action override for `consult-man', open CAND man page."
279280
(man (get-text-property 0 'consult-man cand)))
280281

281282
(setf (alist-get 'consult-man embark-default-action-overrides)
@@ -284,6 +285,7 @@ This function is meant to be added to `embark-collect-mode-hook'."
284285
(declare-function consult-info--action "ext:consult-info")
285286

286287
(defun embark-consult-info (cand)
288+
"Default action override for `consult-info', open CAND info manual."
287289
(consult-info--action cand)
288290
(pulse-momentary-highlight-one-line (point)))
289291

@@ -295,28 +297,28 @@ This function is meant to be added to `embark-collect-mode-hook'."
295297

296298
;;; Bindings for consult commands in embark keymaps
297299

298-
(define-key embark-become-file+buffer-map "Cb" #'consult-buffer)
299-
(define-key embark-become-file+buffer-map "C4b" #'consult-buffer-other-window)
300+
(keymap-set embark-become-file+buffer-map "C b" #'consult-buffer)
301+
(keymap-set embark-become-file+buffer-map "C 4 b" #'consult-buffer-other-window)
300302

301303
;;; Support for Consult search commands
302304

303-
(embark-define-keymap embark-consult-sync-search-map
304-
"Keymap for Consult sync search commands"
305+
(defvar-keymap embark-consult-sync-search-map
306+
:doc "Keymap for Consult sync search commands"
305307
:parent nil
306-
("o" consult-outline)
307-
("i" 'consult-imenu)
308-
("I" 'consult-imenu-multi)
309-
("l" consult-line)
310-
("L" consult-line-multi))
311-
312-
(embark-define-keymap embark-consult-async-search-map
313-
"Keymap for Consult async search commands"
308+
"o" #'consult-outline
309+
"i" 'consult-imenu
310+
"I" 'consult-imenu-multi
311+
"l" #'consult-line
312+
"L" #'consult-line-multi)
313+
314+
(defvar-keymap embark-consult-async-search-map
315+
:doc "Keymap for Consult async search commands"
314316
:parent nil
315-
("g" consult-grep)
316-
("r" consult-ripgrep)
317-
("G" consult-git-grep)
318-
("f" consult-find)
319-
("F" consult-locate))
317+
"g" #'consult-grep
318+
"r" #'consult-ripgrep
319+
"G" #'consult-git-grep
320+
"f" #'consult-find
321+
"F" #'consult-locate)
320322

321323
(defvar embark-consult-search-map
322324
(keymap-canonicalize
@@ -325,12 +327,12 @@ This function is meant to be added to `embark-collect-mode-hook'."
325327
"Keymap for all Consult search commands.")
326328

327329
(fset 'embark-consult-sync-search-map embark-consult-sync-search-map)
328-
(define-key embark-become-match-map "C" 'embark-consult-sync-search-map)
330+
(keymap-set embark-become-match-map "C" 'embark-consult-sync-search-map)
329331

330332
(cl-pushnew 'embark-consult-async-search-map embark-become-keymaps)
331333

332334
(fset 'embark-consult-search-map embark-consult-search-map)
333-
(define-key embark-general-map "C" 'embark-consult-search-map)
335+
(keymap-set embark-general-map "C" 'embark-consult-search-map)
334336

335337
(map-keymap
336338
(lambda (_key cmd)

0 commit comments

Comments
 (0)