emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] Changes to emacs/lisp/progmodes/which-func.el,v


From: Glenn Morris
Subject: [Emacs-diffs] Changes to emacs/lisp/progmodes/which-func.el,v
Date: Tue, 30 Sep 2008 03:41:36 +0000

CVSROOT:        /sources/emacs
Module name:    emacs
Changes by:     Glenn Morris <gm>       08/09/30 03:41:35

Index: which-func.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/progmodes/which-func.el,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -b -r1.23 -r1.24
--- which-func.el       6 May 2008 07:18:39 -0000       1.23
+++ which-func.el       30 Sep 2008 03:41:35 -0000      1.24
@@ -152,6 +152,12 @@
   :type 'sexp)
 ;;;###autoload (put 'which-func-format 'risky-local-variable t)
 
+(defvar which-func-imenu-joiner-function #'last
+  "Function to call when using imenu to join together multiple
+levels of nomenclature. Called with a single argument, a list of
+strings giving the names of the menus we had to traverse to get
+to the item. Return a single string, the new name of the item.")
+
 (defvar which-func-cleanup-function nil
   "Function to transform a string before displaying it in the mode line.
 The function is called with one argument, the string to display.
@@ -281,25 +287,38 @@
               (boundp 'imenu--index-alist) imenu--index-alist)
       (let ((alist imenu--index-alist)
             (minoffset (point-max))
-            offset elem pair mark)
-        (while alist
-          (setq elem  (car-safe alist)
-                alist (cdr-safe alist))
+            offset pair mark imstack namestack)
           ;; Elements of alist are either ("name" . marker), or
-          ;; ("submenu" ("name" . marker) ... ).
-          (unless (listp (cdr elem))
-              (setq elem (list elem)))
-          (while elem
-            (setq pair (car elem)
-                  elem (cdr elem))
-            (and (consp pair)
-                 (number-or-marker-p (setq mark (cdr pair)))
+        ;; ("submenu" ("name" . marker) ... ). The list can be
+        ;; arbitrarily nested.
+        (while (or alist imstack)
+          (if alist
+              (progn
+                (setq pair (car-safe alist)
+                      alist (cdr-safe alist))
+
+                (cond ((atom pair))     ; skip anything not a cons
+
+                      ((imenu--subalist-p pair)
+                       (setq imstack   (cons alist imstack)
+                             namestack (cons (car pair) namestack)
+                             alist     (cdr pair)))
+
+                      ((number-or-marker-p (setq mark (cdr pair)))
                  (if (>= (setq offset (- (point) mark)) 0)
                      (if (< offset minoffset) ; find the closest item
                          (setq minoffset offset
-                               name (car pair)))
+                                     name (funcall
+                                           which-func-imenu-joiner-function
+                                           (reverse (cons (car pair) 
namestack)))))
                    ;; Entries in order, so can skip all those after point.
-                   (setq elem nil)))))))
+                         (setq alist nil
+                               imstack nil)))))
+
+            (setq alist     (car imstack)
+                  namestack (cdr namestack)
+                  imstack   (cdr imstack))))))
+
     ;; Try using add-log support.
     (when (and (null name) (boundp 'add-log-current-defun-function)
               add-log-current-defun-function)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]