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

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

[elpa] externals/el-search 3218858 261/332: [el-search] Add some key bin


From: Stefan Monnier
Subject: [elpa] externals/el-search 3218858 261/332: [el-search] Add some key bindings
Date: Tue, 1 Dec 2020 15:48:59 -0500 (EST)

branch: externals/el-search
commit 3218858108521a88f65b4f1fcbb0af8cbee80117
Author: Michael Heerdegen <michael_heerdegen@web.de>
Commit: Michael Heerdegen <michael_heerdegen@web.de>

    [el-search] Add some key bindings
    
    This commit adds key bindings for the recently added scroll commands.
    It also provides a way to officially cancel a search or query-replace
    session by hitting RET.
    Update comments in header and bump version to 1.7.7.
    
    * packages/el-search/el-search.el
    (el-search-keep-transient-map-commands): Add 'el-search-scroll-down'
    and 'el-search-scroll-up'.
    (el-search-pause-search): New command.
    (el-search-basic-transient-map): New keymap that is always enabled
    when a search is active.  Bind RET to 'el-search-pause-search'.
    (el-search-prefix-key-transient-map): Add binding for
    'el-search-scroll-down' and 'el-search-scroll-up'.  Set parent keymap
    to 'el-search-basic-transient-map'.
    (el-search-prefix-key-maybe-set-transient-map): Enable
    'el-search-prefix-key-transient-map' or only the new
    'el-search-basic-transient-map' depending on the value of
    'el-search-use-transient-map'.
    (el-search-install-shift-bindings): Add bindings for
    'el-search-scroll-down' and 'el-search-scroll-up'.
    (el-search--search-and-replace-pattern): Let RET terminate
    query-replace.
---
 NEWS         | 33 +++++++++++++++++++++++----------
 el-search.el | 57 +++++++++++++++++++++++++++++++++++++++++++++++++--------
 2 files changed, 72 insertions(+), 18 deletions(-)

diff --git a/NEWS b/NEWS
index 2e44c8e..af00d2f 100644
--- a/NEWS
+++ b/NEWS
@@ -1,22 +1,35 @@
 Some of the user visible news were:
 
 
+Version: 1.7.7
+
+  The new scroll commands `el-search-scroll-down' and
+  `el-search-scroll-up', bound to C-S-next and C-S-prior, or v and V
+  respectively, perform by-match scrolling: `el-search-scroll-down'
+  scrolls the next matches after `window-end' into view, i.e. it
+  selects the first match after `window-end'.  Likewise,
+  `el-search-scroll-up' selects the last match before `window-start'.
+
+  You can now explicitly terminate (pause) search and query-replace
+  sessions by hitting RET.
+
 Version: 1.7.5
 
-The meaning of the prefix argument of `el-search-jump-to-search-head'
-(C-J or M-s e j with the default bindings) has been extended: A
-numeric prefix N jumps to the Nth match after `window-start', while a
-negative prefix -N jumps to the Nth match before `window-end'.  Prefix
-0 jumps to the match following point, which is also useful to resume
-the current search from any buffer position.
-A former search can now be made current with a plain C-u prefix arg.
+  The meaning of the prefix argument of
+  `el-search-jump-to-search-head' (C-J or M-s e j with the default
+  bindings) has been extended: A numeric prefix N jumps to the Nth
+  match after `window-start', while a negative prefix -N jumps to the
+  Nth match before `window-end'.  Prefix 0 jumps to the match
+  following point, which is also useful to resume the current search
+  from any buffer position.  A former search can now be made current
+  with a plain C-u prefix arg.
 
 
 Version: 1.7.3
 
-Match highlighting faces have been improved to look better on text
-terminals.  Matches in *El Occur* buffers are now highlighted with a
-separate face.
+  Match highlighting faces have been improved to look better on text
+  terminals.  Matches in *El Occur* buffers are now highlighted with a
+  separate face.
 
 Version: 1.7
 
diff --git a/el-search.el b/el-search.el
index 43c43c9..6cd83d8 100644
--- a/el-search.el
+++ b/el-search.el
@@ -7,7 +7,7 @@
 ;; Created: 29 Jul 2015
 ;; Keywords: lisp
 ;; Compatibility: GNU Emacs 25
-;; Version: 1.7.6
+;; Version: 1.7.7
 ;; Package-Requires: ((emacs "25") (stream "2.2.4") (cl-print "1.0"))
 
 
@@ -76,6 +76,12 @@
 ;;   C-S, M-s e s (el-search-pattern)
 ;;     Start a search in the current buffer/go to the next match.
 ;;
+;;     While searching, the searched buffer is current (not the
+;;     minibuffer).  All commands that are not search or scrolling
+;;     commands terminate the search, while the state of the search is
+;;     always automatically saved.  Like in isearch you can also just
+;;     hit RET to exit.
+;;
 ;;   C-R, M-s e r (el-search-pattern-backward)
 ;;     Search backward.
 ;;
