unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Andrii Kolomoiets <andreyk.mad@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: Re: master f450798: Don't move point in vc-dir on vc-register/vc-checkin (bug#43188)
Date: Fri, 18 Sep 2020 17:57:29 +0300	[thread overview]
Message-ID: <m2v9gbqgiu.fsf@gmail.com> (raw)
In-Reply-To: <jwvh7ryvl21.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Tue, 15 Sep 2020 16:32:39 -0400")

[-- Attachment #1: Type: text/plain, Size: 316 bytes --]

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> Also I would move point by offset rather than percent to save exactly
>> the same position.
>
> Feel free to do that, yes (of course taking care of the case where the
> new text is shorter than the original position).

Done.  Please see attached patch.

Thanks!

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Save-and-restore-point-in-ewoc-invalidate.patch --]
[-- Type: text/x-patch, Size: 4362 bytes --]

From b630aa0f63312585c65847e1cec4a61d57face98 Mon Sep 17 00:00:00 2001
From: Andrii Kolomoiets <andreyk.mad@gmail.com>
Date: Sat, 5 Sep 2020 22:18:59 +0300
Subject: [PATCH] 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 78ada3e076..5112322cfd 100644
--- a/lisp/emacs-lisp/ewoc.el
+++ b/lisp/emacs-lisp/ewoc.el
@@ -205,15 +205,26 @@ ewoc--insert-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 @@ ewoc-map
       ((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 @@ ewoc-invalidate
 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 @@ ewoc-set-hf
        (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)))
 
 \f
 (provide 'ewoc)
diff --git a/lisp/vc/vc-dir.el b/lisp/vc/vc-dir.el
index 6c219005ce..cdf8ab984e 100644
--- a/lisp/vc/vc-dir.el
+++ b/lisp/vc/vc-dir.el
@@ -451,11 +451,7 @@ vc-dir-update
 		      (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.
-- 
2.15.1


  reply	other threads:[~2020-09-18 14:57 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20200904211737.15548.63989@vcs0.savannah.gnu.org>
     [not found] ` <20200904211738.DA94720667@vcs0.savannah.gnu.org>
2020-09-04 21:44   ` master f450798: Don't move point in vc-dir on vc-register/vc-checkin (bug#43188) Stefan Monnier
2020-09-05 19:34     ` Andrii Kolomoiets
2020-09-05 19:41       ` Stefan Monnier
2020-09-13 18:58         ` Andrii Kolomoiets
2020-09-13 20:27           ` Stefan Monnier
2020-09-15 19:14             ` Andrii Kolomoiets
2020-09-15 20:32               ` Stefan Monnier
2020-09-18 14:57                 ` Andrii Kolomoiets [this message]
2020-09-18 15:23                   ` Stefan Monnier
2020-09-18 15:47                     ` Andrii Kolomoiets
2020-09-18 15:53                       ` Stefan Monnier
2020-09-24 20:21                         ` Andrii Kolomoiets
2020-09-28 17:13                           ` Stefan Monnier
2020-09-30 20:08                             ` Andrii Kolomoiets

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2v9gbqgiu.fsf@gmail.com \
    --to=andreyk.mad@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).