emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 4dc7326: Add Isearch commands for going to absolute


From: Juri Linkov
Subject: [Emacs-diffs] master 4dc7326: Add Isearch commands for going to absolute occurrence of matches (bug#29321)
Date: Thu, 22 Nov 2018 17:03:03 -0500 (EST)

branch: master
commit 4dc73269561237d04280b0a212eee603f1e73c9f
Author: Juri Linkov <address@hidden>
Commit: Juri Linkov <address@hidden>

    Add Isearch commands for going to absolute occurrence of matches (bug#29321)
    
    * lisp/isearch.el (isearch-mode-map): Bind 'M-s M-<' to
    'isearch-beginning-of-buffer' and 'isearch-end-of-buffer' to 'M-s M->'.
    (isearch-beginning-of-buffer, isearch-end-of-buffer): New commands.
---
 etc/NEWS        |  8 ++++++++
 lisp/isearch.el | 49 +++++++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 53 insertions(+), 4 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index dc08e1c..f413bbe 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -647,6 +647,14 @@ A negative argument repeats the search in the opposite 
direction.
 This makes possible also to use a prefix argument for 'M-s .'
 ('isearch-forward-symbol-at-point') to find the next Nth symbol.
 
+*** To go to the first/last occurrence of the current search string
+is possible now with new commands 'isearch-beginning-of-buffer' and
+'isearch-end-of-buffer' bound to 'M-s M-<' and 'M-s M->' in Isearch.
+With a numeric argument, they go to the Nth absolute occurrence
+counting from the beginning/end of the buffer.  This complements
+'C-s'/'C-r' that searches for the next Nth relative occurrence
+with a numeric argument.
+
 *** 'isearch-lazy-count' shows the current match number and total number
 of matches in the Isearch prompt.  Customizable variables
 'lazy-count-prefix-format' and 'lazy-count-suffix-format' define the
diff --git a/lisp/isearch.el b/lisp/isearch.el
index b05805c..5099fb3 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -544,6 +544,9 @@ This is like `describe-bindings', but displays only Isearch 
keys."
     (define-key map    "\C-y" 'isearch-yank-kill)
     (define-key map "\M-s\C-e" 'isearch-yank-line)
 
+    (define-key map "\M-s\M-<" 'isearch-beginning-of-buffer)
+    (define-key map "\M-s\M->" 'isearch-end-of-buffer)
+
     (define-key map (char-to-string help-char) isearch-help-map)
     (define-key map [help] isearch-help-map)
     (define-key map [f1] isearch-help-map)
@@ -1622,8 +1625,12 @@ Use `isearch-exit' to quit without signaling."
 
 (defun isearch-repeat-forward (&optional arg)
   "Repeat incremental search forwards.
-With a prefix argument, repeat the search ARG times.
-A negative argument searches backwards."
+With a numeric argument, repeat the search ARG times.
+A negative argument searches backwards.
+\\<isearch-mode-map>
+This command finds the next relative occurrence of the current
+search string.  To find the absolute occurrence from the beginning
+of the buffer, type \\[isearch-beginning-of-buffer] with a numeric argument."
   (interactive "P")
   (if arg
       (let ((count (prefix-numeric-value arg)))
@@ -1639,8 +1646,12 @@ A negative argument searches backwards."
 
 (defun isearch-repeat-backward (&optional arg)
   "Repeat incremental search backwards.
-With a prefix argument, repeat the search ARG times.
-A negative argument searches forwards."
+With a numeric argument, repeat the search ARG times.
+A negative argument searches forwards.
+\\<isearch-mode-map>
+This command finds the next relative occurrence of the current
+search string.  To find the absolute occurrence from the end
+of the buffer, type \\[isearch-end-of-buffer] with a numeric argument."
   (interactive "P")
   (if arg
       (let ((count (prefix-numeric-value arg)))
@@ -1654,6 +1665,36 @@ A negative argument searches forwards."
                (isearch-repeat 'backward count))))
     (isearch-repeat 'backward)))
 
+(defun isearch-beginning-of-buffer (&optional arg)
+  "Go to the first occurrence of the current search string.
+Move point to the beginning of the buffer and search forwards from the top.
+\\<isearch-mode-map>
+With a numeric argument, go to the ARGth absolute occurrence counting from
+the beginning of the buffer.  To find the next relative occurrence forwards,
+type \\[isearch-repeat-forward] with a numeric argument."
+  (interactive "p")
+  (if (and arg (< arg 0))
+      (isearch-end-of-buffer (abs arg))
+    ;; For the case when the match is at bobp,
+    ;; don't forward char in isearch-repeat
+    (setq isearch-just-started t)
+    (goto-char (point-min))
+    (isearch-repeat 'forward arg)))
+
+(defun isearch-end-of-buffer (&optional arg)
+  "Go to the last occurrence of the current search string.
+Move point to the end of the buffer and search backwards from the bottom.
+\\<isearch-mode-map>
+With a numeric argument, go to the ARGth absolute occurrence counting from
+the end of the buffer.  To find the next relative occurrence backwards,
+type \\[isearch-repeat-backward] with a numeric argument."
+  (interactive "p")
+  (if (and arg (< arg 0))
+      (isearch-beginning-of-buffer (abs arg))
+    (setq isearch-just-started t)
+    (goto-char (point-max))
+    (isearch-repeat 'backward arg)))
+
 
 ;;; Toggles for `isearch-regexp-function' and `search-default-mode'.
 (defmacro isearch-define-mode-toggle (mode key function &optional docstring 
&rest body)



reply via email to

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