@@ -125,6 +131,12 @@
 ;;     With a plain C-u prefix arg, prompt for a former search to
 ;;     resume.
 ;;
+;;   C-S-next, v   when search is active (el-search-scroll-down)
+;;   C-S-prior, V  when search is active (el-search-scroll-up)
+;;     Scrolling by matches: Select the first match after
+;;     `window-end', or select the first match before `window-start',
+;;     respectively.
+;;
 ;;   C-H, M-s e h (el-search-this-sexp)
 ;;     Grab the symbol or sexp under point and initiate an el-search
 ;;     for other occurrences.
@@ -553,6 +565,8 @@ The default value is ask-multi."
     el-search-from-beginning
     el-search-last-buffer-match
     el-search-continue-in-next-buffer
+    el-search-scroll-down
+    el-search-scroll-up
     universal-argument universal-argument-more
     digit-argument negative-argument)
   "List of commands that don't end repeatability of el-search commands.
@@ -1680,6 +1694,21 @@ in, in order, when called with no arguments."
     (with-eval-after-load 'ibuffer
       (keybind ibuffer-mode-map ?s #'el-search-ibuffer-marked-buffers))))
 
+(defun el-search-pause-search ()
+  "Exit el-search normally.
+
+You also can invoke any other non-search command to exit an el-search
+normally - the state of the current search is automatically saved in
+any case."
+  (interactive)
+  nil)
+
+(defvar el-search-basic-transient-map
+  (let ((transient-map (make-sparse-keymap)))
+    (define-key transient-map [return]    #'el-search-pause-search)
+    (define-key transient-map (kbd "RET") #'el-search-pause-search)
+    transient-map))
+
 (defvar el-search-prefix-key-transient-map
   (let ((transient-map (make-sparse-keymap)))
     (el-search-loop-over-bindings
@@ -1694,6 +1723,13 @@ in, in order, when called with no arguments."
                              el-search-continue-in-next-buffer
                              el-search-occur))
          (define-key transient-map (vector key) command))))
+
+    ;; v and V are analogue to Ediff - FIXME: this doesn't fit into the
+    ;; `el-search-loop-over-bindings' abstraction
+    (define-key transient-map [?v] #'el-search-scroll-down)
+    (define-key transient-map [?V] #'el-search-scroll-up)
+
+    (set-keymap-parent transient-map el-search-basic-transient-map)
     transient-map))
 
 (defun el-search-keep-session-command-p (command)
@@ -1705,10 +1741,12 @@ in, in order, when called with no arguments."
        (get command 'scroll-command))))
 
 (defun el-search-prefix-key-maybe-set-transient-map ()
-  (when el-search-use-transient-map
-    (set-transient-map el-search-prefix-key-transient-map
-                       (lambda () (or (memq this-command 
el-search-keep-transient-map-commands)
-                                      (el-search-keep-session-command-p 
this-command))))))
+  (set-transient-map
+   (if el-search-use-transient-map
+       el-search-prefix-key-transient-map
+     el-search-basic-transient-map)
+   (lambda () (or (memq this-command el-search-keep-transient-map-commands)
+                  (el-search-keep-session-command-p this-command)))))
 
 (defun el-search-shift-bindings-bind-function (map key command)
   (define-key map `[(control ,@(if (<= ?a key ?z) `(shift ,key) `(,key)))] 
command))
@@ -1716,7 +1754,9 @@ in, in order, when called with no arguments."
 ;;;###autoload
 (defun el-search-install-shift-bindings ()
   (interactive)
-  (el-search-loop-over-bindings #'el-search-shift-bindings-bind-function))
+  (el-search-loop-over-bindings #'el-search-shift-bindings-bind-function)
+  (define-key el-search-basic-transient-map [C-S-next]  
#'el-search-scroll-down)
+  (define-key el-search-basic-transient-map [C-S-prior] #'el-search-scroll-up))
 
 (defun el-search-bind-under-prefix-key-function (prefix)
   (lambda (map key command)
@@ -3627,7 +3667,8 @@ exactly you did?  Thanks!"))))
                                                      (substitute-command-keys 
"\
 Toggle splicing mode (\\[describe-function] el-search-query-replace for 
details)")))
                                           '(?o "show" "Show replacement in a 
buffer")
-                                          '(?q "quit"))))))))
+                                          '(?q  "quit")
+                                          '(?\r "quit"))))))))
                          (if replace-all
                              (funcall do-replace)
                            (while (not (pcase (funcall query)
@@ -3685,7 +3726,7 @@ Replace all matches in all buffers"))))
                                             (kill-buffer buffer)
                                             (el-search--after-scroll 
(selected-window) (window-start))
                                             nil))
-                                         ((or ?q ?\C-g) (signal 'quit t))))))
+                                         ((or ?q ?\C-g ?\r) (signal 'quit 
t))))))
                          (unless (eobp)
                            (let* ((replacement-end-pos
                                    (and replaced-this



reply via email to

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