X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/d90216747705a08fbf8407eac95143c0265e0514..6bd677fa1b7f574b1610fc874ef8117a96b7b3ea:/lisp/emerge.el diff --git a/lisp/emerge.el b/lisp/emerge.el index 250df827d1..023727e26b 100644 --- a/lisp/emerge.el +++ b/lisp/emerge.el @@ -2,7 +2,7 @@ ;;; The author has placed this file in the public domain. -;; Author: Dale R. Worley +;; Author: Dale R. Worley ;; Version: 5fsf ;; Keywords: unix, tools @@ -28,25 +28,25 @@ ;;;###autoload (define-key menu-bar-emerge-menu [emerge-merge-directories] - '("Merge Directories ..." . emerge-merge-directories)) + '("Merge Directories..." . emerge-merge-directories)) ;;;###autoload (define-key menu-bar-emerge-menu [emerge-revisions-with-ancestor] - '("Revisions with Ancestor ..." . emerge-revisions-with-ancestor)) + '("Revisions with Ancestor..." . emerge-revisions-with-ancestor)) ;;;###autoload (define-key menu-bar-emerge-menu [emerge-revisions] - '("Revisions ..." . emerge-revisions)) + '("Revisions..." . emerge-revisions)) ;;;###autoload (define-key menu-bar-emerge-menu [emerge-files-with-ancestor] - '("Files with Ancestor ..." . emerge-files-with-ancestor)) + '("Files with Ancestor..." . emerge-files-with-ancestor)) ;;;###autoload (define-key menu-bar-emerge-menu [emerge-files] - '("Files ..." . emerge-files)) + '("Files..." . emerge-files)) ;;;###autoload (define-key menu-bar-emerge-menu [emerge-buffers-with-ancestor] - '("Buffers with Ancestor ..." . emerge-buffers-with-ancestor)) + '("Buffers with Ancestor..." . emerge-buffers-with-ancestor)) ;;;###autoload (define-key menu-bar-emerge-menu [emerge-buffers] - '("Buffers ..." . emerge-buffers)) + '("Buffers..." . emerge-buffers)) ;;; Macros @@ -113,6 +113,10 @@ When called interactively, displays the version." ;;; 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 @@ -124,69 +128,102 @@ When called interactively, displays the version." ;; 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.") @@ -246,27 +283,26 @@ depend on the flags." ;; 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 (getenv "TMPDIR")) - 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 @@ -274,7 +310,9 @@ The template is inserted as a string, with the following interpolations: %% 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 @@ -296,9 +334,11 @@ Makes Emerge commands directly available.") (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. @@ -851,17 +891,16 @@ This is *not* a user option, since Emerge uses it for its own processing.") (let (f) (list current-prefix-arg (setq f (emerge-read-file-name "File A to merge" emerge-last-dir-A - nil nil)) - (emerge-read-file-name "File B to merge" emerge-last-dir-B nil f) + nil nil t)) + (emerge-read-file-name "File B to merge" emerge-last-dir-B nil f t) (and current-prefix-arg (emerge-read-file-name "Output file" emerge-last-dir-output - f f))))) + 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 @@ -872,19 +911,18 @@ This is *not* a user option, since Emerge uses it for its own processing.") (let (f) (list current-prefix-arg (setq f (emerge-read-file-name "File A to merge" emerge-last-dir-A - nil nil)) - (emerge-read-file-name "File B to merge" emerge-last-dir-B nil f) + nil nil t)) + (emerge-read-file-name "File B to merge" emerge-last-dir-B nil f t) (emerge-read-file-name "Ancestor file" emerge-last-dir-ancestor - nil f) + nil f t) (and current-prefix-arg (emerge-read-file-name "Output file" emerge-last-dir-output - f f))))) + 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. @@ -1247,8 +1285,10 @@ Otherwise, the A or B file present is copied to the output file." ;;; 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) @@ -1554,8 +1594,8 @@ With an argument, reestablish the default three-window display." (let* ((merge-buffer emerge-merge-buffer) (buffer-A emerge-A-buffer) (buffer-B emerge-B-buffer) - (window-A (get-buffer-window buffer-A)) - (window-B (get-buffer-window buffer-B)) + (window-A (get-buffer-window buffer-A 'visible)) + (window-B (get-buffer-window buffer-B 'visible)) (merge-window (get-buffer-window merge-buffer)) (diff-vector (aref emerge-difference-list emerge-current-difference))) @@ -1599,8 +1639,8 @@ With an argument, reestablish the default three-window display." (let* ((merge-buffer emerge-merge-buffer) (buffer-A emerge-A-buffer) (buffer-B emerge-B-buffer) - (window-A (get-buffer-window buffer-A)) - (window-B (get-buffer-window buffer-B)) + (window-A (get-buffer-window buffer-A 'visible)) + (window-B (get-buffer-window buffer-B 'visible)) (merge-window (get-buffer-window merge-buffer))) (if window-A (progn (select-window window-A) @@ -1739,7 +1779,7 @@ to the left margin, if they are in windows." ;; If there are min-lines lines above and below the region, then don't do ;; anything. ;; If not, recenter the region to make it so. -;; If that isn't possible, remove context lines balancedly from top and botton +;; If that isn't possible, remove context lines balancedly from top and bottom ;; so the entire region shows. ;; If that isn't possible, show the top of the region. ;; BEG must be at the beginning of a line. @@ -1978,8 +2018,7 @@ need not be prefixed with \\\\[emerge-basic-keymap]." (setq emerge-fast-mode t) (setq emerge-edit-mode nil) (message "Fast mode set") - ;; force mode line redisplay - (set-buffer-modified-p (buffer-modified-p))) + (force-mode-line-update)) (defun emerge-edit-mode () "Set edit mode, for Emerge. @@ -1992,8 +2031,7 @@ must be prefixed with \\\\[emerge-basic-keymap]." (setq emerge-fast-mode nil) (setq emerge-edit-mode t) (message "Edit mode set") - ;; force mode line redisplay - (set-buffer-modified-p (buffer-modified-p))) + (force-mode-line-update)) (defun emerge-auto-advance (arg) "Toggle Auto-Advance mode, for Emerge. @@ -2005,11 +2043,10 @@ With a negative argument, turn off Auto-Advance mode." (setq emerge-auto-advance (if (null arg) (not emerge-auto-advance) (> (prefix-numeric-value arg) 0))) - (message (if emerge-skip-prefers + (message (if emerge-auto-advance "Auto-advance set" "Auto-advance cleared")) - ;; force mode line redisplay - (set-buffer-modified-p (buffer-modified-p))) + (force-mode-line-update)) (defun emerge-skip-prefers (arg) "Toggle Skip-Prefers mode, for Emerge. @@ -2024,8 +2061,7 @@ With a negative argument, turn off Skip-Prefers mode." (message (if emerge-skip-prefers "Skip-prefers set" "Skip-prefers cleared")) - ;; force mode line redisplay - (set-buffer-modified-p (buffer-modified-p))) + (force-mode-line-update)) (defun emerge-copy-as-kill-A () "Put the A variant of this difference in the kill ring." @@ -2146,7 +2182,10 @@ Use C-u l to reset the windows afterward." (princ "Ancestor buffer is: ") (princ (buffer-name)))) (princ "\n"))) - (princ emerge-output-description)))) + (princ emerge-output-description) + (save-excursion + (set-buffer standard-output) + (help-mode))))) (defun emerge-join-differences (arg) "Join the selected difference with the following one. @@ -2732,7 +2771,7 @@ keymap. Leaves merge in fast mode." ;; Read a file name, handling all of the various defaulting rules. (defun emerge-read-file-name (prompt alternative-default-dir default-file - A-file) + A-file must-match) ;; `prompt' should not have trailing ": ", so that it can be modified ;; according to context. ;; If alternative-default-dir is non-nil, it should be used as the default @@ -2760,7 +2799,7 @@ keymap. Leaves merge in fast mode." alternative-default-dir (concat alternative-default-dir (file-name-nondirectory A-file)) - 'confirm)) + (and must-match 'confirm))) ;; If there is a default file, use it. (default-file (read-file-name (format "%s (default %s): " prompt default-file) @@ -2769,7 +2808,7 @@ keymap. Leaves merge in fast mode." ;; Emerge as the default for this argument. (and emerge-default-last-directories alternative-default-dir) - default-file 'confirm)) + default-file (and must-match 'confirm))) (t (read-file-name (concat prompt ": ") ;; If emerge-default-last-directories is set, use the @@ -2777,7 +2816,7 @@ keymap. Leaves merge in fast mode." ;; Emerge as the default for this argument. (and emerge-default-last-directories alternative-default-dir) - nil 'confirm)))) + nil (and must-match 'confirm))))) ;; Revise the mode line to display which difference we have selected @@ -2798,8 +2837,7 @@ keymap. Leaves merge in fast mode." (prefer-B . " - B*") (combined . " - comb")))) "")))) - ;; Force mode-line redisplay - (set-buffer-modified-p (buffer-modified-p))) + (force-mode-line-update)) ;; compare two regions in two buffers for containing the same text (defun emerge-compare-buffers (buffer-x x-begin x-end buffer-y y-begin y-end) @@ -2847,7 +2885,7 @@ keymap. Leaves merge in fast mode." ;; a list of variables. The argument is a list of symbols (the names of ;; the variables). A list element can also be a list of two functions, ;; the first of which (when called with no arguments) gets the value, and -;; the second (when called with a value as an argment) sets the value. +;; the second (when called with a value as an argument) sets the value. ;; A "function" is anything that funcall can handle as an argument. (defun emerge-save-variables (vars) @@ -2987,6 +3025,9 @@ If some prefix of KEY has a non-prefix definition, it is redefined." ;; minor-mode indicator)) ;; (princ (documentation minor-mode))))) ;; (setq minor-modes (cdr minor-modes)))) +;; (save-excursion +;; (set-buffer standard-output) +;; (help-mode)) ;; (print-help-return-message))) ;; This goes with the redefinition of describe-mode. @@ -3153,9 +3194,11 @@ See also `auto-save-file-name-p'." ;; 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)