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

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

[elpa] master 8b80237: [el-search] Implement an explicit quit command


From: Michael Heerdegen
Subject: [elpa] master 8b80237: [el-search] Implement an explicit quit command
Date: Sun, 16 Dec 2018 16:25:54 -0500 (EST)

branch: master
commit 8b8023728c8c1207de2fc81356b0036cda882836
Author: Michael Heerdegen <address@hidden>
Commit: Michael Heerdegen <address@hidden>

    [el-search] Implement an explicit quit command
    
    Let C-g quit and jump to the starting position like in
    isearch ('el-search-keyboard-quit').
    Update header comment and bump version to 1.8.4.
    
    * packages/el-search/el-search.el
    (el-search--set-search-origin-maybe): New function.
    (el-search-keyboard-quit): New command.
    (el-search-basic-transient-map): Add binding for
    'el-search-keyboard-quit'.
    (el-search-setup-search-1, el-search-jump-to-search-head)
    (el-search-continue-search, el-search-from-beginning)
    (el-search-last-buffer-match): Call
    'el-search--set-search-origin-maybe'.
    (el-search-display-match-count): Handle quit.
---
 packages/el-search/NEWS         |  5 +++++
 packages/el-search/el-search.el | 46 ++++++++++++++++++++++++++++++++---------
 2 files changed, 41 insertions(+), 10 deletions(-)

diff --git a/packages/el-search/NEWS b/packages/el-search/NEWS
index a27b322..138d2b5 100644
--- a/packages/el-search/NEWS
+++ b/packages/el-search/NEWS
@@ -1,6 +1,11 @@
 Some of the user visible news were:
 
 
+Version: 1.8.4
+
+  Quitting (C-g) while el-searching now brings you back to the
+  starting point like in isearch.
+
 Version: 1.8.3
 
   `el-search-query-replace' now adds undo boundaries for each manual
diff --git a/packages/el-search/el-search.el b/packages/el-search/el-search.el
index ee3b641..a2ce888 100644
--- a/packages/el-search/el-search.el
+++ b/packages/el-search/el-search.el
@@ -7,7 +7,7 @@
 ;; Created: 29 Jul 2015
 ;; Keywords: lisp
 ;; Compatibility: GNU Emacs 25
-;; Version: 1.8.3
+;; Version: 1.8.4
 ;; Package-Requires: ((emacs "25") (stream "2.2.4") (cl-print "1.0"))
 
 
@@ -80,7 +80,8 @@
 ;;     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.
+;;     hit RET to exit or C-g to abort and jump back to where you
+;;     started.
 ;;
 ;;   C-R, M-s e r (el-search-pattern-backward)
 ;;     Search backward.
@@ -409,10 +410,6 @@
 ;;
 ;; TODO:
 ;;
-;; - There should be a way to go back to the starting position, like
-;;   in Isearch, which does this with (push-mark isearch-opoint t) in
-;;   `isearch-done'.
-;;
 ;; - Add a help command that can be called while searching.
 ;;
 ;; - Make searching work in comments, too? (->
@@ -675,6 +672,8 @@ useful for debugging.")
 (defvar el-search--current-search nil
   "The currently active search, an `el-search-object', or nil.")
 
+(defvar el-search--search-origin nil)
+
 (defvar-local el-search--temp-buffer-flag nil
   "Non-nil tags file visiting buffers as temporarily opened for searching.")
 
@@ -1767,10 +1766,31 @@ any case."
   (interactive)
   nil)
 
+(defun el-search--set-search-origin-maybe ()
+  (unless (el-search--pending-search-p)
+    (setq el-search--search-origin
+          (list (copy-marker (point))
+                (selected-window)))))
+
+(defun el-search-keyboard-quit (&optional dont-quit)
+  "Abort el-search, signaling quit.
+Go back to the place where the search had been started."
+  (interactive)
+  (setq el-search--success nil)
+  (el-search-hl-post-command-fun) ;clear highlighting
+  (let ((w (cadr el-search--search-origin)))
+    (when (window-live-p w)
+      (select-frame-set-input-focus (window-frame w))
+      (select-window w)))
+  (switch-to-buffer (marker-buffer (car el-search--search-origin)))
+  (goto-char (car el-search--search-origin))
+  (unless dont-quit (signal 'quit 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)
+    (define-key transient-map [return]       #'el-search-pause-search)
+    (define-key transient-map (kbd "RET")    #'el-search-pause-search)
+    (define-key transient-map [(control ?g)] #'el-search-keyboard-quit)
     transient-map))
 
 (defvar el-search-prefix-key-transient-map
@@ -1834,6 +1854,7 @@ any case."
   (setq el-search-use-transient-map t))
 
 (defun el-search-setup-search-1 (pattern get-buffer-stream  &optional 
from-here setup-function)
+  (el-search--set-search-origin-maybe)
   (setq el-search--success nil)
   (setq el-search--current-search
         (el-search-make-search pattern get-buffer-stream))
@@ -2326,7 +2347,8 @@ created.")
                  (concat "[Not at a match]   "
                          (if (= matches-<=-here total-matches)
                              (format "(%s/%s <-)" matches-<=-here 
total-matches)
-                           (format "(-> %s/%s)" (1+ matches-<=-here) 
total-matches))))))))))))
+                           (format "(-> %s/%s)" (1+ matches-<=-here) 
total-matches))))))))))
+    (when quit-flag (el-search-keyboard-quit 'dont-quit))))
 
 (defun el-search-hl-other-matches (matcher)
   "Highlight all visible matches.
@@ -2411,6 +2433,7 @@ In a non-interactive call, ARG should be an integer, 
having the
 same meaning as a numeric prefix arg, or an el-search-object to
 make current."
   (interactive "P")
+  (el-search--set-search-origin-maybe)
   (when (integerp arg)
     (el-search-barf-if-not-search-buffer
      (current-buffer)
@@ -2517,6 +2540,8 @@ instead of the position where the search would normally be
 continued."
   (interactive "P")
   (setq this-command 'el-search-pattern)
+  (unless (eq last-command this-command)
+    (el-search--set-search-origin-maybe))
   (el-search-compile-pattern-in-search el-search--current-search)
   (el-search-protect-search-head
    (unwind-protect
@@ -2687,6 +2712,7 @@ executed, and nil else."
 With prefix ARG, restart the current search when positive; go to the
 last match in the current buffer when negative."
   (interactive "P")
+  (el-search--set-search-origin-maybe)
   (cond
    ((< (prefix-numeric-value arg) 0)
     (el-search-last-buffer-match))
@@ -2704,7 +2730,7 @@ last match in the current buffer when negative."
 (defun el-search-last-buffer-match ()
   "Go to the last of this buffer's matches."
   (interactive)
-  (setq this-command 'el-search-pattern)
+  (el-search--set-search-origin-maybe)
   (el-search-barf-if-not-search-buffer)
   (el-search--unless-no-buffer-match
     (goto-char (point-max))



reply via email to

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