]> code.delx.au - gnu-emacs/blobdiff - lisp/log-edit.el
(tildify-ignored-environments-alist): Recognize \verb* right.
[gnu-emacs] / lisp / log-edit.el
index 6b238835a9cc7548accd7e5dfc4fcba1b40483b1..6a4b316e8e13e8f30f26b75417a2be7f5217c6a3 100644 (file)
@@ -1,11 +1,10 @@
 ;;; log-edit.el --- Major mode for editing CVS commit messages
 
-;; Copyright (C) 1999-2000  Free Software Foundation, Inc.
+;; Copyright (C) 19992000  Free Software Foundation, Inc.
 
 ;; Author: Stefan Monnier <monnier@cs.yale.edu>
 ;; Keywords: pcl-cvs cvs commit log
-;; Version: $Name:  $
-;; Revision: $Id: log-edit.el,v 1.8 2000/03/05 21:32:21 monnier Exp $
+;; Revision: $Id: log-edit.el,v 1.15 2001/03/07 00:26:25 monnier Exp $
 
 ;; This file is part of GNU Emacs.
 
 
 ;; Todo:
 
-;; - Remove a single leading `* <file>' in log-edit-insert-changelog
 ;; - Move in VC's code
 ;; - Add compatibility for VC's hook variables
-;; - add compatibility with cvs-edit.el
 
 ;;; Code:
 
 ;;;; 
 
 (defgroup log-edit nil
-  "Major mode for editing commit messages for PCL-CVS."
+  "Major mode for editing RCS and CVS commit messages."
   :group 'pcl-cvs
+  :group 'vc                           ; It's used by VC.
+  :version "21.1"
   :prefix "log-edit-")
 
 ;; compiler pacifiers
     ("\C-c\C-a" . log-edit-insert-changelog)
     ("\C-c\C-f" . log-edit-show-files)
     ("\C-c?" . log-edit-mode-help))
-  "Keymap for the `log-edit-mode' (used when editing cvs log messages)."
+  "Keymap for the `log-edit-mode' (to edit version control log messages)."
   :group 'log-edit
