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

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

[elpa] externals/el-search d9acf3a 314/332: [el-search] Fix sanity check


From: Stefan Monnier
Subject: [elpa] externals/el-search d9acf3a 314/332: [el-search] Fix sanity check regarding comments
Date: Tue, 1 Dec 2020 15:49:12 -0500 (EST)

branch: externals/el-search
commit d9acf3a19e764312970edb5bc9c2a6d9d08cb319
Author: Michael Heerdegen <michael_heerdegen@web.de>
Commit: Michael Heerdegen <michael_heerdegen@web.de>

    [el-search] Fix sanity check regarding comments
    
    Also bump version to 1.11.4.
    
    * packages/el-search/el-search.el
    (el-search-query-replace--comments-preserved-p): Fix counting ";"
    occurrences in strings as comment starts by mistake.  Fix equality
    test of comment multi sets.
---
 el-search.el | 45 +++++++++++++++++++++++++++++----------------
 1 file changed, 29 insertions(+), 16 deletions(-)

diff --git a/el-search.el b/el-search.el
index f798ce7..2485558 100644
--- a/el-search.el
+++ b/el-search.el
@@ -7,7 +7,7 @@
 ;; Created: 29 Jul 2015
 ;; Keywords: lisp
 ;; Compatibility: GNU Emacs 25
-;; Version: 1.11.3
+;; Version: 1.11.4
 ;; Package-Requires: ((emacs "25") (stream "2.2.4") (cl-print "1.0"))
 
 
@@ -4295,21 +4295,34 @@ exactly you did?  Thanks!"))))
                          hook-funs)
                   'ediff-regions-linewise nil nil)))))
 
-(defun el-search-query-replace--comments-preserved-p (from to)
-  (cl-flet ((get-comments
-             (lambda (text)
-               (let ((comments '()))
-                 (with-temp-buffer
-                   (insert text)
-                   (goto-char (point-min))
-                   (emacs-lisp-mode)
-                   (while (search-forward-regexp comment-start-skip nil t)
-                     (let ((comment-text (buffer-substring (point) 
(line-end-position))))
-                       (unless (string= comment-text "")
-                         (push comment-text comments)))
-                     (forward-line +1))
-                   comments)))))
-    (seq-set-equal-p (get-comments from) (get-comments to) #'string=)))
+(defun el-search-query-replace--comments-preserved-p (from-text to-text)
+  ;; Return non-nil when strings FROM-TEXT and TO-TEXT contain the same
+  ;; comments.
+  (cl-flet* ((goto-next-comment-start-p
+              (lambda ()
+                (let ((success nil) (done nil))
+                  (while (not (or done success))
+                    (if (not (search-forward-regexp comment-start-skip nil t))
+                        (setq done t)
+                      (setq success (not (nth 3 (syntax-ppss))))))
+                  success)))
+             (get-comments
+              (lambda (text)
+                (let ((comments '()))
+                  (with-temp-buffer
+                    (insert text)
+                    (goto-char (point-min))
+                    (emacs-lisp-mode)
+                    (while (goto-next-comment-start-p)
+                      (let ((comment-text (buffer-substring (point) 
(line-end-position))))
+                        (unless (string= comment-text "")
+                          (push comment-text comments)))
+                      (forward-line +1))
+                    comments)))))
+    (cl-tree-equal
+     (sort (get-comments from-text) #'string-lessp)
+     (sort (get-comments to-text)   #'string-lessp)
+     :test #'string=)))
 
 (defun el-search--search-and-replace-pattern
     (pattern replacement &optional splice to-input-string use-current-search)



reply via email to

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