From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Daniel Colascione Newsgroups: gmane.emacs.devel Subject: [PATCH] nested imenu support for which-func Date: Thu, 25 Sep 2008 17:02:48 -0400 Organization: Merrill Press Message-ID: <200809251702.48660.danc@merrillpress.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1222376596 27271 80.91.229.12 (25 Sep 2008 21:03:16 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 25 Sep 2008 21:03:16 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Sep 25 23:04:14 2008 connect(): Connection refused Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Kiy0M-0006KC-Kv for ged-emacs-devel@m.gmane.org; Thu, 25 Sep 2008 23:04:07 +0200 Original-Received: from localhost ([127.0.0.1]:34747 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KixzF-0002R4-Go for ged-emacs-devel@m.gmane.org; Thu, 25 Sep 2008 17:02:57 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KixzB-0002Qp-O4 for emacs-devel@gnu.org; Thu, 25 Sep 2008 17:02:53 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Kixz9-0002PI-9k for emacs-devel@gnu.org; Thu, 25 Sep 2008 17:02:52 -0400 Original-Received: from [199.232.76.173] (port=44511 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Kixz9-0002PF-3o for emacs-devel@gnu.org; Thu, 25 Sep 2008 17:02:51 -0400 Original-Received: from vpn.merrillpress.com ([64.61.107.78]:36296) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Kixz8-0003vr-IZ for emacs-devel@gnu.org; Thu, 25 Sep 2008 17:02:50 -0400 Original-Received: from pluto.merrillpress.net ([10.136.5.5]) by mars.merrillpress.net with esmtpsa (TLSv1:DHE-RSA-AES256-SHA:256) (Exim 4.63) (envelope-from ) id 1Kixz7-00067H-Hd for emacs-devel@gnu.org; Thu, 25 Sep 2008 17:02:49 -0400 User-Agent: KMail/1.9.9 X-Face: 9VC; >}hM+`K4j{H4n=pq/!61'7Rt"vEaPUdCwpS'=; @B7Ll,~Q.xb(|A>; 8M[\UzKQi{>Q Iptc6NY\M(0<{W?ob}e/91Y!k|XE:2SA2LU"cni>#Dmw4siEWG7|L9zkOZ\[nQPe9[PG|s P2n_jW\TzsG2N1Z0q:E#NmWU~0i]JE)gqB|4{jCjolaX6)KO[@k\:>01.58.Pk5Nb\5s": R,Q78_s; 6+vLj\V1y(`]\G3("(Y!G^79x}q[4L8w[.qEs|+ZN0R`Hk,>y; d7!SFx%M2M39 y[/Kc!p!:.E3Zx')v*l6IlR Content-Disposition: inline X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:104156 Archived-At: 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)