diff options
| author | Juri Linkov | 2018-11-23 00:02:56 +0200 |
|---|---|---|
| committer | Juri Linkov | 2018-11-23 00:02:56 +0200 |
| commit | 4dc73269561237d04280b0a212eee603f1e73c9f (patch) | |
| tree | 9c33074dd030f9846303d42eb5620a9cce53d438 | |
| parent | 7a85753d35b9b010baed7e297f72b308318c3b67 (diff) | |
| download | emacs-4dc73269561237d04280b0a212eee603f1e73c9f.tar.gz emacs-4dc73269561237d04280b0a212eee603f1e73c9f.zip | |
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.
| -rw-r--r-- | etc/NEWS | 8 | ||||
| -rw-r--r-- | lisp/isearch.el | 49 |
2 files changed, 53 insertions, 4 deletions
| @@ -647,6 +647,14 @@ A negative argument repeats the search in the opposite direction. | |||
| 647 | This makes possible also to use a prefix argument for 'M-s .' | 647 | This makes possible also to use a prefix argument for 'M-s .' |
| 648 | ('isearch-forward-symbol-at-point') to find the next Nth symbol. | 648 | ('isearch-forward-symbol-at-point') to find the next Nth symbol. |
| 649 | 649 | ||
| 650 | *** To go to the first/last occurrence of the current search string | ||
| 651 | is possible now with new commands 'isearch-beginning-of-buffer' and | ||
| 652 | 'isearch-end-of-buffer' bound to 'M-s M-<' and 'M-s M->' in Isearch. | ||
| 653 | With a numeric argument, they go to the Nth absolute occurrence | ||
| 654 | counting from the beginning/end of the buffer. This complements | ||
| 655 | 'C-s'/'C-r' that searches for the next Nth relative occurrence | ||
| 656 | with a numeric argument. | ||
| 657 | |||
| 650 | *** 'isearch-lazy-count' shows the current match number and total number | 658 | *** 'isearch-lazy-count' shows the current match number and total number |
| 651 | of matches in the Isearch prompt. Customizable variables | 659 | of matches in the Isearch prompt. Customizable variables |
| 652 | 'lazy-count-prefix-format' and 'lazy-count-suffix-format' define the | 660 | 'lazy-count-prefix-format' and 'lazy-count-suffix-format' define the |
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." | |||
| 544 | (define-key map "\C-y" 'isearch-yank-kill) | 544 | (define-key map "\C-y" 'isearch-yank-kill) |
| 545 | (define-key map "\M-s\C-e" 'isearch-yank-line) | 545 | (define-key map "\M-s\C-e" 'isearch-yank-line) |
| 546 | 546 | ||
| 547 | (define-key map "\M-s\M-<" 'isearch-beginning-of-buffer) | ||
| 548 | (define-key map "\M-s\M->" 'isearch-end-of-buffer) | ||
| 549 | |||
| 547 | (define-key map (char-to-string help-char) isearch-help-map) | 550 | (define-key map (char-to-string help-char) isearch-help-map) |
| 548 | (define-key map [help] isearch-help-map) | 551 | (define-key map [help] isearch-help-map) |
| 549 | (define-key map [f1] isearch-help-map) | 552 | (define-key map [f1] isearch-help-map) |
| @@ -1622,8 +1625,12 @@ Use `isearch-exit' to quit without signaling." | |||
| 1622 | 1625 | ||
| 1623 | (defun isearch-repeat-forward (&optional arg) | 1626 | (defun isearch-repeat-forward (&optional arg) |
| 1624 | "Repeat incremental search forwards. | 1627 | "Repeat incremental search forwards. |
| 1625 | With a prefix argument, repeat the search ARG times. | 1628 | With a numeric argument, repeat the search ARG times. |
| 1626 | A negative argument searches backwards." | 1629 | A negative argument searches backwards. |
| 1630 | \\<isearch-mode-map> | ||
| 1631 | This command finds the next relative occurrence of the current | ||
| 1632 | search string. To find the absolute occurrence from the beginning | ||
| 1633 | of the buffer, type \\[isearch-beginning-of-buffer] with a numeric argument." | ||
| 1627 | (interactive "P") | 1634 | (interactive "P") |
| 1628 | (if arg | 1635 | (if arg |
| 1629 | (let ((count (prefix-numeric-value arg))) | 1636 | (let ((count (prefix-numeric-value arg))) |
| @@ -1639,8 +1646,12 @@ A negative argument searches backwards." | |||
| 1639 | 1646 | ||
| 1640 | (defun isearch-repeat-backward (&optional arg) | 1647 | (defun isearch-repeat-backward (&optional arg) |
| 1641 | "Repeat incremental search backwards. | 1648 | "Repeat incremental search backwards. |
| 1642 | With a prefix argument, repeat the search ARG times. | 1649 | With a numeric argument, repeat the search ARG times. |
| 1643 | A negative argument searches forwards." | 1650 | A negative argument searches forwards. |
| 1651 | \\<isearch-mode-map> | ||
| 1652 | This command finds the next relative occurrence of the current | ||
| 1653 | search string. To find the absolute occurrence from the end | ||
| 1654 | of the buffer, type \\[isearch-end-of-buffer] with a numeric argument." | ||
| 1644 | (interactive "P") | 1655 | (interactive "P") |
| 1645 | (if arg | 1656 | (if arg |
| 1646 | (let ((count (prefix-numeric-value arg))) | 1657 | (let ((count (prefix-numeric-value arg))) |
| @@ -1654,6 +1665,36 @@ A negative argument searches forwards." | |||
| 1654 | (isearch-repeat 'backward count)))) | 1665 | (isearch-repeat 'backward count)))) |
| 1655 | (isearch-repeat 'backward))) | 1666 | (isearch-repeat 'backward))) |
| 1656 | 1667 | ||
| 1668 | (defun isearch-beginning-of-buffer (&optional arg) | ||
| 1669 | "Go to the first occurrence of the current search string. | ||
| 1670 | Move point to the beginning of the buffer and search forwards from the top. | ||
| 1671 | \\<isearch-mode-map> | ||
| 1672 | With a numeric argument, go to the ARGth absolute occurrence counting from | ||
| 1673 | the beginning of the buffer. To find the next relative occurrence forwards, | ||
| 1674 | type \\[isearch-repeat-forward] with a numeric argument." | ||
| 1675 | (interactive "p") | ||
| 1676 | (if (and arg (< arg 0)) | ||
| 1677 | (isearch-end-of-buffer (abs arg)) | ||
| 1678 | ;; For the case when the match is at bobp, | ||
| 1679 | ;; don't forward char in isearch-repeat | ||
| 1680 | (setq isearch-just-started t) | ||
| 1681 | (goto-char (point-min)) | ||
| 1682 | (isearch-repeat 'forward arg))) | ||
| 1683 | |||
| 1684 | (defun isearch-end-of-buffer (&optional arg) | ||
| 1685 | "Go to the last occurrence of the current search string. | ||
| 1686 | Move point to the end of the buffer and search backwards from the bottom. | ||
| 1687 | \\<isearch-mode-map> | ||
| 1688 | With a numeric argument, go to the ARGth absolute occurrence counting from | ||
| 1689 | the end of the buffer. To find the next relative occurrence backwards, | ||
| 1690 | type \\[isearch-repeat-backward] with a numeric argument." | ||
| 1691 | (interactive "p") | ||
| 1692 | (if (and arg (< arg 0)) | ||
| 1693 | (isearch-beginning-of-buffer (abs arg)) | ||
| 1694 | (setq isearch-just-started t) | ||
| 1695 | (goto-char (point-max)) | ||
| 1696 | (isearch-repeat 'backward arg))) | ||
| 1697 | |||
| 1657 | 1698 | ||
| 1658 | ;;; Toggles for `isearch-regexp-function' and `search-default-mode'. | 1699 | ;;; Toggles for `isearch-regexp-function' and `search-default-mode'. |
| 1659 | (defmacro isearch-define-mode-toggle (mode key function &optional docstring &rest body) | 1700 | (defmacro isearch-define-mode-toggle (mode key function &optional docstring &rest body) |