diff options
author | Barry Warsaw <barry@python.org> | 1996-09-04 15:12:42 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 1996-09-04 15:12:42 (GMT) |
commit | b3e81d58aa04989dbdb5da91a5cd1e65e646872d (patch) | |
tree | 4fe47c777f328585b75b5f6b7112c7ec7631ee8c | |
parent | 01af401e277b1bbea83744b6eb2172a1f2a54f68 (diff) | |
download | cpython-b3e81d58aa04989dbdb5da91a5cd1e65e646872d.zip cpython-b3e81d58aa04989dbdb5da91a5cd1e65e646872d.tar.gz cpython-b3e81d58aa04989dbdb5da91a5cd1e65e646872d.tar.bz2 |
I have been increasingly annoyed about the fact that
add-change-log-entry-other-window is so bad about guessing the proper
name of Python functions, methods and variables, so finally I wrote
the following (unidiff patch against python-mode.el 2.73):
Per Cederqvist <ceder@signum.se>
-rw-r--r-- | Misc/python-mode.el | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Misc/python-mode.el b/Misc/python-mode.el index f461c15..c24b15a 100644 --- a/Misc/python-mode.el +++ b/Misc/python-mode.el @@ -393,6 +393,20 @@ Currently-active file is at the head of the list.") "\\)") "Regexp matching lines to not outdent after.") +(defvar py-defun-start-re + "^\\([ \t]*\\)def[ \t]+\\([a-zA-Z_0-9]+\\)\\|\\(^[a-zA-Z_0-9]+\\)[ \t]*=" + "Regexp matching a function, method or variable assignment. + +If you change this, you probably have to change `py-current-defun' as well. +This is only used by `py-current-defun' to find the name for add-log.el.") + +(defvar py-class-start-re "^class[ \t]*\\([a-zA-Z_0-9]+\\)" + "Regexp for finding a class name. + +If you change this, you probably have to change `py-current-defun' as well. +This is only used by `py-current-defun' to find the name for add-log.el.") + + ;; Menu definitions, only relevent if you have the easymenu.el package ;; (standard in the latest Emacs 19 and XEmacs 19 distributions). @@ -671,6 +685,7 @@ py-beep-if-tab-change\t\tring the bell if tab-width is changed" (make-local-variable 'comment-column) (make-local-variable 'indent-region-function) (make-local-variable 'indent-line-function) + (make-local-variable 'add-log-current-defun-function) ;; (set-syntax-table py-mode-syntax-table) (setq major-mode 'python-mode @@ -685,6 +700,8 @@ py-beep-if-tab-change\t\tring the bell if tab-width is changed" comment-column 40 indent-region-function 'py-indent-region indent-line-function 'py-indent-line + ;; tell add-log.el how to find the current function/method/variable + add-log-current-defun-function 'py-current-defun ) (use-local-map py-mode-map) ;; add the menu @@ -2330,6 +2347,17 @@ local bindings to py-newline-and-indent.")) (set-buffer cbuf)) (sit-for 0)) +(defun py-current-defun () + ;; tell add-log.el how to find the current function/method/variable + (save-excursion + (if (re-search-backward py-defun-start-re nil t) + (or (match-string 3) + (let ((method (match-string 2))) + (if (and (not (zerop (length (match-string 1)))) + (re-search-backward py-class-start-re nil t)) + (concat (match-string 1) "." method) + method))) + nil))) (defconst py-version "$Revision$" |