aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlenn Morris2008-09-30 03:41:35 +0000
committerGlenn Morris2008-09-30 03:41:35 +0000
commitfd1c81ef8493855a34a3259f52670cfd322b3d6c (patch)
tree9d0246081a41f16e7acbad46bacc4fc463284fd6
parentc27c178cd23dcc5b977c6f97ccc7005b4f712088 (diff)
downloademacs-fd1c81ef8493855a34a3259f52670cfd322b3d6c.tar.gz
emacs-fd1c81ef8493855a34a3259f52670cfd322b3d6c.zip
Daniel Colascione <danc at merrillpress.com>
(which-func-imenu-joiner-function): New. (which-function): Handle nested imenu trees.
-rw-r--r--lisp/progmodes/which-func.el57
1 files changed, 38 insertions, 19 deletions
diff --git a/lisp/progmodes/which-func.el b/lisp/progmodes/which-func.el
index 385ed91b403..fa5fbee63de 100644
--- a/lisp/progmodes/which-func.el
+++ b/lisp/progmodes/which-func.el
@@ -152,6 +152,12 @@ Zero means compute the Imenu menu regardless of size."
152 :type 'sexp) 152 :type 'sexp)
153;;;###autoload (put 'which-func-format 'risky-local-variable t) 153;;;###autoload (put 'which-func-format 'risky-local-variable t)
154 154
155(defvar which-func-imenu-joiner-function #'last
156 "Function to call when using imenu to join together multiple
157levels of nomenclature. Called with a single argument, a list of
158strings giving the names of the menus we had to traverse to get
159to the item. Return a single string, the new name of the item.")
160
155(defvar which-func-cleanup-function nil 161(defvar which-func-cleanup-function nil
156 "Function to transform a string before displaying it in the mode line. 162 "Function to transform a string before displaying it in the mode line.
157The function is called with one argument, the string to display. 163The function is called with one argument, the string to display.
@@ -281,25 +287,38 @@ If no function name is found, return nil."
281 (boundp 'imenu--index-alist) imenu--index-alist) 287 (boundp 'imenu--index-alist) imenu--index-alist)
282 (let ((alist imenu--index-alist) 288 (let ((alist imenu--index-alist)
283 (minoffset (point-max)) 289 (minoffset (point-max))
284 offset elem pair mark) 290 offset pair mark imstack namestack)
285 (while alist 291 ;; Elements of alist are either ("name" . marker), or
286 (setq elem (car-safe alist) 292 ;; ("submenu" ("name" . marker) ... ). The list can be
287 alist (cdr-safe alist)) 293 ;; arbitrarily nested.
288 ;; Elements of alist are either ("name" . marker), or 294 (while (or alist imstack)
289 ;; ("submenu" ("name" . marker) ... ). 295 (if alist
290 (unless (listp (cdr elem)) 296 (progn
291 (setq elem (list elem))) 297 (setq pair (car-safe alist)
292 (while elem 298 alist (cdr-safe alist))
293 (setq pair (car elem) 299
294 elem (cdr elem)) 300 (cond ((atom pair)) ; skip anything not a cons
295 (and (consp pair) 301
296 (number-or-marker-p (setq mark (cdr pair))) 302 ((imenu--subalist-p pair)
297 (if (>= (setq offset (- (point) mark)) 0) 303 (setq imstack (cons alist imstack)
298 (if (< offset minoffset) ; find the closest item 304 namestack (cons (car pair) namestack)
299 (setq minoffset offset 305 alist (cdr pair)))
300 name (car pair))) 306
301 ;; Entries in order, so can skip all those after point. 307 ((number-or-marker-p (setq mark (cdr pair)))
302 (setq elem nil))))))) 308 (if (>= (setq offset (- (point) mark)) 0)
309 (if (< offset minoffset) ; find the closest item
310 (setq minoffset offset
311 name (funcall
312 which-func-imenu-joiner-function
313 (reverse (cons (car pair) namestack)))))
314 ;; Entries in order, so can skip all those after point.
315 (setq alist nil
316 imstack nil)))))
317
318 (setq alist (car imstack)
319 namestack (cdr namestack)
320 imstack (cdr imstack))))))
321
303 ;; Try using add-log support. 322 ;; Try using add-log support.
304 (when (and (null name) (boundp 'add-log-current-defun-function) 323 (when (and (null name) (boundp 'add-log-current-defun-function)
305 add-log-current-defun-function) 324 add-log-current-defun-function)