diff options
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 34 |
1 files changed, 26 insertions, 8 deletions
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) |