Commit 7d85a64e authored by Stefan Monnier's avatar Stefan Monnier
Browse files

(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.
parent 197d4ebc
;;; 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 @@ Used in `smerge-diff-base-mine' and related functions."
`((,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 @@ some major modes. Uses `smerge-resolve-function' to do the actual work."
(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))))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment