annotate lisp/add-log.el @ 5150:60fa14264c3b

(add-change-log-entry): put buffer in change-log-mode. (find-change-log): correct calculation of file one directory out.
author Richard M. Stallman <rms@gnu.org>
date Wed, 24 Nov 1993 01:53:58 +0000
parents 61c4250fb760
children 7caf06258d7b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1 ;;; add-log.el --- change log maintenance commands for Emacs
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2
1956
02bb7721b67c (add-change-log-entry): Find end of first paragraph from after the header line.
Richard M. Stallman <rms@gnu.org>
parents: 1847
diff changeset
3 ;; Copyright (C) 1985, 1986, 1988, 1993 Free Software Foundation, Inc.
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
4
2247
2c7997f249eb Add or correct keywords
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1999
diff changeset
5 ;; Keywords: maint
2c7997f249eb Add or correct keywords
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1999
diff changeset
6
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
7 ;; This file is part of GNU Emacs.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
8
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
10 ;; it under the terms of the GNU General Public License as published by
811
e694e0879463 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 678
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
12 ;; any later version.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
13
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
14 ;; GNU Emacs is distributed in the hope that it will be useful,
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
17 ;; GNU General Public License for more details.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
18
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
20 ;; along with GNU Emacs; see the file COPYING. If not, write to
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
21 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
22
2307
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2247
diff changeset
23 ;;; Commentary:
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2247
diff changeset
24
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2247
diff changeset
25 ;; This facility is documented in the Emacs Manual.
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2247
diff changeset
26
811
e694e0879463 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 678
diff changeset
27 ;;; Code:
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
28
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
29 (defvar change-log-default-name nil
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
30 "*Name of a change log file for \\[add-change-log-entry].")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
31
4154
20a0593431b7 (add-log-current-defun-function): New defvar.
Roland McGrath <roland@gnu.org>
parents: 3897
diff changeset
32 (defvar add-log-current-defun-function nil
20a0593431b7 (add-log-current-defun-function): New defvar.
Roland McGrath <roland@gnu.org>
parents: 3897
diff changeset
33 "\
20a0593431b7 (add-log-current-defun-function): New defvar.
Roland McGrath <roland@gnu.org>
parents: 3897
diff changeset
34 *If non-nil, function to guess name of current function from surrounding text.
20a0593431b7 (add-log-current-defun-function): New defvar.
Roland McGrath <roland@gnu.org>
parents: 3897
diff changeset
35 \\[add-change-log-entry] calls this function (if nil, `add-log-current-defun'
20a0593431b7 (add-log-current-defun-function): New defvar.
Roland McGrath <roland@gnu.org>
parents: 3897
diff changeset
36 instead) with no arguments. It returns a string or nil if it cannot guess.")
20a0593431b7 (add-log-current-defun-function): New defvar.
Roland McGrath <roland@gnu.org>
parents: 3897
diff changeset
37
5038
61c4250fb760 (change-log-default-name, add-log-current-defun-function)
Richard M. Stallman <rms@gnu.org>
parents: 4741
diff changeset
38 ;; This MUST not be autoloaded, since user-login-name
61c4250fb760 (change-log-default-name, add-log-current-defun-function)
Richard M. Stallman <rms@gnu.org>
parents: 4741
diff changeset
39 ;; cannot be known at Emacs dump time.
4741
c0ea0009268a add-log-full-name, add-log-mailing-address: new varialbes
Brian Fox <bfox@gnu.org>
parents: 4380
diff changeset
40 (defvar add-log-full-name (user-full-name)
c0ea0009268a add-log-full-name, add-log-mailing-address: new varialbes
Brian Fox <bfox@gnu.org>
parents: 4380
diff changeset
41 "*Full name of user, for inclusion in ChangeLog daily headers.
c0ea0009268a add-log-full-name, add-log-mailing-address: new varialbes
Brian Fox <bfox@gnu.org>
parents: 4380
diff changeset
42 This defaults to the value returned by the `user-full-name' function.")
c0ea0009268a add-log-full-name, add-log-mailing-address: new varialbes
Brian Fox <bfox@gnu.org>
parents: 4380
diff changeset
43
5038
61c4250fb760 (change-log-default-name, add-log-current-defun-function)
Richard M. Stallman <rms@gnu.org>
parents: 4741
diff changeset
44 ;; This MUST not be autoloaded, since user-login-name
61c4250fb760 (change-log-default-name, add-log-current-defun-function)
Richard M. Stallman <rms@gnu.org>
parents: 4741
diff changeset
45 ;; cannot be known at Emacs dump time.
4741
c0ea0009268a add-log-full-name, add-log-mailing-address: new varialbes
Brian Fox <bfox@gnu.org>
parents: 4380
diff changeset
46 (defvar add-log-mailing-address (concat (user-login-name) "@" (system-name))
c0ea0009268a add-log-full-name, add-log-mailing-address: new varialbes
Brian Fox <bfox@gnu.org>
parents: 4380
diff changeset
47 "*Electronic mail address of user, for inclusion in ChangeLog daily headers.
c0ea0009268a add-log-full-name, add-log-mailing-address: new varialbes
Brian Fox <bfox@gnu.org>
parents: 4380
diff changeset
48 This defaults to the value returned by `user-login-name', followed by
c0ea0009268a add-log-full-name, add-log-mailing-address: new varialbes
Brian Fox <bfox@gnu.org>
parents: 4380
diff changeset
49 an `@' character, followed by the value returned by `system-name'.")
c0ea0009268a add-log-full-name, add-log-mailing-address: new varialbes
Brian Fox <bfox@gnu.org>
parents: 4380
diff changeset
50
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
51 (defun change-log-name ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
52 (or change-log-default-name
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
53 (if (eq system-type 'vax-vms) "$CHANGE_LOG$.TXT" "ChangeLog")))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
54
4157
d2316090d029 (prompt-for-change-log-name): Autoload this (for vc-comment-to-change-log).
Roland McGrath <roland@gnu.org>
parents: 4154
diff changeset
55 ;;;###autoload
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
56 (defun prompt-for-change-log-name ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
57 "Prompt for a change log name."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
58 (let ((default (change-log-name)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
59 (expand-file-name
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
60 (read-file-name (format "Log file (default %s): " default)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
61 nil default))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
62
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
63 ;;;###autoload
2463
d3c9f0ad5964 (find-change-log): New function.
Roland McGrath <roland@gnu.org>
parents: 2307
diff changeset
64 (defun find-change-log (&optional file-name)
d3c9f0ad5964 (find-change-log): New function.
Roland McGrath <roland@gnu.org>
parents: 2307
diff changeset
65 "Find a change log file for \\[add-change-log-entry] and return the name.
d3c9f0ad5964 (find-change-log): New function.
Roland McGrath <roland@gnu.org>
parents: 2307
diff changeset
66 Optional arg FILE-NAME is a name to try first.
d3c9f0ad5964 (find-change-log): New function.
Roland McGrath <roland@gnu.org>
parents: 2307
diff changeset
67 If FILE-NAME is nil, use the value of `change-log-default-name' if non-nil.
d3c9f0ad5964 (find-change-log): New function.
Roland McGrath <roland@gnu.org>
parents: 2307
diff changeset
68 Failing that, use \"ChangeLog\" in the current directory.
d3c9f0ad5964 (find-change-log): New function.
Roland McGrath <roland@gnu.org>
parents: 2307
diff changeset
69 If the file does not exist in the named directory, successive parent
d3c9f0ad5964 (find-change-log): New function.
Roland McGrath <roland@gnu.org>
parents: 2307
diff changeset
70 directories are tried.
d3c9f0ad5964 (find-change-log): New function.
Roland McGrath <roland@gnu.org>
parents: 2307
diff changeset
71
d3c9f0ad5964 (find-change-log): New function.
Roland McGrath <roland@gnu.org>
parents: 2307
diff changeset
72 Once a file is found, `change-log-default-name' is set locally in the
d3c9f0ad5964 (find-change-log): New function.
Roland McGrath <roland@gnu.org>
parents: 2307
diff changeset
73 current buffer to the complete file name."
d3c9f0ad5964 (find-change-log): New function.
Roland McGrath <roland@gnu.org>
parents: 2307
diff changeset
74 (or file-name
d3c9f0ad5964 (find-change-log): New function.
Roland McGrath <roland@gnu.org>
parents: 2307
diff changeset
75 (setq file-name (or change-log-default-name
3221
8e605e107faa (find-log-file): Use source file's truename dir.
Richard M. Stallman <rms@gnu.org>
parents: 3201
diff changeset
76 ;; Chase links in the source file
8e605e107faa (find-log-file): Use source file's truename dir.
Richard M. Stallman <rms@gnu.org>
parents: 3201
diff changeset
77 ;; and use the change log in the dir where it points.
8e605e107faa (find-log-file): Use source file's truename dir.
Richard M. Stallman <rms@gnu.org>
parents: 3201
diff changeset
78 (and buffer-file-name
3261
50b8f8d5f932 (find-change-log): Use file-chase-links.
Richard M. Stallman <rms@gnu.org>
parents: 3222
diff changeset
79 (file-name-directory
50b8f8d5f932 (find-change-log): Use file-chase-links.
Richard M. Stallman <rms@gnu.org>
parents: 3222
diff changeset
80 (file-chase-links buffer-file-name)))
2463
d3c9f0ad5964 (find-change-log): New function.
Roland McGrath <roland@gnu.org>
parents: 2307
diff changeset
81 default-directory)))
2712
8291de1718d4 (find-change-log): If there is a buffer-local value of
Roland McGrath <roland@gnu.org>
parents: 2463
diff changeset
82 (if (and (eq file-name change-log-default-name)
8291de1718d4 (find-change-log): If there is a buffer-local value of
Roland McGrath <roland@gnu.org>
parents: 2463
diff changeset
83 (assq 'change-log-default-name (buffer-local-variables)))
8291de1718d4 (find-change-log): If there is a buffer-local value of
Roland McGrath <roland@gnu.org>
parents: 2463
diff changeset
84 ;; Don't do the searching if we already have a buffer-local value.
8291de1718d4 (find-change-log): If there is a buffer-local value of
Roland McGrath <roland@gnu.org>
parents: 2463
diff changeset
85 file-name
8291de1718d4 (find-change-log): If there is a buffer-local value of
Roland McGrath <roland@gnu.org>
parents: 2463
diff changeset
86
8291de1718d4 (find-change-log): If there is a buffer-local value of
Roland McGrath <roland@gnu.org>
parents: 2463
diff changeset
87 (if (file-directory-p file-name)
8291de1718d4 (find-change-log): If there is a buffer-local value of
Roland McGrath <roland@gnu.org>
parents: 2463
diff changeset
88 (setq file-name (expand-file-name (change-log-name) file-name)))
8291de1718d4 (find-change-log): If there is a buffer-local value of
Roland McGrath <roland@gnu.org>
parents: 2463
diff changeset
89 ;; Chase links before visiting the file.
8291de1718d4 (find-change-log): If there is a buffer-local value of
Roland McGrath <roland@gnu.org>
parents: 2463
diff changeset
90 ;; This makes it easier to use a single change log file
8291de1718d4 (find-change-log): If there is a buffer-local value of
Roland McGrath <roland@gnu.org>
parents: 2463
diff changeset
91 ;; for several related directories.
3261
50b8f8d5f932 (find-change-log): Use file-chase-links.
Richard M. Stallman <rms@gnu.org>
parents: 3222
diff changeset
92 (setq file-name (file-chase-links file-name))
3201
6ae7487f1a3d (find-change-log): Chase symlinks multiple levels.
Richard M. Stallman <rms@gnu.org>
parents: 2712
diff changeset
93 (setq file-name (expand-file-name file-name))
2712
8291de1718d4 (find-change-log): If there is a buffer-local value of
Roland McGrath <roland@gnu.org>
parents: 2463
diff changeset
94 ;; Move up in the dir hierarchy till we find a change log file.
8291de1718d4 (find-change-log): If there is a buffer-local value of
Roland McGrath <roland@gnu.org>
parents: 2463
diff changeset
95 (let ((file1 file-name)
8291de1718d4 (find-change-log): If there is a buffer-local value of
Roland McGrath <roland@gnu.org>
parents: 2463
diff changeset
96 parent-dir)
3897
83d0fc1ccca9 (find-change-log): Try get-file-buffer before file-exists-p.
Roland McGrath <roland@gnu.org>
parents: 3853
diff changeset
97 (while (and (not (or (get-file-buffer file1) (file-exists-p file1)))
2712
8291de1718d4 (find-change-log): If there is a buffer-local value of
Roland McGrath <roland@gnu.org>
parents: 2463
diff changeset
98 (progn (setq parent-dir
8291de1718d4 (find-change-log): If there is a buffer-local value of
Roland McGrath <roland@gnu.org>
parents: 2463
diff changeset
99 (file-name-directory
8291de1718d4 (find-change-log): If there is a buffer-local value of
Roland McGrath <roland@gnu.org>
parents: 2463
diff changeset
100 (directory-file-name
8291de1718d4 (find-change-log): If there is a buffer-local value of
Roland McGrath <roland@gnu.org>
parents: 2463
diff changeset
101 (file-name-directory file1))))
8291de1718d4 (find-change-log): If there is a buffer-local value of
Roland McGrath <roland@gnu.org>
parents: 2463
diff changeset
102 ;; Give up if we are already at the root dir.
8291de1718d4 (find-change-log): If there is a buffer-local value of
Roland McGrath <roland@gnu.org>
parents: 2463
diff changeset
103 (not (string= (file-name-directory file1)
8291de1718d4 (find-change-log): If there is a buffer-local value of
Roland McGrath <roland@gnu.org>
parents: 2463
diff changeset
104 parent-dir))))
8291de1718d4 (find-change-log): If there is a buffer-local value of
Roland McGrath <roland@gnu.org>
parents: 2463
diff changeset
105 ;; Move up to the parent dir and try again.
5150
60fa14264c3b (add-change-log-entry): put buffer in change-log-mode.
Richard M. Stallman <rms@gnu.org>
parents: 5038
diff changeset
106 (setq file1 (expand-file-name
60fa14264c3b (add-change-log-entry): put buffer in change-log-mode.
Richard M. Stallman <rms@gnu.org>
parents: 5038
diff changeset
107 (file-name-nondirectory (change-log-name))
60fa14264c3b (add-change-log-entry): put buffer in change-log-mode.
Richard M. Stallman <rms@gnu.org>
parents: 5038
diff changeset
108 parent-dir)))
2712
8291de1718d4 (find-change-log): If there is a buffer-local value of
Roland McGrath <roland@gnu.org>
parents: 2463
diff changeset
109 ;; If we found a change log in a parent, use that.
3897
83d0fc1ccca9 (find-change-log): Try get-file-buffer before file-exists-p.
Roland McGrath <roland@gnu.org>
parents: 3853
diff changeset
110 (if (or (get-file-buffer file1) (file-exists-p file1))
2712
8291de1718d4 (find-change-log): If there is a buffer-local value of
Roland McGrath <roland@gnu.org>
parents: 2463
diff changeset
111 (setq file-name file1)))
8291de1718d4 (find-change-log): If there is a buffer-local value of
Roland McGrath <roland@gnu.org>
parents: 2463
diff changeset
112 ;; Make a local variable in this buffer so we needn't search again.
8291de1718d4 (find-change-log): If there is a buffer-local value of
Roland McGrath <roland@gnu.org>
parents: 2463
diff changeset
113 (set (make-local-variable 'change-log-default-name) file-name)
8291de1718d4 (find-change-log): If there is a buffer-local value of
Roland McGrath <roland@gnu.org>
parents: 2463
diff changeset
114 file-name))
2463
d3c9f0ad5964 (find-change-log): New function.
Roland McGrath <roland@gnu.org>
parents: 2307
diff changeset
115
d3c9f0ad5964 (find-change-log): New function.
Roland McGrath <roland@gnu.org>
parents: 2307
diff changeset
116 ;;;###autoload
4157
d2316090d029 (prompt-for-change-log-name): Autoload this (for vc-comment-to-change-log).
Roland McGrath <roland@gnu.org>
parents: 4154
diff changeset
117 (defun add-change-log-entry (&optional whoami file-name other-window new-entry)
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
118 "Find change log file and add an entry for today.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
119 Optional arg (interactive prefix) non-nil means prompt for user name and site.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
120 Second arg is file name of change log. If nil, uses `change-log-default-name'.
4157
d2316090d029 (prompt-for-change-log-name): Autoload this (for vc-comment-to-change-log).
Roland McGrath <roland@gnu.org>
parents: 4154
diff changeset
121 Third arg OTHER-WINDOW non-nil means visit in other window.
d2316090d029 (prompt-for-change-log-name): Autoload this (for vc-comment-to-change-log).
Roland McGrath <roland@gnu.org>
parents: 4154
diff changeset
122 Fourth arg NEW-ENTRY non-nil means always create a new entry at the front;
d2316090d029 (prompt-for-change-log-name): Autoload this (for vc-comment-to-change-log).
Roland McGrath <roland@gnu.org>
parents: 4154
diff changeset
123 never append to an existing entry."
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
124 (interactive (list current-prefix-arg
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
125 (prompt-for-change-log-name)))
4741
c0ea0009268a add-log-full-name, add-log-mailing-address: new varialbes
Brian Fox <bfox@gnu.org>
parents: 4380
diff changeset
126 (if whoami
c0ea0009268a add-log-full-name, add-log-mailing-address: new varialbes
Brian Fox <bfox@gnu.org>
parents: 4380
diff changeset
127 (progn
c0ea0009268a add-log-full-name, add-log-mailing-address: new varialbes
Brian Fox <bfox@gnu.org>
parents: 4380
diff changeset
128 (setq add-log-full-name (read-input "Full name: " add-log-full-name))
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
129 ;; Note that some sites have room and phone number fields in
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
130 ;; full name which look silly when inserted. Rather than do
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
131 ;; anything about that here, let user give prefix argument so that
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
132 ;; s/he can edit the full name field in prompter if s/he wants.
4741
c0ea0009268a add-log-full-name, add-log-mailing-address: new varialbes
Brian Fox <bfox@gnu.org>
parents: 4380
diff changeset
133 (setq add-log-mailing-address
c0ea0009268a add-log-full-name, add-log-mailing-address: new varialbes
Brian Fox <bfox@gnu.org>
parents: 4380
diff changeset
134 (read-input "Mailing address: " add-log-mailing-address))))
c0ea0009268a add-log-full-name, add-log-mailing-address: new varialbes
Brian Fox <bfox@gnu.org>
parents: 4380
diff changeset
135 (let ((defun (funcall (or add-log-current-defun-function
c0ea0009268a add-log-full-name, add-log-mailing-address: new varialbes
Brian Fox <bfox@gnu.org>
parents: 4380
diff changeset
136 'add-log-current-defun)))
c0ea0009268a add-log-full-name, add-log-mailing-address: new varialbes
Brian Fox <bfox@gnu.org>
parents: 4380
diff changeset
137 paragraph-end entry)
1752
b2af3186e7a7 (add-change-log-entry): Search for existing ChangeLog
Richard M. Stallman <rms@gnu.org>
parents: 1727
diff changeset
138
2463
d3c9f0ad5964 (find-change-log): New function.
Roland McGrath <roland@gnu.org>
parents: 2307
diff changeset
139 (setq file-name (find-change-log file-name))
1727
d6cc12c97a59 (add-change-log-entry): Notice when ENTRY is equal to FILE-NAME,
Roland McGrath <roland@gnu.org>
parents: 1644
diff changeset
140
d6cc12c97a59 (add-change-log-entry): Notice when ENTRY is equal to FILE-NAME,
Roland McGrath <roland@gnu.org>
parents: 1644
diff changeset
141 ;; Set ENTRY to the file name to use in the new entry.
d6cc12c97a59 (add-change-log-entry): Notice when ENTRY is equal to FILE-NAME,
Roland McGrath <roland@gnu.org>
parents: 1644
diff changeset
142 (and buffer-file-name
d6cc12c97a59 (add-change-log-entry): Notice when ENTRY is equal to FILE-NAME,
Roland McGrath <roland@gnu.org>
parents: 1644
diff changeset
143 ;; Never want to add a change log entry for the ChangeLog file itself.
d6cc12c97a59 (add-change-log-entry): Notice when ENTRY is equal to FILE-NAME,
Roland McGrath <roland@gnu.org>
parents: 1644
diff changeset
144 (not (string= buffer-file-name file-name))
d6cc12c97a59 (add-change-log-entry): Notice when ENTRY is equal to FILE-NAME,
Roland McGrath <roland@gnu.org>
parents: 1644
diff changeset
145 (setq entry (if (string-match
d6cc12c97a59 (add-change-log-entry): Notice when ENTRY is equal to FILE-NAME,
Roland McGrath <roland@gnu.org>
parents: 1644
diff changeset
146 (concat "^" (regexp-quote (file-name-directory
d6cc12c97a59 (add-change-log-entry): Notice when ENTRY is equal to FILE-NAME,
Roland McGrath <roland@gnu.org>
parents: 1644
diff changeset
147 file-name)))
d6cc12c97a59 (add-change-log-entry): Notice when ENTRY is equal to FILE-NAME,
Roland McGrath <roland@gnu.org>
parents: 1644
diff changeset
148 buffer-file-name)
d6cc12c97a59 (add-change-log-entry): Notice when ENTRY is equal to FILE-NAME,
Roland McGrath <roland@gnu.org>
parents: 1644
diff changeset
149 (substring buffer-file-name (match-end 0))
d6cc12c97a59 (add-change-log-entry): Notice when ENTRY is equal to FILE-NAME,
Roland McGrath <roland@gnu.org>
parents: 1644
diff changeset
150 (file-name-nondirectory buffer-file-name))))
d6cc12c97a59 (add-change-log-entry): Notice when ENTRY is equal to FILE-NAME,
Roland McGrath <roland@gnu.org>
parents: 1644
diff changeset
151
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
152 (if (and other-window (not (equal file-name buffer-file-name)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
153 (find-file-other-window file-name)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
154 (find-file file-name))
5150
60fa14264c3b (add-change-log-entry): put buffer in change-log-mode.
Richard M. Stallman <rms@gnu.org>
parents: 5038
diff changeset
155 (or (eq major-mode 'change-log-mode)
60fa14264c3b (add-change-log-entry): put buffer in change-log-mode.
Richard M. Stallman <rms@gnu.org>
parents: 5038
diff changeset
156 (change-log-mode))
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
157 (undo-boundary)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
158 (goto-char (point-min))
1956
02bb7721b67c (add-change-log-entry): Find end of first paragraph from after the header line.
Richard M. Stallman <rms@gnu.org>
parents: 1847
diff changeset
159 (if (looking-at (concat (regexp-quote (substring (current-time-string)
1727
d6cc12c97a59 (add-change-log-entry): Notice when ENTRY is equal to FILE-NAME,
Roland McGrath <roland@gnu.org>
parents: 1644
diff changeset
160 0 10))
4741
c0ea0009268a add-log-full-name, add-log-mailing-address: new varialbes
Brian Fox <bfox@gnu.org>
parents: 4380
diff changeset
161 ".* " (regexp-quote add-log-full-name)
c0ea0009268a add-log-full-name, add-log-mailing-address: new varialbes
Brian Fox <bfox@gnu.org>
parents: 4380
diff changeset
162 " (" (regexp-quote add-log-mailing-address)))
1956
02bb7721b67c (add-change-log-entry): Find end of first paragraph from after the header line.
Richard M. Stallman <rms@gnu.org>
parents: 1847
diff changeset
163 (forward-line 1)
02bb7721b67c (add-change-log-entry): Find end of first paragraph from after the header line.
Richard M. Stallman <rms@gnu.org>
parents: 1847
diff changeset
164 (insert (current-time-string)
4741
c0ea0009268a add-log-full-name, add-log-mailing-address: new varialbes
Brian Fox <bfox@gnu.org>
parents: 4380
diff changeset
165 " " add-log-full-name
c0ea0009268a add-log-full-name, add-log-mailing-address: new varialbes
Brian Fox <bfox@gnu.org>
parents: 4380
diff changeset
166 " (" add-log-mailing-address ")\n\n"))
1727
d6cc12c97a59 (add-change-log-entry): Notice when ENTRY is equal to FILE-NAME,
Roland McGrath <roland@gnu.org>
parents: 1644
diff changeset
167
1847
63af9f715bd3 (add-change-log-entry): Undo Jan 25 change. It worked for buffers in
Roland McGrath <roland@gnu.org>
parents: 1813
diff changeset
168 ;; Search only within the first paragraph.
1999
ced6a5b2519d (add-change-log-entry): Never move past second hdr line.
Richard M. Stallman <rms@gnu.org>
parents: 1956
diff changeset
169 (if (looking-at "\n*[^\n* \t]")
ced6a5b2519d (add-change-log-entry): Never move past second hdr line.
Richard M. Stallman <rms@gnu.org>
parents: 1956
diff changeset
170 (skip-chars-forward "\n")
ced6a5b2519d (add-change-log-entry): Never move past second hdr line.
Richard M. Stallman <rms@gnu.org>
parents: 1956
diff changeset
171 (forward-paragraph 1))
1727
d6cc12c97a59 (add-change-log-entry): Notice when ENTRY is equal to FILE-NAME,
Roland McGrath <roland@gnu.org>
parents: 1644
diff changeset
172 (setq paragraph-end (point))
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
173 (goto-char (point-min))
1727
d6cc12c97a59 (add-change-log-entry): Notice when ENTRY is equal to FILE-NAME,
Roland McGrath <roland@gnu.org>
parents: 1644
diff changeset
174
837
a8aef92e0025 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 811
diff changeset
175 ;; Now insert the new line for this entry.
1727
d6cc12c97a59 (add-change-log-entry): Notice when ENTRY is equal to FILE-NAME,
Roland McGrath <roland@gnu.org>
parents: 1644
diff changeset
176 (cond ((re-search-forward "^\\s *\\*\\s *$" paragraph-end t)
d6cc12c97a59 (add-change-log-entry): Notice when ENTRY is equal to FILE-NAME,
Roland McGrath <roland@gnu.org>
parents: 1644
diff changeset
177 ;; Put this file name into the existing empty entry.
d6cc12c97a59 (add-change-log-entry): Notice when ENTRY is equal to FILE-NAME,
Roland McGrath <roland@gnu.org>
parents: 1644
diff changeset
178 (if entry
d6cc12c97a59 (add-change-log-entry): Notice when ENTRY is equal to FILE-NAME,
Roland McGrath <roland@gnu.org>
parents: 1644
diff changeset
179 (insert entry)))
4157
d2316090d029 (prompt-for-change-log-name): Autoload this (for vc-comment-to-change-log).
Roland McGrath <roland@gnu.org>
parents: 4154
diff changeset
180 ((and (not new-entry)
d2316090d029 (prompt-for-change-log-name): Autoload this (for vc-comment-to-change-log).
Roland McGrath <roland@gnu.org>
parents: 4154
diff changeset
181 (re-search-forward
1727
d6cc12c97a59 (add-change-log-entry): Notice when ENTRY is equal to FILE-NAME,
Roland McGrath <roland@gnu.org>
parents: 1644
diff changeset
182 (concat (regexp-quote (concat "* " entry))
d6cc12c97a59 (add-change-log-entry): Notice when ENTRY is equal to FILE-NAME,
Roland McGrath <roland@gnu.org>
parents: 1644
diff changeset
183 ;; Don't accept `foo.bar' when
d6cc12c97a59 (add-change-log-entry): Notice when ENTRY is equal to FILE-NAME,
Roland McGrath <roland@gnu.org>
parents: 1644
diff changeset
184 ;; looking for `foo':
d6cc12c97a59 (add-change-log-entry): Notice when ENTRY is equal to FILE-NAME,
Roland McGrath <roland@gnu.org>
parents: 1644
diff changeset
185 "\\(\\s \\|[(),:]\\)")
d6cc12c97a59 (add-change-log-entry): Notice when ENTRY is equal to FILE-NAME,
Roland McGrath <roland@gnu.org>
parents: 1644
diff changeset
186 paragraph-end t))
d6cc12c97a59 (add-change-log-entry): Notice when ENTRY is equal to FILE-NAME,
Roland McGrath <roland@gnu.org>
parents: 1644
diff changeset
187 ;; Add to the existing entry for the same file.
d6cc12c97a59 (add-change-log-entry): Notice when ENTRY is equal to FILE-NAME,
Roland McGrath <roland@gnu.org>
parents: 1644
diff changeset
188 (re-search-forward "^\\s *$\\|^\\s \\*")
837
a8aef92e0025 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 811
diff changeset
189 (beginning-of-line)
912
1c37c99856de *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 846
diff changeset
190 (while (and (not (eobp)) (looking-at "^\\s *$"))
837
a8aef92e0025 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 811
diff changeset
191 (delete-region (point) (save-excursion (forward-line 1) (point))))
a8aef92e0025 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 811
diff changeset
192 (insert "\n\n")
a8aef92e0025 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 811
diff changeset
193 (forward-line -2)
678
8cff3b3bd089 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 666
diff changeset
194 (indent-relative-maybe))
666
7fa6b835da67 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 661
diff changeset
195 (t
678
8cff3b3bd089 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 666
diff changeset
196 ;; Make a new entry.
8cff3b3bd089 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 666
diff changeset
197 (forward-line 1)
8cff3b3bd089 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 666
diff changeset
198 (while (looking-at "\\sW")
8cff3b3bd089 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 666
diff changeset
199 (forward-line 1))
912
1c37c99856de *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 846
diff changeset
200 (while (and (not (eobp)) (looking-at "^\\s *$"))
837
a8aef92e0025 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 811
diff changeset
201 (delete-region (point) (save-excursion (forward-line 1) (point))))
a8aef92e0025 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 811
diff changeset
202 (insert "\n\n\n")
a8aef92e0025 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 811
diff changeset
203 (forward-line -2)
678
8cff3b3bd089 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 666
diff changeset
204 (indent-to left-margin)
8cff3b3bd089 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 666
diff changeset
205 (insert "* " (or entry ""))))
837
a8aef92e0025 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 811
diff changeset
206 ;; Now insert the function name, if we have one.
666
7fa6b835da67 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 661
diff changeset
207 ;; Point is at the entry for this file,
7fa6b835da67 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 661
diff changeset
208 ;; either at the end of the line or at the first blank line.
7fa6b835da67 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 661
diff changeset
209 (if defun
7fa6b835da67 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 661
diff changeset
210 (progn
678
8cff3b3bd089 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 666
diff changeset
211 ;; Make it easy to get rid of the function name.
666
7fa6b835da67 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 661
diff changeset
212 (undo-boundary)
678
8cff3b3bd089 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 666
diff changeset
213 (insert (if (save-excursion
8cff3b3bd089 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 666
diff changeset
214 (beginning-of-line 1)
8cff3b3bd089 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 666
diff changeset
215 (looking-at "\\s *$"))
8cff3b3bd089 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 666
diff changeset
216 ""
8cff3b3bd089 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 666
diff changeset
217 " ")
8cff3b3bd089 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 666
diff changeset
218 "(" defun "): "))
837
a8aef92e0025 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 811
diff changeset
219 ;; No function name, so put in a colon unless we have just a star.
678
8cff3b3bd089 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 666
diff changeset
220 (if (not (save-excursion
8cff3b3bd089 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 666
diff changeset
221 (beginning-of-line 1)
8cff3b3bd089 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 666
diff changeset
222 (looking-at "\\s *\\(\\*\\s *\\)?$")))
837
a8aef92e0025 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 811
diff changeset
223 (insert ": ")))))
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
224
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
225 ;;;###autoload
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
226 (defun add-change-log-entry-other-window (&optional whoami file-name)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
227 "Find change log file in other window and add an entry for today.
4154
20a0593431b7 (add-log-current-defun-function): New defvar.
Roland McGrath <roland@gnu.org>
parents: 3897
diff changeset
228 Optional arg (interactive prefix) non-nil means prompt for user name and site.
20a0593431b7 (add-log-current-defun-function): New defvar.
Roland McGrath <roland@gnu.org>
parents: 3897
diff changeset
229 Second arg is file name of change log. \
20a0593431b7 (add-log-current-defun-function): New defvar.
Roland McGrath <roland@gnu.org>
parents: 3897
diff changeset
230 If nil, uses `change-log-default-name'."
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
231 (interactive (if current-prefix-arg
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
232 (list current-prefix-arg
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
233 (prompt-for-change-log-name))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
234 (add-change-log-entry whoami file-name t))
1727
d6cc12c97a59 (add-change-log-entry): Notice when ENTRY is equal to FILE-NAME,
Roland McGrath <roland@gnu.org>
parents: 1644
diff changeset
235 ;;;###autoload (define-key ctl-x-4-map "a" 'add-change-log-entry-other-window)
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
236
980
b62886fbf2a7 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 953
diff changeset
237 ;;;###autoload
666
7fa6b835da67 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 661
diff changeset
238 (defun change-log-mode ()
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 3499
diff changeset
239 "Major mode for editing change logs; like Indented Text Mode.
912
1c37c99856de *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 846
diff changeset
240 Prevents numeric backups and sets `left-margin' to 8 and `fill-column' to 74.
951
c23539669808 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 947
diff changeset
241 New log entries are usually made with \\[add-change-log-entry] or \\[add-change-log-entry-other-window].
c23539669808 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 947
diff changeset
242 Each entry behaves as a paragraph, and the entries for one day as a page.
c23539669808 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 947
diff changeset
243 Runs `change-log-mode-hook'."
666
7fa6b835da67 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 661
diff changeset
244 (interactive)
7fa6b835da67 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 661
diff changeset
245 (kill-all-local-variables)
7fa6b835da67 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 661
diff changeset
246 (indented-text-mode)
1727
d6cc12c97a59 (add-change-log-entry): Notice when ENTRY is equal to FILE-NAME,
Roland McGrath <roland@gnu.org>
parents: 1644
diff changeset
247 (setq major-mode 'change-log-mode
d6cc12c97a59 (add-change-log-entry): Notice when ENTRY is equal to FILE-NAME,
Roland McGrath <roland@gnu.org>
parents: 1644
diff changeset
248 mode-name "Change Log"
d6cc12c97a59 (add-change-log-entry): Notice when ENTRY is equal to FILE-NAME,
Roland McGrath <roland@gnu.org>
parents: 1644
diff changeset
249 left-margin 8
d6cc12c97a59 (add-change-log-entry): Notice when ENTRY is equal to FILE-NAME,
Roland McGrath <roland@gnu.org>
parents: 1644
diff changeset
250 fill-column 74)
4157
d2316090d029 (prompt-for-change-log-name): Autoload this (for vc-comment-to-change-log).
Roland McGrath <roland@gnu.org>
parents: 4154
diff changeset
251 (use-local-map change-log-mode-map)
666
7fa6b835da67 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 661
diff changeset
252 ;; Let each entry behave as one paragraph:
4380
0c7aefc58e0f (change-log-mode): Use \f for formfeed, to avoid syntax error.
Richard M. Stallman <rms@gnu.org>
parents: 4157
diff changeset
253 (set (make-local-variable 'paragraph-start) "^\\s *$\\|^\f")
0c7aefc58e0f (change-log-mode): Use \f for formfeed, to avoid syntax error.
Richard M. Stallman <rms@gnu.org>
parents: 4157
diff changeset
254 (set (make-local-variable 'paragraph-separate) "^\\s *$\\|^\f\\|^\\sw")
666
7fa6b835da67 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 661
diff changeset
255 ;; Let all entries for one day behave as one page.
1078
15b4ed20e524 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 1062
diff changeset
256 ;; Match null string on the date-line so that the date-line
15b4ed20e524 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 1062
diff changeset
257 ;; is grouped with what follows.
4380
0c7aefc58e0f (change-log-mode): Use \f for formfeed, to avoid syntax error.
Richard M. Stallman <rms@gnu.org>
parents: 4157
diff changeset
258 (set (make-local-variable 'page-delimiter) "^\\<\\|^\f")
678
8cff3b3bd089 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 666
diff changeset
259 (set (make-local-variable 'version-control) 'never)
8cff3b3bd089 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 666
diff changeset
260 (set (make-local-variable 'adaptive-fill-regexp) "\\s *")
666
7fa6b835da67 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 661
diff changeset
261 (run-hooks 'change-log-mode-hook))
7fa6b835da67 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 661
diff changeset
262
4157
d2316090d029 (prompt-for-change-log-name): Autoload this (for vc-comment-to-change-log).
Roland McGrath <roland@gnu.org>
parents: 4154
diff changeset
263 (defvar change-log-mode-map nil
d2316090d029 (prompt-for-change-log-name): Autoload this (for vc-comment-to-change-log).
Roland McGrath <roland@gnu.org>
parents: 4154
diff changeset
264 "Keymap for Change Log major mode.")
d2316090d029 (prompt-for-change-log-name): Autoload this (for vc-comment-to-change-log).
Roland McGrath <roland@gnu.org>
parents: 4154
diff changeset
265 (if change-log-mode-map
d2316090d029 (prompt-for-change-log-name): Autoload this (for vc-comment-to-change-log).
Roland McGrath <roland@gnu.org>
parents: 4154
diff changeset
266 nil
d2316090d029 (prompt-for-change-log-name): Autoload this (for vc-comment-to-change-log).
Roland McGrath <roland@gnu.org>
parents: 4154
diff changeset
267 (setq change-log-mode-map (make-sparse-keymap))
d2316090d029 (prompt-for-change-log-name): Autoload this (for vc-comment-to-change-log).
Roland McGrath <roland@gnu.org>
parents: 4154
diff changeset
268 (define-key change-log-mode-map "\M-q" 'change-log-fill-paragraph))
d2316090d029 (prompt-for-change-log-name): Autoload this (for vc-comment-to-change-log).
Roland McGrath <roland@gnu.org>
parents: 4154
diff changeset
269
d2316090d029 (prompt-for-change-log-name): Autoload this (for vc-comment-to-change-log).
Roland McGrath <roland@gnu.org>
parents: 4154
diff changeset
270 ;; It might be nice to have a general feature to replace this. The idea I
d2316090d029 (prompt-for-change-log-name): Autoload this (for vc-comment-to-change-log).
Roland McGrath <roland@gnu.org>
parents: 4154
diff changeset
271 ;; have is a variable giving a regexp matching text which should not be
d2316090d029 (prompt-for-change-log-name): Autoload this (for vc-comment-to-change-log).
Roland McGrath <roland@gnu.org>
parents: 4154
diff changeset
272 ;; moved from bol by filling. change-log-mode would set this to "^\\s *\\s(".
d2316090d029 (prompt-for-change-log-name): Autoload this (for vc-comment-to-change-log).
Roland McGrath <roland@gnu.org>
parents: 4154
diff changeset
273 ;; But I don't feel up to implementing that today.
d2316090d029 (prompt-for-change-log-name): Autoload this (for vc-comment-to-change-log).
Roland McGrath <roland@gnu.org>
parents: 4154
diff changeset
274 (defun change-log-fill-paragraph (&optional justify)
d2316090d029 (prompt-for-change-log-name): Autoload this (for vc-comment-to-change-log).
Roland McGrath <roland@gnu.org>
parents: 4154
diff changeset
275 "Fill the paragraph, but preserve open parentheses at beginning of lines.
d2316090d029 (prompt-for-change-log-name): Autoload this (for vc-comment-to-change-log).
Roland McGrath <roland@gnu.org>
parents: 4154
diff changeset
276 Prefix arg means justify as well."
d2316090d029 (prompt-for-change-log-name): Autoload this (for vc-comment-to-change-log).
Roland McGrath <roland@gnu.org>
parents: 4154
diff changeset
277 (interactive "P")
d2316090d029 (prompt-for-change-log-name): Autoload this (for vc-comment-to-change-log).
Roland McGrath <roland@gnu.org>
parents: 4154
diff changeset
278 (let ((paragraph-separate (concat paragraph-separate "\\|^\\s *\\s("))
d2316090d029 (prompt-for-change-log-name): Autoload this (for vc-comment-to-change-log).
Roland McGrath <roland@gnu.org>
parents: 4154
diff changeset
279 (paragraph-start (concat paragraph-start "\\|^\\s *\\s(")))
d2316090d029 (prompt-for-change-log-name): Autoload this (for vc-comment-to-change-log).
Roland McGrath <roland@gnu.org>
parents: 4154
diff changeset
280 (fill-paragraph justify)))
d2316090d029 (prompt-for-change-log-name): Autoload this (for vc-comment-to-change-log).
Roland McGrath <roland@gnu.org>
parents: 4154
diff changeset
281
666
7fa6b835da67 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 661
diff changeset
282 (defvar add-log-current-defun-header-regexp
1369
e5cb5060bb51 (add-log-current-defun): In normal C case,
Richard M. Stallman <rms@gnu.org>
parents: 1351
diff changeset
283 "^\\([A-Z][A-Z_ ]*[A-Z_]\\|[a-z_---A-Z]+\\)[ \t]*[:=]"
666
7fa6b835da67 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 661
diff changeset
284 "*Heuristic regexp used by `add-log-current-defun' for unknown major modes.")
7fa6b835da67 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 661
diff changeset
285
7fa6b835da67 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 661
diff changeset
286 (defun add-log-current-defun ()
7fa6b835da67 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 661
diff changeset
287 "Return name of function definition point is in, or nil.
7fa6b835da67 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 661
diff changeset
288
3499
6428162f137c (add-log-current-defun): Fix typos in last change.
Richard M. Stallman <rms@gnu.org>
parents: 3486
diff changeset
289 Understands C, Lisp, LaTeX (\"functions\" are chapters, sections, ...),
6428162f137c (add-log-current-defun): Fix typos in last change.
Richard M. Stallman <rms@gnu.org>
parents: 3486
diff changeset
290 Texinfo (@node titles), and Fortran.
666
7fa6b835da67 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 661
diff changeset
291
7fa6b835da67 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 661
diff changeset
292 Other modes are handled by a heuristic that looks in the 10K before
7fa6b835da67 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 661
diff changeset
293 point for uppercase headings starting in the first column or
7fa6b835da67 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 661
diff changeset
294 identifiers followed by `:' or `=', see variable
7fa6b835da67 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 661
diff changeset
295 `add-log-current-defun-header-regexp'.
7fa6b835da67 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 661
diff changeset
296
7fa6b835da67 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 661
diff changeset
297 Has a preference of looking backwards."
1447
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
298 (condition-case nil
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
299 (save-excursion
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
300 (let ((location (point)))
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
301 (cond ((memq major-mode '(emacs-lisp-mode lisp-mode scheme-mode))
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
302 ;; If we are now precisely a the beginning of a defun,
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
303 ;; make sure beginning-of-defun finds that one
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
304 ;; rather than the previous one.
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
305 (or (eobp) (forward-char 1))
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
306 (beginning-of-defun)
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
307 ;; Make sure we are really inside the defun found, not after it.
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
308 (if (and (progn (end-of-defun)
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
309 (< location (point)))
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
310 (progn (forward-sexp -1)
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
311 (>= location (point))))
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
312 (progn
3853
d771acf8f6ef * add-log.el (add-log-current-defun): To find the name of the
Jim Blandy <jimb@redhat.com>
parents: 3591
diff changeset
313 (if (looking-at "\\s(")
d771acf8f6ef * add-log.el (add-log-current-defun): To find the name of the
Jim Blandy <jimb@redhat.com>
parents: 3591
diff changeset
314 (forward-char 1))
d771acf8f6ef * add-log.el (add-log-current-defun): To find the name of the
Jim Blandy <jimb@redhat.com>
parents: 3591
diff changeset
315 (forward-sexp 1)
1447
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
316 (skip-chars-forward " ")
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
317 (buffer-substring (point)
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
318 (progn (forward-sexp 1) (point))))))
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
319 ((and (memq major-mode '(c-mode 'c++-mode))
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
320 (save-excursion (beginning-of-line)
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
321 ;; Use eq instead of = here to avoid
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
322 ;; error when at bob and char-after
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
323 ;; returns nil.
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
324 (while (eq (char-after (- (point) 2)) ?\\)
953
7c035a87c691 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 951
diff changeset
325 (forward-line -1))
1447
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
326 (looking-at "[ \t]*#[ \t]*define[ \t]")))
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
327 ;; Handle a C macro definition.
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
328 (beginning-of-line)
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
329 (while (eq (char-after (- (point) 2)) ?\\) ;not =; note above
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
330 (forward-line -1))
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
331 (search-forward "define")
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
332 (skip-chars-forward " \t")
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
333 (buffer-substring (point)
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
334 (progn (forward-sexp 1) (point))))
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
335 ((memq major-mode '(c-mode 'c++-mode))
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
336 (beginning-of-line)
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
337 ;; See if we are in the beginning part of a function,
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
338 ;; before the open brace. If so, advance forward.
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
339 (while (not (looking-at "{\\|\\(\\s *$\\)"))
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
340 (forward-line 1))
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
341 (or (eobp)
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
342 (forward-char 1))
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
343 (beginning-of-defun)
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
344 (if (progn (end-of-defun)
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
345 (< location (point)))
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
346 (progn
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
347 (backward-sexp 1)
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
348 (let (beg tem)
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
349
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
350 (forward-line -1)
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
351 ;; Skip back over typedefs of arglist.
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
352 (while (and (not (bobp))
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
353 (looking-at "[ \t\n]"))
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
354 (forward-line -1))
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
355 ;; See if this is using the DEFUN macro used in Emacs,
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
356 ;; or the DEFUN macro used by the C library.
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
357 (if (condition-case nil
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
358 (and (save-excursion
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
359 (forward-line 1)
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
360 (backward-sexp 1)
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
361 (beginning-of-line)
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
362 (setq tem (point))
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
363 (looking-at "DEFUN\\b"))
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
364 (>= location tem))
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
365 (error nil))
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
366 (progn
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
367 (goto-char tem)
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
368 (down-list 1)
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
369 (if (= (char-after (point)) ?\")
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
370 (progn
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
371 (forward-sexp 1)
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
372 (skip-chars-forward " ,")))
953
7c035a87c691 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 951
diff changeset
373 (buffer-substring (point)
1447
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
374 (progn (forward-sexp 1) (point))))
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
375 ;; Ordinary C function syntax.
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
376 (setq beg (point))
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
377 (if (condition-case nil
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
378 ;; Protect against "Unbalanced parens" error.
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
379 (progn
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
380 (down-list 1) ; into arglist
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
381 (backward-up-list 1)
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
382 (skip-chars-backward " \t")
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
383 t)
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
384 (error nil))
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
385 ;; Verify initial pos was after
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
386 ;; real start of function.
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
387 (if (and (save-excursion
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
388 (goto-char beg)
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
389 ;; For this purpose, include the line
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
390 ;; that has the decl keywords. This
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
391 ;; may also include some of the
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
392 ;; comments before the function.
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
393 (while (and (not (bobp))
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
394 (save-excursion
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
395 (forward-line -1)
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
396 (looking-at "[^\n\f]")))
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
397 (forward-line -1))
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
398 (>= location (point)))
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
399 ;; Consistency check: going down and up
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
400 ;; shouldn't take us back before BEG.
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
401 (> (point) beg))
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
402 (buffer-substring (point)
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
403 (progn (backward-sexp 1)
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
404 (point))))))))))
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
405 ((memq major-mode
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
406 '(TeX-mode plain-TeX-mode LaTeX-mode;; tex-mode.el
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
407 plain-tex-mode latex-mode;; cmutex.el
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
408 ))
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
409 (if (re-search-backward
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
410 "\\\\\\(sub\\)*\\(section\\|paragraph\\|chapter\\)" nil t)
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
411 (progn
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
412 (goto-char (match-beginning 0))
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
413 (buffer-substring (1+ (point));; without initial backslash
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
414 (progn
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
415 (end-of-line)
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
416 (point))))))
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
417 ((eq major-mode 'texinfo-mode)
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
418 (if (re-search-backward "^@node[ \t]+\\([^,]+\\)," nil t)
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
419 (buffer-substring (match-beginning 1)
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
420 (match-end 1))))
3486
a4b23b25b671 (add-log-current-defun): Handle Fortran.
Richard M. Stallman <rms@gnu.org>
parents: 3261
diff changeset
421 ((eq major-mode 'fortran-mode)
a4b23b25b671 (add-log-current-defun): Handle Fortran.
Richard M. Stallman <rms@gnu.org>
parents: 3261
diff changeset
422 ;; must be inside function body for this to work
a4b23b25b671 (add-log-current-defun): Handle Fortran.
Richard M. Stallman <rms@gnu.org>
parents: 3261
diff changeset
423 (beginning-of-fortran-subprogram)
a4b23b25b671 (add-log-current-defun): Handle Fortran.
Richard M. Stallman <rms@gnu.org>
parents: 3261
diff changeset
424 (let ((case-fold-search t)) ; case-insensitive
a4b23b25b671 (add-log-current-defun): Handle Fortran.
Richard M. Stallman <rms@gnu.org>
parents: 3261
diff changeset
425 ;; search for fortran subprogram start
a4b23b25b671 (add-log-current-defun): Handle Fortran.
Richard M. Stallman <rms@gnu.org>
parents: 3261
diff changeset
426 (if (re-search-forward
a4b23b25b671 (add-log-current-defun): Handle Fortran.
Richard M. Stallman <rms@gnu.org>
parents: 3261
diff changeset
427 "^[ \t]*\\(program\\|subroutine\\|function\
a4b23b25b671 (add-log-current-defun): Handle Fortran.
Richard M. Stallman <rms@gnu.org>
parents: 3261
diff changeset
428 \\|[ \ta-z0-9*]*[ \t]+function\\)"
3499
6428162f137c (add-log-current-defun): Fix typos in last change.
Richard M. Stallman <rms@gnu.org>
parents: 3486
diff changeset
429 nil t)
3486
a4b23b25b671 (add-log-current-defun): Handle Fortran.
Richard M. Stallman <rms@gnu.org>
parents: 3261
diff changeset
430 (progn
a4b23b25b671 (add-log-current-defun): Handle Fortran.
Richard M. Stallman <rms@gnu.org>
parents: 3261
diff changeset
431 ;; move to EOL or before first left paren
a4b23b25b671 (add-log-current-defun): Handle Fortran.
Richard M. Stallman <rms@gnu.org>
parents: 3261
diff changeset
432 (if (re-search-forward "[(\n]" nil t)
a4b23b25b671 (add-log-current-defun): Handle Fortran.
Richard M. Stallman <rms@gnu.org>
parents: 3261
diff changeset
433 (progn (forward-char -1)
a4b23b25b671 (add-log-current-defun): Handle Fortran.
Richard M. Stallman <rms@gnu.org>
parents: 3261
diff changeset
434 (skip-chars-backward " \t"))
a4b23b25b671 (add-log-current-defun): Handle Fortran.
Richard M. Stallman <rms@gnu.org>
parents: 3261
diff changeset
435 (end-of-line))
a4b23b25b671 (add-log-current-defun): Handle Fortran.
Richard M. Stallman <rms@gnu.org>
parents: 3261
diff changeset
436 ;; Use the name preceding that.
a4b23b25b671 (add-log-current-defun): Handle Fortran.
Richard M. Stallman <rms@gnu.org>
parents: 3261
diff changeset
437 (buffer-substring (point)
a4b23b25b671 (add-log-current-defun): Handle Fortran.
Richard M. Stallman <rms@gnu.org>
parents: 3261
diff changeset
438 (progn (forward-sexp -1)
a4b23b25b671 (add-log-current-defun): Handle Fortran.
Richard M. Stallman <rms@gnu.org>
parents: 3261
diff changeset
439 (point)))))))
1447
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
440 (t
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
441 ;; If all else fails, try heuristics
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
442 (let (case-fold-search)
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
443 (end-of-line)
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
444 (if (re-search-backward add-log-current-defun-header-regexp
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
445 (- (point) 10000)
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
446 t)
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
447 (buffer-substring (match-beginning 1)
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
448 (match-end 1))))))))
75fa9ad982a5 (add-log-current-defun): Add condition-case around
Richard M. Stallman <rms@gnu.org>
parents: 1369
diff changeset
449 (error nil)))
999
d8d503897aa5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 980
diff changeset
450
d8d503897aa5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 980
diff changeset
451
980
b62886fbf2a7 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 953
diff changeset
452 (provide 'add-log)
b62886fbf2a7 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 953
diff changeset
453
811
e694e0879463 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 678
diff changeset
454 ;;; add-log.el ends here