]> code.delx.au - gnu-emacs/blobdiff - lisp/log-edit.el
Rename `MS-DOG' into `MS-DOS'.
[gnu-emacs] / lisp / log-edit.el
index fa7ea4e842d27ea856457f20d7c110395b137ed2..611bab0a24771393ef3d7493610adbc2a4d23c65 100644 (file)
@@ -1,8 +1,9 @@
 ;;; log-edit.el --- Major mode for editing CVS commit messages
 
-;; Copyright (C) 1999,2000,2003  Free Software Foundation, Inc.
+;; Copyright (C) 1999, 2000, 2002, 2003, 2004,
+;;   2005, 2006 Free Software Foundation, Inc.
 
-;; Author: Stefan Monnier <monnier@cs.yale.edu>
+;; Author: Stefan Monnier <monnier@iro.umontreal.ca>
 ;; Keywords: pcl-cvs cvs commit log
 
 ;; This file is part of GNU Emacs.
@@ -19,8 +20,8 @@
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;;; Commentary:
 
@@ -119,8 +120,10 @@ If SETUP is 'force, this variable has no effect."
                           log-edit-insert-changelog)
   "*Hook run at the end of `log-edit'."
   :group 'log-edit
-  :type '(hook :options (log-edit-insert-cvs-template
-                        log-edit-insert-changelog)))
+  :type '(hook :options (log-edit-insert-changelog
+                         log-edit-insert-cvs-rcstemplate
+                         log-edit-insert-cvs-template
+                        log-edit-insert-filenames)))
 
 (defcustom log-edit-mode-hook (if (boundp 'vc-log-mode-hook) vc-log-mode-hook)
   "*Hook run when entering `log-edit-mode'."
@@ -154,12 +157,12 @@ different paragraphs are unrelated.
 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
+need to understand the change.  This is the behavior you get when this
 variable is set to t.
 
 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 log is per-file.  This is the behaviour you get
+file, because the log is per-file.  This is the behavior you get
 when this variable is set to nil.")
 
 ;;;; Internal global or buffer-local vars
@@ -280,25 +283,23 @@ automatically."
        (insert "\n"))))
 
 ;; Compatibility with old names.
-(defvaralias 'vc-comment-ring 'log-edit-comment-ring)
-(make-obsolete-variable 'vc-comment-ring 'log-edit-comment-ring "21.5")
-(defvaralias 'vc-comment-ring-index 'log-edit-comment-ring-index)
-(make-obsolete-variable 'vc-comment-ring-index 'log-edit-comment-ring-index "21.5")
-(defalias 'vc-previous-comment 'log-edit-previous-comment)
-(make-obsolete 'vc-previous-comment 'log-edit-previous-comment "21.5")
-(defalias 'vc-next-comment 'log-edit-next-comment)
-(make-obsolete 'vc-next-comment 'log-edit-next-comment "21.5")
-(defalias 'vc-comment-search-reverse 'log-edit-comment-search-backward)
-(make-obsolete 'vc-comment-search-reverse 'log-edit-comment-search-backward "21.5")
-(defalias 'vc-comment-search-forward 'log-edit-comment-search-forward)
-(make-obsolete 'vc-comment-search-forward 'log-edit-comment-search-forward "21.5")
-(defalias 'vc-comment-to-change-log 'log-edit-comment-to-change-log)
-(make-obsolete 'vc-comment-to-change-log 'log-edit-comment-to-change-log "21.5")
+(define-obsolete-variable-alias 'vc-comment-ring 'log-edit-comment-ring "22.1")
+(define-obsolete-variable-alias 'vc-comment-ring-index 'log-edit-comment-ring-index "22.1")
+(define-obsolete-function-alias 'vc-previous-comment 'log-edit-previous-comment "22.1")
+(define-obsolete-function-alias 'vc-next-comment 'log-edit-next-comment "22.1")
+(define-obsolete-function-alias 'vc-comment-search-reverse 'log-edit-comment-search-backward "22.1")
+(define-obsolete-function-alias 'vc-comment-search-forward 'log-edit-comment-search-forward "22.1")
+(define-obsolete-function-alias 'vc-comment-to-change-log 'log-edit-comment-to-change-log "22.1")
 
 ;;;
 ;;; Actual code
 ;;;
 
+(defvar log-edit-font-lock-keywords
+  '(("\\`\\(Summary:\\)\\(.*\\)"
+     (1 font-lock-keyword-face)
+     (2 font-lock-function-name-face))))
+
 ;;;###autoload
 (defun log-edit (callback &optional setup listfun buffer &rest ignore)
   "Setup a buffer to enter a log message.
@@ -325,7 +326,7 @@ If BUFFER is non-nil `log-edit' will jump to that buffer, use it to edit the
     (set (make-local-variable 'log-edit-initial-files) (log-edit-files))
     (when setup (run-hooks 'log-edit-hook))
     (goto-char (point-min)) (push-mark (point-max))
-    (message (substitute-command-keys
+    (message "%s" (substitute-command-keys
              "Press \\[log-edit-done] when you are done editing."))))
 
 (define-derived-mode log-edit-mode text-mode "Log-Edit"
@@ -337,6 +338,8 @@ the package from which this is used might also provide additional
 commands (under C-x v for VC, for example).
 
 \\{log-edit-mode-map}"
+  (set (make-local-variable 'font-lock-defaults)
+       '(log-edit-font-lock-keywords t))
   (make-local-variable 'log-edit-comment-ring-index))
 
 (defun log-edit-hide-buf (&optional buf where)
@@ -375,7 +378,7 @@ If you want to abort the commit, simply delete the buffer."
                       (equal (log-edit-files) log-edit-initial-files)))
             (progn
               (log-edit-show-files)
-              (not (y-or-n-p "Really commit ? "))))
+              (not (y-or-n-p "Really commit? "))))
        (progn (when (not win) (log-edit-hide-buf))
               (message "Oh, well!  Later maybe?"))
       (run-hooks 'log-edit-done-hook)
@@ -388,37 +391,12 @@ If you want to abort the commit, simply delete the buffer."
   "Return the list of files that are about to be committed."
   (ignore-errors (funcall log-edit-listfun)))
 
-
-(defun log-edit-insert-changelog ()
-  "Insert a log message by looking at the ChangeLog.
-The idea is to write your ChangeLog entries first, and then use this
-command to commit your changes.
-
-To select default log text, we:
-- find the ChangeLog entries for the files to be checked in,
-- verify that the top entry in the ChangeLog is on the current date
-  and by the current user; if not, we don't provide any default text,
-- search the ChangeLog entry for paragraphs containing the names of
-  the files we're checking in, and finally
-- use those paragraphs as the log text."
-  (interactive)
-  (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'."
   (interactive)
   (if (eq last-command 'log-edit-mode-help)
       (describe-function major-mode)
-    (message
+    (message "%s"
      (substitute-command-keys
       "Type `\\[log-edit-done]' to finish commit.  Try `\\[describe-function] log-edit-done' for more help."))))
 
@@ -457,11 +435,29 @@ To select default log text, we:
        (selected-window)))))
 
 (defun log-edit-insert-cvs-template ()
-  "Insert the template specified by the CVS administrator, if any."
+  "Insert the template specified by the CVS administrator, if any.
+This simply uses the local CVS/Template file."
   (interactive)
-  (when (file-readable-p "CVS/Template")
-    (insert-file-contents "CVS/Template")))
-
+  (when (or (interactive-p) (= (point-min) (point-max)))
+    (when (file-readable-p "CVS/Template")
+      (insert-file-contents "CVS/Template"))))
+
+(defun log-edit-insert-cvs-rcstemplate ()
+  "Insert the rcstemplate from the CVS repository.
+This contacts the repository to get the rcstemplate file and
+can thus take some time."
+  (interactive)
+  (when (or (interactive-p) (= (point-min) (point-max)))
+    (when (file-readable-p "CVS/Root")
+      ;; Ignore the stderr stuff, even if it's an error.
+      (call-process "cvs" nil '(t nil) nil
+                    "checkout" "-p" "CVSROOT/rcstemplate"))))
+
+(defun log-edit-insert-filenames ()
+  "Insert the list of files that are to be committed."
+  (interactive)
+  (insert "Affected files:  \n"
+          (mapconcat 'identity (log-edit-files) "  \n")))
 
 (defun log-edit-add-to-changelog ()
   "Insert this log message into the appropriate ChangeLog file."
@@ -474,6 +470,37 @@ To select default log text, we:
       (save-excursion
        (log-edit-comment-to-change-log)))))
 
+(defvar log-edit-changelog-use-first nil)
+(defun log-edit-insert-changelog (&optional use-first)
+  "Insert a log message by looking at the ChangeLog.
+The idea is to write your ChangeLog entries first, and then use this
+command to commit your changes.
+
+To select default log text, we:
+- find the ChangeLog entries for the files to be checked in,
+- verify that the top entry in the ChangeLog is on the current date
+  and by the current user; if not, we don't provide any default text,
+- search the ChangeLog entry for paragraphs containing the names of
+  the files we're checking in, and finally
+- use those paragraphs as the log text.
+
+If the optional prefix arg USE-FIRST is given (via \\[universal-argument]),
+or if the command is repeated a second time in a row, use the first log entry
+regardless of user name or time."
+  (interactive "P")
+  (let ((log-edit-changelog-use-first
+        (or use-first (eq last-command 'log-edit-insert-changelog))))
+    (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)))))
+
 ;;;;
 ;;;; functions for getting commit message from ChangeLog a file...
 ;;;; Courtesy Jim Blandy
@@ -553,7 +580,9 @@ Return non-nil iff it is."
                       (functionp add-log-time-format)
                       (funcall add-log-time-format))
                  (format-time-string "%Y-%m-%d"))))
-    (looking-at (regexp-quote (format "%s  %s  <%s>" time name mail)))))
+    (looking-at (if log-edit-changelog-use-first
+                    "[^ \t]"
+                  (regexp-quote (format "%s  %s  <%s>" time name mail))))))
 
 (defun log-edit-changelog-entries (file)
   "Return the ChangeLog entries for FILE, and the ChangeLog they came from.
@@ -600,8 +629,12 @@ where LOGBUFFER is the name of the ChangeLog buffer, and each
                           (search-forward pattern nil t))))
                (setq pattern (file-name-nondirectory file)))
 
+            (setq pattern (concat "\\(^\\|[^[:alnum:]]\\)"
+                                  pattern
+                                  "\\($\\|[^[:alnum:]]\\)"))
+
            (let (texts)
-             (while (search-forward pattern nil t)
+             (while (re-search-forward pattern nil t)
                (let ((entry (log-edit-changelog-entry)))
                  (push entry texts)
                  (goto-char (elt entry 1))))
@@ -639,5 +672,5 @@ Sort REGIONS front-to-back first."
 
 (provide 'log-edit)
 
-;;; arch-tag: 8089b39c-983b-4e83-93cd-ed0a64c7fdcc
+;; arch-tag: 8089b39c-983b-4e83-93cd-ed0a64c7fdcc
 ;;; log-edit.el ends here