* [PATCH] nested imenu support for which-func
@ 2008-09-25 21:02 Daniel Colascione
2008-09-27 19:53 ` Chong Yidong
2008-09-30 3:41 ` Glenn Morris
0 siblings, 2 replies; 3+ messages in thread
From: Daniel Colascione @ 2008-09-25 21:02 UTC (permalink / raw)
To: emacs-devel
As it is in 22.1, which-func only looks one level down the imenu tree. This
patch has it look down all branches. In addition, there's a new variable,
which-func-imenu-joiner-function. It's called with the names of all
the levels of imenu that which-func had to traverse to reach the given
function. By default, which-func just uses the deepest name; that matches
existing behavior.
--- /dev/stdin 2008-09-25 17:00:50.305409082 -0400
+++ which-func.el 2008-09-25 16:03:41.000000000 -0400
@@ -153,6 +153,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.
@@ -282,25 +288,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))
- ;; 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)))
- (if (>= (setq offset (- (point) mark)) 0)
- (if (< offset minoffset) ; find the closest item
- (setq minoffset offset
- name (car pair)))
- ;; Entries in order, so can skip all those after point.
- (setq elem nil)))))))
+ offset pair mark imstack namestack)
+ ;; Elements of alist are either ("name" . marker), or
+ ;; ("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 (funcall
+ which-func-imenu-joiner-function
+ (reverse (cons (car pair)
namestack)))))
+ ;; Entries in order, so can skip all those after
point.
+ (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)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] nested imenu support for which-func
2008-09-25 21:02 [PATCH] nested imenu support for which-func Daniel Colascione
@ 2008-09-27 19:53 ` Chong Yidong
2008-09-30 3:41 ` Glenn Morris
1 sibling, 0 replies; 3+ messages in thread
From: Chong Yidong @ 2008-09-27 19:53 UTC (permalink / raw)
To: Daniel Colascione; +Cc: emacs-devel
Daniel Colascione <danc@merrillpress.com> writes:
> As it is in 22.1, which-func only looks one level down the imenu tree. This
> patch has it look down all branches. In addition, there's a new variable,
> which-func-imenu-joiner-function. It's called with the names of all
> the levels of imenu that which-func had to traverse to reach the given
> function. By default, which-func just uses the deepest name; that matches
> existing behavior.
Looks OK to me. I don't have access to CVS right now; could someone
help check it in?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] nested imenu support for which-func
2008-09-25 21:02 [PATCH] nested imenu support for which-func Daniel Colascione
2008-09-27 19:53 ` Chong Yidong
@ 2008-09-30 3:41 ` Glenn Morris
1 sibling, 0 replies; 3+ messages in thread
From: Glenn Morris @ 2008-09-30 3:41 UTC (permalink / raw)
To: Daniel Colascione; +Cc: emacs-devel
Daniel Colascione wrote:
> As it is in 22.1, which-func only looks one level down the imenu tree. This
> patch has it look down all branches. In addition, there's a new variable,
> which-func-imenu-joiner-function.
Installed. Please supply a NEWS entry if appropriate.
> +(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
The first line of a doc-string should be a complete sentence.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-09-30 3:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-25 21:02 [PATCH] nested imenu support for which-func Daniel Colascione
2008-09-27 19:53 ` Chong Yidong
2008-09-30 3:41 ` Glenn Morris
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.