Function: emerge-execute-line
emerge-execute-line is an interactive and byte-compiled function
defined in emerge.el.gz.
Signature
(emerge-execute-line)
Documentation
Run Emerge using files named in current text line.
Looks in that line for whitespace-separated entries of these forms:
a=file1
b=file2
ancestor=file3
output=file4
to specify the files to use in Emerge.
In addition, if only one of a=file or b=file is present, and output=file
is present:
If emerge-execute-line-deletions is non-nil and ancestor=file is present,
it is assumed that the file in question has been deleted, and it is
not copied to the output file.
Otherwise, the A or B file present is copied to the output file.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/vc/emerge.el.gz
;;; Function to start Emerge based on a line in a file
(defun emerge-execute-line ()
"Run Emerge using files named in current text line.
Looks in that line for whitespace-separated entries of these forms:
a=file1
b=file2
ancestor=file3
output=file4
to specify the files to use in Emerge.
In addition, if only one of `a=file' or `b=file' is present, and `output=file'
is present:
If `emerge-execute-line-deletions' is non-nil and `ancestor=file' is present,
it is assumed that the file in question has been deleted, and it is
not copied to the output file.
Otherwise, the A or B file present is copied to the output file."
(interactive)
(let (file-A file-B file-ancestor file-out
(case-fold-search t))
;; Stop if at end of buffer (even though we might be in a line, if
;; the line does not end with newline)
(if (eobp)
(error "At end of buffer"))
;; Go to the beginning of the line
(beginning-of-line)
;; Skip any initial whitespace
(if (looking-at "[ \t]*")
(goto-char (match-end 0)))
;; Process the entire line
(while (not (eolp))
;; Get the next entry
(if (looking-at "\\([a-z]+\\)=\\([^ \t\n]+\\)[ \t]*")
;; Break apart the tab (before =) and the filename (after =)
(let ((tag (downcase
(buffer-substring (match-beginning 1) (match-end 1))))
(file (buffer-substring (match-beginning 2) (match-end 2))))
;; Move point after the entry
(goto-char (match-end 0))
;; Store the filename in the right variable
(cond
((string-equal tag "a")
(if file-A
(error "This line has two `A' entries"))
(setq file-A file))
((string-equal tag "b")
(if file-B
(error "This line has two `B' entries"))
(setq file-B file))
((or (string-equal tag "anc") (string-equal tag "ancestor"))
(if file-ancestor
(error "This line has two `ancestor' entries"))
(setq file-ancestor file))
((or (string-equal tag "out") (string-equal tag "output"))
(if file-out
(error "This line has two `output' entries"))
(setq file-out file))
(t
(error "Unrecognized entry"))))
;; If the match on the entry pattern failed
(error "Unparsable entry")))
;; Make sure that file-A and file-B are present
(if (not (or (and file-A file-B) file-out))
(error "Must have both `A' and `B' entries"))
(if (not (or file-A file-B))
(error "Must have `A' or `B' entry"))
;; Go to the beginning of the next line, so next execution will use
;; next line in buffer.
(beginning-of-line 2)
;; Execute the correct command
(cond
;; Merge of two files with ancestor
((and file-A file-B file-ancestor)
(message "Merging %s and %s..." file-A file-B)
(emerge-files-with-ancestor (not (not file-out)) file-A file-B
file-ancestor file-out
nil
;; When done, return to this buffer.
(let ((buf (current-buffer)))
(list (lambda ()
(switch-to-buffer buf)
(message "Merge done"))))))
;; Merge of two files without ancestor
((and file-A file-B)
(message "Merging %s and %s..." file-A file-B)
(emerge-files (not (not file-out)) file-A file-B file-out
nil
;; When done, return to this buffer.
(let ((buf (current-buffer)))
(list (lambda ()
(switch-to-buffer buf)
(message "Merge done"))))))
;; There is an output file (or there would have been an error above),
;; but only one input file.
;; The file appears to have been deleted in one version; do nothing.
((and file-ancestor emerge-execute-line-deletions)
(message "No action."))
;; The file should be copied from the version that contains it
(t (let ((input-file (or file-A file-B)))
(message "Copying...")
(copy-file input-file file-out)
(message "%s copied to %s." input-file file-out))))))