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

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

[elpa] externals/el-search 2366cda 107/332: Improve `change' and `change


From: Stefan Monnier
Subject: [elpa] externals/el-search 2366cda 107/332: Improve `change' and `changed'
Date: Tue, 1 Dec 2020 15:48:22 -0500 (EST)

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

    Improve `change' and `changed'
    
    - Renew cache when saved file version has changed.
    
    - Use markers as region boundaries so that replacing inside changed
    expressions works.
---
 el-search-x.el | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/el-search-x.el b/el-search-x.el
index 8b8c10b..7c050cf 100644
--- a/el-search-x.el
+++ b/el-search-x.el
@@ -47,8 +47,10 @@
 Use variable `el-search--cached-changes' for caching."
   (if (and (consp el-search--cached-changes)
            (equal (car el-search--cached-changes)
-                  revision))
+                  (list revision (visited-file-modtime))))
       (cdr el-search--cached-changes)
+    (when (buffer-modified-p)
+      (error "Buffer is modified - please save"))
     (require 'diff-hl)
     ;; `diff-hl-changes' returns line numbers.  We must convert them into 
positions.
     (save-restriction
@@ -58,20 +60,19 @@ Use variable `el-search--cached-changes' for caching."
               (current-line-nbr 1) change-beg)
           (goto-char 1)
           (cdr (setq el-search--cached-changes
-                     (cons revision
+                     (cons (list revision (visited-file-modtime))
                            (delq nil (mapcar (pcase-lambda (`(,start-line 
,nbr-lines ,kind))
                                                (if (eq kind 'delete) nil
                                                  (forward-line (- start-line 
current-line-nbr))
                                                  (setq change-beg (point))
                                                  (forward-line (1- nbr-lines))
                                                  (setq current-line-nbr (+ 
start-line nbr-lines -1))
-                                                 (cons change-beg 
(line-end-position))))
+                                                 (cons (copy-marker change-beg)
+                                                       (copy-marker 
(line-end-position)))))
                                              (diff-hl-changes)))))))))))
 
 (defun el-search--change-p (posn &optional revision)
   ;; Non-nil when sexp after POSN is part of a change
-  (when (buffer-modified-p)
-    (error "Buffer is modified - please save"))
   (save-restriction
     (widen)
     (let ((changes (el-search--changes-from-diff-hl revision))



reply via email to

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