Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ctrlf-mode-map #64

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ The format is based on [Keep a Changelog].
was included in [#59]. This integration happens automatically and
requires no user input/customisation.

* 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

rgrinberg marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
90 changes: 55 additions & 35 deletions ctrlf.el
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down Expand Up @@ -173,11 +177,12 @@ 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
: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.
Expand Down Expand Up @@ -892,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 <https://github.com/raxod502/ctrlf/issues/51> without
;; introducing the problems summarized in
;; <https://github.com/raxod502/ctrlf/issues/80> and also reported
;; in <https://github.com/raxod502/ctrlf/issues/67> as well as
;; <https://github.com/raxod502/ctrlf/issues/52>.
(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 <https://github.com/raxod502/ctrlf/issues/51> without
;; introducing the problems summarized in
;; <https://github.com/raxod502/ctrlf/issues/80> and also reported
;; in <https://github.com/raxod502/ctrlf/issues/67> as well as
;; <https://github.com/raxod502/ctrlf/issues/52>.
(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)
Expand Down Expand Up @@ -1280,26 +1288,38 @@ 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
(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
"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
Expand Down