GNU bug report logs - #8724
23.2; js-mode imenu should be more thorough

Previous Next

Package: emacs;

Reported by: dino chiesa <dpchiesa <at> hotmail.com>

Date: Tue, 24 May 2011 13:16:02 UTC

Severity: wishlist

Found in version 23.2

To reply to this bug, email your comments to 8724 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#8724; Package emacs. (Tue, 24 May 2011 13:16:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to dino chiesa <dpchiesa <at> hotmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 24 May 2011 13:16:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: dino chiesa <dpchiesa <at> hotmail.com>
To: <bug-gnu-emacs <at> gnu.org>
Subject: 23.2; js-mode imenu should be more thorough
Date: Tue, 24 May 2011 05:51:36 -0700
[Message part 1 (text/plain, inline)]
Module /emacs/lisp/progmodes/js.el
 
In js-mode, editing a short javascript file, the imenu indexing works
nicely but the actual menu is incomplete, truncated. The defun
js--pitems-to-imenu seems to make an insufficient effort, when
nested function definitions are used in the source. 
 
For example, supposing this js source: 
 
  jQuery(document).ready(function () {
      var $th = jQuery('thead > tr > th');
      $th.each(function(column, elt) {
          jQuery(this).addClass('sortable').click(function() {
             ...
          });
      });
  });
 
(this is fairly typical with javascript)
 
In this case js-mode will index all of the anonymous functions, but will 
produce an imenu that contains only the outer anonymous function. This is 
done in js--pitems-to-imenu. Also, in the same defun, the imenu entry uses
"Unknown" as the name of the anonymous function.
 
I propose 2 things: 
  - replace the name "unknown" with "Anonymous"
  - recurse into js--pitems-to-imenu for functions that define 
    child functions. 

