bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#10709: Feature request: vc-hg should activate smerge-mode for confli


From: Glenn Morris
Subject: bug#10709: Feature request: vc-hg should activate smerge-mode for conflicts
Date: Fri, 30 Nov 2012 20:12:54 -0500
User-agent: Gnus (www.gnus.org), GNU Emacs (www.gnu.org/software/emacs/)

Wolfgang Schnerring wrote:

> vc-svn has the useful behaviour (via vc-svn-find-file-hook) that when
> you visit a file with conflicts, it drops you into smerge-mode, and
> automatically marks the file as resolved once you've removed all
> conflict markers. This makes for a very seamless editing experience. :-)
>
> It would be nice if vc-hg did the same. I guess most of the behaviour
> can be lifted straight from vc-svn, however I didn't find anything to
> suggest that vc-hg talks to "hg resolve -l" at the moment, which is
> needed to find out whether the current file is conflicted. So I guess
> that would be the starting point.

Maybe something like this, copied from vc-bzr?

The detection of a conflict is poor and Needs Work. With bzr we have
.BASE, .OTHER, and .THIS files present. With hg, conflicts don't even
seem to show up in "hg status". It's probably not a good idea to call
"hg resolve -l" on every single visit to an hg controlled file.
Nor is it probably a good idea to search the entirety of every file for
<<<< markers without some other clue suggesting a conflict. I used .orig
files because I seemed to get one in my two minutes playing with hg.
These don't seem to get cleaned up on hg resolve, so maybe
vc-hg-resolve-when-done should do that too? However, .orig is a very
vague, general file name.

*** lisp/vc/vc-hg.el    2012-07-19 14:38:01 +0000
--- lisp/vc/vc-hg.el    2012-12-01 01:01:18 +0000
***************
*** 464,469 ****
--- 464,492 ----
          (vc-hg-command t 0 file "cat" "-r" rev)
        (vc-hg-command t 0 file "cat")))))
  
+ (defun vc-hg-resolve-when-done ()
+   "Call \"hg resolve -m\" if the conflict markers have been removed."
+   (save-excursion
+     (goto-char (point-min))
+     (unless (re-search-forward "^<<<<<<< " nil t)
+       (vc-hg-command nil 0 buffer-file-name "resolve" "-m")
+       ;; Remove the hook so that it is not called multiple times.
+       (remove-hook 'after-save-hook 'vc-hg-resolve-when-done t))))
+ 
+ (defun vc-hg-find-file-hook ()
+   (when (and buffer-file-name
+              (file-exists-p (concat buffer-file-name ".orig"))
+              ;; FIXME: We should check that "hg resolve -l" says "U".
+              ;; If "hg resolve -l" says there's a conflict but there are no
+              ;; conflict markers, it's not clear what we should do.
+              (save-excursion
+                (goto-char (point-min))
+                (re-search-forward "^<<<<<<< " nil t)))
+     (smerge-start-session)
+     (add-hook 'after-save-hook 'vc-hg-resolve-when-done nil t)
+     (message "There are unresolved conflicts in this file")))
+ 
+ 
  ;; Modeled after the similar function in vc-bzr.el
  (defun vc-hg-workfile-unchanged-p (file)
    (eq 'up-to-date (vc-hg-state file)))





reply via email to

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