]> git.neil.brown.name Git - edlib.git/commitdiff
mergeview: auto-position on merge at first visit.
authorNeilBrown <neil@brown.name>
Tue, 13 Jun 2023 22:22:21 +0000 (08:22 +1000)
committerNeilBrown <neil@brown.name>
Wed, 28 Jun 2023 07:51:41 +0000 (17:51 +1000)
When first visiting a file with a merge, auto-find that merge.

I'm not sure this is a good idea, and won't know until I try.

Signed-off-by: NeilBrown <neil@brown.name>
DOC/TODO.md
python/lib-mergeview.py

index 0a33c44bbbedf1c4f0929e475f075a8917e54f0f..851392dcbb9800e19ffc5ccf145766fc9e41373e 100644 (file)
@@ -29,7 +29,7 @@ the file.
 
 ### Medium
 
-- [ ] lib-mergeview improvements
+- [X] lib-mergeview improvements
 - [ ] lib-diff slowness with large diff
 - [ ] linecount :when used in 'view' mode, stack the counting pane with all the
       others so it can easily catch view-changed.
@@ -243,7 +243,7 @@ Module features
 - [ ] Consider what else can be done with < and > on other markers.
 - [X] Capture :CX:C-x command to cycle through matching places in the
       three branches.
-- [ ] merge-mode automatic detect, enable, goto-first
+- [X] merge-mode automatic detect, enable, goto-first
        I'm not sure I want this, but probably try it and see
       Maybe time-limit on search
 
index 3e2cffa2518bc99295ca99c69446d0c32a291130..35fed1987fa01ada0b23653a0406d5aba7445f7b 100644 (file)
@@ -25,6 +25,10 @@ class MergePane(edlib.Pane):
         self.merge_char = None
         self.call("doc:request:doc:replaced")
         self.call("doc:request:mark:moving")
+        if focus["mergeview-autofind"] == "true":
+            focus.call("doc:set:mergeview-autofind")
+            m = self.call("doc:point", ret='mark')
+            self.call("K:A-m", self, m)
 
     def fore(self, m, end, ptn):
         if not m:
@@ -438,6 +442,18 @@ class MergePane(edlib.Pane):
 
             return edlib.Efallthrough
 
+def merge_appeared(key, focus, **a):
+    t = focus["doc-type"]
+    if t != "text":
+        return 1
+    m = edlib.Mark(focus)
+    try:
+        focus.call("text-search", m, "^<<<<<<<")
+        focus.call("doc:append:view-default", ",merge")
+        focus.call("doc:set:mergeview-autofind", "true")
+    except:
+        pass
+
 def merge_view_attach(key, focus, comm2, **a):
     p = MergePane(focus)
     if not p:
@@ -459,3 +475,4 @@ def add_merge(key, focus, mark, **a):
 edlib.editor.call("global-set-command", "attach-merge", merge_view_attach)
 edlib.editor.call("global-set-command", "interactive-cmd-merge-mode", add_merge)
 edlib.editor.call("global-load-module", "lib-wiggle")
+edlib.editor.call("global-set-command", "doc:appeared-mergeview", merge_appeared)