From 60ecb69f9b1f537874cac4e0791eddb0b15426c1 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Fri, 4 Dec 2020 20:23:37 -0800 Subject: [PATCH 1/4] Add ctrlf-mode-map Signed-off-by: Rudi Grinberg --- CHANGELOG.md | 6 ++++++ README.md | 4 ++-- ctrlf.el | 27 +++++++++++++++++---------- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 30e7d94..231da78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,12 @@ The format is based on [Keep a Changelog]. [#66]: https://github.com/raxod502/ctrlf/issues/66 [#73]: https://github.com/raxod502/ctrlf/pull/73 +* Customize keybindings by modifying the mode map `ctrlf-mode-map` + instead of the `ctrlf-mode-bindings` variable. `ctrlf-mode-bindings` + is obsolete but remains available. + +[#64] https://github.com/raxod502/ctrlf/pull/64 + ## 1.2 (released 2020-10-20) ### Features * More Isearch compatibility was added in [#48]. Additions include: diff --git a/README.md b/README.md index cf809aa..8282536 100644 --- a/README.md +++ b/README.md @@ -171,8 +171,8 @@ You can customize the visual appearance of CTRLF: You can also customize the keybindings: -* User option `ctrlf-mode-bindings` lists keybindings that are made - globally available in Emacs when `ctrlf-mode` is enabled. +* `ctrlf-mode-map` contains keybindings that are made globally + available in Emacs when `ctrlf-mode` is enabled. * User option `ctrlf-minibuffer-bindings` lists keybindings that are made available in the minibuffer during a CTRLF search session. diff --git a/ctrlf.el b/ctrlf.el index 10df0e9..099fa8d 100644 --- a/ctrlf.el +++ b/ctrlf.el @@ -123,7 +123,10 @@ lists with the following keys (all mandatory): ([remap isearch-backward-regexp] . ctrlf-backward-regexp) ([remap isearch-forward-symbol] . ctrlf-forward-symbol) ([remap isearch-forward-symbol-at-point] . ctrlf-forward-symbol-at-point)) - "Keybindings enabled in `ctrlf-mode'. This is not a keymap. + "This variable is deprecated. To customize the keybindings, modify +`ctrlf-mode-map' directly. + +Keybindings enabled in `ctrlf-mode'. This is not a keymap. Rather it is an alist that is converted into a keymap just before `ctrlf-mode' is (re-)enabled. The keys are strings or raw key events and the values are command symbols. @@ -138,6 +141,7 @@ active in the minibuffer during a search." (set var val) (when (bound-and-true-p ctrlf-mode) (ctrlf-mode +1)))) +(make-obsolete-variable 'ctrlf-mode-bindings 'ctrlf-mode-map) (defcustom ctrlf-minibuffer-bindings '(([remap abort-recursive-edit] . ctrlf-cancel) @@ -1280,26 +1284,29 @@ search, change back to fuzzy-regexp search." ;;;; Minor mode ;;;###autoload -(defvar ctrlf--keymap (make-sparse-keymap) - "Keymap for `ctrlf-mode'. Populated when mode is enabled. -See `ctrlf-mode-bindings'.") +(defvar ctrlf-mode-map + (let ((map (make-sparse-keymap))) + (dolist (binding ctrlf-mode-bindings) + (define-key map (car binding) (cdr binding))) + map) + "Keymap for `ctrlf-mode'.") ;;;###autoload (progn (define-minor-mode ctrlf-local-mode "Minor mode to use CTRLF in place of Isearch. See `ctrlf-mode-bindings' to customize." - :keymap ctrlf--keymap + :keymap ctrlf-mode-map (require 'map) - (when ctrlf-local-mode - ;; Hack to clear out keymap. Presumably there's a `clear-keymap' - ;; function lying around somewhere...? - (setcdr ctrlf--keymap nil) + (when (and ctrlf-local-mode + (not (equal ctrlf-mode-bindings + (get 'ctrlf-mode-bindings 'standard-value)))) + (setcdr ctrlf-mode-map nil) (map-apply (lambda (key cmd) (when (stringp key) (setq key (kbd key))) - (define-key ctrlf--keymap key cmd)) + (define-key ctrlf-mode-map key cmd)) ctrlf-mode-bindings)) (with-eval-after-load 'ctrlf ;; TODO: This appears to have a bug where if CTRLF is enabled From 60bd2d14d0e35b54aca73b90b691ac1192bcf73f Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Fri, 1 Jan 2021 13:19:46 -0800 Subject: [PATCH 2/4] Update another mention of ctrlf-mode-bindings Signed-off-by: Rudi Grinberg --- ctrlf.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ctrlf.el b/ctrlf.el index 099fa8d..e8fc09b 100644 --- a/ctrlf.el +++ b/ctrlf.el @@ -177,7 +177,7 @@ entering the minibuffer. The keys are strings or raw key events and the values are command symbols. The keymap so constructed inherits from `minibuffer-local-map'. -See also `ctrlf-mode-bindings', which defines bindings that are +See also `ctrlf-mode-map', which defines a keymap that is available globally in Emacs when `ctrlf-mode' is active." :type '(alist :key-type sexp From c574eba73314a34047aea640d82f171556f7aa9d Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Sat, 27 Feb 2021 12:56:18 -0800 Subject: [PATCH 3/4] Add ctrlf-minibuffer-mode-map --- ctrlf.el | 61 ++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/ctrlf.el b/ctrlf.el index e8fc09b..e231e05 100644 --- a/ctrlf.el +++ b/ctrlf.el @@ -182,6 +182,7 @@ available globally in Emacs when `ctrlf-mode' is active." :type '(alist :key-type sexp :value-type function)) +(make-obsolete-variable 'ctrlf-minibuffer-bindings 'ctrlf-minibuffer-mode-map) (defcustom ctrlf-zero-length-match-width 0.2 "Width of vertical bar to display for a zero-length match. @@ -896,30 +897,33 @@ And self-destruct this hook." Use optional INITIAL-CONTENTS as initial contents and POSITION as current starting point." (ctrlf--evil-set-jump) - (let ((keymap (make-sparse-keymap))) - (set-keymap-parent keymap minibuffer-local-map) - (map-apply - (lambda (key cmd) - (when (stringp key) - (setq key (kbd key))) - (define-key keymap key cmd)) - ctrlf-minibuffer-bindings) - ;; Solve without - ;; introducing the problems summarized in - ;; and also reported - ;; in as well as - ;; . - (map-apply - (lambda (key _) - (when (stringp key) - (setq key (kbd key))) - (pcase key - (`[remap ,orig-cmd] - (when-let ((global-key - (where-is-internal - orig-cmd global-map 'firstonly nil 'no-remap))) - (define-key keymap global-key nil))))) - ctrlf-mode-bindings) + (let ((keymap)) + (if (equal ctrlf-minibuffer-bindings (get 'ctrlf-minibuffer-bindings 'standard-value)) + (setq keymap ctrlf-minibuffer-mode-map) + (setq keymap (make-sparse-keymap)) + (set-keymap-parent keymap minibuffer-local-map) + (map-apply + (lambda (key cmd) + (when (stringp key) + (setq key (kbd key))) + (define-key keymap key cmd)) + ctrlf-minibuffer-bindings) + ;; Solve without + ;; introducing the problems summarized in + ;; and also reported + ;; in as well as + ;; . + (map-apply + (lambda (key _) + (when (stringp key) + (setq key (kbd key))) + (pcase key + (`[remap ,orig-cmd] + (when-let ((global-key + (where-is-internal + orig-cmd global-map 'firstonly nil 'no-remap))) + (define-key keymap global-key nil))))) + ctrlf-mode-bindings)) (setq ctrlf--starting-point (point)) (setq ctrlf--current-starting-point (or position (point))) (setq ctrlf--last-input nil) @@ -1291,6 +1295,15 @@ search, change back to fuzzy-regexp search." map) "Keymap for `ctrlf-mode'.") +;;;###autoload +(defvar ctrlf-minibuffer-mode-map + (let ((map (make-sparse-keymap))) + (set-keymap-parent map minibuffer-local-map) + (dolist (binding ctrlf-minibuffer-bindings) + (define-key map (car binding) (cdr binding))) + map) + "Keymap in the minibuffer when ctrlf is enabled.") + ;;;###autoload (progn (define-minor-mode ctrlf-local-mode From ad34a0436dd96e9d666086a0f7de004b5aba8e4f Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Sat, 27 Feb 2021 12:57:27 -0800 Subject: [PATCH 4/4] format readme Signed-off-by: Rudi Grinberg --- CHANGELOG.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 231da78..2581e8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,15 +36,14 @@ The format is based on [Keep a Changelog]. was included in [#59]. This integration happens automatically and requires no user input/customisation. -[#59]: https://github.com/raxod502/ctrlf/issues/59 -[#66]: https://github.com/raxod502/ctrlf/issues/66 -[#73]: https://github.com/raxod502/ctrlf/pull/73 - * Customize keybindings by modifying the mode map `ctrlf-mode-map` instead of the `ctrlf-mode-bindings` variable. `ctrlf-mode-bindings` is obsolete but remains available. +[#59]: https://github.com/raxod502/ctrlf/issues/59 [#64] https://github.com/raxod502/ctrlf/pull/64 +[#66]: https://github.com/raxod502/ctrlf/issues/66 +[#73]: https://github.com/raxod502/ctrlf/pull/73 ## 1.2 (released 2020-10-20) ### Features