Mercurial > emacs
comparison lisp/progmodes/python.el @ 81824:0a0e79e50844
(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.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Thu, 12 Jul 2007 04:36:48 +0000 |
parents | f0107aee8e99 |
children | b98604865ea0 a66921565bcb |
comparison
equal
deleted
inserted
replaced
81823:d3277da93598 | 81824:0a0e79e50844 |
---|---|
994 (python-skip-comments/blanks t) | 994 (python-skip-comments/blanks t) |
995 (beginning-of-line 2) | 995 (beginning-of-line 2) |
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) |
1003 (defun python-imenu-create-index () | 1012 (defun python-imenu-create-index () |
1004 "`imenu-create-index-function' for Python. | 1013 "`imenu-create-index-function' for Python. |
1812 The level is the number of `python-indent' steps of indentation | 1821 The level is the number of `python-indent' steps of indentation |
1813 of current line." | 1822 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. |
1836 Uses `python-beginning-of-block', `python-end-of-block'." | 1853 Uses `python-beginning-of-block', `python-end-of-block'." |
1837 (interactive) | 1854 (interactive) |
2246 (set (make-local-variable 'open-paren-in-column-0-is-defun-start) nil) | 2263 (set (make-local-variable 'open-paren-in-column-0-is-defun-start) nil) |
2247 (make-local-variable 'python-saved-check-command) | 2264 (make-local-variable 'python-saved-check-command) |
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) |
2254 (add-hook 'eldoc-mode-hook | 2272 (add-hook 'eldoc-mode-hook |
2255 (lambda () (run-python nil t)) ; need it running | 2273 (lambda () (run-python nil t)) ; need it running |