unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] Don’t run smerge multiple times
@ 2020-02-11 18:55 Matthew Bauer
  2020-02-13 16:17 ` Stefan Monnier
  0 siblings, 1 reply; 4+ messages in thread
From: Matthew Bauer @ 2020-02-11 18:55 UTC (permalink / raw)
  To: emacs-devel


[-- Attachment #1.1: Type: text/plain, Size: 384 bytes --]

autorevert ends up calling vc-git-find-file-hook multiple times. When
this happens, smerge restarts and goes to the next hunk. This is not
desired when in the middle of an edit. To fix, don’t start smerge when
smerge is already enabled.

Related to
https://lists.gnu.org/archive/html/emacs-devel/2015-10/msg02201.html

Attached is a patch that avoids this bug.

-Matthew

[-- Attachment #1.2: Type: text/html, Size: 545 bytes --]

[-- Attachment #2: 0001-Don-t-run-smerge-multiple-times.patch --]
[-- Type: text/x-patch, Size: 1316 bytes --]

From ff70ad053c9077ef3e01047f0ab8ad3067a66646 Mon Sep 17 00:00:00 2001
From: Matthew Bauer <mjbauer95@gmail.com>
Date: Tue, 11 Feb 2020 13:49:17 -0500
Subject: [PATCH]  Don’t run smerge multiple times
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

autorevert ends up calling vc-git-find-file-hook multiple times. When
this happens, smerge restarts and goes to the next hunk. This is not
desired when in the middle of an edit. To fix, don’t start smerge when
smerge is already enabled.

Related to https://lists.gnu.org/archive/html/emacs-devel/2015-10/msg02201.html
---
 lisp/vc/vc-git.el | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index 2caa287bce..7a7050a14b 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -1109,8 +1109,8 @@ This prompts for a branch to merge from."
              (save-excursion
                (goto-char (point-min))
                (re-search-forward "^<<<<<<< " nil 'noerror)))
-    (smerge-start-session)
+    (unless (and (boundp 'smerge-mode) smerge-mode)
+      (smerge-start-session))
     (when vc-git-resolve-conflicts
       (add-hook 'after-save-hook 'vc-git-resolve-when-done nil 'local))
     (vc-message-unresolved-conflicts buffer-file-name)))
--
2.23.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Don’t run smerge multiple times
  2020-02-11 18:55 [PATCH] Don’t run smerge multiple times Matthew Bauer
@ 2020-02-13 16:17 ` Stefan Monnier
       [not found]   ` <CAFnZKr0Fij5A_Th0=LU=9-nAbFJ=8XHD9dduDmFBFZCTOJY_DA@mail.gmail.com>
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Monnier @ 2020-02-13 16:17 UTC (permalink / raw)
  To: Matthew Bauer; +Cc: emacs-devel

Hi Matthew,

> autorevert ends up calling vc-git-find-file-hook multiple times.

This sounds like a problem in itself.
Or is it really because the file gets modified multiple times?

> When this happens, smerge restarts and goes to the next hunk.  This is
> not desired when in the middle of an edit.

Indeed.

> To fix, don’t start smerge when smerge is already enabled.

That sounds good.

Tho now that I think about it, going to the next hunk sounds like a bad
idea when in the middle of an edit reagrdless of you were already in
smerge-mode.

> Related to
> https://lists.gnu.org/archive/html/emacs-devel/2015-10/msg02201.html

That patch was never installed.  Has that problem been
fixed/circumvented some other way?


        Stefan




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Fwd: [PATCH] Don’t run smerge multiple times
       [not found]   ` <CAFnZKr0Fij5A_Th0=LU=9-nAbFJ=8XHD9dduDmFBFZCTOJY_DA@mail.gmail.com>
@ 2020-03-18  0:07     ` Matthew Bauer
  2020-03-18 14:20       ` Stefan Monnier
  0 siblings, 1 reply; 4+ messages in thread
From: Matthew Bauer @ 2020-03-18  0:07 UTC (permalink / raw)
  To: emacs-devel

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

Sorry for the late reply - just started going through forgotten emails.

