aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuri Linkov2018-11-23 00:02:56 +0200
committerJuri Linkov2018-11-23 00:02:56 +0200
commit4dc73269561237d04280b0a212eee603f1e73c9f (patch)
tree9c33074dd030f9846303d42eb5620a9cce53d438
parent7a85753d35b9b010baed7e297f72b308318c3b67 (diff)
downloademacs-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/NEWS8
-rw-r--r--lisp/isearch.el49
2 files changed, 53 insertions, 4 deletions
diff --git a/etc/NEWS b/etc/NEWS
index dc08e1caf25..f413bbea069 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -647,6 +647,14 @@ A negative argument repeats the search in the opposite direction.
647This makes possible also to use a prefix argument for 'M-s .' 647This 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
651is 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.
653With a numeric argument, they go to the Nth absolute occurrence
654counting from the beginning/end of the buffer. This complements
655'C-s'/'C-r' that searches for the next Nth relative occurrence
656with 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
651of matches in the Isearch prompt. Customizable variables 659of 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.
1625With a prefix argument, repeat the search ARG times. 1628With a numeric argument, repeat the search ARG times.
1626A negative argument searches backwards." 1629A negative argument searches backwards.
1630\\<isearch-mode-map>
1631This command finds the next relative occurrence of the current
1632search string. To find the absolute occurrence from the beginning
1633of 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.
1642With a prefix argument, repeat the search ARG times. 1649With a numeric argument, repeat the search ARG times.
1643A negative argument searches forwards." 1650A negative argument searches forwards.
1651\\<isearch-mode-map>
1652This command finds the next relative occurrence of the current
1653search string. To find the absolute occurrence from the end
1654of 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.
1670Move point to the beginning of the buffer and search forwards from the top.
1671\\<isearch-mode-map>
1672With a numeric argument, go to the ARGth absolute occurrence counting from
1673the beginning of the buffer. To find the next relative occurrence forwards,
1674type \\[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.
1686Move point to the end of the buffer and search backwards from the bottom.
1687\\<isearch-mode-map>
1688With a numeric argument, go to the ARGth absolute occurrence counting from
1689the end of the buffer. To find the next relative occurrence backwards,
1690type \\[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)