]> code.delx.au - gnu-emacs-elpa/blobdiff - packages/el-search/el-search.el
Merge commit '2841c4413eceed257c7f79ab0d47d2034d472391'
[gnu-emacs-elpa] / packages / el-search / el-search.el
index 1ad895aa2ccb635d760bde8e561dd486e314e178..6e9fa5e082d40c21b55cf86b048367774225043b 100644 (file)
@@ -32,7 +32,7 @@
 ;; Introduction
 ;; ============
 ;;
-;; 
+;;
 ;; The main user entry point is the command `el-search-pattern'.  It
 ;; prompts for a `pcase' pattern and searches the current buffer for
 ;; expressions that are matched by it when read.  Point is put at the
 ;; Example: In some buffer you want to swap the two expressions at the
 ;; places of the first two arguments in all calls of function `foo',
 ;; so that e.g.
-;; 
+;;
 ;;   (foo 'a (* 2 (+ 3 4)) t)
-;;   
+;;
 ;; becomes
-;; 
+;;
 ;;   (foo (* 2 (+ 3 4)) 'a t).
-;;   
+;;
 ;; This will do it:
 ;;
 ;;    M-x el-search-query-replace RET
@@ -247,9 +247,10 @@ expression."
   ;;Point must be at sexp beginning
   (or (scan-sexps (point) 1) (point-max)))
 
-(defun el-search--goto-next-sexp ()
-  "Move point to the beginning of the next sexp.
-Don't move if already at beginning of a sexp."
+(defun el-search--ensure-sexp-start ()
+  "Move point to the beginning of the next sexp if necessary.
+Don't move if already at beginning of a sexp.
+Point must not be inside a string or comment."
   (let ((not-done t) res)
     (while not-done
       (let ((stop-here nil) syntax-here
@@ -308,7 +309,7 @@ return nil (no error)."
     (if (catch 'no-match
           (while (not match-beg)
             (condition-case nil
-                (setq current-expr (el-search--goto-next-sexp))
+                (setq current-expr (el-search--ensure-sexp-start))
               (end-of-buffer
                (goto-char opoint)
                (throw 'no-match t)))
@@ -326,10 +327,10 @@ return nil (no error)."
     (condition-case nil
         (while (< (point) (or bound (point-max)))
           (let* ((this-sexp-end (save-excursion (thing-at-point--end-of-sexp) (point)))
-                 (this-sexp (buffer-substring-no-properties (point) this-sexp-end)))
-            (funcall do-fun this-sexp this-sexp-end))
+                 (this-sexp-bounds (buffer-substring-no-properties (point) this-sexp-end)))
+            (funcall do-fun this-sexp-bounds this-sexp-end))
           (forward-char)
-          (el-search--goto-next-sexp))
+          (el-search--ensure-sexp-start))
       (end-of-buffer))
     (when ret-fun (funcall ret-fun))))