Now Reading
Enhancing Emacs isearch Usability with Transient

Enhancing Emacs isearch Usability with Transient

2023-12-18 20:50:22

Emacs incremental search (isearch) has an embarrassingly rich feature set. That stated, I hardly ever use isearch past its fundamentals for the twofold causes:

  • There are lots of isearch instructions which might be tough to find, a lot much less bear in mind.
  • The default keybindings for stated instructions are cursed. (Severely, C-M-@ to name isearch-query-replace-regexp ?)

Nonetheless with the addition of the Transient package deal to Emacs 29.1, there’s now recourse to work round these objections: when in isearch mode, we will make out there an isearch-specific Transient menu. This put up reveals you ways.

That is the use case I need solved:

When in primary isearch, I need to have the ability to use the perform key (on this case <f2>) to invoke a Transient menu providing a set of isearch-specific instructions. These instructions can be grouped as follows:

Whereas not all isearch instructions are enumerated on this menu, this choice appears greater than enough for my routine wants.

The next demo screenshots present this menu at work. First is a screenshot of Emacs in primary isearch mode, looking for the string “Screenshot 2”.

Screenshot of Emacs with basic isearch.

Urgent the <f2> button will activate the isearch-specific Transient menu proven under. The consumer can then choose the following motion by both a key press or mouse button (sometimes 1) press.

Screenshot of Emacs isearch Transient menu.

The next source reveals the implementation of the workflow above, patterned after the examples proven in Transient Showcase.

See Also

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
(require 'transient)

(transient-define-prefix cc/isearch-menu ()
  "isearch Menu"
  [["Edit Search String"
    ("e"
     "Edit the search string (recursive)"
     isearch-edit-string
     :transient nil)
    ("w"
     "Pull next word or character word from buffer"
     isearch-yank-word-or-char
     :transient nil)
    ("s"
     "Pull next symbol or character from buffer"
     isearch-yank-symbol-or-char
     :transient nil)
    ("l"
     "Pull rest of line from buffer"
     isearch-yank-line
     :transient nil)
    ("y"
     "Pull string from kill ring"
     isearch-yank-kill
     :transient nil)
    ("t"
     "Pull thing from buffer"
     isearch-forward-thing-at-point
     :transient nil)]

   ["Replace"
    ("q"
     "Start ‘query-replace’"
     isearch-query-replace
     :if-nil buffer-read-only
     :transient nil)
    ("x"
     "Start ‘query-replace-regexp’"
     isearch-query-replace-regexp
     :if-nil buffer-read-only     
     :transient nil)]]

  [["Toggle"
    ("X"
     "Toggle regexp searching"
     isearch-toggle-regexp
     :transient nil)
    ("S"
     "Toggle symbol searching"
     isearch-toggle-symbol
     :transient nil)
    ("W"
     "Toggle word searching"
     isearch-toggle-word
     :transient nil)
    ("F"
     "Toggle case fold"
     isearch-toggle-case-fold
     :transient nil)
    ("L"
     "Toggle lax whitespace"
     isearch-toggle-lax-whitespace
     :transient nil)]

   ["Misc"
    ("o"
     "occur"
     isearch-occur
     :transient nil)]])

(define-key isearch-mode-map (kbd "<f2>") 'cc/isearch-menu)

Verified in Emacs 29.1

Since implementing this Transient menu, isearch has develop into my main interface to query-replace and query-replace-regexp. Additionally the flexibility to yank totally different object varieties and toggle totally different search habits as I am going alongside has been revelatory. Regardless of that incontrovertible fact that these options have all the time been there, their discoverability and keybindings have made all of them however unusable to me. With Transient these options are lastly made usable.

Whereas the inclusion of Transient in Emacs 29.1 is comparatively latest, the potential to revisit older Emacs workflows with this new functionality appears to be a inexperienced area. I look ahead to seeing what others do with Transient.

emacs

Source Link

What's Your Reaction?
Excited
0
Happy
0
In Love
0
Not Sure
0
Silly
0
View Comments (0)

Leave a Reply

Your email address will not be published.

2022 Blinking Robots.
WordPress by Doejo

Scroll To Top