[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/el-search d9b2ff6 257/332: [el-search] Extend meaning o
From: |
Stefan Monnier |
Subject: |
[elpa] externals/el-search d9b2ff6 257/332: [el-search] Extend meaning of C-J prefix arg |
Date: |
Tue, 1 Dec 2020 15:48:58 -0500 (EST) |
branch: externals/el-search
commit d9b2ff6e0abcf8d33fca705869332f0e1d56cbf4
Author: Michael Heerdegen <michael_heerdegen@web.de>
Commit: Michael Heerdegen <michael_heerdegen@web.de>
[el-search] Extend meaning of C-J prefix arg
* packages/el-search/el-search.el
(el-search-jump-to-search-head): Make numerical prefix jump between
matches: 0 jumps to the match following point, N and -N jump to the
Nth match visible in the selected window or the Nth match before
'window-end'.
---
el-search.el | 64 ++++++++++++++++++++++++++++++++++++++++++++----------------
1 file changed, 47 insertions(+), 17 deletions(-)
diff --git a/el-search.el b/el-search.el
index 731b98b..2acd9ed 100644
--- a/el-search.el
+++ b/el-search.el
@@ -116,7 +116,14 @@
;;
;; C-J, M-s e j (el-search-jump-to-search-head)
;; Resume the last search from the position of the last visited
-;; match, or (with prefix arg) prompt for an old search to resume.
+;; match.
+;; With prefix arg 0, resume from the position of the match
+;; following point instead. With prefix arg 1 or -1, jump to the
+;; first or last match visible in the selected window. This can
+;; be useful even when a search is current, e.g. after scrolling
+;; the searched buffer.
+;; With a plain C-u prefix arg, prompt for a former search to
+;; resume.
;;
;; C-H, M-s e h (el-search-this-sexp)
;; Grab the symbol or sexp under point and initiate an el-search
@@ -2264,19 +2271,32 @@ local binding of `window-scroll-functions'."
(interactive)
(el-search--skip-to-next-buffer))
-(defun el-search-jump-to-search-head (&optional previous-search)
- "Switch to current search buffer and go to the last match.
-With argument PREVIOUS-SEARCH non-nil (the prefix argument in an
-interactive call), prompt for a prior search to resume, and make
-that the current search. In a non-interactive call,
-PREVIOUS-SEARCH can directly specify an el-search-object to make
-current."
+(defun el-search-jump-to-search-head (&optional arg)
+ "Switch to current search buffer and go to the last visited match.
+This resumes the last active search. With plain C-u prefix
+argument, prompt for a former search to resume, and make that the
+current search.
+
+Any other numeric prefix arg has the following meaning:
+
+ 0: go to the match following point
+ N: go to the Nth match after `window-start'
+-N: go to the Nth match before `window-end'
+
+In a non-interactive call, ARG should be an integer, having the
+same meaning as a numeric prefix arg, or an el-search-object to
+make current."
(interactive "P")
- (when previous-search
+ (pcase arg
+ ((or 'nil (pred el-search-object-p) `(,(pred integerp))))
+ (_ (el-search-barf-if-not-search-buffer
+ (current-buffer)
+ "Numeric ARG only allowed in current search's current buffer")))
+ (when (or (consp arg) (el-search-object-p arg))
;; FIXME: would it be better to include some context around the search
;; head - or to even use an overview buffer for selection?
(setq el-search--current-search
- (if (el-search-object-p previous-search) previous-search
+ (if (el-search-object-p arg) arg
(ring-ref
el-search-history
(let ((input
@@ -2325,16 +2345,26 @@ current."
(setq this-command 'el-search-pattern)
(pop-to-buffer current-search-buffer
el-search-display-buffer-popup-action)
(let ((last-match (el-search-object-last-match search)))
- (if (not (and last-match
- (eq (marker-buffer last-match) (current-buffer))))
- ;; this should only happen for bad search patterns
- (goto-char (el-search-head-position current-head))
- (goto-char last-match))
+ (cond
+ ((< (prefix-numeric-value arg) 0)
+ (progn (setq arg (prefix-numeric-value arg))
+ (goto-char (window-end))))
+ ((not (numberp arg))
+ (goto-char (if (not (and last-match
+ ;; this should only happen for bad search
patterns
+ (eq (marker-buffer last-match)
(current-buffer))))
+ (el-search-head-position current-head)
+ last-match)))
+ ((zerop arg) (setq arg 1))
+ (t (goto-char (window-start))))
(let ((match-pos
(save-excursion
(el-search--search-pattern-1
- (el-search--current-matcher) t nil
(el-search--current-heuristic-matcher)))))
- (unless (eq (point) match-pos)
+ (el-search--current-matcher)
+ (not (numberp arg)) nil ;FIXME: Handle no match case
explicitly
+ (el-search--current-heuristic-matcher)
+ (if (numberp arg) arg 1)))))
+ (unless (or (numberp arg) (eq (point) match-pos))
(message "No match at search head any more - going to the next
match")
(redisplay)
;; Don't just `sit-for' here: `pop-to-buffer' may have generated
frame
- [elpa] externals/el-search 061464c 303/332: [el-search] Improvise eldoc support for search pattern prompt, (continued)
- [elpa] externals/el-search 061464c 303/332: [el-search] Improvise eldoc support for search pattern prompt, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 9f4a9e5 310/332: [el-search] Improve "Make replacement editable and ediff'able", Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 3da4529 316/332: [el-search] Minor tweaks and version bump, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search e96c51e 319/332: [el-search] Key syntax cleanup, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search f091ed5 320/332: [el-search] Prefer rx forms to stringish regexps, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 47ee6b1 226/332: Improve working of `el-search-kill-left-over-search-buffers', Stefan Monnier, 2020/12/01
- [elpa] externals/el-search e21a53d 240/332: [el-search] Use current buffer to check for matches in replacement, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 188fb4a 259/332: [el-search] Minor tweaks and bump version to 1.7.5, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search d909f2e 260/332: [el-search] Follow-ups to transient map handling, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search d9950e1 264/332: [el-search] Fix nested match issues in *El Occur*, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search d9b2ff6 257/332: [el-search] Extend meaning of C-J prefix arg,
Stefan Monnier <=
- [elpa] externals/el-search 656869c 235/332: * el-search/el-search.el: Fix heuristic matcher for 'nil, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search adbf76d 262/332: [el-search] Open invisible text, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 60ad12e 268/332: [el-search] Small fix in el-search--reset-wrap-flag, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 73a15d2 274/332: [el-search] Stop for problematic comments, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 4961830 273/332: [el-search] Make replacement editable and ediff'able, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search da1f46b 282/332: [el-search] Make mouse clicks not abort the search, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 2a098da 293/332: [el-search] Unify go-to-previous/next-match key bindings, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search d4f8b3b 289/332: [el-search] Tweak my last commit "Add menus", Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 4d81139 299/332: [el-search] Fine tune separator for splicing replace, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 424138b 307/332: [el-search] Tweak 'display-buffer' actions, Stefan Monnier, 2020/12/01