aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoakim Verona2012-12-01 06:05:38 +0100
committerJoakim Verona2012-12-01 06:05:38 +0100
commit5cbfa1d898916fdbc9165e2db7b690baa4de5fba (patch)
treee9a17b83255e59492bbe99f7665afd722d82d07d
parent1e9365204f27206b86e32e2b25114f5614b655b6 (diff)
parentba03d0d932888f687ae9c9fb12e20908c6b0620f (diff)
downloademacs-5cbfa1d898916fdbc9165e2db7b690baa4de5fba.tar.gz
emacs-5cbfa1d898916fdbc9165e2db7b690baa4de5fba.zip
auto upstream
-rw-r--r--lisp/ChangeLog32
-rw-r--r--lisp/emacs-lisp/lisp-mode.el26
-rw-r--r--lisp/progmodes/cc-mode.el4
-rw-r--r--lisp/progmodes/cperl-mode.el6
-rw-r--r--lisp/progmodes/m4-mode.el13
-rw-r--r--lisp/progmodes/perl-mode.el8
-rw-r--r--lisp/progmodes/scheme.el68
-rw-r--r--lisp/textmodes/tex-mode.el11
-rw-r--r--lisp/textmodes/texinfo.el12
-rw-r--r--lisp/vc/add-log.el104
10 files changed, 157 insertions, 127 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 334efbc10e1..c7fb5cabe07 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,37 @@
12012-12-01 Chong Yidong <cyd@gnu.org> 12012-12-01 Chong Yidong <cyd@gnu.org>
2 2
3 Modularize add-log-current-defun (Bug#2224).
4 Suggested by Jari Aalto.
5
6 * vc/add-log.el (add-log-current-defun-function): Doc fix.
7 (add-log-current-defun): Move mode-specific code to other files.
8 (add-log-lisp-like-modes, add-log-c-like-modes)
9 (add-log-tex-like-modes): Variables deleted.
10
11 * emacs-lisp/lisp-mode.el (lisp-current-defun-name): New.
12 (lisp-mode-variables): Use it.
13
14 * progmodes/cc-mode.el (c-common-init):
15 * progmodes/cperl-mode.el (cperl-mode): Set a value for
16 add-log-current-defun-function.
17
18 * progmodes/m4-mode.el (m4-current-defun-name): New function.
19 (m4-mode): Use it.
20
21 * progmodes/perl-mode.el (perl-current-defun-name): New.
22 (perl-mode): Use it.
23
24 * progmodes/scheme.el (scheme-mode-variables, dsssl-mode): Use
25 lisp-current-defun-name.
26
27 * textmodes/tex-mode.el (tex-current-defun-name): New.
28 (tex-common-initialization): Use it.
29
30 * textmodes/texinfo.el (texinfo-current-defun-name): New.
31 (texinfo-mode): Use it.
32
332012-12-01 Chong Yidong <cyd@gnu.org>
34
3 * emacs-lisp/lisp-mode.el (lisp-mode-variables, lisp-mode): 35 * emacs-lisp/lisp-mode.el (lisp-mode-variables, lisp-mode):
4 * progmodes/autoconf.el (autoconf-mode): 36 * progmodes/autoconf.el (autoconf-mode):
5 * progmodes/js.el (js-mode): 37 * progmodes/js.el (js-mode):
diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el
index 81adab53c93..11dd6dc6ee2 100644
--- a/lisp/emacs-lisp/lisp-mode.el
+++ b/lisp/emacs-lisp/lisp-mode.el
@@ -209,6 +209,7 @@ font-lock keywords will not be case sensitive."
209 (setq-local indent-line-function 'lisp-indent-line) 209 (setq-local indent-line-function 'lisp-indent-line)
210 (setq-local outline-regexp ";;;\\(;* [^ \t\n]\\|###autoload\\)\\|(") 210 (setq-local outline-regexp ";;;\\(;* [^ \t\n]\\|###autoload\\)\\|(")
211 (setq-local outline-level 'lisp-outline-level) 211 (setq-local outline-level 'lisp-outline-level)
212 (setq-local add-log-current-defun-function #'lisp-current-defun-name)
212 (setq-local comment-start ";") 213 (setq-local comment-start ";")
213 ;; Look within the line for a ; following an even number of backslashes 214 ;; Look within the line for a ; following an even number of backslashes
214 ;; after either a non-backslash or the line beginning. 215 ;; after either a non-backslash or the line beginning.
@@ -237,6 +238,31 @@ font-lock keywords will not be case sensitive."
237 1000 238 1000
238 len))) 239 len)))
239 240
241(defun lisp-current-defun-name ()
242 "Return the name of the defun at point, or nil."
243 (let ((location (point)))
244 ;; If we are now precisely at the beginning of a defun, make sure
245 ;; beginning-of-defun finds that one rather than the previous one.
246 (or (eobp) (forward-char 1))
247 (beginning-of-defun)
248 ;; Make sure we are really inside the defun found, not after it.
249 (when (and (looking-at "\\s(")
250 (progn (end-of-defun)
251 (< location (point)))
252 (progn (forward-sexp -1)
253 (>= location (point))))
254 (if (looking-at "\\s(")
255 (forward-char 1))
256 ;; Skip the defining construct name, typically "defun" or
257 ;; "defvar".
258 (forward-sexp 1)
259 ;; The second element is usually a symbol being defined. If it
260 ;; is not, use the first symbol in it.
261 (skip-chars-forward " \t\n'(")
262 (buffer-substring-no-properties (point)
263 (progn (forward-sexp 1)
264 (point))))))
265
240(defvar lisp-mode-shared-map 266(defvar lisp-mode-shared-map
241 (let ((map (make-sparse-keymap))) 267 (let ((map (make-sparse-keymap)))
242 (define-key map "\e\C-q" 'indent-sexp) 268 (define-key map "\e\C-q" 'indent-sexp)
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
index 91866278e28..a904ffdb811 100644
--- a/lisp/progmodes/cc-mode.el
+++ b/lisp/progmodes/cc-mode.el
@@ -647,7 +647,9 @@ compatible with old code; callers should always specify it."
647 647
648 (set (make-local-variable 'outline-regexp) "[^#\n\^M]") 648 (set (make-local-variable 'outline-regexp) "[^#\n\^M]")
649 (set (make-local-variable 'outline-level) 'c-outline-level) 649 (set (make-local-variable 'outline-level) 'c-outline-level)
650 650 (set (make-local-variable 'add-log-current-defun-function)
651 (lambda ()
652 (or (c-cpp-define-name) (c-defun-name))))
651 (let ((rfn (assq mode c-require-final-newline))) 653 (let ((rfn (assq mode c-require-final-newline)))
652 (when rfn 654 (when rfn
653 (and (cdr rfn) 655 (and (cdr rfn)
diff --git a/lisp/progmodes/cperl-mode.el b/lisp/progmodes/cperl-mode.el
index e1430b67e99..5b5097803c3 100644
--- a/lisp/progmodes/cperl-mode.el
+++ b/lisp/progmodes/cperl-mode.el
@@ -1742,6 +1742,12 @@ or as help on variables `cperl-tips', `cperl-problems',
1742 (setq outline-regexp cperl-outline-regexp) 1742 (setq outline-regexp cperl-outline-regexp)
1743 (make-local-variable 'outline-level) 1743 (make-local-variable 'outline-level)
1744 (setq outline-level 'cperl-outline-level) 1744 (setq outline-level 'cperl-outline-level)
1745 (make-local-variable 'add-log-current-defun-function)
1746 (setq add-log-current-defun-function
1747 (lambda ()
1748 (if (re-search-backward "^sub[ \t]+\\([^({ \t\n]+\\)" nil t)
1749 (match-string-no-properties 1))))
1750
1745 (make-local-variable 'paragraph-start) 1751 (make-local-variable 'paragraph-start)
1746 (setq paragraph-start (concat "^$\\|" page-delimiter)) 1752 (setq paragraph-start (concat "^$\\|" page-delimiter))
1747 (make-local-variable 'paragraph-separate) 1753 (make-local-variable 'paragraph-separate)
diff --git a/lisp/progmodes/m4-mode.el b/lisp/progmodes/m4-mode.el
index 20f91ce2d9e..9cf98d979f6 100644
--- a/lisp/progmodes/m4-mode.el
+++ b/lisp/progmodes/m4-mode.el
@@ -141,13 +141,20 @@
141 "*m4-output*" nil) 141 "*m4-output*" nil)
142 (switch-to-buffer-other-window "*m4-output*")) 142 (switch-to-buffer-other-window "*m4-output*"))
143 143
144(defun m4-current-defun-name ()
145 "Return the name of the M4 function at point, or nil."
146 (if (re-search-backward
147 "^\\(\\(m4_\\)?define\\|A._DEFUN\\)(\\[?\\([A-Za-z0-9_]+\\)" nil t)
148 (match-string-no-properties 3)))
149
144;;;###autoload 150;;;###autoload
145(define-derived-mode m4-mode prog-mode "m4" 151(define-derived-mode m4-mode prog-mode "m4"
146 "A major mode to edit m4 macro files." 152 "A major mode to edit m4 macro files."
147 :abbrev-table m4-mode-abbrev-table 153 :abbrev-table m4-mode-abbrev-table
148 (set (make-local-variable 'comment-start) "#") 154 (setq-local comment-start "#")
149 (set (make-local-variable 'parse-sexp-ignore-comments) t) 155 (setq-local parse-sexp-ignore-comments t)
150 (set (make-local-variable 'font-lock-defaults) '(m4-font-lock-keywords nil))) 156 (setq-local add-log-current-defun-function #'m4-current-defun-name)
157 (setq font-lock-defaults '(m4-font-lock-keywords nil)))
151 158
152(provide 'm4-mode) 159(provide 'm4-mode)
153;;stuff to play with for debugging 160;;stuff to play with for debugging
diff --git a/lisp/progmodes/perl-mode.el b/lisp/progmodes/perl-mode.el
index f8ae0030cf0..82f742de274 100644
--- a/lisp/progmodes/perl-mode.el
+++ b/lisp/progmodes/perl-mode.el
@@ -578,6 +578,11 @@ create a new comment."
578 ((looking-at "=head[0-9]") (- (char-before (match-end 0)) ?0)) 578 ((looking-at "=head[0-9]") (- (char-before (match-end 0)) ?0))
579 ((looking-at "=cut") 1) 579 ((looking-at "=cut") 1)
580 (t 3))) 580 (t 3)))
581
582(defun perl-current-defun-name ()
583 "The `add-log-current-defun' function in Perl mode."
584 (if (re-search-backward "^sub[ \t]+\\([^({ \t\n]+\\)" nil t)
585 (match-string-no-properties 1)))
581 586
582(defvar perl-mode-hook nil 587(defvar perl-mode-hook nil
583 "Normal hook to run when entering Perl mode.") 588 "Normal hook to run when entering Perl mode.")
@@ -660,7 +665,8 @@ Turning on Perl mode runs the normal hook `perl-mode-hook'."
660 (setq imenu-case-fold-search nil) 665 (setq imenu-case-fold-search nil)
661 ;; Setup outline-minor-mode. 666 ;; Setup outline-minor-mode.
662 (setq-local outline-regexp perl-outline-regexp) 667 (setq-local outline-regexp perl-outline-regexp)
663 (setq-local outline-level 'perl-outline-level)) 668 (setq-local outline-level 'perl-outline-level)
669 (setq-local add-log-current-defun-function #'perl-current-defun-name))
664 670
665;; This is used by indent-for-comment 671;; This is used by indent-for-comment
666;; to decide how much to indent a comment in Perl code 672;; to decide how much to indent a comment in Perl code
diff --git a/lisp/progmodes/scheme.el b/lisp/progmodes/scheme.el
index 7cab07fe387..1a15f9eda3c 100644
--- a/lisp/progmodes/scheme.el
+++ b/lisp/progmodes/scheme.el
@@ -126,44 +126,44 @@
126(defun scheme-mode-variables () 126(defun scheme-mode-variables ()
127 (set-syntax-table scheme-mode-syntax-table) 127 (set-syntax-table scheme-mode-syntax-table)
128 (setq local-abbrev-table scheme-mode-abbrev-table) 128 (setq local-abbrev-table scheme-mode-abbrev-table)
129 (set (make-local-variable 'paragraph-start) (concat "$\\|" page-delimiter)) 129 (setq-local paragraph-start (concat "$\\|" page-delimiter))
130 (set (make-local-variable 'paragraph-separate) paragraph-start) 130 (setq-local paragraph-separate paragraph-start)
131 (set (make-local-variable 'paragraph-ignore-fill-prefix) t) 131 (setq-local paragraph-ignore-fill-prefix t)
132 (set (make-local-variable 'fill-paragraph-function) 'lisp-fill-paragraph) 132 (setq-local fill-paragraph-function 'lisp-fill-paragraph)
133 ;; Adaptive fill mode gets in the way of auto-fill, 133 ;; Adaptive fill mode gets in the way of auto-fill,
134 ;; and should make no difference for explicit fill 134 ;; and should make no difference for explicit fill
135 ;; because lisp-fill-paragraph should do the job. 135 ;; because lisp-fill-paragraph should do the job.
136 (set (make-local-variable 'adaptive-fill-mode) nil) 136 (setq-local adaptive-fill-mode nil)
137 (set (make-local-variable 'indent-line-function) 'lisp-indent-line) 137 (setq-local indent-line-function 'lisp-indent-line)
138 (set (make-local-variable 'parse-sexp-ignore-comments) t) 138 (setq-local parse-sexp-ignore-comments t)
139 (set (make-local-variable 'outline-regexp) ";;; \\|(....") 139 (setq-local outline-regexp ";;; \\|(....")
140 (set (make-local-variable 'comment-start) ";") 140 (setq-local add-log-current-defun-function #'lisp-current-defun-name)
141 (set (make-local-variable 'comment-add) 1) 141 (setq-local comment-start ";")
142 (setq-local comment-add 1)
142 ;; Look within the line for a ; following an even number of backslashes 143 ;; Look within the line for a ; following an even number of backslashes
143 ;; after either a non-backslash or the line beginning. 144 ;; after either a non-backslash or the line beginning.
144 (set (make-local-variable 'comment-start-skip) 145 (setq-local comment-start-skip
145 "\\(\\(^\\|[^\\\\\n]\\)\\(\\\\\\\\\\)*\\);+[ \t]*") 146 "\\(\\(^\\|[^\\\\\n]\\)\\(\\\\\\\\\\)*\\);+[ \t]*")
146 (set (make-local-variable 'font-lock-comment-start-skip) ";+ *") 147 (setq-local font-lock-comment-start-skip ";+ *")
147 (set (make-local-variable 'comment-column) 40) 148 (setq-local comment-column 40)
148 (set (make-local-variable 'parse-sexp-ignore-comments) t) 149 (setq-local parse-sexp-ignore-comments t)
149 (set (make-local-variable 'lisp-indent-function) 'scheme-indent-function) 150 (setq-local lisp-indent-function 'scheme-indent-function)
150 (setq mode-line-process '("" scheme-mode-line-process)) 151 (setq mode-line-process '("" scheme-mode-line-process))
151 (set (make-local-variable 'imenu-case-fold-search) t) 152 (setq-local imenu-case-fold-search t)
152 (setq imenu-generic-expression scheme-imenu-generic-expression) 153 (setq imenu-generic-expression scheme-imenu-generic-expression)
153 (set (make-local-variable 'imenu-syntax-alist) 154 (setq-local imenu-syntax-alist
154 '(("+-*/.<>=?!$%_&~^:" . "w"))) 155 '(("+-*/.<>=?!$%_&~^:" . "w")))
155 (set (make-local-variable 'font-lock-defaults) 156 (setq font-lock-defaults
156 '((scheme-font-lock-keywords 157 '((scheme-font-lock-keywords
157 scheme-font-lock-keywords-1 scheme-font-lock-keywords-2) 158 scheme-font-lock-keywords-1 scheme-font-lock-keywords-2)
158 nil t (("+-*/.<>=!?$%_&~^:" . "w") (?#. "w 14")) 159 nil t (("+-*/.<>=!?$%_&~^:" . "w") (?#. "w 14"))
159 beginning-of-defun 160 beginning-of-defun
160 (font-lock-mark-block-function . mark-defun) 161 (font-lock-mark-block-function . mark-defun)
161 (font-lock-syntactic-face-function 162 (font-lock-syntactic-face-function
162 . scheme-font-lock-syntactic-face-function) 163 . scheme-font-lock-syntactic-face-function)
163 (parse-sexp-lookup-properties . t) 164 (parse-sexp-lookup-properties . t)
164 (font-lock-extra-managed-props syntax-table))) 165 (font-lock-extra-managed-props syntax-table)))
165 (set (make-local-variable 'lisp-doc-string-elt-property) 166 (setq-local lisp-doc-string-elt-property 'scheme-doc-string-elt))
166 'scheme-doc-string-elt))
167 167
168(defvar scheme-mode-line-process "") 168(defvar scheme-mode-line-process "")
169 169
@@ -386,7 +386,7 @@ Blank lines separate paragraphs. Semicolons start comments.
386Entering this mode runs the hooks `scheme-mode-hook' and then 386Entering this mode runs the hooks `scheme-mode-hook' and then
387`dsssl-mode-hook' and inserts the value of `dsssl-sgml-declaration' if 387`dsssl-mode-hook' and inserts the value of `dsssl-sgml-declaration' if
388that variable's value is a string." 388that variable's value is a string."
389 (set (make-local-variable 'page-delimiter) "^;;;") ; ^L not valid SGML char 389 (setq-local page-delimiter "^;;;") ; ^L not valid SGML char
390 ;; Insert a suitable SGML declaration into an empty buffer. 390 ;; Insert a suitable SGML declaration into an empty buffer.
391 ;; FIXME: This should use `auto-insert-alist' instead. 391 ;; FIXME: This should use `auto-insert-alist' instead.
392 (and (zerop (buffer-size)) 392 (and (zerop (buffer-size))
@@ -397,10 +397,10 @@ that variable's value is a string."
397 nil t (("+-*/.<>=?$%_&~^:" . "w")) 397 nil t (("+-*/.<>=?$%_&~^:" . "w"))
398 beginning-of-defun 398 beginning-of-defun
399 (font-lock-mark-block-function . mark-defun))) 399 (font-lock-mark-block-function . mark-defun)))
400 (set (make-local-variable 'imenu-case-fold-search) nil) 400 (setq-local add-log-current-defun-function #'lisp-current-defun-name)
401 (setq-local imenu-case-fold-search nil)
401 (setq imenu-generic-expression dsssl-imenu-generic-expression) 402 (setq imenu-generic-expression dsssl-imenu-generic-expression)
402 (set (make-local-variable 'imenu-syntax-alist) 403 (setq-local imenu-syntax-alist '(("+-*/.<>=?$%_&~^:" . "w"))))
403 '(("+-*/.<>=?$%_&~^:" . "w"))))
404 404
405;; Extra syntax for DSSSL. This isn't separated from Scheme, but 405;; Extra syntax for DSSSL. This isn't separated from Scheme, but
406;; shouldn't cause much trouble in scheme-mode. 406;; shouldn't cause much trouble in scheme-mode.
diff --git a/lisp/textmodes/tex-mode.el b/lisp/textmodes/tex-mode.el
index c4fe0d629b4..966fa60e6de 100644
--- a/lisp/textmodes/tex-mode.el
+++ b/lisp/textmodes/tex-mode.el
@@ -421,6 +421,16 @@ An alternative value is \" . \", if you use a font with a narrow period."
421 (if (looking-at latex-outline-regexp) 421 (if (looking-at latex-outline-regexp)
422 (1+ (or (cdr (assoc (match-string 1) latex-section-alist)) -1)) 422 (1+ (or (cdr (assoc (match-string 1) latex-section-alist)) -1))
423 1000)) 423 1000))
424
425(defun tex-current-defun-name ()
426 "Return the name of the TeX section/paragraph/chapter at point, or nil."
427 (when (re-search-backward
428 "\\\\\\(sub\\)*\\(section\\|paragraph\\|chapter\\)"
429 nil t)
430 (goto-char (match-beginning 0))
431 (buffer-substring-no-properties
432 (1+ (point)) ; without initial backslash
433 (line-end-position))))
424 434
425;;;; 435;;;;
426;;;; Font-Lock support 436;;;; Font-Lock support
@@ -1202,6 +1212,7 @@ Entering SliTeX mode runs the hook `text-mode-hook', then the hook
1202 ;; A line starting with $$ starts a paragraph, 1212 ;; A line starting with $$ starts a paragraph,
1203 ;; but does not separate paragraphs if it has more stuff on it. 1213 ;; but does not separate paragraphs if it has more stuff on it.
1204 (setq-local paragraph-separate "[ \t]*$\\|[\f\\\\%]\\|[ \t]*\\$\\$[ \t]*$") 1214 (setq-local paragraph-separate "[ \t]*$\\|[\f\\\\%]\\|[ \t]*\\$\\$[ \t]*$")
1215 (setq-local add-log-current-defun-function #'tex-current-defun-name)
1205 (setq-local comment-start "%") 1216 (setq-local comment-start "%")
1206 (setq-local comment-add 1) 1217 (setq-local comment-add 1)
1207 (setq-local comment-start-skip 1218 (setq-local comment-start-skip
diff --git a/lisp/textmodes/texinfo.el b/lisp/textmodes/texinfo.el
index 91405ba0744..0e45b603c1a 100644
--- a/lisp/textmodes/texinfo.el
+++ b/lisp/textmodes/texinfo.el
@@ -511,6 +511,11 @@ Subexpression 1 is what goes into the corresponding `@end' statement.")
511 (regexp-opt (texinfo-filter 2 texinfo-section-list)) 511 (regexp-opt (texinfo-filter 2 texinfo-section-list))
512 "Regular expression matching just the Texinfo chapter level headings.") 512 "Regular expression matching just the Texinfo chapter level headings.")
513 513
514(defun texinfo-current-defun-name ()
515 "Return the name of the Texinfo node at point, or nil."
516 (if (re-search-backward "^@node[ \t]+\\([^,\n]+\\)" nil t)
517 (match-string-no-properties 1)))
518
514;;; Texinfo mode 519;;; Texinfo mode
515 520
516;;;###autoload 521;;;###autoload
@@ -587,8 +592,10 @@ value of `texinfo-mode-hook'."
587 (setq-local require-final-newline mode-require-final-newline) 592 (setq-local require-final-newline mode-require-final-newline)
588 (setq-local indent-tabs-mode nil) 593 (setq-local indent-tabs-mode nil)
589 (setq-local paragraph-separate 594 (setq-local paragraph-separate
590 (concat "\b\\|@[a-zA-Z]*[ \n]\\|" paragraph-separate)) 595 (concat "\b\\|@[a-zA-Z]*[ \n]\\|"
591 (setq-local paragraph-start (concat "\b\\|@[a-zA-Z]*[ \n]\\|" paragraph-start)) 596 paragraph-separate))
597 (setq-local paragraph-start (concat "\b\\|@[a-zA-Z]*[ \n]\\|"
598 paragraph-start))
592 (setq-local sentence-end-base "\\(@\\(end\\)?dots{}\\|[.?!]\\)[]\"'”)}]*") 599 (setq-local sentence-end-base "\\(@\\(end\\)?dots{}\\|[.?!]\\)[]\"'”)}]*")
593 (setq-local fill-column 70) 600 (setq-local fill-column 70)
594 (setq-local comment-start "@c ") 601 (setq-local comment-start "@c ")
@@ -600,6 +607,7 @@ value of `texinfo-mode-hook'."
600 '(texinfo-font-lock-keywords nil nil nil backward-paragraph)) 607 '(texinfo-font-lock-keywords nil nil nil backward-paragraph))
601 (setq-local syntax-propertize-function texinfo-syntax-propertize-function) 608 (setq-local syntax-propertize-function texinfo-syntax-propertize-function)
602 (setq-local parse-sexp-lookup-properties t) 609 (setq-local parse-sexp-lookup-properties t)
610 (setq-local add-log-current-defun-function #'texinfo-current-defun-name)
603 611
604 ;; Outline settings. 612 ;; Outline settings.
605 (setq-local outline-heading-alist 613 (setq-local outline-heading-alist
diff --git a/lisp/vc/add-log.el b/lisp/vc/add-log.el
index 5a378df6513..0d2b82cb9a7 100644
--- a/lisp/vc/add-log.el
+++ b/lisp/vc/add-log.el
@@ -61,8 +61,9 @@
61;;;###autoload 61;;;###autoload
62(defcustom add-log-current-defun-function nil 62(defcustom add-log-current-defun-function nil
63 "If non-nil, function to guess name of surrounding function. 63 "If non-nil, function to guess name of surrounding function.
64It is used by `add-log-current-defun' in preference to built-in rules. 64It is called by `add-log-current-defun' with no argument, and
65Returns function's name as a string, or nil if outside a function." 65should return the function's name as a string, or nil if point is
66outside a function."
66 :type '(choice (const nil) function) 67 :type '(choice (const nil) function)
67 :group 'change-log) 68 :group 'change-log)
68 69
@@ -1118,21 +1119,6 @@ parentheses."
1118 :type 'regexp 1119 :type 'regexp
1119 :group 'change-log) 1120 :group 'change-log)
1120 1121
1121;;;###autoload
1122(defvar add-log-lisp-like-modes
1123 '(emacs-lisp-mode lisp-mode scheme-mode dsssl-mode lisp-interaction-mode)
1124 "Modes that look like Lisp to `add-log-current-defun'.")
1125
1126;;;###autoload
1127(defvar add-log-c-like-modes
1128 '(c-mode c++-mode c++-c-mode objc-mode)
1129 "Modes that look like C to `add-log-current-defun'.")
1130
1131;;;###autoload
1132(defvar add-log-tex-like-modes
1133 '(TeX-mode plain-TeX-mode LaTeX-mode tex-mode)
1134 "Modes that look like TeX to `add-log-current-defun'.")
1135
1136(declare-function c-cpp-define-name "cc-cmds" ()) 1122(declare-function c-cpp-define-name "cc-cmds" ())
1137(declare-function c-defun-name "cc-cmds" ()) 1123(declare-function c-defun-name "cc-cmds" ())
1138 1124
@@ -1152,75 +1138,21 @@ identifiers followed by `:' or `='. See variables
1152Has a preference of looking backwards." 1138Has a preference of looking backwards."
1153 (condition-case nil 1139 (condition-case nil
1154 (save-excursion 1140 (save-excursion
1155 (let ((location (point))) 1141 (if add-log-current-defun-function
1156 (cond (add-log-current-defun-function 1142 (funcall add-log-current-defun-function)
1157 (funcall add-log-current-defun-function)) 1143 ;; If all else fails, try heuristics
1158 ((apply 'derived-mode-p add-log-lisp-like-modes) 1144 (let (case-fold-search
1159 ;; If we are now precisely at the beginning of a defun, 1145 result)
1160 ;; make sure beginning-of-defun finds that one 1146 (end-of-line)
1161 ;; rather than the previous one. 1147 (when (re-search-backward add-log-current-defun-header-regexp
1162 (or (eobp) (forward-char 1)) 1148 (- (point) 10000) t)
1163 (beginning-of-defun) 1149 (setq result (or (match-string-no-properties 1)
1164 ;; Make sure we are really inside the defun found, 1150 (match-string-no-properties 0)))
1165 ;; not after it. 1151 ;; Strip whitespace away
1166 (when (and (looking-at "\\s(") 1152 (when (string-match "\\([^ \t\n\r\f].*[^ \t\n\r\f]\\)"
1167 (progn (end-of-defun) 1153 result)
1168 (< location (point))) 1154 (setq result (match-string-no-properties 1 result)))
1169 (progn (forward-sexp -1) 1155 result))))
1170 (>= location (point))))
1171 (if (looking-at "\\s(")
1172 (forward-char 1))
1173 ;; Skip the defining construct name, typically "defun"
1174 ;; or "defvar".
1175 (forward-sexp 1)
1176 ;; The second element is usually a symbol being defined.
1177 ;; If it is not, use the first symbol in it.
1178 (skip-chars-forward " \t\n'(")
1179 (buffer-substring-no-properties (point)
1180 (progn (forward-sexp 1)
1181 (point)))))
1182 ((apply 'derived-mode-p add-log-c-like-modes)
1183 (or (c-cpp-define-name)
1184 (c-defun-name)))
1185 ((apply #'derived-mode-p add-log-tex-like-modes)
1186 (if (re-search-backward
1187 "\\\\\\(sub\\)*\\(section\\|paragraph\\|chapter\\)"
1188 nil t)
1189 (progn
1190 (goto-char (match-beginning 0))
1191 (buffer-substring-no-properties
1192 (1+ (point)) ; without initial backslash
1193 (line-end-position)))))
1194 ((derived-mode-p 'texinfo-mode)
1195 (if (re-search-backward "^@node[ \t]+\\([^,\n]+\\)" nil t)
1196 (match-string-no-properties 1)))
1197 ((derived-mode-p 'perl-mode 'cperl-mode)
1198 (if (re-search-backward "^sub[ \t]+\\([^({ \t\n]+\\)" nil t)
1199 (match-string-no-properties 1)))
1200 ;; Emacs's autoconf-mode installs its own
1201 ;; `add-log-current-defun-function'. This applies to
1202 ;; a different mode apparently for editing .m4
1203 ;; autoconf source.
1204 ((derived-mode-p 'autoconf-mode)
1205 (if (re-search-backward
1206 "^\\(\\(m4_\\)?define\\|A._DEFUN\\)(\\[?\\([A-Za-z0-9_]+\\)" nil t)
1207 (match-string-no-properties 3)))
1208 (t
1209 ;; If all else fails, try heuristics
1210 (let (case-fold-search
1211 result)
1212 (end-of-line)
1213 (when (re-search-backward
1214 add-log-current-defun-header-regexp
1215 (- (point) 10000)
1216 t)
1217 (setq result (or (match-string-no-properties 1)
1218 (match-string-no-properties 0)))
1219 ;; Strip whitespace away
1220 (when (string-match "\\([^ \t\n\r\f].*[^ \t\n\r\f]\\)"
1221 result)
1222 (setq result (match-string-no-properties 1 result)))
1223 result))))))
1224 (error nil))) 1156 (error nil)))
1225 1157
1226(defvar change-log-get-method-definition-md) 1158(defvar change-log-get-method-definition-md)