[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/el-search 39da179 313/332: [el-search] Minibuffer patte
From: |
Stefan Monnier |
Subject: |
[elpa] externals/el-search 39da179 313/332: [el-search] Minibuffer pattern prompt hints part 3 |
Date: |
Tue, 1 Dec 2020 15:49:11 -0500 (EST) |
branch: externals/el-search
commit 39da179c94a4de4dbf338f0f6ed0b3b6d76fa1ed
Author: Michael Heerdegen <michael_heerdegen@web.de>
Commit: Michael Heerdegen <michael_heerdegen@web.de>
[el-search] Minibuffer pattern prompt hints part 3
Restore the ability of 'el-search-read-display-mb-hints' to warn about
errors happening while counting (i.e. searching for) matches, i.e. for
patterns that are syntactically valid and compile ok but raise an
error when applied to some value. That capability had been gotten
lost with the fix in "Fix quits in minibuffer in emacs -nw".
We also let 'el-search-display-match-count' accept an ANIMATOR
function argument.
* packages/el-search/el-search.el (el-search-display-match-count):
Allow to pass an animator function as second argument. Change callers
to do that.
(el-search-read-display-mb-hints): Handle cases when
'el-search-display-match-count' exits nonlocally.
---
el-search.el | 271 ++++++++++++++++++++++++++++++-----------------------------
1 file changed, 136 insertions(+), 135 deletions(-)
diff --git a/el-search.el b/el-search.el
index eefb03b..f798ce7 100644
--- a/el-search.el
+++ b/el-search.el
@@ -1040,15 +1040,17 @@ nil."
;; A very common mistake: input "foo" instead
of "'foo"
(display-message " [%s]" msg)
(sit-for 2))
- (let ((el-search--search-pattern-1-do-fun
-
(el-search--make-display-animation-function
- (lambda (icon)
- (display-message (concat " "
icon))))))
- (when-let ((count
- (try (with-current-buffer buf
- (cl-letf (((point)
(window-point base-win)))
-
(el-search-display-match-count 'dont-message))))))
- (display-message " %-12s" count)
+ (let ((count
+ (try (with-current-buffer buf
+ (cl-letf (((point) (window-point
base-win)))
+ (el-search-display-match-count
+ 'dont-message
+
(el-search--make-display-animation-function
+ (lambda (icon)
+ (display-message (concat "
" icon))))))))))
+ (when (eq count t) (setq count nil))
+ (when-let ((show-this (or count err)))
+ (display-message " %-12s" show-this)
(sit-for el-search-mb-hints-timeout))))
(delete-overlay ol))))
(unless (string= input "")
@@ -2696,119 +2698,120 @@ The value is a list of elements
MATCHES is a stream of matches in this buffer. The other values
are used to check validity.")
-(defun el-search-display-match-count (&optional just-count)
+(defun el-search-display-match-count (&optional just-count animator)
"Display an x/y-style match count in the echo area.
With optional argument JUST-COUNT non-nil, only return a string,
don't display anything"
(when (or just-count (and el-search--success (not el-search--wrap-flag)))
(prog1
- (while-no-input
- (apply (if just-count #'format
- (lambda (&rest args)
- (setq el-search--last-message (apply
#'el-search--message-no-log args))))
- (progn
-
- ;; Check whether cached stream of buffer matches is still
valid
- (pcase el-search--buffer-match-count-data
- ((or
- (and `(,(and (pred el-search-object-p)
- (pred (eq el-search--current-search)))
- . ,_)
- (pred (eq
el-search--this-session-match-count-data)))
- `(,(pred (eq el-search--current-search))
- ,(pred (eq (buffer-chars-modified-tick)))
- (,(pred (eq (point-min))) ,(pred (eq (point-max))))
. ,_)))
-
- (_
- ;; (message "Refreshing match count data") (sit-for 1)
- (redisplay) ;don't delay highlighting
- (setq-local el-search--buffer-match-count-data
- (let ((stream-of-buffer-matches
- (seq-map #'cadr
- (el-search--all-matches
- (el-search-make-search
-
(el-search--current-pattern)
- (let ((current-buffer
(current-buffer)))
- (lambda () (stream (list
current-buffer)))))
- 'dont-copy))))
- (list
- el-search--current-search
- (buffer-chars-modified-tick)
- `(,(point-min) ,(point-max))
- stream-of-buffer-matches)))
- (setq el-search--this-session-match-count-data
- el-search--buffer-match-count-data)))
-
- (let ((pos-here (point)) (matches-<=-here 1) total-matches
- (defun-bounds (or (el-search--bounds-of-defun) (cons
(point) (point))))
- (matches-<=-here-in-defun 1) (total-matches-in-defun
0)
- (largest-match-start-not-after-pos-here nil))
- (pcase-let ((`(,_ ,_ ,_ ,matches)
el-search--buffer-match-count-data))
- (setq total-matches (let ((inhibit-message t))
(seq-length matches)))
- (while (and (not (stream-empty-p matches))
- (< (stream-first matches) (cdr
defun-bounds)))
- (when (<= (stream-first matches) pos-here)
- (setq largest-match-start-not-after-pos-here
(stream-first matches))
- (unless (= (stream-first matches) pos-here)
- (cl-incf matches-<=-here)))
- (when (<= (car defun-bounds) (stream-first matches))
- (cl-incf total-matches-in-defun)
- (when (< (stream-first matches) pos-here)
- (cl-incf matches-<=-here-in-defun)))
- (stream-pop matches))
- (if (zerop total-matches)
- (list "(No matches)")
- (let* ((at-a-match-but-not-at-match-beginning
- (and largest-match-start-not-after-pos-here
- (and (<
largest-match-start-not-after-pos-here pos-here)
- (save-excursion
- (goto-char
largest-match-start-not-after-pos-here)
- (<= pos-here
(el-search--end-of-sexp))))))
- (at-a-match
- (and largest-match-start-not-after-pos-here
- (or (= pos-here
largest-match-start-not-after-pos-here)
-
at-a-match-but-not-at-match-beginning))))
- (when (or at-a-match-but-not-at-match-beginning
- (not at-a-match))
- (cl-decf matches-<=-here)
- (cl-decf matches-<=-here-in-defun))
- (if at-a-match
- (let ((buffer-or-file
- (let ((head (el-search-object-head
el-search--current-search)))
- (or (el-search-head-file head)
- (buffer-name
(el-search-head-buffer head))))))
- (if just-count
- (list "%d/%d" matches-<=-here
total-matches)
- (list
- "%s %d/%d %s"
- buffer-or-file
- matches-<=-here
- total-matches
- (format
- (pcase (save-excursion
- (goto-char (car defun-bounds))
- (and (el-search-looking-at '`(,_
,_ . ,_))
- (looking-at "(") ;exclude
toplevel `ATOM and sim.
- (let ((region (list
- (progn
(down-list) (point))
- (min
(line-end-position)
-
(scan-sexps (point) 2)))))
- (when (bound-and-true-p
jit-lock-mode)
- (apply
#'jit-lock-fontify-now region))
- (apply #'buffer-substring
region))))
- ((and (pred stringp) signature)
- (format "(%s %%d/%%d)"
- (truncate-string-to-width
- signature
- 40 nil nil 'ellipsis)))
- (_ "(%d/%d)"))
- matches-<=-here-in-defun
total-matches-in-defun))))
- (list
- (concat (if (not just-count) "[Not at a match]
" "")
- (if (= matches-<=-here total-matches)
- (format "(%s/%s <-)" matches-<=-here
total-matches)
- (format "(-> %s/%s)" (1+
matches-<=-here) total-matches)))))))))
- )))
+ (let ((el-search--search-pattern-1-do-fun animator))
+ (while-no-input
+ (apply (if just-count #'format
+ (lambda (&rest args)
+ (setq el-search--last-message (apply
#'el-search--message-no-log args))))
+ (progn
+
+ ;; Check whether cached stream of buffer matches is still
valid
+ (pcase el-search--buffer-match-count-data
+ ((or
+ (and `(,(and (pred el-search-object-p)
+ (pred (eq el-search--current-search)))
+ . ,_)
+ (pred (eq
el-search--this-session-match-count-data)))
+ `(,(pred (eq el-search--current-search))
+ ,(pred (eq (buffer-chars-modified-tick)))
+ (,(pred (eq (point-min))) ,(pred (eq (point-max))))
. ,_)))
+
+ (_
+ ;; (message "Refreshing match count data") (sit-for 1)
+ (redisplay) ;don't delay highlighting
+ (setq-local el-search--buffer-match-count-data
+ (let ((stream-of-buffer-matches
+ (seq-map #'cadr
+ (el-search--all-matches
+ (el-search-make-search
+
(el-search--current-pattern)
+ (let ((current-buffer
(current-buffer)))
+ (lambda () (stream
(list current-buffer)))))
+ 'dont-copy))))
+ (list
+ el-search--current-search
+ (buffer-chars-modified-tick)
+ `(,(point-min) ,(point-max))
+ stream-of-buffer-matches)))
+ (setq el-search--this-session-match-count-data
+ el-search--buffer-match-count-data)))
+
+ (let ((pos-here (point)) (matches-<=-here 1) total-matches
+ (defun-bounds (or (el-search--bounds-of-defun)
(cons (point) (point))))
+ (matches-<=-here-in-defun 1)
(total-matches-in-defun 0)
+ (largest-match-start-not-after-pos-here nil))
+ (pcase-let ((`(,_ ,_ ,_ ,matches)
el-search--buffer-match-count-data))
+ (setq total-matches (let ((inhibit-message t))
(seq-length matches)))
+ (while (and (not (stream-empty-p matches))
+ (< (stream-first matches) (cdr
defun-bounds)))
+ (when (<= (stream-first matches) pos-here)
+ (setq largest-match-start-not-after-pos-here
(stream-first matches))
+ (unless (= (stream-first matches) pos-here)
+ (cl-incf matches-<=-here)))
+ (when (<= (car defun-bounds) (stream-first matches))
+ (cl-incf total-matches-in-defun)
+ (when (< (stream-first matches) pos-here)
+ (cl-incf matches-<=-here-in-defun)))
+ (stream-pop matches))
+ (if (zerop total-matches)
+ (list "(No matches)")
+ (let* ((at-a-match-but-not-at-match-beginning
+ (and largest-match-start-not-after-pos-here
+ (and (<
largest-match-start-not-after-pos-here pos-here)
+ (save-excursion
+ (goto-char
largest-match-start-not-after-pos-here)
+ (<= pos-here
(el-search--end-of-sexp))))))
+ (at-a-match
+ (and largest-match-start-not-after-pos-here
+ (or (= pos-here
largest-match-start-not-after-pos-here)
+
at-a-match-but-not-at-match-beginning))))
+ (when (or at-a-match-but-not-at-match-beginning
+ (not at-a-match))
+ (cl-decf matches-<=-here)
+ (cl-decf matches-<=-here-in-defun))
+ (if at-a-match
+ (let ((buffer-or-file
+ (let ((head (el-search-object-head
el-search--current-search)))
+ (or (el-search-head-file head)
+ (buffer-name
(el-search-head-buffer head))))))
+ (if just-count
+ (list "%d/%d" matches-<=-here
total-matches)
+ (list
+ "%s %d/%d %s"
+ buffer-or-file
+ matches-<=-here
+ total-matches
+ (format
+ (pcase (save-excursion
+ (goto-char (car defun-bounds))
+ (and (el-search-looking-at
'`(,_ ,_ . ,_))
+ (looking-at "(") ;exclude
toplevel `ATOM and sim.
+ (let ((region (list
+ (progn
(down-list) (point))
+ (min
(line-end-position)
+
(scan-sexps (point) 2)))))
+ (when (bound-and-true-p
jit-lock-mode)
+ (apply
#'jit-lock-fontify-now region))
+ (apply
#'buffer-substring region))))
+ ((and (pred stringp) signature)
+ (format "(%s %%d/%%d)"
+ (truncate-string-to-width
+ signature
+ 40 nil nil 'ellipsis)))
+ (_ "(%d/%d)"))
+ matches-<=-here-in-defun
total-matches-in-defun))))
+ (list
+ (concat (if (not just-count) "[Not at a match]
" "")
+ (if (= matches-<=-here total-matches)
+ (format "(%s/%s <-)"
matches-<=-here total-matches)
+ (format "(-> %s/%s)" (1+
matches-<=-here) total-matches)))))))))
+ ))))
(when quit-flag (el-search-keyboard-quit 'dont-quit)))))
(defun el-search-hl-other-matches (matcher)
@@ -2863,24 +2866,22 @@ With argument STOP non-nil, force cleanup."
('el-search-query-replace)
((guard (el-search--entering-prefix-arg-p))) ; don't hide key input
feedback
('el-search-pattern
- (let ((el-search--search-pattern-1-do-fun
- (if (eq this-command last-command)
- el-search-hl-post-command-fun--last-animator
- (setq el-search-hl-post-command-fun--last-animator
- (el-search--make-display-animation-function
- (lambda (icon)
- (let ((inhibit-message nil))
- (setq el-search--last-message
- (el-search--message-no-log
- "%s %s"
- (let ((head (el-search-object-head
el-search--current-search)))
- (or (el-search-head-file head)
- (el-search-head-buffer head)))
- icon)))))))))
- (condition-case-unless-debug err (el-search-display-match-count)
- (error
- (el-search--message-no-log
- "Error counting matches: %s" (error-message-string err))))))
+ (unless (eq this-command last-command)
+ (setq el-search-hl-post-command-fun--last-animator
+ (el-search--make-display-animation-function
+ (lambda (icon)
+ (let ((inhibit-message nil))
+ (setq el-search--last-message
+ (el-search--message-no-log
+ "%s %s"
+ (let ((head (el-search-object-head
el-search--current-search)))
+ (or (el-search-head-file head)
+ (el-search-head-buffer head)))
+ icon)))))))
+ (condition-case-unless-debug err
+ (el-search-display-match-count nil
el-search-hl-post-command-fun--last-animator)
+ (error (el-search--message-no-log
+ "Error counting matches: %s" (error-message-string err)))))
((pred el-search-keep-session-command-p))
(_ (unless el-search-keep-hl (stop))))))
- [elpa] externals/el-search 7d621de 216/332: * el-search/el-search.el: Some minor tweaks, (continued)
- [elpa] externals/el-search 7d621de 216/332: * el-search/el-search.el: Some minor tweaks, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 29eeda2 228/332: Show progress of automatic el-search-query-replace, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 4b934f1 238/332: * el-search/el-search.el: Skip over #N read syntaxes, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 01d4431 269/332: [el-search] Don't initially fold El Occur buffers, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 1169ef1 294/332: [el-search] Add accessible buffer area to a validity check, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search c0947c3 295/332: [el-search] Minibuffer pattern prompt hints part 1: preparations, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 749aa0c 300/332: [el-search] Improvements for 'change' and 'changed', Stefan Monnier, 2020/12/01
- [elpa] externals/el-search e522b71 305/332: [el-search] Enhance docstring of el-search-occur-mode, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search fdc4663 308/332: [el-search] Bump version to 1.11.1, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search e790747 309/332: [el-search] Fix quits in minibuffer in emacs -nw, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 39da179 313/332: [el-search] Minibuffer pattern prompt hints part 3,
Stefan Monnier <=
- [elpa] externals/el-search 01c663b 315/332: [el-search] Make el-search-query-replace resumable, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search c95de2b 317/332: [el-search] Shorten el-search-query-replace prompt again, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 76d63d9 326/332: [el-search] Extend possible search domains, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 0212cf9 328/332: * packages/el-search/el-search.el: New command el-search-repository, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 6df1362 332/332: * .gitignore: New file, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 6c0475e 212/332: Allow to save the current el-search to a register, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 7c19468 215/332: Fix el-search's to register save when no search started yet, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search c7709ab 233/332: Fix el-search's check for buffers visiting a given file, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search cda69ae 230/332: * el-search/el-search-x.el: New user option `el-search-lazy-l', Stefan Monnier, 2020/12/01
- [elpa] externals/el-search ce8835b 242/332: [el-search] Factor out `el-search-backward', Stefan Monnier, 2020/12/01