-  :inherit (if (boundp 'vc-log-entry-mode) vc-log-entry-mode))
-
-(defcustom log-edit-confirm t
+  :inherit (if (boundp 'vc-log-entry-mode) vc-log-entry-mode
+            (if (boundp 'vc-log-mode-map) vc-log-mode-map)))
+
+(easy-menu-define log-edit-menu log-edit-mode-map
+  "Menu used for `log-edit-mode'."
+  '("Log-Edit"
+    ["Done" log-edit-done
+     :help "Exit log-edit and proceed with the actual action."]
+    "--"
+    ["Insert ChangeLog" log-edit-insert-changelog]
+    ["Add to ChangeLog" log-edit-add-to-changelog]
+    "--"
+    ["List files" log-edit-show-files
+     :help "Show the list of relevant files."]
+    "--"
+    ["Previous comment" vc-previous-comment]
+    ["Next comment" vc-next-comment]
+    ["Search comment forward" vc-comment-search-forward]
+    ["Search comment backward" vc-comment-search-reverse]))
+
+(defcustom log-edit-confirm 'changed
   "*If non-nil, `log-edit-done' will request confirmation.
 If 'changed, only request confirmation if the list of files has
   changed since the beginning of the log-edit session."
@@ -97,7 +114,7 @@ If SETUP is 'force, this variable has no effect."
   :type '(hook :options (log-edit-insert-cvs-template
                         log-edit-insert-changelog)))
 
-(defcustom log-edit-mode-hook nil
+(defcustom log-edit-mode-hook (if (boundp 'vc-log-mode-hook) vc-log-mode-hook)
   "*Hook run when entering `log-edit-mode'."
   :group 'log-edit
   :type 'hook)
@@ -109,11 +126,14 @@ conventions, or to allow recording the message in some other database,
 such as a bug-tracking system.  The list of files about to be committed
 can be obtained from `log-edit-files'."
   :group 'log-edit
-  :type '(hook :options (log-edit-delete-common-indentation
+  :type '(hook :options (log-edit-set-common-indentation
                         log-edit-add-to-changelog)))
 
 (defvar cvs-changelog-full-paragraphs t
-  "*If non-nil, include full ChangeLog paragraphs in the CVS log.
+  "Obsolete, use `log-edit-changelog-full-paragraphs'.")
+
+(defvar log-edit-changelog-full-paragraphs cvs-changelog-full-paragraphs
+  "*If non-nil, include full ChangeLog paragraphs in the log.
 This may be set in the ``local variables'' section of a ChangeLog, to
 indicate the policy for that ChangeLog.
 
@@ -122,15 +142,15 @@ a paragraph usually describes a set of changes with a single purpose,
 but perhaps spanning several functions in several files.  Changes in
 different paragraphs are unrelated.
 
-You could argue that the CVS log entry for a file should contain the
+You could argue that the log entry for a file should contain the
 full ChangeLog paragraph mentioning the change to the file, even though
 it may mention other files, because that gives you the full context you
 need to understand the change.  This is the behaviour you get when this
 variable is set to t.
 
-On the other hand, you could argue that the CVS log entry for a change
+On the other hand, you could argue that the log entry for a change
 should contain only the text for the changes which occurred in that
-file, because the CVS log is per-file.  This is the behaviour you get
+file, because the log is per-file.  This is the behaviour you get
 when this variable is set to nil.")
 
 ;;;; Internal global or buffer-local vars
@@ -139,40 +159,51 @@ when this variable is set to nil.")
 (defvar log-edit-initial-files nil)
 (defvar log-edit-callback nil)
 (defvar log-edit-listfun nil)
+(defvar log-edit-parent-buffer nil)
 
-;;;
-;;;; Actual code
-;;;
+;;;
+;;; Actual code
+;;;
 
 ;;;###autoload
-(defun log-edit (callback &optional setup listfun &rest ignore)
+(defun log-edit (callback &optional setup listfun buffer &rest ignore)
   "Setup a buffer to enter a log message.
-The buffer will be put in `log-edit-mode'.
+\\<log-edit-mode-map>The buffer will be put in `log-edit-mode'.
 If SETUP is non-nil, the buffer is then erased and `log-edit-hook' is run.
 Mark and point will be set around the entire contents of the
 buffer so that it is easy to kill the contents of the buffer with \\[kill-region].
 Once you're done editing the message, pressing \\[log-edit-done] will call
-`log-edit-done' which will end up calling CALLBACK to do the actual commit."
-  (when (and log-edit-setup-invert (not (eq setup 'force)))
-    (setq setup (not setup)))
-  (when setup (erase-buffer))
-  (log-edit-mode)
-  (set (make-local-variable 'log-edit-callback) callback)
-  (set (make-local-variable 'log-edit-listfun) listfun)
-  (when setup (run-hooks 'log-edit-hook))
-  (goto-char (point-min)) (push-mark (point-max))
-  (set (make-local-variable 'log-edit-initial-files) (log-edit-files))
-  (message (substitute-command-keys
-           "Press \\[log-edit-done] when you are done editing.")))
+`log-edit-done' which will end up calling CALLBACK to do the actual commit.
+LISTFUN if non-nil is a function of no arguments returning the list of files
+  that are concerned by the current operation (using relative names).
+If BUFFER is non-nil `log-edit' will jump to that buffer, use it to edit the
+  log message and go back to the current buffer when done.  Otherwise, it
+  uses the current buffer."
+  (let ((parent (current-buffer)))
+    (if buffer (pop-to-buffer buffer))
+    (when (and log-edit-setup-invert (not (eq setup 'force)))
+      (setq setup (not setup)))
+    (when setup (erase-buffer))
+    (log-edit-mode)
+    (set (make-local-variable 'log-edit-callback) callback)
+    (set (make-local-variable 'log-edit-listfun) listfun)
+    (if buffer (set (make-local-variable 'log-edit-parent-buffer) parent))
+    (when setup (run-hooks 'log-edit-hook))
+    (goto-char (point-min)) (push-mark (point-max))
+    (set (make-local-variable 'log-edit-initial-files) (log-edit-files))
+    (message (substitute-command-keys
+             "Press \\[log-edit-done] when you are done editing."))))
 
 (define-derived-mode log-edit-mode text-mode "Log-Edit"
-  "Major mode for entering commit messages.
-This mode is intended for entering messages in a *cvs-commit*
-buffer when using PCL-CVS.  It provides a binding for the
-\\[log-edit-done] command that should be used when done editing
-to trigger the actual commit, as well as a few handy support
-commands.
-\\{log-edit-mode-map}")
+  "Major mode for editing version-control log messages.
+When done editing the log entry, just type \\[log-edit-done] which
+will trigger the actual commit of the file(s).
+Several other handy support commands are provided of course and
+the package from which this is used might also provide additional
+commands (under C-x v for VC, for example).
+
+\\{log-edit-mode-map}"
+  (make-local-variable 'vc-comment-ring-index))
 
 (defun log-edit-hide-buf (&optional buf where)
   (when (setq buf (get-buffer (or buf log-edit-files-buf)))
@@ -182,12 +213,16 @@ commands.
 
 (defun log-edit-done ()
   "Finish editing the log message and commit the files.
-This can only be used in the *cvs-commit* buffer.
-With a prefix argument, prompt for cvs commit flags.
 If you want to abort the commit, simply delete the buffer."
   (interactive)
-  (if (and (> (point-max) 1)
-          (/= (char-after (1- (point-max))) ?\n)
+  ;; Get rid of trailing empty lines
+  (goto-char (point-max))
+  (skip-syntax-backward " ")
+  (when (equal (char-after) ?\n) (forward-char 1))
+  (delete-region (point) (point-max))
+  ;; Check for final newline
+  (if (and (> (point-max) (point-min))
+          (/= (char-before (point-max)) ?\n)
           (or (eq log-edit-require-final-newline t)
               (and log-edit-require-final-newline
                    (y-or-n-p
@@ -196,7 +231,10 @@ If you want to abort the commit, simply delete the buffer."
       (save-excursion
        (goto-char (point-max))
        (insert ?\n)))
-  (if (boundp 'vc-comment-ring) (ring-insert vc-comment-ring (buffer-string)))
+  (let ((comment (buffer-string)))
+    (when (or (ring-empty-p vc-comment-ring)
+             (not (equal comment (ring-ref vc-comment-ring 0))))
+      (ring-insert vc-comment-ring comment)))
   (let ((win (get-buffer-window log-edit-files-buf)))
     (if (and log-edit-confirm
             (not (and (eq log-edit-confirm 'changed)
@@ -208,9 +246,8 @@ If you want to abort the commit, simply delete the buffer."
               (message "Oh, well!  Later maybe?"))
       (run-hooks 'log-edit-done-hook)
       (log-edit-hide-buf)
-      (unless log-edit-keep-buffer
-       (cvs-bury-buffer (current-buffer)
-                        (when (boundp 'cvs-buffer) cvs-buffer)))
+      (unless (or log-edit-keep-buffer (not log-edit-parent-buffer))
+       (cvs-bury-buffer (current-buffer) log-edit-parent-buffer))
       (call-interactively log-edit-callback))))
 
 (defun log-edit-files ()
@@ -231,8 +268,16 @@ To select default log text, we:
   the files we're checking in, and finally
 - use those paragraphs as the log text."
   (interactive)
-  (cvs-insert-changelog-entries (log-edit-files))
-  (log-edit-delete-common-indentation))
+  (log-edit-insert-changelog-entries (log-edit-files))
+  (log-edit-set-common-indentation)
+  (goto-char (point-min))
+  (when (looking-at "\\*\\s-+")
+    (forward-line 1)
+    (when (not (re-search-forward "^\\*\\s-+" nil t))
+      (goto-char (point-min))
+      (skip-chars-forward "^():")
+      (skip-chars-forward ": ")
+      (delete-region (point-min) (point)))))
 
 (defun log-edit-mode-help ()
   "Provide help for the `log-edit-mode-map'."
@@ -243,8 +288,13 @@ To select default log text, we:
      (substitute-command-keys
       "Type `\\[log-edit-done]' to finish commit.  Try `\\[describe-function] log-edit-done' for more help."))))
 
-(defun log-edit-delete-common-indentation ()
-  "Unindent the current buffer rigidly until at least one line is flush left."
+(defcustom log-edit-common-indent 0
+  "Minimum indentation to use in `log-edit-set-common-indentation'."
+  :group 'log-edit
+  :type 'integer)
+
+(defun log-edit-set-common-indentation ()
+  "(Un)Indent the current buffer rigidly to `log-edit-common-indent'."
   (save-excursion
     (let ((common (point-max)))
       (goto-char (point-min))
@@ -252,19 +302,20 @@ To select default log text, we:
         (if (not (looking-at "^[ \t]*$"))
             (setq common (min common (current-indentation))))
         (forward-line 1))
-      (indent-rigidly (point-min) (point-max) (- common)))))
+      (indent-rigidly (point-min) (point-max)
+                     (- log-edit-common-indent common)))))
 
 (defun log-edit-show-files ()
   "Show the list of files to be committed."
   (interactive)
   (let* ((files (log-edit-files))
         (editbuf (current-buffer))
-        (buf (get-buffer-create "*log-edit-files*")))
+        (buf (get-buffer-create log-edit-files-buf)))
     (with-current-buffer buf
       (log-edit-hide-buf buf 'all)
       (setq buffer-read-only nil)
       (erase-buffer)
-      (insert (mapconcat 'identity files "\n"))
+      (cvs-insert-strings files)
       (setq buffer-read-only t)
       (goto-char (point-min))
       (save-selected-window
@@ -295,12 +346,12 @@ To select default log text, we:
 ;;;; Courtesy Jim Blandy
 ;;;; 
 
-(defun cvs-narrow-changelog ()
+(defun log-edit-narrow-changelog ()
   "Narrow to the top page of the current buffer, a ChangeLog file.
 Actually, the narrowed region doesn't include the date line.
 A \"page\" in a ChangeLog file is the area between two dates."
   (or (eq major-mode 'change-log-mode)
-      (error "cvs-narrow-changelog: current buffer isn't a ChangeLog"))
+      (error "log-edit-narrow-changelog: current buffer isn't a ChangeLog"))
 
   (goto-char (point-min))
 
@@ -314,7 +365,7 @@ A \"page\" in a ChangeLog file is the area between two dates."
     (narrow-to-region start (point))
     (goto-char (point-min))))
 
-(defun cvs-changelog-paragraph ()
+(defun log-edit-changelog-paragraph ()
   "Return the bounds of the ChangeLog paragraph containing point.
 If we are between paragraphs, return the previous paragraph."
   (save-excursion
@@ -329,7 +380,7 @@ If we are between paragraphs, return the previous paragraph."
               (match-beginning 0)
             (point)))))
 
-(defun cvs-changelog-subparagraph ()
+(defun log-edit-changelog-subparagraph ()
   "Return the bounds of the ChangeLog subparagraph containing point.
 A subparagraph is a block of non-blank lines beginning with an asterisk.
 If we are between sub-paragraphs, return the previous subparagraph."
@@ -337,25 +388,25 @@ If we are between sub-paragraphs, return the previous subparagraph."
     (end-of-line)
     (if (search-backward "*" nil t)
         (list (progn (beginning-of-line) (point))
-              (progn 
+              (progn
                 (forward-line 1)
                 (if (re-search-forward "^[ \t]*[\n*]" nil t)
                     (match-beginning 0)
                   (point-max))))
       (list (point) (point)))))
 
-(defun cvs-changelog-entry ()
+(defun log-edit-changelog-entry ()
   "Return the bounds of the ChangeLog entry containing point.
-The variable `cvs-changelog-full-paragraphs' decides whether an
+The variable `log-edit-changelog-full-paragraphs' decides whether an
 \"entry\" is a paragraph or a subparagraph; see its documentation string
 for more details."
-  (if cvs-changelog-full-paragraphs
-      (cvs-changelog-paragraph)
-    (cvs-changelog-subparagraph)))
+  (if log-edit-changelog-full-paragraphs
+      (log-edit-changelog-paragraph)
+    (log-edit-changelog-subparagraph)))
 
 (defvar user-full-name)
 (defvar user-mail-address)
-(defun cvs-changelog-ours-p ()
+(defun log-edit-changelog-ours-p ()
   "See if ChangeLog entry at point is for the current user, today.
 Return non-nil iff it is."
   ;; Code adapted from add-change-log-entry.
@@ -371,14 +422,14 @@ Return non-nil iff it is."
                  (format-time-string "%Y-%m-%d"))))
     (looking-at (regexp-quote (format "%s  %s  <%s>" time name mail)))))
 
-(defun cvs-changelog-entries (file)
+(defun log-edit-changelog-entries (file)
   "Return the ChangeLog entries for FILE, and the ChangeLog they came from.
 The return value looks like this:
   (LOGBUFFER (ENTRYSTART . ENTRYEND) ...)
 where LOGBUFFER is the name of the ChangeLog buffer, and each
 \(ENTRYSTART . ENTRYEND\) pair is a buffer region."
   (save-excursion
-    (let ((changelog-file-name 
+    (let ((changelog-file-name
           (let ((default-directory
                   (file-name-directory (expand-file-name file))))
             ;; `find-change-log' uses `change-log-default-name' if set
@@ -390,10 +441,10 @@ where LOGBUFFER is the name of the ChangeLog buffer, and each
       (unless (eq major-mode 'change-log-mode) (change-log-mode))
       (goto-char (point-min))
       (if (looking-at "\\s-*\n") (goto-char (match-end 0)))
-      (if (not (cvs-changelog-ours-p))
+      (if (not (log-edit-changelog-ours-p))
          (list (current-buffer))
        (save-restriction
-         (cvs-narrow-changelog)
+         (log-edit-narrow-changelog)
          (goto-char (point-min))
          
          ;; Search for the name of FILE relative to the ChangeLog.  If that
@@ -409,13 +460,13 @@ where LOGBUFFER is the name of the ChangeLog buffer, and each
 
            (let (texts)
              (while (search-forward pattern nil t)
-               (let ((entry (cvs-changelog-entry)))
+               (let ((entry (log-edit-changelog-entry)))
                  (push entry texts)
                  (goto-char (elt entry 1))))
 
              (cons (current-buffer) texts))))))))
 
-(defun cvs-changelog-insert-entries (buffer regions)
+(defun log-edit-changelog-insert-entries (buffer regions)
   "Insert those regions in BUFFER specified in REGIONS.
 Sort REGIONS front-to-back first."
   (let ((regions (sort regions 'car-less-than-car))
@@ -425,14 +476,14 @@ Sort REGIONS front-to-back first."
       (setq last (elt region 1))
       (apply 'insert-buffer-substring buffer region))))
 
-(defun cvs-insert-changelog-entries (files)
+(defun log-edit-insert-changelog-entries (files)
   "Given a list of files FILES, insert the ChangeLog entries for them."
   (let ((buffer-entries nil))
 
     ;; Add each buffer to buffer-entries, and associate it with the list
     ;; of entries we want from that file.
     (dolist (file files)
-      (let* ((entries (cvs-changelog-entries file))
+      (let* ((entries (log-edit-changelog-entries file))
              (pair (assq (car entries) buffer-entries)))
         (if pair
             (setcdr pair (cvs-union (cdr pair) (cdr entries)))
@@ -441,8 +492,9 @@ Sort REGIONS front-to-back first."
     ;; Now map over each buffer in buffer-entries, sort the entries for
     ;; each buffer, and extract them as strings.
     (dolist (buffer-entry buffer-entries)
-      (cvs-changelog-insert-entries (car buffer-entry) (cdr buffer-entry))
+      (log-edit-changelog-insert-entries (car buffer-entry) (cdr buffer-entry))
       (when (cdr buffer-entry) (newline)))))
 
 (provide 'log-edit)
+
 ;;; log-edit.el ends here