(rmail-reply): Don't forget to narrow header in
[bpt/emacs.git] / lisp / log-edit.el
index 1631a7c..6a4b316 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/10/24 11:27:41 fx Exp $
+;; Revision: $Id: log-edit.el,v 1.15 2001/03/07 00:26:25 monnier Exp $
 
 ;; This file is part of GNU Emacs.
 
     ("\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
             (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
@@ -110,7 +126,7 @@ 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
@@ -143,31 +159,40 @@ 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.
 \\<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 editing version-control log messages.
@@ -196,8 +221,8 @@ If you want to abort the commit, simply delete the buffer."
   (when (equal (char-after) ?\n) (forward-char 1))
   (delete-region (point) (point-max))
   ;; Check for final newline
-  (if (and (> (point-max) 1)
-          (/= (char-after (1- (point-max))) ?\n)
+  (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
@@ -207,10 +232,8 @@ If you want to abort the commit, simply delete the buffer."
        (goto-char (point-max))
        (insert ?\n)))
   (let ((comment (buffer-string)))
-    (when (and (boundp 'vc-comment-ring)
-              (ring-p vc-comment-ring)
-              (not (ring-empty-p vc-comment-ring))
-              (not (equal comment (ring-ref vc-comment-ring 0))))
+    (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
@@ -223,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 ()
@@ -247,7 +269,7 @@ To select default log text, we:
 - use those paragraphs as the log text."
   (interactive)
   (log-edit-insert-changelog-entries (log-edit-files))
-  (log-edit-delete-common-indentation)
+  (log-edit-set-common-indentation)
   (goto-char (point-min))
   (when (looking-at "\\*\\s-+")
     (forward-line 1)
@@ -266,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))
@@ -275,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
@@ -469,7 +497,4 @@ Sort REGIONS front-to-back first."
 
 (provide 'log-edit)
 
-;;; Change Log:
-;; $log$
-
 ;;; log-edit.el ends here