aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes
diff options
context:
space:
mode:
authorMiles Bader2007-07-15 04:47:46 +0000
committerMiles Bader2007-07-15 04:47:46 +0000
commit8c406a9bc42ee77fcbbb4201fe8bda855eafd832 (patch)
tree14c8fa2e72341edd9db40b17079fd5208b1554c8 /lisp/progmodes
parent9bdeb5e9bedd773cc6845bc29a98e1e2a208f1ff (diff)
parent6f8a87c027ebd6f9cfdac5c0df97d651227bec62 (diff)
downloademacs-8c406a9bc42ee77fcbbb4201fe8bda855eafd832.tar.gz
emacs-8c406a9bc42ee77fcbbb4201fe8bda855eafd832.zip
Merge from emacs--devo--0
Patches applied: * emacs--devo--0 (patch 806-813) - Merge from emacs--rel--22 - Update from CVS * emacs--rel--22 (patch 51-58) - Update from CVS - Merge from gnus--rel--5.10 * gnus--rel--5.10 (patch 233-236) - Merge from emacs--devo--0 - Update from CVS Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-230
Diffstat (limited to 'lisp/progmodes')
-rw-r--r--lisp/progmodes/compile.el136
-rw-r--r--lisp/progmodes/gdb-ui.el2
-rw-r--r--lisp/progmodes/gud.el20
-rw-r--r--lisp/progmodes/python.el34
-rw-r--r--lisp/progmodes/which-func.el4
5 files changed, 119 insertions, 77 deletions
diff --git a/lisp/progmodes/compile.el b/lisp/progmodes/compile.el
index a9f5f77c126..94def936fb9 100644
--- a/lisp/progmodes/compile.el
+++ b/lisp/progmodes/compile.el
@@ -87,13 +87,13 @@
87 87
88;;;###autoload 88;;;###autoload
89(defcustom compilation-mode-hook nil 89(defcustom compilation-mode-hook nil
90 "*List of hook functions run by `compilation-mode' (see `run-mode-hooks')." 90 "List of hook functions run by `compilation-mode' (see `run-mode-hooks')."
91 :type 'hook 91 :type 'hook
92 :group 'compilation) 92 :group 'compilation)
93 93
94;;;###autoload 94;;;###autoload
95(defcustom compilation-window-height nil 95(defcustom compilation-window-height nil
96 "*Number of lines in a compilation window. If nil, use Emacs default." 96 "Number of lines in a compilation window. If nil, use Emacs default."
97 :type '(choice (const :tag "Default" nil) 97 :type '(choice (const :tag "Default" nil)
98 integer) 98 integer)
99 :group 'compilation) 99 :group 'compilation)
@@ -442,7 +442,7 @@ Highlight entire line if t; don't highlight source lines if nil.")
442 "Overlay used to temporarily highlight compilation matches.") 442 "Overlay used to temporarily highlight compilation matches.")
443 443
444(defcustom compilation-error-screen-columns t 444(defcustom compilation-error-screen-columns t
445 "*If non-nil, column numbers in error messages are screen columns. 445 "If non-nil, column numbers in error messages are screen columns.
446Otherwise they are interpreted as character positions, with 446Otherwise they are interpreted as character positions, with
447each character occupying one column. 447each character occupying one column.
448The default is to use screen columns, which requires that the compilation 448The default is to use screen columns, which requires that the compilation
@@ -453,21 +453,21 @@ especially the TAB character."
453 :version "20.4") 453 :version "20.4")
454 454
455(defcustom compilation-read-command t 455(defcustom compilation-read-command t
456 "*Non-nil means \\[compile] reads the compilation command to use. 456 "Non-nil means \\[compile] reads the compilation command to use.
457Otherwise, \\[compile] just uses the value of `compile-command'." 457Otherwise, \\[compile] just uses the value of `compile-command'."
458 :type 'boolean 458 :type 'boolean
459 :group 'compilation) 459 :group 'compilation)
460 460
461;;;###autoload 461;;;###autoload
462(defcustom compilation-ask-about-save t 462(defcustom compilation-ask-about-save t
463 "*Non-nil means \\[compile] asks which buffers to save before compiling. 463 "Non-nil means \\[compile] asks which buffers to save before compiling.
464Otherwise, it saves all modified buffers without asking." 464Otherwise, it saves all modified buffers without asking."
465 :type 'boolean 465 :type 'boolean
466 :group 'compilation) 466 :group 'compilation)
467 467
468;;;###autoload 468;;;###autoload
469(defcustom compilation-search-path '(nil) 469(defcustom compilation-search-path '(nil)
470 "*List of directories to search for source files named in error messages. 470 "List of directories to search for source files named in error messages.
471Elements should be directory names, not file names of directories. 471Elements should be directory names, not file names of directories.
472The value nil as an element means to try the default directory." 472The value nil as an element means to try the default directory."
473 :type '(repeat (choice (const :tag "Default" nil) 473 :type '(repeat (choice (const :tag "Default" nil)
@@ -476,7 +476,7 @@ The value nil as an element means to try the default directory."
476 476
477;;;###autoload 477;;;###autoload
478(defcustom compile-command "make -k " 478(defcustom compile-command "make -k "
479 "*Last shell command used to do a compilation; default for next compilation. 479 "Last shell command used to do a compilation; default for next compilation.
480 480
481Sometimes it is useful for files to supply local values for this variable. 481Sometimes it is useful for files to supply local values for this variable.
482You might also use mode hooks to specify it in certain modes, like this: 482You might also use mode hooks to specify it in certain modes, like this:
@@ -494,7 +494,7 @@ You might also use mode hooks to specify it in certain modes, like this:
494 494
495;;;###autoload 495;;;###autoload
496(defcustom compilation-disable-input nil 496(defcustom compilation-disable-input nil
497 "*If non-nil, send end-of-file as compilation process input. 497 "If non-nil, send end-of-file as compilation process input.
498This only affects platforms that support asynchronous processes (see 498This only affects platforms that support asynchronous processes (see
499`start-process'); synchronous compilation processes never accept input." 499`start-process'); synchronous compilation processes never accept input."
500 :type 'boolean 500 :type 'boolean
@@ -605,6 +605,14 @@ Faces `compilation-error-face', `compilation-warning-face',
605(defvar compilation-error-list nil) 605(defvar compilation-error-list nil)
606(defvar compilation-old-error-list nil) 606(defvar compilation-old-error-list nil)
607 607
608(defcustom compilation-auto-jump-to-first-error nil
609 "If non-nil, automatically jump to the first error after `compile'."
610 :type 'boolean)
611
612(defvar compilation-auto-jump-to-next nil
613 "If non-nil, automatically jump to the next error encountered.")
614(make-variable-buffer-local 'compilation-auto-jump-to-next)
615
608(defun compilation-face (type) 616(defun compilation-face (type)
609 (or (and (car type) (match-end (car type)) compilation-warning-face) 617 (or (and (car type) (match-end (car type)) compilation-warning-face)
610 (and (cdr type) (match-end (cdr type)) compilation-info-face) 618 (and (cdr type) (match-end (cdr type)) compilation-info-face)
@@ -652,13 +660,18 @@ Faces `compilation-error-face', `compilation-warning-face',
652 l2 660 l2
653 (setcdr l1 (cons (list ,key) l2))))))) 661 (setcdr l1 (cons (list ,key) l2)))))))
654 662
663(defun compilation-auto-jump (buffer pos)
664 (with-current-buffer buffer
665 (goto-char pos)
666 (compile-goto-error)))
655 667
656;; This function is the central driver, called when font-locking to gather 668;; This function is the central driver, called when font-locking to gather
657;; all information needed to later jump to corresponding source code. 669;; all information needed to later jump to corresponding source code.
658;; Return a property list with all meta information on this error location. 670;; Return a property list with all meta information on this error location.
659 671
660(defun compilation-error-properties (file line end-line col end-col type fmt) 672(defun compilation-error-properties (file line end-line col end-col type fmt)
661 (unless (< (next-single-property-change (match-beginning 0) 'directory nil (point)) 673 (unless (< (next-single-property-change (match-beginning 0)
674 'directory nil (point))
662 (point)) 675 (point))
663 (if file 676 (if file
664 (if (functionp file) 677 (if (functionp file)
@@ -710,6 +723,13 @@ Faces `compilation-error-face', `compilation-warning-face',
710 (setq type (or (and (car type) (match-end (car type)) 1) 723 (setq type (or (and (car type) (match-end (car type)) 1)
711 (and (cdr type) (match-end (cdr type)) 0) 724 (and (cdr type) (match-end (cdr type)) 0)
712 2))) 725 2)))
726
727 (when (and compilation-auto-jump-to-next
728 (>= type compilation-skip-threshold))
729 (kill-local-variable 'compilation-auto-jump-to-next)
730 (run-with-timer 0 nil 'compilation-auto-jump
731 (current-buffer) (match-beginning 0)))
732
713 (compilation-internal-error-properties file line end-line col end-col type fmt))) 733 (compilation-internal-error-properties file line end-line col end-col type fmt)))
714 734
715(defun compilation-move-to-column (col screen) 735(defun compilation-move-to-column (col screen)
@@ -932,7 +952,7 @@ original use. Otherwise, recompile using `compile-command'."
932 `(,(eval compile-command)))))) 952 `(,(eval compile-command))))))
933 953
934(defcustom compilation-scroll-output nil 954(defcustom compilation-scroll-output nil
935 "*Non-nil to scroll the *compilation* buffer window as output appears. 955 "Non-nil to scroll the *compilation* buffer window as output appears.
936 956
937Setting it causes the Compilation mode commands to put point at the 957Setting it causes the Compilation mode commands to put point at the
938end of their output window so that the end of the output is always 958end of their output window so that the end of the output is always
@@ -1026,8 +1046,9 @@ Returns the compilation buffer created."
1026 ;; Clear out the compilation buffer. 1046 ;; Clear out the compilation buffer.
1027 (let ((inhibit-read-only t) 1047 (let ((inhibit-read-only t)
1028 (default-directory thisdir)) 1048 (default-directory thisdir))
1029 ;; Then evaluate a cd command if any, but don't perform it yet, else start-command 1049 ;; Then evaluate a cd command if any, but don't perform it yet, else
1030 ;; would do it again through the shell: (cd "..") AND sh -c "cd ..; make" 1050 ;; start-command would do it again through the shell: (cd "..") AND
1051 ;; sh -c "cd ..; make"
1031 (cd (if (string-match "^\\s *cd\\(?:\\s +\\(\\S +?\\)\\)?\\s *[;&\n]" command) 1052 (cd (if (string-match "^\\s *cd\\(?:\\s +\\(\\S +?\\)\\)?\\s *[;&\n]" command)
1032 (if (match-end 1) 1053 (if (match-end 1)
1033 (substitute-env-vars (match-string 1 command)) 1054 (substitute-env-vars (match-string 1 command))
@@ -1043,6 +1064,8 @@ Returns the compilation buffer created."
1043 (if highlight-regexp 1064 (if highlight-regexp
1044 (set (make-local-variable 'compilation-highlight-regexp) 1065 (set (make-local-variable 'compilation-highlight-regexp)
1045 highlight-regexp)) 1066 highlight-regexp))
1067 (if compilation-auto-jump-to-first-error
1068 (set (make-local-variable 'compilation-auto-jump-to-next) t))
1046 ;; Output a mode setter, for saving and later reloading this buffer. 1069 ;; Output a mode setter, for saving and later reloading this buffer.
1047 (insert "-*- mode: " name-of-mode 1070 (insert "-*- mode: " name-of-mode
1048 "; default-directory: " (prin1-to-string default-directory) 1071 "; default-directory: " (prin1-to-string default-directory)
@@ -1075,7 +1098,8 @@ Returns the compilation buffer created."
1075 (unless (getenv "EMACS") 1098 (unless (getenv "EMACS")
1076 (list "EMACS=t")) 1099 (list "EMACS=t"))
1077 (list "INSIDE_EMACS=t") 1100 (list "INSIDE_EMACS=t")
1078 (copy-sequence process-environment)))) 1101 (copy-sequence process-environment)))
1102 (start-process (symbol-function 'start-process)))
1079 (set (make-local-variable 'compilation-arguments) 1103 (set (make-local-variable 'compilation-arguments)
1080 (list command mode name-function highlight-regexp)) 1104 (list command mode name-function highlight-regexp))
1081 (set (make-local-variable 'revert-buffer-function) 1105 (set (make-local-variable 'revert-buffer-function)
@@ -1091,53 +1115,39 @@ Returns the compilation buffer created."
1091 (funcall compilation-process-setup-function)) 1115 (funcall compilation-process-setup-function))
1092 (compilation-set-window-height outwin) 1116 (compilation-set-window-height outwin)
1093 ;; Start the compilation. 1117 ;; Start the compilation.
1094 (if (fboundp 'start-process) 1118 (let ((proc
1095 (let ((proc (if (eq mode t) 1119 (if (eq mode t)
1096 (get-buffer-process 1120 ;; comint uses `start-file-process'.
1097 (with-no-warnings 1121 (get-buffer-process
1098 (comint-exec outbuf (downcase mode-name) 1122 (with-no-warnings
1099 shell-file-name nil `("-c" ,command)))) 1123 (comint-exec outbuf (downcase mode-name)
1100 (start-process-shell-command (downcase mode-name) 1124 shell-file-name nil `("-c" ,command))))
1101 outbuf command)))) 1125 ;; Redefine temporarily `start-process' in order to
1102 ;; Make the buffer's mode line show process state. 1126 ;; handle remote compilation.
1103 (setq mode-line-process '(":%s")) 1127 (fset 'start-process
1104 (set-process-sentinel proc 'compilation-sentinel) 1128 (lambda (name buffer program &rest program-args)
1105 (set-process-filter proc 'compilation-filter) 1129 (apply
1106 (set-marker (process-mark proc) (point) outbuf) 1130 (if (file-remote-p default-directory)
1107 (when compilation-disable-input 1131 'start-file-process
1108 (condition-case nil 1132 start-process)
1109 (process-send-eof proc) 1133 name buffer program program-args)))
1110 ;; The process may have exited already. 1134 (unwind-protect
1111 (error nil))) 1135 (start-process-shell-command (downcase mode-name)
1112 (setq compilation-in-progress 1136 outbuf command)
1113 (cons proc compilation-in-progress))) 1137 ;; Unwindform: Reset original definition of `start-process'.
1114 ;; No asynchronous processes available. 1138 (fset 'start-process start-process)))))
1115 (message "Executing `%s'..." command) 1139 ;; Make the buffer's mode line show process state.
1116 ;; Fake modeline display as if `start-process' were run. 1140 (setq mode-line-process '(":%s"))
1117 (setq mode-line-process ":run") 1141 (set-process-sentinel proc 'compilation-sentinel)
1118 (force-mode-line-update) 1142 (set-process-filter proc 'compilation-filter)
1119 (sit-for 0) ; Force redisplay 1143 (set-marker (process-mark proc) (point) outbuf)
1120 (let* ((buffer-read-only nil) ; call-process needs to modify outbuf 1144 (when compilation-disable-input
1121 (status (call-process shell-file-name nil outbuf nil "-c" 1145 (condition-case nil
1122 command))) 1146 (process-send-eof proc)
1123 (cond ((numberp status) 1147 ;; The process may have exited already.
1124 (compilation-handle-exit 'exit status 1148 (error nil)))
1125 (if (zerop status) 1149 (setq compilation-in-progress
1126 "finished\n" 1150 (cons proc compilation-in-progress))))
1127 (format "\
1128exited abnormally with code %d\n"
1129 status))))
1130 ((stringp status)
1131 (compilation-handle-exit 'signal status
1132 (concat status "\n")))
1133 (t
1134 (compilation-handle-exit 'bizarre status status))))
1135 ;; Without async subprocesses, the buffer is not yet
1136 ;; fontified, so fontify it now.
1137 (let ((font-lock-verbose nil)) ; shut up font-lock messages
1138 (font-lock-fontify-buffer))
1139 (set-buffer-modified-p nil)
1140 (message "Executing `%s'...done" command)))
1141 ;; Now finally cd to where the shell started make/grep/... 1151 ;; Now finally cd to where the shell started make/grep/...
1142 (setq default-directory thisdir)) 1152 (setq default-directory thisdir))
1143 (if (buffer-local-value 'compilation-scroll-output outbuf) 1153 (if (buffer-local-value 'compilation-scroll-output outbuf)
@@ -1258,7 +1268,7 @@ exited abnormally with code %d\n"
1258 "*If non-nil, skip multiple error messages for the same source location.") 1268 "*If non-nil, skip multiple error messages for the same source location.")
1259 1269
1260(defcustom compilation-skip-threshold 1 1270(defcustom compilation-skip-threshold 1
1261 "*Compilation motion commands skip less important messages. 1271 "Compilation motion commands skip less important messages.
1262The value can be either 2 -- skip anything less than error, 1 -- 1272The value can be either 2 -- skip anything less than error, 1 --
1263skip anything less than warning or 0 -- don't skip any messages. 1273skip anything less than warning or 0 -- don't skip any messages.
1264Note that all messages not positively identified as warning or 1274Note that all messages not positively identified as warning or
@@ -1270,7 +1280,7 @@ info, are considered errors."
1270 :version "22.1") 1280 :version "22.1")
1271 1281
1272(defcustom compilation-skip-visited nil 1282(defcustom compilation-skip-visited nil
1273 "*Compilation motion commands skip visited messages if this is t. 1283 "Compilation motion commands skip visited messages if this is t.
1274Visited messages are ones for which the file, line and column have been jumped 1284Visited messages are ones for which the file, line and column have been jumped
1275to from the current content in the current compilation buffer, even if it was 1285to from the current content in the current compilation buffer, even if it was
1276from a different message." 1286from a different message."
@@ -1371,6 +1381,8 @@ Optional argument MINOR indicates this is called from
1371 ;; with the next-error function in simple.el, and it's only 1381 ;; with the next-error function in simple.el, and it's only
1372 ;; coincidentally named similarly to compilation-next-error. 1382 ;; coincidentally named similarly to compilation-next-error.
1373 (setq next-error-function 'compilation-next-error-function) 1383 (setq next-error-function 'compilation-next-error-function)
1384 (set (make-local-variable 'comint-file-name-prefix)
1385 (or (file-remote-p default-directory) ""))
1374 (set (make-local-variable 'font-lock-extra-managed-props) 1386 (set (make-local-variable 'font-lock-extra-managed-props)
1375 '(directory message help-echo mouse-face debug)) 1387 '(directory message help-echo mouse-face debug))
1376 (set (make-local-variable 'compilation-locs) 1388 (set (make-local-variable 'compilation-locs)
diff --git a/lisp/progmodes/gdb-ui.el b/lisp/progmodes/gdb-ui.el
index 4dbc9893f61..7bc904f8319 100644
--- a/lisp/progmodes/gdb-ui.el
+++ b/lisp/progmodes/gdb-ui.el
@@ -1765,7 +1765,7 @@ static char *magick[] = {
1765 1765
1766(defface breakpoint-enabled 1766(defface breakpoint-enabled
1767 '((t 1767 '((t
1768 :foreground "red" 1768 :foreground "red1"
1769 :weight bold)) 1769 :weight bold))
1770 "Face for enabled breakpoint icon in fringe." 1770 "Face for enabled breakpoint icon in fringe."
1771 :group 'gud) 1771 :group 'gud)
diff --git a/lisp/progmodes/gud.el b/lisp/progmodes/gud.el
index aa382d4e185..97144fec83b 100644
--- a/lisp/progmodes/gud.el
+++ b/lisp/progmodes/gud.el
@@ -237,7 +237,7 @@ Used to grey out relevant toolbar icons.")
237 ([menu-bar run] menu-item 237 ([menu-bar run] menu-item
238 ,(propertize "run" 'face 'font-lock-doc-face) gud-run 238 ,(propertize "run" 'face 'font-lock-doc-face) gud-run
239 :visible (memq gud-minor-mode '(gdbmi gdb dbx jdb))) 239 :visible (memq gud-minor-mode '(gdbmi gdb dbx jdb)))
240 ([menu-bar go] menu-item 240 ([menu-bar go] menu-item
241 ,(propertize " go " 'face 'font-lock-doc-face) gud-go 241 ,(propertize " go " 'face 'font-lock-doc-face) gud-go
242 :visible (and (not gud-running) 242 :visible (and (not gud-running)
243 (eq gud-minor-mode 'gdba))) 243 (eq gud-minor-mode 'gdba)))
@@ -292,6 +292,11 @@ Used to grey out relevant toolbar icons.")
292(defun gud-file-name (f) 292(defun gud-file-name (f)
293 "Transform a relative file name to an absolute file name. 293 "Transform a relative file name to an absolute file name.
294Uses `gud-<MINOR-MODE>-directories' to find the source files." 294Uses `gud-<MINOR-MODE>-directories' to find the source files."
295 ;; When `default-directory' is a remote file name, prepend its
296 ;; remote part to f, which is the local file name. Fortunately,
297 ;; `file-remote-p' returns exactly this remote file name part (or
298 ;; nil otherwise).
299 (setq f (concat (or (file-remote-p default-directory) "") f))
295 (if (file-exists-p f) (expand-file-name f) 300 (if (file-exists-p f) (expand-file-name f)
296 (let ((directories (gud-val 'directories)) 301 (let ((directories (gud-val 'directories))
297 (result nil)) 302 (result nil))
@@ -2510,7 +2515,10 @@ comint mode, which see."
2510 (while (and w (not (eq (car w) t))) 2515 (while (and w (not (eq (car w) t)))
2511 (setq w (cdr w))) 2516 (setq w (cdr w)))
2512 (if w 2517 (if w
2513 (setcar w file))) 2518 (setcar w
2519 (if (file-remote-p default-directory)
2520 (setq file (file-name-nondirectory file))
2521 file))))
2514 (apply 'make-comint (concat "gud" filepart) program nil 2522 (apply 'make-comint (concat "gud" filepart) program nil
2515 (if massage-args (funcall massage-args file args) args)) 2523 (if massage-args (funcall massage-args file args) args))
2516 ;; Since comint clobbered the mode, we don't set it until now. 2524 ;; Since comint clobbered the mode, we don't set it until now.
@@ -3114,7 +3122,7 @@ class of the file (using s to separate nested class ids)."
3114 'syntax-table (eval-when-compile 3122 'syntax-table (eval-when-compile
3115 (string-to-syntax "> b"))) 3123 (string-to-syntax "> b")))
3116 ;; Make sure that rehighlighting the previous line won't erase our 3124 ;; Make sure that rehighlighting the previous line won't erase our
3117 ;; syntax-table property. 3125 ;; syntax-table property.
3118 (put-text-property (1- (match-beginning 0)) (match-end 0) 3126 (put-text-property (1- (match-beginning 0)) (match-end 0)
3119 'font-lock-multiline t) 3127 'font-lock-multiline t)
3120 nil))))) 3128 nil)))))
@@ -3193,8 +3201,12 @@ Treats actions as defuns."
3193 (goto-char (point-max))) 3201 (goto-char (point-max)))
3194 t) 3202 t)
3195 3203
3204;; Besides .gdbinit, gdb documents other names to be usable for init
3205;; files, cross-debuggers can use something like
3206;; .PROCESSORNAME-gdbinit so that the host and target gdbinit files
3207;; don't interfere with each other.
3196;;;###autoload 3208;;;###autoload
3197(add-to-list 'auto-mode-alist '("/\\.gdbinit" . gdb-script-mode)) 3209(add-to-list 'auto-mode-alist '("/\\.[a-z0-9-]*gdbinit" . gdb-script-mode))
3198 3210
3199;;;###autoload 3211;;;###autoload
3200(define-derived-mode gdb-script-mode nil "GDB-Script" 3212(define-derived-mode gdb-script-mode nil "GDB-Script"
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 5c117dffd5d..26fc122631d 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -996,7 +996,16 @@ don't move and return nil. Otherwise return t."
996 (throw 'done t))))))) 996 (throw 'done t)))))))
997 (setq arg (1- arg))) 997 (setq arg (1- arg)))
998 (zerop arg))) 998 (zerop arg)))
999 999
1000(defvar python-which-func-length-limit 40
1001 "Non-strict length limit for `python-which-func' output.")
1002
1003(defun python-which-func ()
1004 (let ((function-name (python-current-defun python-which-func-length-limit)))
1005 (set-text-properties 0 (length function-name) nil function-name)
1006 function-name))
1007
1008
1000;;;; Imenu. 1009;;;; Imenu.
1001 1010
1002(defvar python-recursing) 1011(defvar python-recursing)
@@ -1814,22 +1823,30 @@ of current line."
1814 (1+ (/ (current-indentation) python-indent))) 1823 (1+ (/ (current-indentation) python-indent)))
1815 1824
1816;; Fixme: Consider top-level assignments, imports, &c. 1825;; Fixme: Consider top-level assignments, imports, &c.
1817(defun python-current-defun () 1826(defun python-current-defun (&optional length-limit)
1818 "`add-log-current-defun-function' for Python." 1827 "`add-log-current-defun-function' for Python."
1819 (save-excursion 1828 (save-excursion
1820 ;; Move up the tree of nested `class' and `def' blocks until we 1829 ;; Move up the tree of nested `class' and `def' blocks until we
1821 ;; get to zero indentation, accumulating the defined names. 1830 ;; get to zero indentation, accumulating the defined names.
1822 (let ((start t) 1831 (let ((start t)
1823 accum) 1832 (accum)
1824 (while (or start (> (current-indentation) 0)) 1833 (length -1))
1834 (while (and (or start (> (current-indentation) 0))
1835 (or (null length-limit)
1836 (null (cdr accum))
1837 (< length length-limit)))
1825 (setq start nil) 1838 (setq start nil)
1826 (python-beginning-of-block) 1839 (python-beginning-of-block)
1827 (end-of-line) 1840 (end-of-line)
1828 (beginning-of-defun) 1841 (beginning-of-defun)
1829 (if (looking-at (rx (0+ space) (or "def" "class") (1+ space) 1842 (when (looking-at (rx (0+ space) (or "def" "class") (1+ space)
1830 (group (1+ (or word (syntax symbol)))))) 1843 (group (1+ (or word (syntax symbol))))))
1831 (push (match-string 1) accum))) 1844 (push (match-string 1) accum)
1832 (if accum (mapconcat 'identity accum "."))))) 1845 (setq length (+ length 1 (length (car accum))))))
1846 (when accum
1847 (when (and length-limit (> length length-limit))
1848 (setcar accum ".."))
1849 (mapconcat 'identity accum ".")))))
1833 1850
1834(defun python-mark-block () 1851(defun python-mark-block ()
1835 "Mark the block around point. 1852 "Mark the block around point.
@@ -2248,6 +2265,7 @@ with skeleton expansions for compound statement templates.
2248 (set (make-local-variable 'beginning-of-defun-function) 2265 (set (make-local-variable 'beginning-of-defun-function)
2249 'python-beginning-of-defun) 2266 'python-beginning-of-defun)
2250 (set (make-local-variable 'end-of-defun-function) 'python-end-of-defun) 2267 (set (make-local-variable 'end-of-defun-function) 'python-end-of-defun)
2268 (add-hook 'which-func-functions 'python-which-func nil t)
2251 (setq imenu-create-index-function #'python-imenu-create-index) 2269 (setq imenu-create-index-function #'python-imenu-create-index)
2252 (set (make-local-variable 'eldoc-documentation-function) 2270 (set (make-local-variable 'eldoc-documentation-function)
2253 #'python-eldoc-function) 2271 #'python-eldoc-function)
diff --git a/lisp/progmodes/which-func.el b/lisp/progmodes/which-func.el
index 43c70f67dfb..5b5c13342ad 100644
--- a/lisp/progmodes/which-func.el
+++ b/lisp/progmodes/which-func.el
@@ -76,8 +76,8 @@
76 :version "20.3") 76 :version "20.3")
77 77
78(defcustom which-func-modes 78(defcustom which-func-modes
79 '(emacs-lisp-mode c-mode c++-mode perl-mode cperl-mode makefile-mode 79 '(emacs-lisp-mode c-mode c++-mode perl-mode cperl-mode python-mode
80 sh-mode fortran-mode f90-mode ada-mode) 80 makefile-mode sh-mode fortran-mode f90-mode ada-mode)
81 "List of major modes for which Which Function mode should be used. 81 "List of major modes for which Which Function mode should be used.
82For other modes it is disabled. If this is equal to t, 82For other modes it is disabled. If this is equal to t,
83then Which Function mode is enabled in any major mode that supports it." 83then Which Function mode is enabled in any major mode that supports it."