aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2007-07-12 04:36:48 +0000
committerStefan Monnier2007-07-12 04:36:48 +0000
commit4f7a582baa73efb4e6d4cbe7205572b6f03a15eb (patch)
tree4bf230f9118632722de5f25046dafcffc691c848
parent8b9571399325e40c53e193178f29a2a94594421c (diff)
downloademacs-4f7a582baa73efb4e6d4cbe7205572b6f03a15eb.tar.gz
emacs-4f7a582baa73efb4e6d4cbe7205572b6f03a15eb.zip
(python-which-func-length-limit): New var.
(python-which-func): New function. (python-current-defun): Add optional `length-limit' and try to fit computed function name to that length. (python-mode): Hook `python-which-func' up.
-rw-r--r--lisp/ChangeLog10
-rw-r--r--lisp/progmodes/python.el34
2 files changed, 36 insertions, 8 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index e21e1ce5bcd..0792291a4a3 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,13 @@
12007-07-12 Paul Pogonyshev <pogonyshev@gmx.net>
2
3 * progmodes/which-func.el (which-func-modes): Add `python-mode'.
4
5 * progmodes/python.el (python-which-func-length-limit): New var.
6 (python-which-func): New function.
7 (python-current-defun): Add optional `length-limit' and try to fit
8 computed function name to that length.
9 (python-mode): Hook `python-which-func' up.
10
12007-07-12 Sean O'Rourke <sorourke@cs.ucsd.edu> (tiny change) 112007-07-12 Sean O'Rourke <sorourke@cs.ucsd.edu> (tiny change)
2 12
3 * pcomplete.el (pcomplete-entries): Obey pcomplete-ignore-case. 13 * pcomplete.el (pcomplete-entries): Obey pcomplete-ignore-case.
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)