changeset 54332:118715eba3b3

(smerge-check-cache, smerge-check): New var and fun. (smerge-mode-menu): Use it to deactivate menu entries. (smerge-keep-current): New fun. (smerge-keep-current): Use it.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Wed, 10 Mar 2004 23:42:37 +0000
parents 8f69fa8038cb
children 085835de6939
files lisp/smerge-mode.el
diffstat 1 files changed, 47 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/smerge-mode.el	Wed Mar 10 22:56:45 2004 +0000
+++ b/lisp/smerge-mode.el	Wed Mar 10 23:42:37 2004 +0000
@@ -1,10 +1,10 @@
 ;;; smerge-mode.el --- Minor mode to resolve diff3 conflicts
 
-;; Copyright (C) 1999, 2000, 2001  Free Software Foundation, Inc.
+;; Copyright (C) 1999, 2000, 01, 03, 2004  Free Software Foundation, Inc.
 
 ;; Author: Stefan Monnier <monnier@cs.yale.edu>
 ;; Keywords: merge diff3 cvs conflict
-;; Revision: $Id$
+;; Revision: $Id: smerge-mode.el,v 1.24 2003/10/06 16:34:59 fx Exp $
 
 ;; This file is part of GNU Emacs.
 
@@ -137,26 +137,54 @@
   `((,smerge-command-prefix . ,smerge-basic-map))
   "Keymap for `smerge-mode'.")
 
+(defvar smerge-check-cache nil)
+(make-variable-buffer-local 'smerge-check-cache)
+(defun smerge-check (n)
+  (condition-case nil
+      (let ((state (cons (point) (buffer-modified-tick))))
+	(unless (equal (cdr smerge-check-cache) state)
+	  (smerge-match-conflict)
+	  (setq smerge-check-cache (cons (match-data) state)))
+	(nth (* 2 n) (car smerge-check-cache)))
+    (error nil)))
+
 (easy-menu-define smerge-mode-menu smerge-mode-map
   "Menu for `smerge-mode'."
   '("SMerge"
     ["Next" smerge-next :help "Go to next conflict"]
     ["Previous" smerge-prev :help "Go to previous conflict"]
-    ["Keep All" smerge-keep-all :help "Keep all three versions"]
-    ["Revert to Base" smerge-keep-base :help "Revert to base version"]
-    ["Keep Other" smerge-keep-other :help "Keep `other' version"]
-    ["Keep Yours" smerge-keep-mine :help "Keep your version"]
-    ["Keep Current" smerge-keep-current :help "Use current (at point) version"]
+    "--"
+    ["Keep All" smerge-keep-all :help "Keep all three versions"
+     :active (smerge-check 1)]
+    ["Keep Current" smerge-keep-current :help "Use current (at point) version"
+     :active (and (smerge-check 1) (> (smerge-get-current) 0))]
+    "--"
+    ["Revert to Base" smerge-keep-base :help "Revert to base version"
+     :active (smerge-check 2)]
+    ["Keep Other" smerge-keep-other :help "Keep `other' version"
+     :active (smerge-check 3)]
+    ["Keep Yours" smerge-keep-mine :help "Keep your version"
+     :active (smerge-check 1)]
     "--"
     ["Diff Base/Mine" smerge-diff-base-mine
-     :help "Diff `base' and `mine' for current conflict"]
+     :help "Diff `base' and `mine' for current conflict"
+     :active (smerge-check 2)]
     ["Diff Base/Other" smerge-diff-base-other
-     :help "Diff `base' and `other' for current conflict"]
+     :help "Diff `base' and `other' for current conflict"
+     :active (smerge-check 2)]
     ["Diff Mine/Other" smerge-diff-mine-other
-     :help "Diff `mine' and `other' for current conflict"]
+     :help "Diff `mine' and `other' for current conflict"
+     :active (smerge-check 1)]
     "--"
     ["Invoke Ediff" smerge-ediff
-     :help "Use Ediff to resolve the conflicts"]
+     :help "Use Ediff to resolve the conflicts"
+     :active (smerge-check 1)]
+    ["Auto Resolve" smerge-resolve
+     :help "Use mode-provided resolution function"
+     :active (and (smerge-check 1) (local-variable-p 'smerge-resolve-function))]
+    ["Combine" smerge-combine-with-next
+     :help "Combine current conflict with next"
+     :active (smerge-check 1)]
     ))
 
 (defconst smerge-font-lock-keywords
@@ -288,15 +316,19 @@
   (replace-match (match-string 1) t t)
   (smerge-auto-leave))
 
-(defun smerge-keep-current ()
-  "Use the current (under the cursor) version."
-  (interactive)
-  (smerge-match-conflict)
+(defun smerge-get-current ()
   (let ((i 3))
     (while (or (not (match-end i))
 	       (< (point) (match-beginning i))
 	       (>= (point) (match-end i)))
       (decf i))
+    i))
+
+(defun smerge-keep-current ()
+  "Use the current (under the cursor) version."
+  (interactive)
+  (smerge-match-conflict)
+  (let ((i (smerge-get-current)))
     (if (<= i 0) (error "Not inside a version")
       (replace-match (match-string i) t t)
       (smerge-auto-leave))))