1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-11-26 07:33:47 +00:00

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.
This commit is contained in:
Juri Linkov 2018-11-23 00:02:56 +02:00
parent 7a85753d35
commit 4dc7326956
2 changed files with 53 additions and 4 deletions

View File

@ -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

View File

@ -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)