]> git.eshelyaron.com Git - emacs.git/commitdiff
(python-which-func-length-limit): New var.
authorStefan Monnier <monnier@iro.umontreal.ca>
Thu, 12 Jul 2007 04:36:48 +0000 (04:36 +0000)
committerStefan Monnier <monnier@iro.umontreal.ca>
Thu, 12 Jul 2007 04:36:48 +0000 (04:36 +0000)
(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.

lisp/ChangeLog
lisp/progmodes/python.el

index e21e1ce5bcd35b9cf691349866ef6e210d956b09..0792291a4a32dd4a5023e77311a4e3213364cdc7 100644 (file)
@@ -1,3 +1,13 @@
+2007-07-12  Paul Pogonyshev  <pogonyshev@gmx.net>
+
+       * progmodes/which-func.el (which-func-modes): Add `python-mode'.
+
+       * progmodes/python.el (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.
+
 2007-07-12  Sean O'Rourke  <sorourke@cs.ucsd.edu>  (tiny change)
 
        * pcomplete.el (pcomplete-entries): Obey pcomplete-ignore-case.
index 5c117dffd5ddea0c8dc6308617f8a25027c98a59..26fc122631d4f15f8d10c246b8aad756f5018ff4 100644 (file)
@@ -996,7 +996,16 @@ don't move and return nil.  Otherwise return t."
                          (throw 'done t)))))))
       (setq arg (1- arg)))
     (zerop arg)))
-\f
+
+(defvar python-which-func-length-limit 40
+  "Non-strict length limit for `python-which-func' output.")
+
+(defun python-which-func ()
+  (let ((function-name (python-current-defun python-which-func-length-limit)))
+    (set-text-properties 0 (length function-name) nil function-name)
+    function-name))
+
 ;;;; Imenu.
 
 (defvar python-recursing)
@@ -1814,22 +1823,30 @@ of current line."
   (1+ (/ (current-indentation) python-indent)))
 
 ;; Fixme: Consider top-level assignments, imports, &c.
-(defun python-current-defun ()
+(defun python-current-defun (&optional length-limit)
   "`add-log-current-defun-function' for Python."
   (save-excursion
     ;; Move up the tree of nested `class' and `def' blocks until we
     ;; get to zero indentation, accumulating the defined names.
     (let ((start t)
-         accum)
-      (while (or start (> (current-indentation) 0))
+         (accum)
+         (length -1))
+      (while (and (or start (> (current-indentation) 0))
+                 (or (null length-limit)
+                     (null (cdr accum))
+                     (< length length-limit)))
        (setq start nil)
        (python-beginning-of-block)
        (end-of-line)
        (beginning-of-defun)
-       (if (looking-at (rx (0+ space) (or "def" "class") (1+ space)
-                           (group (1+ (or word (syntax symbol))))))
-           (push (match-string 1) accum)))
-      (if accum (mapconcat 'identity accum ".")))))
+       (when (looking-at (rx (0+ space) (or "def" "class") (1+ space)
+                             (group (1+ (or word (syntax symbol))))))
+         (push (match-string 1) accum)
+         (setq length (+ length 1 (length (car accum))))))
+      (when accum
+       (when (and length-limit (> length length-limit))
+         (setcar accum ".."))
+       (mapconcat 'identity accum ".")))))
 
 (defun python-mark-block ()
   "Mark the block around point.
@@ -2248,6 +2265,7 @@ with skeleton expansions for compound statement templates.
   (set (make-local-variable 'beginning-of-defun-function)
        'python-beginning-of-defun)
   (set (make-local-variable 'end-of-defun-function) 'python-end-of-defun)
+  (add-hook 'which-func-functions 'python-which-func nil t)
   (setq imenu-create-index-function #'python-imenu-create-index)
   (set (make-local-variable 'eldoc-documentation-function)
        #'python-eldoc-function)