[Top][All Lists]

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

[elpa] master 11438ac: [el-search] Add command 'el-search-last-buffer-ma

From: Michael Heerdegen
Subject: [elpa] master 11438ac: [el-search] Add command 'el-search-last-buffer-match'
Date: Sat, 23 Jun 2018 05:53:54 -0400 (EDT)

branch: master
commit 11438ac9caf8eb53fc49342dd22c75705e022fcd
Author: Michael Heerdegen <address@hidden>
Commit: Michael Heerdegen <address@hidden>

    [el-search] Add command 'el-search-last-buffer-match'
    * packages/el-search/el-search.el
    (el-search--unless-no-buffer-match): New macro.
    (el-search-pattern-backward): Use it.
    (el-search-last-buffer-match): New command jumping to the last of the
    current buffer's matches.
    (el-search-from-beginning): Let a negative prefix arg make it jump to
    the last buffer match.
 packages/el-search/el-search.el | 68 ++++++++++++++++++++++++++++-------------
 1 file changed, 47 insertions(+), 21 deletions(-)

diff --git a/packages/el-search/el-search.el b/packages/el-search/el-search.el
index 9ee1a5f..19acf3d 100644
--- a/packages/el-search/el-search.el
+++ b/packages/el-search/el-search.el
@@ -2467,16 +2467,50 @@ See `el-search-defined-patterns' for a list of defined 
      (lambda (search) (setf (alist-get 'is-single-buffer 
(el-search-object-properties search)) t))
-(defun el-search-from-beginning (&optional restart-search)
+(defmacro el-search--unless-no-buffer-match (&rest body)
+  "Execute BODY unless no match for current search in current buffer.
+In this case, ignore BODY and emit a message saying \"No matches\".
+The return value is the result of the last form in BODY if it is
+executed, and nil else."
+  (declare (indent 0) (debug (body)))
+  `(if (not (or el-search--success
+                (save-excursion
+                  (goto-char (point-min))
+                  (el-search--search-pattern-1
+                   (el-search--current-matcher) t nil 
+       (progn
+         (ding)
+         (el-search--message-no-log "No matches")
+         (sit-for .7)
+         nil)
+     ,@body))
+(defun el-search-from-beginning (&optional arg)
   "Go to the first of this buffer's matches.
-With prefix arg, restart the current search."
+With prefix ARG, restart the current search when positive; go to the
+last match in the current buffer when negative."
   (interactive "P")
-  (if (not restart-search)
+  (cond
+   ((< (prefix-numeric-value arg) 0)
+    (el-search-last-buffer-match))
+   ((not arg)
+    (el-search--unless-no-buffer-match
       (setf (el-search-head-position (el-search-object-head 
+      (el-search-continue-search)))
+   (t
     (el-search-reset-search el-search--current-search)
-    (setq el-search--success nil))
-  (el-search-continue-search))
+    (setq el-search--success nil)
+    (el-search-continue-search))))
+(defun el-search-last-buffer-match ()
+  "Go to the last of this buffer's matches."
+  (interactive)
+  (setq this-command 'el-search-pattern)
+  (el-search--unless-no-buffer-match
+    (goto-char (point-max))
+    (funcall-interactively #'el-search-pattern-backward 
 (defun el-search--search-backward-1 (matcher &optional noerror bound 
heuristic-matcher count)
   "Like `el-search-backward' but accepts a matcher as first argument.
@@ -2608,22 +2642,14 @@ See the command `el-search-pattern' for more 
         (unless (eq last-command 'el-search-pattern)
           (el-search-hl-other-matches (el-search--current-matcher)))
         (setq el-search--success t))
-    (if (not (or el-search--success
-                 (save-excursion
-                   (goto-char (point-min))
-                   (el-search--search-pattern-1
-                    (el-search--current-matcher) t nil 
-        (progn
-          (ding)
-          (el-search--message-no-log "No matches")
-          (sit-for .7))
-      (let ((keys (car (where-is-internal 'el-search-pattern-backward))))
-        (el-search--message-no-log
-         (if keys
-             (format "No (more) match; hit %s to wrap search" (key-description 
-           "No (more) match")))
-      (sit-for .7)
-      (el-search--set-wrap-flag 'backward))))
+    (el-search--unless-no-buffer-match
+     (let ((keys (car (where-is-internal 'el-search-pattern-backward))))
+       (el-search--message-no-log
+        (if keys
+            (format "No (more) match; hit %s to wrap search" (key-description 
+          "No (more) match")))
+     (sit-for .7)
+     (el-search--set-wrap-flag 'backward))))
 (define-obsolete-function-alias 'el-search-previous-match
   'el-search-pattern-backward "since el-search-1.3")

reply via email to

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