comparison lisp/add-log.el @ 27240:d7748c3e79ad

(add-log-debugging): Deleted. (add-change-log-entry): Treat a backup FILE-NAME as its parent file. Remove debugging code. (change-log-get-method-definition, change-log-name): Add doc. (change-log-sortable-date-at): New function. (change-log-merge): New command.
author Dave Love <fx@gnu.org>
date Fri, 07 Jan 2000 14:28:58 +0000
parents f6f431fc901b
children 9fdcfef41c64
comparison
equal deleted inserted replaced
27239:c681a4318a92 27240:d7748c3e79ad
1 ;;; add-log.el --- change log maintenance commands for Emacs 1 ;;; add-log.el --- change log maintenance commands for Emacs
2 2
3 ;; Copyright (C) 1985, 86, 88, 93, 94, 97, 1998 Free Software Foundation, Inc. 3 ;; Copyright (C) 1985, 86, 88, 93, 94, 97, 1998, 2000 Free Software Foundation, Inc.
4 4
5 ;; Keywords: tools 5 ;; Keywords: tools
6 6
7 ;; This file is part of GNU Emacs. 7 ;; This file is part of GNU Emacs.
8 8
27 27
28 ;;; Code: 28 ;;; Code:
29 29
30 (eval-when-compile 30 (eval-when-compile
31 (require 'fortran) 31 (require 'fortran)
32 (require 'timezone)
32 (require 'cl)) 33 (require 'cl))
33 34
34 (defgroup change-log nil 35 (defgroup change-log nil
35 "Change log maintenance" 36 "Change log maintenance"
36 :group 'tools 37 :group 'tools
59 :group 'change-log) 60 :group 'change-log)
60 61
61 ;;;###autoload 62 ;;;###autoload
62 (defcustom add-log-full-name nil 63 (defcustom add-log-full-name nil
63 "*Full name of user, for inclusion in ChangeLog daily headers. 64 "*Full name of user, for inclusion in ChangeLog daily headers.
64 This defaults to the value returned by the `user-full-name' function." 65 This defaults to the value returned by the function `user-full-name'."
65 :type '(choice (const :tag "Default" nil) 66 :type '(choice (const :tag "Default" nil)
66 string) 67 string)
67 :group 'change-log) 68 :group 'change-log)
68 69
69 ;;;###autoload 70 ;;;###autoload
118 :type 'boolean 119 :type 'boolean
119 :group 'change-log) 120 :group 'change-log)
120 121
121 (defcustom add-log-file-name-function nil 122 (defcustom add-log-file-name-function nil
122 "*If non-nil, function to call to identify the filename for a ChangeLog entry. 123 "*If non-nil, function to call to identify the filename for a ChangeLog entry.
123 This function is called with one argument, `buffer-file-name' in that buffer. 124 This function is called with one argument, the value of variable
124 If this is nil, the default is to use the file's name 125 `buffer-file-name' in that buffer. If this is nil, the default is to
125 relative to the directory of the change log file." 126 use the file's name relative to the directory of the change log file."
126 :type 'function 127 :type 'function
127 :group 'change-log) 128 :group 'change-log)
128 129
129 130
130 (defcustom change-log-version-info-enabled nil 131 (defcustom change-log-version-info-enabled nil
193 (defvar change-log-time-zone-rule nil 194 (defvar change-log-time-zone-rule nil
194 "Time zone used for calculating change log time stamps. 195 "Time zone used for calculating change log time stamps.
195 It takes the same format as the TZ argument of `set-time-zone-rule'. 196 It takes the same format as the TZ argument of `set-time-zone-rule'.
196 If nil, use local time.") 197 If nil, use local time.")
197 198
198 (defvar add-log-debugging)
199
200 (defun add-log-iso8601-time-zone (time) 199 (defun add-log-iso8601-time-zone (time)
201 (let* ((utc-offset (or (car (current-time-zone time)) 0)) 200 (let* ((utc-offset (or (car (current-time-zone time)) 0))
202 (sign (if (< utc-offset 0) ?- ?+)) 201 (sign (if (< utc-offset 0) ?- ?+))
203 (sec (abs utc-offset)) 202 (sec (abs utc-offset))
204 (ss (% sec 60)) 203 (ss (% sec 60))
223 (add-log-iso8601-time-zone now))) 222 (add-log-iso8601-time-zone now)))
224 (set-time-zone-rule tz))) 223 (set-time-zone-rule tz)))
225 (format-time-string "%Y-%m-%d"))) 224 (format-time-string "%Y-%m-%d")))
226 225
227 (defun change-log-name () 226 (defun change-log-name ()
227 "Return (system-dependent) default name for a change log file."
228 (or change-log-default-name 228 (or change-log-default-name
229 (if (eq system-type 'vax-vms) 229 (if (eq system-type 'vax-vms)
230 "$CHANGE_LOG$.TXT" 230 "$CHANGE_LOG$.TXT"
231 "ChangeLog"))) 231 "ChangeLog")))
232 232
391 391
392 ;; Set ENTRY to the file name to use in the new entry. 392 ;; Set ENTRY to the file name to use in the new entry.
393 (and buffer-file-name 393 (and buffer-file-name
394 ;; Never want to add a change log entry for the ChangeLog file itself. 394 ;; Never want to add a change log entry for the ChangeLog file itself.
395 (not (string= buffer-file-name file-name)) 395 (not (string= buffer-file-name file-name))
396 (setq entry 396 (if add-log-file-name-function
397 (if add-log-file-name-function 397 (setq entry
398 (funcall add-log-file-name-function buffer-file-name) 398 (funcall add-log-file-name-function buffer-file-name))
399 (setq entry
399 (if (string-match 400 (if (string-match
400 (concat "^" (regexp-quote (file-name-directory 401 (concat "^" (regexp-quote (file-name-directory
401 file-name))) 402 file-name)))
402 buffer-file-name) 403 buffer-file-name)
403 (substring buffer-file-name (match-end 0)) 404 (substring buffer-file-name (match-end 0))
404 (file-name-nondirectory buffer-file-name))))) 405 (file-name-nondirectory buffer-file-name)))
405 406 ;; If we have a backup file, it's presumably because we're
406 (let ((buffer (find-buffer-visiting file-name))) 407 ;; comparing old and new versions (e.g. for deleted
407 (setq add-log-debugging (list (gap-position) (gap-size)))) 408 ;; functions) and we'll want to use the original name.
409 (if (backup-file-name-p entry)
410 (setq entry (file-name-sans-versions entry)))))
411
408 (if (and other-window (not (equal file-name buffer-file-name))) 412 (if (and other-window (not (equal file-name buffer-file-name)))
409 (find-file-other-window file-name) 413 (find-file-other-window file-name)
410 (find-file file-name)) 414 (find-file file-name))
411 (or (eq major-mode 'change-log-mode) 415 (or (eq major-mode 'change-log-mode)
412 (change-log-mode)) 416 (change-log-mode))
786 (concat change-log-get-method-definition-md 790 (concat change-log-get-method-definition-md
787 (buffer-substring (match-beginning 1) (match-end 1)) 791 (buffer-substring (match-beginning 1) (match-end 1))
788 end)) 792 end))
789 (goto-char (match-end 0))) 793 (goto-char (match-end 0)))
790 794
791 ;; For objective C, return the method name if we are in a method.
792 (defun change-log-get-method-definition () 795 (defun change-log-get-method-definition ()
796 "For objective C, return the method name if we are in a method."
793 (let ((change-log-get-method-definition-md "[")) 797 (let ((change-log-get-method-definition-md "["))
794 (save-excursion 798 (save-excursion
795 (if (re-search-backward "^@implementation\\s-*\\([A-Za-z_]*\\)" nil t) 799 (if (re-search-backward "^@implementation\\s-*\\([A-Za-z_]*\\)" nil t)
796 (change-log-get-method-definition-1 " "))) 800 (change-log-get-method-definition-1 " ")))
797 (save-excursion 801 (save-excursion
801 (while (not (looking-at "[{;]")) 805 (while (not (looking-at "[{;]"))
802 (looking-at 806 (looking-at
803 "\\([A-Za-z_]*:?\\)\\s-*\\(([^)]*)\\)?[A-Za-z_]*[ \t\n\f\r]*") 807 "\\([A-Za-z_]*:?\\)\\s-*\\(([^)]*)\\)?[A-Za-z_]*[ \t\n\f\r]*")
804 (change-log-get-method-definition-1 "")) 808 (change-log-get-method-definition-1 ""))
805 (concat change-log-get-method-definition-md "]")))))) 809 (concat change-log-get-method-definition-md "]"))))))
806 810
811 (defun change-log-sortable-date-at ()
812 "Return date of log entry in a consistent form for sorting.
813 Point is assumed to be at the start of the entry."
814 (require 'timezone)
815 (if (looking-at "^\\sw.........[0-9:+ ]*")
816 (let ((date (match-string-no-properties 0)))
817 (if date
818 (if (string-match "\\(....\\)-\\(..\\)-\\(..\\)\\s-+" date)
819 (concat (match-string 1 date) (match-string 2 date)
820 (match-string 3 date))
821 (condition-case nil
822 (timezone-make-date-sortable date)
823 (error nil)))))
824 (error "Bad date")))
825
826 ;;;###autoload
827 (defun change-log-merge (other-log)
828 "Merge the contents of ChangeLog file OTHER-LOG with this buffer.
829 Both must be found in Change Log mode (since the merging depends on
830 the appropriate motion commands).
831
832 Entries are inserted in chronological order.
833
834 Both the current and old-style time formats for entries are supported,
835 so this command could be used to convert old-style logs by merging
836 with an empty log."
837 (interactive "*fLog file name to merge: ")
838 (if (not (eq major-mode 'change-log-mode))
839 (error "Not in Change Log mode"))
840 (let ((other-buf (find-file-noselect other-log))
841 (buf (current-buffer))
842 date1 start end)
843 (save-excursion
844 (goto-char (point-min))
845 (set-buffer other-buf)
846 (goto-char (point-min))
847 (if (not (eq major-mode 'change-log-mode))
848 (error "%s not found in Change Log mode" other-log))
849 ;; Loop through all the entries in OTHER-LOG.
850 (while (not (eobp))
851 (setq date1 (change-log-sortable-date-at))
852 (setq start (point)
853 end (progn (forward-page) (point)))
854 ;; Look for an entry in original buffer that isn't later.
855 (with-current-buffer buf
856 (while (and (not (eobp))
857 (string< date1 (change-log-sortable-date-at)))
858 (forward-page))
859 (if (not (eobp))
860 (insert-buffer-substring other-buf start end)
861 ;; At the end of the original buffer, insert a newline to
862 ;; separate entries and then the rest of the file being
863 ;; merged. Move to the end of it to terminate outer loop.
864 (insert "\n")
865 (insert-buffer-substring other-buf start
866 (with-current-buffer other-buf
867 (goto-char (point-max))
868 (point)))))))))
807 869
808 (provide 'add-log) 870 (provide 'add-log)
809 871
810 ;;; add-log.el ends here 872 ;;; add-log.el ends here