comparison lisp/log-edit.el @ 51368:cc73795bc08a

(log-edit-maximum-comment-ring-size, log-edit-comment-ring) (log-edit-comment-ring-index, log-edit-last-comment-match): Rename vars from vc-maximum-comment-ring-size, vc-comment-ring, vc-comment-ring-index, and vc-last-comment-match. (log-edit-new-comment-index, log-edit-previous-comment) (log-edit-next-comment, log-edit-comment-search-backward) (log-edit-comment-search-forward, log-edit-comment-to-change-log): Rename funs from vc-new-comment-index, vc-previous-comment, vc-next-comment, vc-comment-search-reverse, vc-comment-search-forward, and vc-comment-to-change-log.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Sat, 31 May 2003 16:43:30 +0000
parents 35933dc8e248
children 695cf19ef79e
comparison
equal deleted inserted replaced
51367:f880f27737f4 51368:cc73795bc08a
55 55
56 (easy-mmode-defmap log-edit-mode-map 56 (easy-mmode-defmap log-edit-mode-map
57 `(("\C-c\C-c" . log-edit-done) 57 `(("\C-c\C-c" . log-edit-done)
58 ("\C-c\C-a" . log-edit-insert-changelog) 58 ("\C-c\C-a" . log-edit-insert-changelog)
59 ("\C-c\C-f" . log-edit-show-files) 59 ("\C-c\C-f" . log-edit-show-files)
60 ("\M-n" . vc-next-comment) 60 ("\M-n" . log-edit-next-comment)
61 ("\M-p" . vc-previous-comment) 61 ("\M-p" . log-edit-previous-comment)
62 ("\M-r" . vc-comment-search-reverse) 62 ("\M-r" . log-edit-comment-search-backward)
63 ("\M-s" . vc-comment-search-forward) 63 ("\M-s" . log-edit-comment-search-forward)
64 ("\C-c?" . log-edit-mode-help)) 64 ("\C-c?" . log-edit-mode-help))
65 "Keymap for the `log-edit-mode' (to edit version control log messages)." 65 "Keymap for the `log-edit-mode' (to edit version control log messages)."
66 :group 'log-edit) 66 :group 'log-edit)
67 67
68 ;; Compatibility with old names. Should we bother ? 68 ;; Compatibility with old names. Should we bother ?
79 ["Add to ChangeLog" log-edit-add-to-changelog] 79 ["Add to ChangeLog" log-edit-add-to-changelog]
80 "--" 80 "--"
81 ["List files" log-edit-show-files 81 ["List files" log-edit-show-files
82 :help "Show the list of relevant files."] 82 :help "Show the list of relevant files."]
83 "--" 83 "--"
84 ["Previous comment" vc-previous-comment] 84 ["Previous comment" log-edit-previous-comment]
85 ["Next comment" vc-next-comment] 85 ["Next comment" log-edit-next-comment]
86 ["Search comment forward" vc-comment-search-forward] 86 ["Search comment forward" log-edit-comment-search-forward]
87 ["Search comment backward" vc-comment-search-reverse])) 87 ["Search comment backward" log-edit-comment-search-backward]))
88 88
89 (defcustom log-edit-confirm 'changed 89 (defcustom log-edit-confirm 'changed
90 "*If non-nil, `log-edit-done' will request confirmation. 90 "*If non-nil, `log-edit-done' will request confirmation.
91 If 'changed, only request confirmation if the list of files has 91 If 'changed, only request confirmation if the list of files has
92 changed since the beginning of the log-edit session." 92 changed since the beginning of the log-edit session."
168 (defvar log-edit-initial-files nil) 168 (defvar log-edit-initial-files nil)
169 (defvar log-edit-callback nil) 169 (defvar log-edit-callback nil)
170 (defvar log-edit-listfun nil) 170 (defvar log-edit-listfun nil)
171 (defvar log-edit-parent-buffer nil) 171 (defvar log-edit-parent-buffer nil)
172 172
173 ;;; Taken from VC-Log mode 173 ;;; Originally taken from VC-Log mode
174 174
175 (defconst vc-maximum-comment-ring-size 32 175 (defconst log-edit-maximum-comment-ring-size 32
176 "Maximum number of saved comments in the comment ring.") 176 "Maximum number of saved comments in the comment ring.")
177 (defvar vc-comment-ring (make-ring vc-maximum-comment-ring-size)) 177 (defvar log-edit-comment-ring (make-ring log-edit-maximum-comment-ring-size))
178 (defvar vc-comment-ring-index nil) 178 (defvar log-edit-comment-ring-index nil)
179 (defvar vc-last-comment-match "") 179 (defvar log-edit-last-comment-match "")
180 180
181 (defun vc-new-comment-index (stride len) 181 (defun log-edit-new-comment-index (stride len)
182 "Return the comment index STRIDE elements from the current one. 182 "Return the comment index STRIDE elements from the current one.
183 LEN is the length of `vc-comment-ring'." 183 LEN is the length of `log-edit-comment-ring'."
184 (mod (cond 184 (mod (cond
185 (vc-comment-ring-index (+ vc-comment-ring-index stride)) 185 (log-edit-comment-ring-index (+ log-edit-comment-ring-index stride))
186 ;; Initialize the index on the first use of this command 186 ;; Initialize the index on the first use of this command
187 ;; so that the first M-p gets index 0, and the first M-n gets 187 ;; so that the first M-p gets index 0, and the first M-n gets
188 ;; index -1. 188 ;; index -1.
189 ((> stride 0) (1- stride)) 189 ((> stride 0) (1- stride))
190 (t stride)) 190 (t stride))
191 len)) 191 len))
192 192
193 (defun vc-previous-comment (arg) 193 (defun log-edit-previous-comment (arg)
194 "Cycle backwards through comment history. 194 "Cycle backwards through comment history.
195 With a numeric prefix ARG, go back ARG comments." 195 With a numeric prefix ARG, go back ARG comments."
196 (interactive "*p") 196 (interactive "*p")
197 (let ((len (ring-length vc-comment-ring))) 197 (let ((len (ring-length log-edit-comment-ring)))
198 (if (<= len 0) 198 (if (<= len 0)
199 (progn (message "Empty comment ring") (ding)) 199 (progn (message "Empty comment ring") (ding))
200 ;; Don't use `erase-buffer' because we don't want to `widen'. 200 ;; Don't use `erase-buffer' because we don't want to `widen'.
201 (delete-region (point-min) (point-max)) 201 (delete-region (point-min) (point-max))
202 (setq vc-comment-ring-index (vc-new-comment-index arg len)) 202 (setq log-edit-comment-ring-index (log-edit-new-comment-index arg len))
203 (message "Comment %d" (1+ vc-comment-ring-index)) 203 (message "Comment %d" (1+ log-edit-comment-ring-index))
204 (insert (ring-ref vc-comment-ring vc-comment-ring-index))))) 204 (insert (ring-ref log-edit-comment-ring log-edit-comment-ring-index)))))
205 205
206 (defun vc-next-comment (arg) 206 (defun log-edit-next-comment (arg)
207 "Cycle forwards through comment history. 207 "Cycle forwards through comment history.
208 With a numeric prefix ARG, go forward ARG comments." 208 With a numeric prefix ARG, go forward ARG comments."
209 (interactive "*p") 209 (interactive "*p")
210 (vc-previous-comment (- arg))) 210 (log-edit-previous-comment (- arg)))
211 211
212 (defun vc-comment-search-reverse (str &optional stride) 212 (defun log-edit-comment-search-backward (str &optional stride)
213 "Search backwards through comment history for substring match of STR. 213 "Search backwards through comment history for substring match of STR.
214 If the optional argument STRIDE is present, that is a step-width to use 214 If the optional argument STRIDE is present, that is a step-width to use
215 when going through the comment ring." 215 when going through the comment ring."
216 ;; Why substring rather than regexp ? -sm 216 ;; Why substring rather than regexp ? -sm
217 (interactive 217 (interactive
218 (list (read-string "Comment substring: " nil nil vc-last-comment-match))) 218 (list (read-string "Comment substring: " nil nil log-edit-last-comment-match)))
219 (unless stride (setq stride 1)) 219 (unless stride (setq stride 1))
220 (if (string= str "") 220 (if (string= str "")
221 (setq str vc-last-comment-match) 221 (setq str log-edit-last-comment-match)
222 (setq vc-last-comment-match str)) 222 (setq log-edit-last-comment-match str))
223 (let* ((str (regexp-quote str)) 223 (let* ((str (regexp-quote str))
224 (len (ring-length vc-comment-ring)) 224 (len (ring-length log-edit-comment-ring))
225 (n (vc-new-comment-index stride len))) 225 (n (log-edit-new-comment-index stride len)))
226 (while (progn (when (or (>= n len) (< n 0)) (error "Not found")) 226 (while (progn (when (or (>= n len) (< n 0)) (error "Not found"))
227 (not (string-match str (ring-ref vc-comment-ring n)))) 227 (not (string-match str (ring-ref log-edit-comment-ring n))))
228 (setq n (+ n stride))) 228 (setq n (+ n stride)))
229 (setq vc-comment-ring-index n) 229 (setq log-edit-comment-ring-index n)
230 (vc-previous-comment 0))) 230 (log-edit-previous-comment 0)))
231 231
232 (defun vc-comment-search-forward (str) 232 (defun log-edit-comment-search-forward (str)
233 "Search forwards through comment history for a substring match of STR." 233 "Search forwards through comment history for a substring match of STR."
234 (interactive 234 (interactive
235 (list (read-string "Comment substring: " nil nil vc-last-comment-match))) 235 (list (read-string "Comment substring: " nil nil log-edit-last-comment-match)))
236 (vc-comment-search-reverse str -1)) 236 (log-edit-comment-search-backward str -1))
237 237
238 238 (defun log-edit-comment-to-change-log (&optional whoami file-name)
239
240 (defun vc-comment-to-change-log (&optional whoami file-name)
241 "Enter last VC comment into the change log for the current file. 239 "Enter last VC comment into the change log for the current file.
242 WHOAMI (interactive prefix) non-nil means prompt for user name 240 WHOAMI (interactive prefix) non-nil means prompt for user name
243 and site. FILE-NAME is the name of the change log; if nil, use 241 and site. FILE-NAME is the name of the change log; if nil, use
244 `change-log-default-name'. 242 `change-log-default-name'.
245 243
246 This may be useful as a `vc-checkin-hook' to update change logs 244 This may be useful as a `log-edit-checkin-hook' to update change logs
247 automatically." 245 automatically."
248 (interactive (if current-prefix-arg 246 (interactive (if current-prefix-arg
249 (list current-prefix-arg 247 (list current-prefix-arg
250 (prompt-for-change-log-name)))) 248 (prompt-for-change-log-name))))
251 (let (;; Extract the comment first so we get any error before doing anything. 249 (let (;; Extract the comment first so we get any error before doing anything.
252 (comment (ring-ref vc-comment-ring 0)) 250 (comment (ring-ref log-edit-comment-ring 0))
253 ;; Don't let add-change-log-entry insert a defun name. 251 ;; Don't let add-change-log-entry insert a defun name.
254 (add-log-current-defun-function 'ignore) 252 (add-log-current-defun-function 'ignore)
255 end) 253 end)
256 ;; Call add-log to do half the work. 254 ;; Call add-log to do half the work.
257 (add-change-log-entry whoami file-name t t) 255 (add-change-log-entry whoami file-name t t)
279 (skip-syntax-forward " " end) 277 (skip-syntax-forward " " end)
280 (delete-char (- (skip-syntax-backward " "))) 278 (delete-char (- (skip-syntax-backward " ")))
281 (or (eobp) (looking-at "\n\n") 279 (or (eobp) (looking-at "\n\n")
282 (insert "\n")))) 280 (insert "\n"))))
283 281
282 ;; Compatibility with old names.
283 (defvaralias 'vc-comment-ring 'log-edit-comment-ring)
284 (make-obsolete-variable 'vc-comment-ring 'log-edit-comment-ring "21.5")
285 (defvaralias 'vc-comment-ring-index 'log-edit-comment-ring-index)
286 (make-obsolete-variable 'vc-comment-ring-index 'log-edit-comment-ring-index "21.5")
287 (defalias 'vc-previous-comment 'log-edit-previous-comment)
288 (make-obsolete 'vc-previous-comment 'log-edit-previous-comment "21.5")
289 (defalias 'vc-next-comment 'log-edit-next-comment)
290 (make-obsolete 'vc-next-comment 'log-edit-next-comment "21.5")
291 (defalias 'vc-comment-search-reverse 'log-edit-comment-search-backward)
292 (make-obsolete 'vc-comment-search-reverse 'log-edit-comment-search-backward "21.5")
293 (defalias 'vc-comment-search-forward 'log-edit-comment-search-forward)
294 (make-obsolete 'vc-comment-search-forward 'log-edit-comment-search-forward "21.5")
295 (defalias 'vc-comment-to-change-log 'log-edit-comment-to-change-log)
296 (make-obsolete 'vc-comment-to-change-log 'log-edit-comment-to-change-log "21.5")
297
284 ;;; 298 ;;;
285 ;;; Actual code 299 ;;; Actual code
286 ;;; 300 ;;;
287 301
288 ;;;###autoload 302 ;;;###autoload
321 Several other handy support commands are provided of course and 335 Several other handy support commands are provided of course and
322 the package from which this is used might also provide additional 336 the package from which this is used might also provide additional
323 commands (under C-x v for VC, for example). 337 commands (under C-x v for VC, for example).
324 338
325 \\{log-edit-mode-map}" 339 \\{log-edit-mode-map}"
326 (make-local-variable 'vc-comment-ring-index)) 340 (make-local-variable 'log-edit-comment-ring-index))
327 341
328 (defun log-edit-hide-buf (&optional buf where) 342 (defun log-edit-hide-buf (&optional buf where)
329 (when (setq buf (get-buffer (or buf log-edit-files-buf))) 343 (when (setq buf (get-buffer (or buf log-edit-files-buf)))
330 (let ((win (get-buffer-window buf where))) 344 (let ((win (get-buffer-window buf where)))
331 (if win (ignore-errors (delete-window win)))) 345 (if win (ignore-errors (delete-window win))))
350 (buffer-name)))))) 364 (buffer-name))))))
351 (save-excursion 365 (save-excursion
352 (goto-char (point-max)) 366 (goto-char (point-max))
353 (insert ?\n))) 367 (insert ?\n)))
354 (let ((comment (buffer-string))) 368 (let ((comment (buffer-string)))
355 (when (or (ring-empty-p vc-comment-ring) 369 (when (or (ring-empty-p log-edit-comment-ring)
356 (not (equal comment (ring-ref vc-comment-ring 0)))) 370 (not (equal comment (ring-ref log-edit-comment-ring 0))))
357 (ring-insert vc-comment-ring comment))) 371 (ring-insert log-edit-comment-ring comment)))
358 (let ((win (get-buffer-window log-edit-files-buf))) 372 (let ((win (get-buffer-window log-edit-files-buf)))
359 (if (and log-edit-confirm 373 (if (and log-edit-confirm
360 (not (and (eq log-edit-confirm 'changed) 374 (not (and (eq log-edit-confirm 'changed)
361 (equal (log-edit-files) log-edit-initial-files))) 375 (equal (log-edit-files) log-edit-initial-files)))
362 (progn 376 (progn
451 465
452 (defun log-edit-add-to-changelog () 466 (defun log-edit-add-to-changelog ()
453 "Insert this log message into the appropriate ChangeLog file." 467 "Insert this log message into the appropriate ChangeLog file."
454 (interactive) 468 (interactive)
455 ;; Yuck! 469 ;; Yuck!
456 (unless (string= (buffer-string) (ring-ref vc-comment-ring 0)) 470 (unless (string= (buffer-string) (ring-ref log-edit-comment-ring 0))
457 (ring-insert vc-comment-ring (buffer-string))) 471 (ring-insert log-edit-comment-ring (buffer-string)))
458 (dolist (f (log-edit-files)) 472 (dolist (f (log-edit-files))
459 (let ((buffer-file-name (expand-file-name f))) 473 (let ((buffer-file-name (expand-file-name f)))
460 (save-excursion 474 (save-excursion
461 (vc-comment-to-change-log))))) 475 (log-edit-comment-to-change-log)))))
462 476
463 ;;;; 477 ;;;;
464 ;;;; functions for getting commit message from ChangeLog a file... 478 ;;;; functions for getting commit message from ChangeLog a file...
465 ;;;; Courtesy Jim Blandy 479 ;;;; Courtesy Jim Blandy
466 ;;;; 480 ;;;;