;;; Emerge configuration variables
+(defgroup emerge nil
+ "Merge diffs under Emacs control."
+ :group 'tools)
+
;; Commands that produce difference files
;; All that can be configured is the name of the programs to execute
;; (emerge-diff-program and emerge-diff3-program) and the options
;; The code which processes the diff/diff3 output depends on all the
;; finicky details of their output, including the somewhat strange
;; way they number lines of a file.
-(defvar emerge-diff-program "diff"
- "*Name of the program which compares two files.")
-(defvar emerge-diff3-program "diff3"
+(defcustom emerge-diff-program "diff"
+ "*Name of the program which compares two files."
+ :type 'string
+ :group 'emerge)
+(defcustom emerge-diff3-program "diff3"
"*Name of the program which compares three files.
-Its arguments are the ancestor file and the two variant files.")
-(defvar emerge-diff-options ""
- "*Options to pass to `emerge-diff-program' and `emerge-diff3-program'.")
-(defvar emerge-match-diff-line (let ((x "\\([0-9]+\\)\\(\\|,\\([0-9]+\\)\\)"))
- (concat "^" x "\\([acd]\\)" x "$"))
+Its arguments are the ancestor file and the two variant files."
+ :type 'string
+ :group 'emerge)
+(defcustom emerge-diff-options ""
+ "*Options to pass to `emerge-diff-program' and `emerge-diff3-program'."
+ :type 'string
+ :group 'emerge)
+(defcustom emerge-match-diff-line
+ (let ((x "\\([0-9]+\\)\\(\\|,\\([0-9]+\\)\\)"))
+ (concat "^" x "\\([acd]\\)" x "$"))
"*Pattern to match lines produced by diff that describe differences.
-This is as opposed to lines from the source files.")
-(defvar emerge-diff-ok-lines-regexp
+This is as opposed to lines from the source files."
+ :type 'regexp
+ :group 'emerge)
+(defcustom emerge-diff-ok-lines-regexp
"^\\([0-9,]+[acd][0-9,]+$\\|[<>] \\|---\\)"
"*Regexp that matches normal output lines from `emerge-diff-program'.
-Lines that do not match are assumed to be error messages.")
-(defvar emerge-diff3-ok-lines-regexp
+Lines that do not match are assumed to be error messages."
+ :type 'regexp
+ :group 'emerge)
+(defcustom emerge-diff3-ok-lines-regexp
"^\\([1-3]:\\|====\\| \\)"
"*Regexp that matches normal output lines from `emerge-diff3-program'.
-Lines that do not match are assumed to be error messages.")
-
-(defvar emerge-rcs-ci-program "ci"
- "*Name of the program that checks in RCS revisions.")
-(defvar emerge-rcs-co-program "co"
- "*Name of the program that checks out RCS revisions.")
-
-(defvar emerge-process-local-variables nil
+Lines that do not match are assumed to be error messages."
+ :type 'regexp
+ :group 'emerge)
+
+(defcustom emerge-rcs-ci-program "ci"
+ "*Name of the program that checks in RCS revisions."
+ :type 'string
+ :group 'emerge)
+(defcustom emerge-rcs-co-program "co"
+ "*Name of the program that checks out RCS revisions."
+ :type 'string
+ :group 'emerge)
+
+(defcustom emerge-process-local-variables nil
"*Non-nil if Emerge should process local-variables lists in merge buffers.
\(You can explicitly request processing the local-variables
-by executing `(hack-local-variables)'.)")
-(defvar emerge-execute-line-deletions nil
+by executing `(hack-local-variables)'.)"
+ :type 'boolean
+ :group 'emerge)
+(defcustom emerge-execute-line-deletions nil
"*If non-nil: `emerge-execute-line' makes no output if an input was deleted.
It concludes that an input version has been deleted when an ancestor entry
is present, only one A or B entry is present, and an output entry is present.
If nil: In such circumstances, the A or B file that is present will be
-copied to the designated output file.")
+copied to the designated output file."
+ :type 'boolean
+ :group 'emerge)
-(defvar emerge-before-flag "vvvvvvvvvvvvvvvvvvvv\n"
+(defcustom emerge-before-flag "vvvvvvvvvvvvvvvvvvvv\n"
"*Flag placed above the highlighted block of code. Must end with newline.
Must be set before Emerge is loaded, or emerge-new-flags must be run
-after setting.")
-(defvar emerge-after-flag "^^^^^^^^^^^^^^^^^^^^\n"
+after setting."
+ :type 'string
+ :group 'emerge)
+(defcustom emerge-after-flag "^^^^^^^^^^^^^^^^^^^^\n"
"*Flag placed below the highlighted block of code. Must end with newline.
Must be set before Emerge is loaded, or emerge-new-flags must be run
-after setting.")
+after setting."
+ :type 'string
+ :group 'emerge)
;; Hook variables
-(defvar emerge-startup-hook nil
- "*Hook to run in the merge buffer after the merge has been set up.")
-(defvar emerge-select-hook nil
+(defcustom emerge-startup-hook nil
+ "*Hook to run in the merge buffer after the merge has been set up."
+ :type 'hook
+ :group 'emerge)
+(defcustom emerge-select-hook nil
"*Hook to run after a difference has been selected.
-The variable `n' holds the (internal) number of the difference.")
-(defvar emerge-unselect-hook nil
+The variable `n' holds the (internal) number of the difference."
+ :type 'hook
+ :group 'emerge)
+(defcustom emerge-unselect-hook nil
"*Hook to run after a difference has been unselected.
-The variable `n' holds the (internal) number of the difference.")
+The variable `n' holds the (internal) number of the difference."
+ :type 'hook
+ :group 'emerge)
;; Variables to control the default directories of the arguments to
;; Emerge commands.
-(defvar emerge-default-last-directories nil
+(defcustom emerge-default-last-directories nil
"*If nil, default dir for filenames in emerge is `default-directory'.
If non-nil, filenames complete in the directory of the last argument of the
-same type to an `emerge-files...' command.")
+same type to an `emerge-files...' command."
+ :type 'boolean
+ :group 'emerge)
(defvar emerge-last-dir-A nil
"Last directory for the first file of an `emerge-files...' command.")
;; Calculate dependent variables
(emerge-new-flags)
-(defvar emerge-min-visible-lines 3
+(defcustom emerge-min-visible-lines 3
"*Number of lines that we want to show above and below the flags when we are
-displaying a difference.")
-
-(defvar emerge-temp-file-prefix
- (let ((env (or (getenv "TMPDIR")
- (getenv "TMP")
- (getenv "TEMP")))
- d)
- (setq d (if (and env (> (length env) 0))
- env
- "/tmp"))
- (if (= (aref d (1- (length d))) ?/)
- (setq d (substring d 0 -1)))
- (concat d "/emerge"))
+displaying a difference."
+ :type 'integer
+ :group 'emerge)
+
+(defcustom emerge-temp-file-prefix
+ (expand-file-name "emerge" temporary-file-directory)
"*Prefix to put on Emerge temporary file names.
-Do not start with `~/' or `~user-name/'.")
+Do not start with `~/' or `~USERNAME/'."
+ :type 'string
+ :group 'emerge)
-(defvar emerge-temp-file-mode 384 ; u=rw only
- "*Mode for Emerge temporary files.")
+(defcustom emerge-temp-file-mode 384 ; u=rw only
+ "*Mode for Emerge temporary files."
+ :type 'integer
+ :group 'emerge)
-(defvar emerge-combine-versions-template
- "#ifdef NEW\n%b#else /* NEW */\n%a#endif /* NEW */\n"
+(defcustom emerge-combine-versions-template
+ "#ifdef NEW\n%b#else /* not NEW */\n%a#endif /* not NEW */\n"
"*Template for `emerge-combine-versions' to combine the two versions.
The template is inserted as a string, with the following interpolations:
%a the A version of the difference
%% the character `%'
Don't forget to end the template with a newline.
Note that this variable can be made local to a particular merge buffer by
-giving a prefix argument to `emerge-set-combine-versions-template'.")
+giving a prefix argument to `emerge-set-combine-versions-template'."
+ :type 'string
+ :group 'emerge)
;; Build keymaps
(defvar emerge-move-menu
(make-sparse-keymap "Move"))
-(defvar emerge-command-prefix "\C-c\C-c"
+(defcustom emerge-command-prefix "\C-c\C-c"
"*Command prefix for Emerge commands in `edit' mode.
-Must be set before Emerge is loaded.")
+Must be set before Emerge is loaded."
+ :type 'string
+ :group 'emerge)
;; This function sets up the fixed keymaps. It is executed when the first
;; Emerge is done to allow the user maximum time to set up the global keymap.
(and current-prefix-arg
(emerge-read-file-name "Output file" emerge-last-dir-output
f f nil)))))
+ (if file-out
+ (add-hook 'quit-hooks (` (lambda () (emerge-files-exit (, file-out))))))
(emerge-files-internal
file-A file-B startup-hooks
- (if file-out
- (cons (` (lambda () (emerge-files-exit (, file-out))))
- quit-hooks)
- quit-hooks)
+ quit-hooks
file-out))
;;;###autoload
(and current-prefix-arg
(emerge-read-file-name "Output file" emerge-last-dir-output
f f nil)))))
+ (if file-out
+ (add-hook 'quit-hooks (` (lambda () (emerge-files-exit (, file-out))))))
(emerge-files-with-ancestor-internal
file-A file-B file-ancestor startup-hooks
- (if file-out
- (cons (` (lambda () (emerge-files-exit (, file-out))))
- quit-hooks)
- quit-hooks)
+ quit-hooks
file-out))
;; Write the merge buffer out in place of the file the A buffer is visiting.
;;; Sample function for creating information for emerge-execute-line
-(defvar emerge-merge-directories-filename-regexp "[^.]"
- "Regexp describing files to be processed by `emerge-merge-directories'.")
+(defcustom emerge-merge-directories-filename-regexp "[^.]"
+ "Regexp describing files to be processed by `emerge-merge-directories'."
+ :type 'regexp
+ :group 'emerge)
;;;###autoload
(defun emerge-merge-directories (a-dir b-dir ancestor-dir output-dir)
;; Make a temporary file that only we have access to.
;; PREFIX is appended to emerge-temp-file-prefix to make the filename prefix.
(defun emerge-make-temp-file (prefix)
- (let ((f (make-temp-name (concat emerge-temp-file-prefix prefix))))
- ;; create the file
- (write-region (point-min) (point-min) f nil 'no-message)
- (set-file-modes f emerge-temp-file-mode)
+ (let (f (old-modes (default-file-modes)))
+ (unwind-protect
+ (progn
+ (set-default-file-modes emerge-temp-file-mode)
+ (setq f (make-temp-file (concat emerge-temp-file-prefix prefix))))
+ (set-default-file-modes old-modes))
f))
;;; Functions that query the user before he can write out the current buffer.
;; Metacharacters that have to be protected from the shell when executing
;; a diff/diff3 command.
-(defvar emerge-metachars "[ \t\n!\"#$&'()*;<=>?[\\^`{|~]"
+(defcustom emerge-metachars "[ \t\n!\"#$&'()*;<=>?[\\^`{|~]"
"Characters that must be quoted with \\ when used in a shell command line.
-More precisely, a [...] regexp to match any one such character.")
+More precisely, a [...] regexp to match any one such character."
+ :type 'regexp
+ :group 'emerge)
;; Quote metacharacters (using \) when executing a diff/diff3 command.
(defun emerge-protect-metachars (s)