Mercurial > emacs
comparison lisp/add-log.el @ 82005:0de2cd15c33d
(add-change-log-entry, add-log-current-defun, change-log-merge):
Use derived-mode-p rather than checking major-mode directly.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Fri, 20 Jul 2007 20:30:51 +0000 |
parents | 571d99dbf19d |
children | c934794f2e69 |
comparison
equal
deleted
inserted
replaced
82004:af49557163c6 | 82005:0de2cd15c33d |
---|---|
53 :group 'change-log) | 53 :group 'change-log) |
54 | 54 |
55 ;; Many modes set this variable, so avoid warnings. | 55 ;; Many modes set this variable, so avoid warnings. |
56 ;;;###autoload | 56 ;;;###autoload |
57 (defcustom add-log-current-defun-function nil | 57 (defcustom add-log-current-defun-function nil |
58 "*If non-nil, function to guess name of surrounding function. | 58 "If non-nil, function to guess name of surrounding function. |
59 It is used by `add-log-current-defun' in preference to built-in rules. | 59 It is used by `add-log-current-defun' in preference to built-in rules. |
60 Returns function's name as a string, or nil if outside a function." | 60 Returns function's name as a string, or nil if outside a function." |
61 :type '(choice (const nil) function) | 61 :type '(choice (const nil) function) |
62 :group 'change-log) | 62 :group 'change-log) |
63 | 63 |
64 ;;;###autoload | 64 ;;;###autoload |
65 (defcustom add-log-full-name nil | 65 (defcustom add-log-full-name nil |
66 "*Full name of user, for inclusion in ChangeLog daily headers. | 66 "Full name of user, for inclusion in ChangeLog daily headers. |
67 This defaults to the value returned by the function `user-full-name'." | 67 This defaults to the value returned by the function `user-full-name'." |
68 :type '(choice (const :tag "Default" nil) | 68 :type '(choice (const :tag "Default" nil) |
69 string) | 69 string) |
70 :group 'change-log) | 70 :group 'change-log) |
71 | 71 |
146 :type '(choice (const nil) function) | 146 :type '(choice (const nil) function) |
147 :group 'change-log) | 147 :group 'change-log) |
148 | 148 |
149 | 149 |
150 (defcustom change-log-version-info-enabled nil | 150 (defcustom change-log-version-info-enabled nil |
151 "*If non-nil, enable recording version numbers with the changes." | 151 "If non-nil, enable recording version numbers with the changes." |
152 :version "21.1" | 152 :version "21.1" |
153 :type 'boolean | 153 :type 'boolean |
154 :group 'change-log) | 154 :group 'change-log) |
155 | 155 |
156 (defcustom change-log-version-number-regexp-list | 156 (defcustom change-log-version-number-regexp-list |
158 (list | 158 (list |
159 ;; (defconst ad-version "2.15" | 159 ;; (defconst ad-version "2.15" |
160 (concat "^(def[^ \t\n]+[ \t]+[^ \t\n][ \t]\"" re) | 160 (concat "^(def[^ \t\n]+[ \t]+[^ \t\n][ \t]\"" re) |
161 ;; Revision: pcl-cvs.el,v 1.72 1999/09/05 20:21:54 monnier Exp | 161 ;; Revision: pcl-cvs.el,v 1.72 1999/09/05 20:21:54 monnier Exp |
162 (concat "^;+ *Revision: +[^ \t\n]+[ \t]+" re))) | 162 (concat "^;+ *Revision: +[^ \t\n]+[ \t]+" re))) |
163 "*List of regexps to search for version number. | 163 "List of regexps to search for version number. |
164 The version number must be in group 1. | 164 The version number must be in group 1. |
165 Note: The search is conducted only within 10%, at the beginning of the file." | 165 Note: The search is conducted only within 10%, at the beginning of the file." |
166 :version "21.1" | 166 :version "21.1" |
167 :type '(repeat regexp) | 167 :type '(repeat regexp) |
168 :group 'change-log) | 168 :group 'change-log) |
508 | 508 |
509 (unless (equal file-name buffer-file-name) | 509 (unless (equal file-name buffer-file-name) |
510 (if (or other-window (window-dedicated-p (selected-window))) | 510 (if (or other-window (window-dedicated-p (selected-window))) |
511 (find-file-other-window file-name) | 511 (find-file-other-window file-name) |
512 (find-file file-name))) | 512 (find-file file-name))) |
513 (or (eq major-mode 'change-log-mode) | 513 (or (derived-mode-p 'change-log-mode) |
514 (change-log-mode)) | 514 (change-log-mode)) |
515 (undo-boundary) | 515 (undo-boundary) |
516 (goto-char (point-min)) | 516 (goto-char (point-min)) |
517 | 517 |
518 (let ((full-name (or add-log-full-name (user-full-name))) | 518 (let ((full-name (or add-log-full-name (user-full-name))) |
749 '(c-mode c++-mode c++-c-mode objc-mode) | 749 '(c-mode c++-mode c++-c-mode objc-mode) |
750 "*Modes that look like C to `add-log-current-defun'.") | 750 "*Modes that look like C to `add-log-current-defun'.") |
751 | 751 |
752 ;;;###autoload | 752 ;;;###autoload |
753 (defvar add-log-tex-like-modes | 753 (defvar add-log-tex-like-modes |
754 '(TeX-mode plain-TeX-mode LaTeX-mode plain-tex-mode latex-mode) | 754 '(TeX-mode plain-TeX-mode LaTeX-mode tex-mode) |
755 "*Modes that look like TeX to `add-log-current-defun'.") | 755 "*Modes that look like TeX to `add-log-current-defun'.") |
756 | 756 |
757 ;;;###autoload | 757 ;;;###autoload |
758 (defun add-log-current-defun () | 758 (defun add-log-current-defun () |
759 "Return name of function definition point is in, or nil. | 759 "Return name of function definition point is in, or nil. |
771 (condition-case nil | 771 (condition-case nil |
772 (save-excursion | 772 (save-excursion |
773 (let ((location (point))) | 773 (let ((location (point))) |
774 (cond (add-log-current-defun-function | 774 (cond (add-log-current-defun-function |
775 (funcall add-log-current-defun-function)) | 775 (funcall add-log-current-defun-function)) |
776 ((memq major-mode add-log-lisp-like-modes) | 776 ((apply 'derived-mode-p add-log-lisp-like-modes) |
777 ;; If we are now precisely at the beginning of a defun, | 777 ;; If we are now precisely at the beginning of a defun, |
778 ;; make sure beginning-of-defun finds that one | 778 ;; make sure beginning-of-defun finds that one |
779 ;; rather than the previous one. | 779 ;; rather than the previous one. |
780 (or (eobp) (forward-char 1)) | 780 (or (eobp) (forward-char 1)) |
781 (beginning-of-defun) | 781 (beginning-of-defun) |
795 ;; If it is not, use the first symbol in it. | 795 ;; If it is not, use the first symbol in it. |
796 (skip-chars-forward " \t\n'(") | 796 (skip-chars-forward " \t\n'(") |
797 (buffer-substring-no-properties (point) | 797 (buffer-substring-no-properties (point) |
798 (progn (forward-sexp 1) | 798 (progn (forward-sexp 1) |
799 (point))))) | 799 (point))))) |
800 ((and (memq major-mode add-log-c-like-modes) | 800 ((and (apply 'derived-mode-p add-log-c-like-modes) |
801 (save-excursion | 801 (save-excursion |
802 (beginning-of-line) | 802 (beginning-of-line) |
803 ;; Use eq instead of = here to avoid | 803 ;; Use eq instead of = here to avoid |
804 ;; error when at bob and char-after | 804 ;; error when at bob and char-after |
805 ;; returns nil. | 805 ;; returns nil. |
813 (search-forward "define") | 813 (search-forward "define") |
814 (skip-chars-forward " \t") | 814 (skip-chars-forward " \t") |
815 (buffer-substring-no-properties (point) | 815 (buffer-substring-no-properties (point) |
816 (progn (forward-sexp 1) | 816 (progn (forward-sexp 1) |
817 (point)))) | 817 (point)))) |
818 ((memq major-mode add-log-c-like-modes) | 818 ((apply 'derived-mode-p add-log-c-like-modes) |
819 ;; See whether the point is inside a defun. | 819 ;; See whether the point is inside a defun. |
820 (let (having-previous-defun | 820 (let (having-previous-defun |
821 having-next-defun | 821 having-next-defun |
822 previous-defun-end | 822 previous-defun-end |
823 next-defun-beginning) | 823 next-defun-beginning) |
955 (forward-char -1) | 955 (forward-char -1) |
956 (skip-chars-backward " \t") | 956 (skip-chars-backward " \t") |
957 (setq end (point))) | 957 (setq end (point))) |
958 (buffer-substring-no-properties | 958 (buffer-substring-no-properties |
959 middle end))))))))) | 959 middle end))))))))) |
960 ((memq major-mode add-log-tex-like-modes) | 960 ((apply 'derived-mode-p add-log-tex-like-modes) |
961 (if (re-search-backward | 961 (if (re-search-backward |
962 "\\\\\\(sub\\)*\\(section\\|paragraph\\|chapter\\)" | 962 "\\\\\\(sub\\)*\\(section\\|paragraph\\|chapter\\)" |
963 nil t) | 963 nil t) |
964 (progn | 964 (progn |
965 (goto-char (match-beginning 0)) | 965 (goto-char (match-beginning 0)) |
966 (buffer-substring-no-properties | 966 (buffer-substring-no-properties |
967 (1+ (point)) ; without initial backslash | 967 (1+ (point)) ; without initial backslash |
968 (line-end-position))))) | 968 (line-end-position))))) |
969 ((eq major-mode 'texinfo-mode) | 969 ((derived-mode-p 'texinfo-mode) |
970 (if (re-search-backward "^@node[ \t]+\\([^,\n]+\\)" nil t) | 970 (if (re-search-backward "^@node[ \t]+\\([^,\n]+\\)" nil t) |
971 (match-string-no-properties 1))) | 971 (match-string-no-properties 1))) |
972 ((memq major-mode '(perl-mode cperl-mode)) | 972 ((derived-mode-p '(perl-mode cperl-mode)) |
973 (if (re-search-backward "^sub[ \t]+\\([^({ \t\n]+\\)" nil t) | 973 (if (re-search-backward "^sub[ \t]+\\([^({ \t\n]+\\)" nil t) |
974 (match-string-no-properties 1))) | 974 (match-string-no-properties 1))) |
975 ;; Emacs's autoconf-mode installs its own | 975 ;; Emacs's autoconf-mode installs its own |
976 ;; `add-log-current-defun-function'. This applies to | 976 ;; `add-log-current-defun-function'. This applies to |
977 ;; a different mode apparently for editing .m4 | 977 ;; a different mode apparently for editing .m4 |
978 ;; autoconf source. | 978 ;; autoconf source. |
979 ((eq major-mode 'autoconf-mode) | 979 ((derived-mode-p 'autoconf-mode) |
980 (if (re-search-backward | 980 (if (re-search-backward |
981 "^\\(\\(m4_\\)?define\\|A._DEFUN\\)(\\[?\\([A-Za-z0-9_]+\\)" nil t) | 981 "^\\(\\(m4_\\)?define\\|A._DEFUN\\)(\\[?\\([A-Za-z0-9_]+\\)" nil t) |
982 (match-string-no-properties 3))) | 982 (match-string-no-properties 3))) |
983 (t | 983 (t |
984 ;; If all else fails, try heuristics | 984 ;; If all else fails, try heuristics |
1063 or a buffer. | 1063 or a buffer. |
1064 | 1064 |
1065 Entries are inserted in chronological order. Both the current and | 1065 Entries are inserted in chronological order. Both the current and |
1066 old-style time formats for entries are supported." | 1066 old-style time formats for entries are supported." |
1067 (interactive "*fLog file name to merge: ") | 1067 (interactive "*fLog file name to merge: ") |
1068 (if (not (eq major-mode 'change-log-mode)) | 1068 (if (not (derived-mode-p 'change-log-mode)) |
1069 (error "Not in Change Log mode")) | 1069 (error "Not in Change Log mode")) |
1070 (let ((other-buf (if (bufferp other-log) other-log | 1070 (let ((other-buf (if (bufferp other-log) other-log |
1071 (find-file-noselect other-log))) | 1071 (find-file-noselect other-log))) |
1072 (buf (current-buffer)) | 1072 (buf (current-buffer)) |
1073 date1 start end) | 1073 date1 start end) |
1074 (save-excursion | 1074 (save-excursion |
1075 (goto-char (point-min)) | 1075 (goto-char (point-min)) |
1076 (set-buffer other-buf) | 1076 (set-buffer other-buf) |
1077 (goto-char (point-min)) | 1077 (goto-char (point-min)) |
1078 (if (not (eq major-mode 'change-log-mode)) | 1078 (if (not (derived-mode-p 'change-log-mode)) |
1079 (error "%s not found in Change Log mode" other-log)) | 1079 (error "%s not found in Change Log mode" other-log)) |
1080 ;; Loop through all the entries in OTHER-LOG. | 1080 ;; Loop through all the entries in OTHER-LOG. |
1081 (while (not (eobp)) | 1081 (while (not (eobp)) |
1082 (setq date1 (change-log-sortable-date-at)) | 1082 (setq date1 (change-log-sortable-date-at)) |
1083 (setq start (point) | 1083 (setq start (point) |