Emacs modes for darcs


Use Emacs as an external merge tool for darcs

(There's a more comprehensive example in the manual for darcs 1.0.5.)

Create the following wrapper script:

#!/bin/sh
#
# 3 way merge using emacs from the command line

emacs --eval="(ediff-merge-files-with-ancestor \"$1\" \"$2\" \"$3\" nil \"$4\")"

then invoke darcs pull as follows:

$ darcs pull --external-merge='/path/to/the/wrapper/script.sh %1 %2 %a %o'

or just put the following line into ~/.darcs/defaults:

ALL external-merge /path/to/the/wrapper/script.sh %1 %2 %a %o


Protect against accidentally editing files in _darcs/current

More than once I found myself making an edit in the _darcs/current copy of a file; probably due to an accident with find-dired. This pops up a warning in that case and will optionally open the normal version of the file.

Add the following to your .emacs:

(add-hook 'find-file-hooks 'warn-if-darcs-file)
(defun warn-if-darcs-file()
  (let ((f (buffer-file-name (current-buffer))))
    (and f (string-match "_darcs" f)
         (if (y-or-n-p "This is a _darcs file, open the real file? ")
             (jump-to-real-file-from-darcs)
           (push '(:propertize "_DARCS-FILE:" face font-lock-warning-face)
                 mode-line-buffer-identification)))))
(defun jump-to-real-file-from-darcs()
  (interactive)
  (let* ((f (buffer-file-name (current-buffer)))
         (match (string-match "_darcs/current" f)))
    (and f match
         (find-alternate-file
          (concat (substring f 0 (match-beginning 0))
                  (substring f (match-end 0)))))))

I have included some code inspired by his in vc-darcs.el; I'd like to credit the original author, please drop me a line. -- JCh

The above code is a nuisance when using darcsum-ediff. Also, the warning label is lost at the end of the ediff. I prefer it as follows. -- trb

; prevent accidental editing of files in darcs repository
(add-hook 'find-file-hooks 'label-darcs-file-with-warning)
;; warn against accidental writing to a _darcs file
(add-hook 'write-file-hooks 'warn-writing-darcs-file)
; affix a warning label to any _darcs file buffer
(defun label-darcs-file-with-warning()
  (let ((f (buffer-file-name (current-buffer))))
    (and f (string-match "_darcs" f)
         (rename-buffer (concat "_DARCS-FILE:" (buffer-name)) t))))
; prevent accidental writing of files in darcs repository
(defun warn-writing-darcs-file()
  (let ((f (buffer-file-name (current-buffer))))
    (and f (string-match "_darcs" f)
         (if (not (y-or-n-p "WARNING: YOU ARE ABOUT TO WRITE TO an _darcs file, are you sure you want to do this? "))
           (keyboard-quit)))))

There is a general facility for preventing unintentional writes at http://www.loveshack.ukfsn.org/emacs/protect-files.el.


Wishlists

People have created wishlists of what an "ideal" darcs mode for emacs would require.

DarcsWiki: CategoryEmacs (last edited 2008-09-22 16:22:42 by Simon Michael)