[Top][All Lists]

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

[elpa] master 403bbb6: [el-search] Avoid most calls to 'scan-sexps'

From: Michael Heerdegen
Subject: [elpa] master 403bbb6: [el-search] Avoid most calls to 'scan-sexps'
Date: Sat, 23 Jun 2018 12:09:47 -0400 (EDT)

branch: master
commit 403bbb6b31e7e28fe76f4a678fc67d13809c4a71
Author: Michael Heerdegen <address@hidden>
Commit: Michael Heerdegen <address@hidden>

    [el-search] Avoid most calls to 'scan-sexps'
    Replace 'scan-sexps' with 'el-search--end-of-sexp' where possible.  We
    do this because 'scan-sexps' currently has a bug - bug#24542 "The
    symbol `@' and sexp scanning" - which we try to avoid.
    * packages/el-search/el-search.el (el-search--end-of-sexp): Implement
    an optional POS argument.
    Replace all calls of 'scan-sexps' with a COUNT argument 1 with
    according 'el-search--end-of-sexp' calls.
    (el-search--search-backward-1): Correct a variable name.
    * packages/el-search/el-search-x.el: Also replace 'scan-sexps' calls.
 packages/el-search/el-search-x.el |  4 ++--
 packages/el-search/el-search.el   | 35 ++++++++++++++++++++---------------
 2 files changed, 22 insertions(+), 17 deletions(-)

diff --git a/packages/el-search/el-search-x.el 
index 1aeff7b..0af955c 100644
--- a/packages/el-search/el-search-x.el
+++ b/packages/el-search/el-search-x.el
@@ -292,7 +292,7 @@ Uses variable `el-search--cached-changes' for caching."
     (let ((changes (el-search--changes-from-diff-hl revision))
-          (sexp-end (scan-sexps posn 1))
+          (sexp-end (el-search--end-of-sexp posn))
           (atomic? (thunk-delay (el-search--atomic-p
                                  (save-excursion (goto-char posn)
@@ -317,7 +317,7 @@ Uses variable `el-search--cached-changes' for caching."
       (while (and changes (<= (cdar changes) posn))
         (pop changes))
       (and changes
-           (< (caar changes) (scan-sexps posn 1))))))
+           (< (caar changes) (el-search--end-of-sexp posn))))))
 (defun el-search-change--heuristic-matcher (&optional revision)
   (let* ((revision (or revision "HEAD"))
diff --git a/packages/el-search/el-search.el b/packages/el-search/el-search.el
index 899272b..249ba8b 100644
--- a/packages/el-search/el-search.el
+++ b/packages/el-search/el-search.el
@@ -639,7 +639,7 @@ nil."
                    (top-level-paren-start pos)
                    ;; Iff at the beginning top-level paren group, this 
succeeds and returns point
                    (and (not (eobp)) (top-level-paren-start (1+ pos)))))
-            (cons defun-beg (scan-sexps defun-beg 1))
+            (cons defun-beg (el-search--end-of-sexp defun-beg))
           ;; This corner case (not inside any s-exp or current top level s-exp
           ;; not a list) is a bit hairy to do with syntax stuff, so let's just
           ;; use el-search:
@@ -784,14 +784,19 @@ PROMPT defaults to \"El-search pattern: \".  The return 
value is the
-(defun el-search--end-of-sexp ()
+(defun el-search--end-of-sexp (&optional pos)
   "Return the value of point at the end of this sexp.
-Point should be at a sexp beginning."
-  (if (eql (char-after) ?@) ;bug#24542
-      (save-excursion
-        (ignore (el-search-read (current-buffer)))
-        (point))
-    (or (scan-sexps (point) 1) (point-max))))
+Point should be at a sexp beginning.
+With POS, a sexp-beginning position, return value of point at the end
+of this sexp."
+  (save-excursion
+    (when pos (goto-char pos))
+    (if (eql (char-after) ?@) ;bug#24542 "The symbol `@' and sexp scanning"
+        (progn
+          (ignore (el-search-read (current-buffer)))
+          (point))
+      (or (scan-sexps (point) 1) (point-max)))))
 (defun el-search--skip-expression (expression &optional read)
   ;; Move forward at least one character.  Don't move into a string or
@@ -1053,7 +1058,7 @@ be specified as fourth argument, and COUNT becomes the 
fifth argument."
                      ((el-search--match-p matcher current-expr)
                       (setq match-beg
                             (and (or (not bound)
-                                     (<= (scan-sexps match-beg 1) bound)
+                                     (<= (el-search--end-of-sexp match-beg) 
                                      ;; don't fail for >: a subsequent match 
may end before BOUND
@@ -2574,7 +2579,7 @@ This function is the counterpart of 
                   ;; Search for the hindmost match starting before 
                   (let ((done nil))
                     (goto-char current-defun-start)
-                    (setq current-defun-end (scan-sexps defun-start 1))
+                    (setq current-defun-end (el-search--end-of-sexp 
                     (when (and bound (< current-defun-end bound))
                       (setq done t
                             outer-loop-done t
@@ -2920,13 +2925,13 @@ Prompt for a new pattern and revert."
     (cons (or context-beg match-beg)
           (if context-beg (scan-lists context-beg 1 0)
-            (scan-sexps match-beg 1)))))
+            (el-search--end-of-sexp match-beg)))))
 (defun el-search-occur-get-defun-context (match-beg)
   (el-search--bounds-of-defun match-beg))
 (defun el-search-occur-get-null-context (match-beg)
-  (cons match-beg (scan-sexps match-beg 1)))
+  (cons match-beg (el-search--end-of-sexp match-beg)))
 (defvar el-search-get-occur-context-function #'el-search-occur-get-some-context
   "Function determining amount of context shown in *El Occur* buffers.")
@@ -3019,7 +3024,7 @@ Prompt for a new pattern and revert."
                                                 (when (< cbeg context-beg)
                                                   (setq context-beg cbeg)
                                                   (setq context-end
-                                                        (or (scan-sexps cbeg 
1) context-end)))))))))
+                                                        (or 
(el-search--end-of-sexp cbeg) context-end)))))))))
                                 (setq matches
                                       (car (stream-divide-with-get-rest-fun
@@ -3032,7 +3037,7 @@ Prompt for a new pattern and revert."
                                                     (with-current-buffer buffer
                                                        (goto-char match-beg)
-                                                       (goto-char (scan-sexps 
(point) 1))))
+                                                       (goto-char 
                                                     'match-data `(,buffer 
,match-beg ,file)))
                                            (let ((ov (make-overlay 
insertion-point (point) nil t)))
                                              (overlay-put ov 'face 
@@ -3057,7 +3062,7 @@ Prompt for a new pattern and revert."
                                    (with-current-buffer buffer
-                                      (point) (scan-sexps context-beg 1))))))
+                                      (point) (el-search--end-of-sexp 
                               (let ((inhibit-message t) (message-log-max nil))
                                 (indent-region insertion-point (point))

reply via email to

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