comparison lisp/add-log.el @ 1727:d6cc12c97a59

(add-change-log-entry): Notice when ENTRY is equal to FILE-NAME, not the hard-wired string "ChangeLog". Added missing regexp-quote's in same-day entry search. Search only in the first paragraph for a similar entry to add to.
author Roland McGrath <roland@gnu.org>
date Tue, 29 Dec 1992 01:07:26 +0000
parents 35fbd349c58d
children b2af3186e7a7
comparison
equal deleted inserted replaced
1726:e44b2de1b698 1727:d6cc12c97a59
56 (user-login-name))) 56 (user-login-name)))
57 (site-name (if whoami 57 (site-name (if whoami
58 (read-input "Site name: " (system-name)) 58 (read-input "Site name: " (system-name))
59 (system-name))) 59 (system-name)))
60 (defun (add-log-current-defun)) 60 (defun (add-log-current-defun))
61 entry entry-position empty-entry) 61 paragraph-end entry)
62 (or file-name 62 (or file-name
63 (setq file-name (or change-log-default-name 63 (setq file-name (or change-log-default-name
64 default-directory))) 64 default-directory)))
65 (setq file-name (if (file-directory-p file-name) 65 (setq file-name (if (file-directory-p file-name)
66 (expand-file-name (change-log-name) file-name) 66 (expand-file-name (change-log-name) file-name)
69 ;; This makes it easier to use a single change log file 69 ;; This makes it easier to use a single change log file
70 ;; for several related directories. 70 ;; for several related directories.
71 (setq file-name 71 (setq file-name
72 (expand-file-name (or (file-symlink-p file-name) file-name))) 72 (expand-file-name (or (file-symlink-p file-name) file-name)))
73 (set (make-local-variable 'change-log-default-name) file-name) 73 (set (make-local-variable 'change-log-default-name) file-name)
74 (if buffer-file-name 74
75 (setq entry (if (string-match 75 ;; Set ENTRY to the file name to use in the new entry.
76 (concat "^" (regexp-quote (file-name-directory 76 (and buffer-file-name
77 file-name))) 77 ;; Never want to add a change log entry for the ChangeLog file itself.
78 buffer-file-name) 78 (not (string= buffer-file-name file-name))
79 (substring buffer-file-name (match-end 0)) 79 (setq entry (if (string-match
80 (file-name-nondirectory buffer-file-name)))) 80 (concat "^" (regexp-quote (file-name-directory
81 ;; Never want to add a change log entry for the ChangeLog file itself. 81 file-name)))
82 (if (equal entry "ChangeLog") 82 buffer-file-name)
83 (setq entry nil 83 (substring buffer-file-name (match-end 0))
84 defun nil)) 84 (file-name-nondirectory buffer-file-name))))
85
85 (if (and other-window (not (equal file-name buffer-file-name))) 86 (if (and other-window (not (equal file-name buffer-file-name)))
86 (find-file-other-window file-name) 87 (find-file-other-window file-name)
87 (find-file file-name)) 88 (find-file file-name))
88 (undo-boundary) 89 (undo-boundary)
89 (goto-char (point-min)) 90 (goto-char (point-min))
90 (or (looking-at (concat (substring (current-time-string) 0 10) 91 (or (looking-at (concat (regexp-quote (substring (current-time-string)
91 ".* " full-name " (" login-name "@")) 92 0 10))
93 ".* " (regexp-quote full-name)
94 " (" (regexp-quote login-name) "@"))
92 (insert (current-time-string) 95 (insert (current-time-string)
93 " " full-name 96 " " full-name
94 " (" login-name 97 " (" login-name "@" site-name ")\n\n"))
95 "@" site-name ")\n\n")) 98
99 ;; Search only within the first paragraph.
100 (forward-paragraph 1)
101 (setq paragraph-end (point))
96 (goto-char (point-min)) 102 (goto-char (point-min))
97 (setq empty-entry 103
98 (and (search-forward "\n\t* \n" nil t)
99 (1- (point))))
100 (if (and entry
101 (not empty-entry))
102 ;; Look for today's entry for the same file.
103 ;; If there is an empty entry (just a `*'), take the hint and
104 ;; use it. This is so that C-x a from the ChangeLog buffer
105 ;; itself can be used to force the next entry to be added at
106 ;; the beginning, even if there are today's entries for the
107 ;; same file (but perhaps different revisions).
108 (let ((entry-boundary (save-excursion
109 (and (re-search-forward "\n[A-Z]" nil t)
110 (point)))))
111 (setq entry-position (save-excursion
112 (and (re-search-forward
113 (concat
114 (regexp-quote (concat "* " entry))
115 ;; don't accept `foo.bar' when
116 ;; looking for `foo':
117 "[ \n\t,:]")
118 entry-boundary
119 t)
120 (1- (match-end 0)))))))
121 ;; Now insert the new line for this entry. 104 ;; Now insert the new line for this entry.
122 (cond (entry-position 105 (cond ((re-search-forward "^\\s *\\*\\s *$" paragraph-end t)
123 ;; Move to the existing entry for the same file. 106 ;; Put this file name into the existing empty entry.
124 (goto-char entry-position) 107 (if entry
125 (re-search-forward "^\\s *$") 108 (insert entry)))
109 ((and (re-search-forward
110 (concat (regexp-quote (concat "* " entry))
111 ;; Don't accept `foo.bar' when
112 ;; looking for `foo':
113 "\\(\\s \\|[(),:]\\)")
114 paragraph-end t))
115 ;; Add to the existing entry for the same file.
116 (re-search-forward "^\\s *$\\|^\\s \\*")
126 (beginning-of-line) 117 (beginning-of-line)
127 (while (and (not (eobp)) (looking-at "^\\s *$")) 118 (while (and (not (eobp)) (looking-at "^\\s *$"))
128 (delete-region (point) (save-excursion (forward-line 1) (point)))) 119 (delete-region (point) (save-excursion (forward-line 1) (point))))
129 (insert "\n\n") 120 (insert "\n\n")
130 (forward-line -2) 121 (forward-line -2)
131 (indent-relative-maybe)) 122 (indent-relative-maybe))
132 (empty-entry
133 ;; Put this file name into the existing empty entry.
134 (goto-char empty-entry)
135 (if entry
136 (insert entry)))
137 (t 123 (t
138 ;; Make a new entry. 124 ;; Make a new entry.
139 (forward-line 1) 125 (forward-line 1)
140 (while (looking-at "\\sW") 126 (while (looking-at "\\sW")
141 (forward-line 1)) 127 (forward-line 1))
163 (beginning-of-line 1) 149 (beginning-of-line 1)
164 (looking-at "\\s *\\(\\*\\s *\\)?$"))) 150 (looking-at "\\s *\\(\\*\\s *\\)?$")))
165 (insert ": "))))) 151 (insert ": ")))))
166 152
167 ;;;###autoload 153 ;;;###autoload
168 (define-key ctl-x-4-map "a" 'add-change-log-entry-other-window)
169
170 ;;;###autoload
171 (defun add-change-log-entry-other-window (&optional whoami file-name) 154 (defun add-change-log-entry-other-window (&optional whoami file-name)
172 "Find change log file in other window and add an entry for today. 155 "Find change log file in other window and add an entry for today.
173 First arg (interactive prefix) non-nil means prompt for user name and site. 156 First arg (interactive prefix) non-nil means prompt for user name and site.
174 Second arg is file name of change log. 157 Second arg is file name of change log.
175 Interactively, with a prefix argument, the file name is prompted for." 158 Interactively, with a prefix argument, the file name is prompted for."
176 (interactive (if current-prefix-arg 159 (interactive (if current-prefix-arg
177 (list current-prefix-arg 160 (list current-prefix-arg
178 (prompt-for-change-log-name)))) 161 (prompt-for-change-log-name))))
179 (add-change-log-entry whoami file-name t)) 162 (add-change-log-entry whoami file-name t))
163 ;;;###autoload (define-key ctl-x-4-map "a" 'add-change-log-entry-other-window)
180 164
181 ;;;###autoload 165 ;;;###autoload
182 (defun change-log-mode () 166 (defun change-log-mode ()
183 "Major mode for editting change logs; like Indented Text Mode. 167 "Major mode for editting change logs; like Indented Text Mode.
184 Prevents numeric backups and sets `left-margin' to 8 and `fill-column' to 74. 168 Prevents numeric backups and sets `left-margin' to 8 and `fill-column' to 74.
186 Each entry behaves as a paragraph, and the entries for one day as a page. 170 Each entry behaves as a paragraph, and the entries for one day as a page.
187 Runs `change-log-mode-hook'." 171 Runs `change-log-mode-hook'."
188 (interactive) 172 (interactive)
189 (kill-all-local-variables) 173 (kill-all-local-variables)
190 (indented-text-mode) 174 (indented-text-mode)
191 (setq major-mode 'change-log-mode) 175 (setq major-mode 'change-log-mode
192 (setq mode-name "Change Log") 176 mode-name "Change Log"
193 (setq left-margin 8) 177 left-margin 8
194 (setq fill-column 74) 178 fill-column 74)
195 ;; Let each entry behave as one paragraph: 179 ;; Let each entry behave as one paragraph:
196 (set (make-local-variable 'paragraph-start) "^\\s *$\\|^^L") 180 (set (make-local-variable 'paragraph-start) "^\\s *$\\|^^L")
197 (set (make-local-variable 'paragraph-separate) "^\\s *$\\|^^L\\|^\\sw") 181 (set (make-local-variable 'paragraph-separate) "^\\s *$\\|^^L\\|^\\sw")
198 ;; Let all entries for one day behave as one page. 182 ;; Let all entries for one day behave as one page.
199 ;; Match null string on the date-line so that the date-line 183 ;; Match null string on the date-line so that the date-line