The proposed new code for the defun is: 
 
     (defun js--pitems-to-imenu (pitems unknown-ctr)
       "Convert list of pitems PITEMS to imenu format"
       (let (imenu-items pitem pitem-type pitem-name subitems)
         (while (setq pitem (pop pitems))
           (setq pitem-type (js--pitem-type pitem))
           (setq pitem-name (js--pitem-strname pitem))
           (when (eq pitem-name t)
             (setq pitem-name (format "Anonymous %s"
                                      (incf (car unknown-ctr)))))
           (cond
            ((memq pitem-type '(function macro))
             (assert (integerp (js--pitem-h-begin pitem)))
             ;; DPC check for children (nested fnc defns)
             (cond
              ((js--pitem-children pitem)
               (setq subitems (js--pitems-to-imenu
                               (js--pitem-children pitem)
                               unknown-ctr))
               (cond
                (subitems
                 ;; DPC index "top" and "bottom" of the enclosure
                 (push (cons "(top)"
                             (js--maybe-make-marker
                              (js--pitem-h-begin pitem)))
                       subitems)
                 (let ((b-end (js--pitem-b-end pitem)))
                   (if b-end
                       (setq subitems
                             (append subitems
                                     (list (cons "(bottom)"
                                                 (js--maybe-make-marker b-end)))
                                     subitems))))
                 (push (cons pitem-name subitems)
                       imenu-items))
                (t
                 (push (cons pitem-name
                             (js--maybe-make-marker
                              (js--pitem-h-begin pitem)))
                       imenu-items))))
              (t
               (push (cons pitem-name
                           (js--maybe-make-marker
                            (js--pitem-h-begin pitem)))
                     imenu-items))))
            ((consp pitem-type) ; class definition
             (setq subitems (js--pitems-to-imenu
                             (js--pitem-children pitem)
                             unknown-ctr))
             (cond (subitems
                    (push (cons pitem-name subitems)
                          imenu-items))
                   ((js--pitem-h-begin pitem)
                    (assert (integerp (js--pitem-h-begin pitem)))
                    (setq subitems (list
                                    (cons "[empty]"
                                          (js--maybe-make-marker
                                           (js--pitem-h-begin pitem)))))
                    (push (cons pitem-name subitems)
                          imenu-items))))
            (t (error "Unknown item type: %S" pitem-type))))
         imenu-items))
 
 
In GNU Emacs 23.2.1 (i386-mingw-nt6.1.7601)
 of 2010-05-08 on G41R2F1
Windowing system distributor `Microsoft Corp.', version 6.1.7601
configured using `configure --with-gcc (3.4) --no-opt --cflags -Ic:/xpm/include'
Important settings:
  value of $LC_ALL: nil
  value of $LC_COLLATE: nil
  value of $LC_CTYPE: nil
  value of $LC_MESSAGES: nil
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: nil
  value of $LANG: ENU
  value of $XMODIFIERS: nil
  locale-coding-system: cp1252
  default enable-multibyte-characters: t
Major mode: Emacs-Lisp
Minor modes in effect:
  auto-revert-mode: t
  yas/minor-mode: t
  global-hl-line-mode: t
  hl-line-mode: t
  global-auto-complete-mode: t
  auto-complete-mode: t
  tooltip-mode: t
  mouse-wheel-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent messages:
Mark saved where search started
Mark set
No closing parenthesis found
Mark set
Matches   '(... [-73-]
Matches (eval-after-load "js" [-74]
Mark set [2 times]
Saving file c:/Users/Dino/elisp/emacs.el...
Wrote c:/Users/Dino/elisp/emacs.el
Mark set
Load-path shadows:
/users/dino/elisp/linum hides c:/emacs/lisp/linum
/users/dino/elisp/css-mode hides c:/emacs/lisp/textmodes/css-mode
Features:
(shadow sort mail-extr message ecomplete rfc822 mml mml-sec
password-cache mm-decode mm-bodies mm-encode mailcap mail-parse rfc2231
rfc2047 rfc2045 qp ietf-drums mailabbrev nnheader gnus-util netrc
time-date mm-util mail-prsvr gmm-utils wid-edit mailheader canlock sha1
hex-util hashcash mail-utils emacsbug help-mode view js find-func
dired-aux flymake-for-jslint-for-wsh flymake-cursor flymake autopair
espresso bytecomp byte-compile ido json thingatpt etags imenu newcomment
cc-mode cc-fonts cc-menus cc-cmds multi-isearch grep compile comint ring
time-stamp sgml-mode autorevert server cperl-mode paren mic-paren
hideshow easymenu cc-styles cc-align cc-engine cc-vars cc-defs dired
regexp-opt defaultcontent yasnippet-bundle dropdown-list yasnippet
easy-mmode cl cl-19 tfs skeleton httpget hl-line advice help-fns
advice-preload auto-complete-config auto-complete edmacro kmacro popup
tooltip ediff-hook vc-hooks lisp-float-type mwheel dos-w32 disp-table
ls-lisp w32-win w32-vars tool-bar dnd fontset image fringe lisp-mode
register page menu-bar rfn-eshadow timer select scroll-bar mldrag mouse
jit-lock font-lock syntax facemenu font-core frame cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese hebrew greek romanian slovak czech european ethiopic indian
cyrillic chinese case-table epa-hook jka-cmpr-hook help simple abbrev
loaddefs button minibuffer faces cus-face files text-properties overlay
md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote make-network-process multi-tty emacs)
 		 	   		  
[Message part 2 (text/html, inline)]

Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#8724; Package emacs. (Sun, 19 Jun 2011 20:41:01 GMT) Full text and rfc822 format available.

Message #8 received at 8724 <at> debbugs.gnu.org (full text, mbox):

From: Daniel Colascione <dan.colascione <at> gmail.com>
To: dino chiesa <dpchiesa <at> hotmail.com>
Cc: 8724 <at> debbugs.gnu.org
Subject: Re: bug#8724: 23.2; js-mode imenu should be more thorough
Date: Sun, 19 Jun 2011 13:40:36 -0700
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Dino,

Thanks for the feature suggestion and code.

On 5/24/11 5:51 AM, dino chiesa wrote:
> 
> Module /emacs/lisp/progmodes/js.el
>  
> In js-mode, editing a short javascript file, the imenu indexing works
> nicely but the actual menu is incomplete, truncated. The defun
> js--pitems-to-imenu seems to make an insufficient effort, when
> nested function definitions are used in the source. 
>  
> For example, supposing this js source: 
>  
>   jQuery(document).ready(function () {
>       var $th = jQuery('thead > tr > th');
>       $th.each(function(column, elt) {
>           jQuery(this).addClass('sortable').click(function() {
>              ...
>           });
>       });
>   });
>  
> (this is fairly typical with javascript)

Fair enough.

>  
> In this case js-mode will index all of the anonymous functions, but will 
> produce an imenu that contains only the outer anonymous function. This is 
> done in js--pitems-to-imenu. Also, in the same defun, the imenu entry uses
> "Unknown" as the name of the anonymous function.
>  
> I propose 2 things: 
>   - replace the name "unknown" with "Anonymous"
>   - recurse into js--pitems-to-imenu for functions that define 
>     child functions. 
> 
> The proposed new code for the defun is: 

I'll see what I can do about looking at your code. In the meantime, it
would be helpful if you could submit your changes as a patch against the
latest code in trunk.

Thanks,
Daniel Colascione

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (Darwin)

iEYEARECAAYFAk3+XsIACgkQ17c2LVA10Vta4ACfab5AvYokQAfTTOn+hmwKIRwl
buIAoJC08O+cthOUL7UTHo+er6kZcFYT
=bT2r
-----END PGP SIGNATURE-----




Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#8724; Package emacs. (Sun, 19 Jun 2011 20:46:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#8724; Package emacs. (Wed, 02 Jun 2021 08:00:02 GMT) Full text and rfc822 format available.

Message #14 received at 8724 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Daniel Colascione <dan.colascione <at> gmail.com>
Cc: dino chiesa <dpchiesa <at> hotmail.com>, 8724 <at> debbugs.gnu.org
Subject: Re: bug#8724: 23.2; js-mode imenu should be more thorough
Date: Wed, 02 Jun 2021 09:58:50 +0200
Daniel Colascione <dan.colascione <at> gmail.com> writes:

>> I propose 2 things: 
>>   - replace the name "unknown" with "Anonymous"
>>   - recurse into js--pitems-to-imenu for functions that define 
>>     child functions. 
>> 
>> The proposed new code for the defun is: 
>
> I'll see what I can do about looking at your code. In the meantime, it
> would be helpful if you could submit your changes as a patch against the
> latest code in trunk.

This was nine years ago -- was there any progress with this?  (It sounds
like a good change, but I haven't looked at the code.)

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#8724; Package emacs. (Sat, 05 Jun 2021 00:25:02 GMT) Full text and rfc822 format available.

Message #17 received at 8724 <at> debbugs.gnu.org (full text, mbox):

From: Dmitry Gutov <dgutov <at> yandex.ru>
To: Lars Ingebrigtsen <larsi <at> gnus.org>,
 Daniel Colascione <dan.colascione <at> gmail.com>
Cc: dino chiesa <dpchiesa <at> hotmail.com>, 8724 <at> debbugs.gnu.org
Subject: Re: bug#8724: 23.2; js-mode imenu should be more thorough
Date: Sat, 5 Jun 2021 03:24:41 +0300
On 02.06.2021 10:58, Lars Ingebrigtsen wrote:
> This was nine years ago -- was there any progress with this?  (It sounds
> like a good change, but I haven't looked at the code.)

Someone should really work in that direction, since in these nine years 
JS has grown more ways to define a function: e.g. arrow functions, or 
'const <function name> = ...'.

I've tried simply replacing the definition.

The patch kinda works, except I'm not sure about the (top) and (bottom) 
items that it adds (we don't have any precedent for this, so I vote no), 
and there's some sort of duplication of the entries: I see both (top) 
and the enclosed function name repeated an extra time in the imenu index.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#8724; Package emacs. (Wed, 10 Jan 2024 11:56:02 GMT) Full text and rfc822 format available.

Message #20 received at 8724 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefankangas <at> gmail.com>
To: Dmitry Gutov <dgutov <at> yandex.ru>
Cc: Lars Ingebrigtsen <larsi <at> gnus.org>,
 Daniel Colascione <dan.colascione <at> gmail.com>,
 dino chiesa <dpchiesa <at> hotmail.com>, 8724 <at> debbugs.gnu.org
Subject: Re: bug#8724: 23.2; js-mode imenu should be more thorough
Date: Wed, 10 Jan 2024 03:55:03 -0800
Dmitry Gutov <dgutov <at> yandex.ru> writes:

> On 02.06.2021 10:58, Lars Ingebrigtsen wrote:
>> This was nine years ago -- was there any progress with this?  (It sounds
>> like a good change, but I haven't looked at the code.)
>
> Someone should really work in that direction, since in these nine years JS has
> grown more ways to define a function: e.g. arrow functions, or 'const <function
> name> = ...'.
>
> I've tried simply replacing the definition.
>
> The patch kinda works, except I'm not sure about the (top) and (bottom) items
> that it adds (we don't have any precedent for this, so I vote no), and there's
> some sort of duplication of the entries: I see both (top) and the enclosed
> function name repeated an extra time in the imenu index.

Did you make any further progress here?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#8724; Package emacs. (Thu, 11 Jan 2024 00:20:02 GMT) Full text and rfc822 format available.

Message #23 received at 8724 <at> debbugs.gnu.org (full text, mbox):

From: Dmitry Gutov <dgutov <at> yandex.ru>
To: Stefan Kangas <stefankangas <at> gmail.com>
Cc: Lars Ingebrigtsen <larsi <at> gnus.org>,
 Daniel Colascione <dan.colascione <at> gmail.com>,
 dino chiesa <dpchiesa <at> hotmail.com>, 8724 <at> debbugs.gnu.org
Subject: Re: bug#8724: 23.2; js-mode imenu should be more thorough
Date: Thu, 11 Jan 2024 02:19:27 +0200
On 10/01/2024 13:55, Stefan Kangas wrote:
> Dmitry Gutov <dgutov <at> yandex.ru> writes:
> 
>> On 02.06.2021 10:58, Lars Ingebrigtsen wrote:
>>> This was nine years ago -- was there any progress with this?  (It sounds
>>> like a good change, but I haven't looked at the code.)
>>
>> Someone should really work in that direction, since in these nine years JS has
>> grown more ways to define a function: e.g. arrow functions, or 'const <function
>> name> = ...'.
>>
>> I've tried simply replacing the definition.
>>
>> The patch kinda works, except I'm not sure about the (top) and (bottom) items
>> that it adds (we don't have any precedent for this, so I vote no), and there's
>> some sort of duplication of the entries: I see both (top) and the enclosed
>> function name repeated an extra time in the imenu index.
> 
> Did you make any further progress here?

Sorry, I did not.

It's still marked as "todo" in my email folder, but not of high 
priority, so far.

And in this day and year, someone might give a shot at porting 
js2-mode's imenu generator (quite featureful, I should say) to 
tree-sitter's API (in js-ts-mode).




Severity set to 'wishlist' from 'normal' Request was from Stefan Kangas <stefankangas <at> gmail.com> to control <at> debbugs.gnu.org. (Fri, 14 Mar 2025 12:22:01 GMT) Full text and rfc822 format available.

This bug report was last modified 95 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.