diff options
| author | Juri Linkov <juri@linkov.net> | 2018-11-23 00:02:56 +0200 |
|---|---|---|
| committer | Juri Linkov <juri@linkov.net> | 2018-11-23 00:02:56 +0200 |
| commit | 4dc73269561237d04280b0a212eee603f1e73c9f (patch) | |
| tree | 9c33074dd030f9846303d42eb5620a9cce53d438 /lisp | |
| parent | 7a85753d35b9b010baed7e297f72b308318c3b67 (diff) | |
| download | emacs-4dc73269561237d04280b0a212eee603f1e73c9f.tar.gz | |
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.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/isearch.el | 49 |
1 files changed, 45 insertions, 4 deletions
diff --git a/lisp/isearch.el b/lisp/isearch.el index b05805ccd6d..5099fb39f65 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) |
