emacs-diffs
[Top][All Lists]
Advanced

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

master a1d9463: Save and restore point in ewoc-invalidate


From: Stefan Monnier
Subject: master a1d9463: Save and restore point in ewoc-invalidate
Date: Fri, 18 Sep 2020 11:53:38 -0400 (EDT)

branch: master
commit a1d9463ae7b00623bb52186e92be6d3388ca188b
Author: Andrii Kolomoiets <andreyk.mad@gmail.com>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>

    Save and restore point in ewoc-invalidate
    
    * lisp/emacs-lisp/ewoc.el (ewoc--refresh-node): Save and restore point line
    and column offset.
    (eowc-map) (ewoc--invalidate) (ewoc-set-hf): Don't use save-excursion
    * lisp/vc/vc-dir.el (vc-dir-update): Don't save/restore point on calling
    'ewoc-invalidate'.
---
 lisp/emacs-lisp/ewoc.el | 48 ++++++++++++++++++++++++++++--------------------
 lisp/vc/vc-dir.el       |  6 +-----
 2 files changed, 29 insertions(+), 25 deletions(-)

diff --git a/lisp/emacs-lisp/ewoc.el b/lisp/emacs-lisp/ewoc.el
index 78ada3e..5112322 100644
--- a/lisp/emacs-lisp/ewoc.el
+++ b/lisp/emacs-lisp/ewoc.el
@@ -205,15 +205,26 @@ NODE and leaving the new node's start there.  Return the 
new node."
 
 (defun ewoc--refresh-node (pp node dll)
   "Redisplay the element represented by NODE using the pretty-printer PP."
-  (let ((inhibit-read-only t)
-        (m (ewoc--node-start-marker node))
-        (R (ewoc--node-right node)))
-    ;; First, remove the string from the buffer:
-    (delete-region m (ewoc--node-start-marker R))
-    ;; Calculate and insert the string.
-    (goto-char m)
-    (funcall pp (ewoc--node-data node))
-    (ewoc--adjust m (point) R dll)))
+  (let* ((m (ewoc--node-start-marker node))
+         (R (ewoc--node-right node))
+         (end (ewoc--node-start-marker R))
+         (inhibit-read-only t)
+         (offset (if (= (point) end)
+                     'end
+                   (when (< m (point) end)
+                     (- (point) m)))))
+    (save-excursion
+      ;; First, remove the string from the buffer:
+      (delete-region m end)
+      ;; Calculate and insert the string.
+      (goto-char m)
+      (funcall pp (ewoc--node-data node))
+      (setq end (point))
+      (ewoc--adjust m (point) R dll))
+    (when offset
+      (goto-char (if (eq offset 'end)
+                     end
+                   (min (+ m offset) (1- end)))))))
 
 (defun ewoc--wrap (func)
   (lambda (data)
@@ -342,11 +353,10 @@ arguments will be passed to MAP-FUNCTION."
       ((footer (ewoc--footer ewoc))
        (pp (ewoc--pretty-printer ewoc))
        (node (ewoc--node-nth dll 1)))
-    (save-excursion
-      (while (not (eq node footer))
-        (if (apply map-function (ewoc--node-data node) args)
-            (ewoc--refresh-node pp node dll))
-        (setq node (ewoc--node-next dll node))))))
+    (while (not (eq node footer))
+      (if (apply map-function (ewoc--node-data node) args)
+          (ewoc--refresh-node pp node dll))
+      (setq node (ewoc--node-next dll node)))))
 
 (defun ewoc-delete (ewoc &rest nodes)
   "Delete NODES from EWOC."
@@ -461,9 +471,8 @@ If the EWOC is empty, nil is returned."
 Delete current text first, thus effecting a \"refresh\"."
   (ewoc--set-buffer-bind-dll-let* ewoc
       ((pp (ewoc--pretty-printer ewoc)))
-    (save-excursion
-      (dolist (node nodes)
-        (ewoc--refresh-node pp node dll)))))
+    (dolist (node nodes)
+      (ewoc--refresh-node pp node dll))))
 
 (defun ewoc-goto-prev (ewoc arg)
   "Move point to the ARGth previous element in EWOC.
@@ -566,9 +575,8 @@ Return nil if the buffer has been deleted."
        (hf-pp (ewoc--hf-pp ewoc)))
     (setf (ewoc--node-data head) header
           (ewoc--node-data foot) footer)
-    (save-excursion
-      (ewoc--refresh-node hf-pp head dll)
-      (ewoc--refresh-node hf-pp foot dll))))
+    (ewoc--refresh-node hf-pp head dll)
+    (ewoc--refresh-node hf-pp foot dll)))
 
 
 (provide 'ewoc)
diff --git a/lisp/vc/vc-dir.el b/lisp/vc/vc-dir.el
index 6c21900..cdf8ab9 100644
--- a/lisp/vc/vc-dir.el
+++ b/lisp/vc/vc-dir.el
@@ -451,11 +451,7 @@ If NOINSERT, ignore elements on ENTRIES which are not in 
the ewoc."
                      (setf (vc-dir-fileinfo->state (ewoc-data node)) (nth 1 
entry))
                      (setf (vc-dir-fileinfo->extra (ewoc-data node)) (nth 2 
entry))
                      (setf (vc-dir-fileinfo->needs-update (ewoc-data node)) 
nil)
-                      ;; `ewoc-invalidate' will kill line and insert new text,
-                      ;; let's keep point column.
-                      (let ((p (point)))
-                       (ewoc-invalidate vc-ewoc node)
-                        (goto-char p)))
+                     (ewoc-invalidate vc-ewoc node))
                  ;; If the state is nil, the file does not exist
                  ;; anymore, so remember the entry so we can remove
                  ;; it after we are done inserting all ENTRIES.



reply via email to

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