emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master 0972213: [el-search] Minibuffer pattern prompt hints part


From: Michael Heerdegen
Subject: [elpa] master 0972213: [el-search] Minibuffer pattern prompt hints part 3
Date: Sun, 24 Feb 2019 08:12:03 -0500 (EST)

branch: master
commit 097221377327ef599b3046c8001fa5ec5b523e86
Author: Michael Heerdegen <address@hidden>
Commit: Michael Heerdegen <address@hidden>

    [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.
---
 packages/el-search/el-search.el | 271 ++++++++++++++++++++--------------------
 1 file changed, 136 insertions(+), 135 deletions(-)

diff --git a/packages/el-search/el-search.el b/packages/el-search/el-search.el
index eefb03b..f798ce7 100644
--- a/packages/el-search/el-search.el
+++ b/packages/el-search/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))))))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]