>> autorevert ends up calling vc-git-find-file-hook multiple times.

> This sounds like a problem in itself.
> Or is it really because the file gets modified multiple times?

I think it is caused by each edit. At least the symptom is that after so
much idle time,
vc-git-find-file-hook gets run. Now that I'm looking for it, I don't
actually see
vc-git-find-file-hook is added to any hooks, so something seems off. It may
be some
kind of interaction with Magit that sets this up.

> Tho now that I think about it, going to the next hunk sounds like a bad
> idea when in the middle of an edit reagrdless of you were already in
> smerge-mode.

>> Related to
>> https://lists.gnu.org/archive/html/emacs-devel/2015-10/msg02201.html

> That patch was never installed.  Has that problem been
> fixed/circumvented some other way?

It looks like it was fixed in
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=21559 in a different way.

[-- Attachment #2: Type: text/html, Size: 1434 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Fwd: [PATCH] Don’t run smerge multiple times
  2020-03-18  0:07     ` Fwd: " Matthew Bauer
@ 2020-03-18 14:20       ` Stefan Monnier
  0 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2020-03-18 14:20 UTC (permalink / raw)
  To: Matthew Bauer; +Cc: emacs-devel

Matthew Bauer [2020-03-17 20:07:25] wrote:

>> This sounds like a problem in itself.
>> Or is it really because the file gets modified multiple times?
> I think it is caused by each edit.

I see, thanks.

> At least the symptom is that after so much idle time,
> vc-git-find-file-hook gets run.  Now that I'm looking for it, I don't
> actually see vc-git-find-file-hook is added to any hooks, so something
> seems off.  It may be some kind of interaction with Magit that sets
> this up.

`vc-git-find-file-hook` is run by `vc-refresh-state`:

    [...]
    (vc-call-backend backend 'find-file-hook)
    [...]

and `vc-refresh-state` is on `find-file-hook`.
This is true regardless of Magit.

>>> Related to
>>> https://lists.gnu.org/archive/html/emacs-devel/2015-10/msg02201.html
>
>> That patch was never installed.  Has that problem been
>> fixed/circumvented some other way?
>
> It looks like it was fixed in
> https://debbugs.gnu.org/cgi/bugreport.cgi?bug=21559 in a different way.

Good, thanks.  I think the original patch's intent was good, tho.
I installed the patch below into `master`.


        Stefan


diff --git a/lisp/vc/smerge-mode.el b/lisp/vc/smerge-mode.el
index 85868b91ec..d0a83fd7c4 100644
--- a/lisp/vc/smerge-mode.el
+++ b/lisp/vc/smerge-mode.el
@@ -1429,15 +1429,16 @@ smerge-mode
     (smerge-remove-props (point-min) (point-max))))
 
 ;;;###autoload
-(defun smerge-start-session ()
+(defun smerge-start-session (&optional interactively)
   "Turn on `smerge-mode' and move point to first conflict marker.
 If no conflict maker is found, turn off `smerge-mode'."
-  (interactive)
-  (smerge-mode 1)
-  (condition-case nil
-      (unless (looking-at smerge-begin-re)
-        (smerge-next))
-    (error (smerge-auto-leave))))
+  (interactive "p")
+  (when (or (null smerge-mode) interactively)
+    (smerge-mode 1)
+    (condition-case nil
+        (unless (looking-at smerge-begin-re)
+          (smerge-next))
+      (error (smerge-auto-leave)))))
 
 (defcustom smerge-change-buffer-confirm t
   "If non-nil, request confirmation before moving to another buffer."




^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-03-18 14:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-02-11 18:55 [PATCH] Don’t run smerge multiple times Matthew Bauer
2020-02-13 16:17 ` Stefan Monnier
     [not found]   ` <CAFnZKr0Fij5A_Th0=LU=9-nAbFJ=8XHD9dduDmFBFZCTOJY_DA@mail.gmail.com>
2020-03-18  0:07     ` Fwd: " Matthew Bauer
2020-03-18 14:20       ` Stefan Monnier

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).