unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* imenu rescan automatically
@ 2024-08-11 16:51 Heime
  2024-08-11 23:41 ` Joel Reicher
  0 siblings, 1 reply; 12+ messages in thread
From: Heime @ 2024-08-11 16:51 UTC (permalink / raw)
  To: Heime via Users list for the GNU Emacs text editor

I made this interactive function that adds items to imenu menubar.

But I want a rescan to happen automatically rather than having to
do it after I call the function.

(defun lumin-expr-elisp (actm)

  (interactive
   (list
     (let ( (cseq '("Declarations")) )
       (completing-read "ACTM: " cseq nil t "Declarations"))))

   (cond
     
     ((equal actm "Declarations")
        (setq imenu-generic-expression
          `( ("defconst"
                ,(concat "^\\s-*"
                         "(defconst\\s-+"
                         "\\(\\(\\sw\\|\\s_\\)+\\)") 1)

             ("defvar"
                ,(concat "^\\s-*"
                         "(\\(defvar\\|defvar-local\\)\\s-+"
                         "\\(\\(\\sw\\|\\s_\\)+\\)") 2)

             ("defcustom"
                ,(concat "^\\s-*"
                         "(defcustom\\s-+"
                         "\\(\\(\\sw\\|\\s_\\)+\\)") 1)

             ("defun"
                ,(concat "^\\s-*"
                         "(\\(defun\\|define-minor-mode\\)\\s-+"
                         "\\(\\(\\sw\\|\\s_\\)+\\)") 2) ))) )

   (when imenu-generic-expression
     (imenu--make-index-alist t)
     (imenu-add-to-menubar "Lumi")
     (call-interactively 'imenu)) )






^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: imenu rescan automatically
  2024-08-11 16:51 imenu rescan automatically Heime
@ 2024-08-11 23:41 ` Joel Reicher
  2024-08-12  9:34   ` Heime
  0 siblings, 1 reply; 12+ messages in thread
From: Joel Reicher @ 2024-08-11 23:41 UTC (permalink / raw)
  To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor

Heime <heimeborgia@protonmail.com> writes:

> I made this interactive function that adds items to imenu 
> menubar.
>
> But I want a rescan to happen automatically rather than having 
> to do it after I call the function.

I think you mean you want your function to do an imenu rescan?

Cheers,

        - Joel



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: imenu rescan automatically
  2024-08-11 23:41 ` Joel Reicher
@ 2024-08-12  9:34   ` Heime
  2024-08-12 10:13     ` Joel Reicher
  0 siblings, 1 reply; 12+ messages in thread
From: Heime @ 2024-08-12  9:34 UTC (permalink / raw)
  To: Joel Reicher; +Cc: Heime via Users list for the GNU Emacs text editor


On Monday, August 12th, 2024 at 11:41 AM, Joel Reicher <joel.reicher@gmail.com> wrote:

> Heime heimeborgia@protonmail.com writes:
> 
> > I made this interactive function that adds items to imenu
> > menubar.
> > 
> > But I want a rescan to happen automatically rather than having
> > to do it after I call the function.
> 
> 
> I think you mean you want your function to do an imenu rescan?
> 
> Cheers,
> 
> - Joel

Yes, the function changes imenu-generic-expression and I want it to do a rescan
so the user does not have to manually do it.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: imenu rescan automatically
  2024-08-12  9:34   ` Heime
@ 2024-08-12 10:13     ` Joel Reicher
  2024-08-12 10:21       ` Heime
  0 siblings, 1 reply; 12+ messages in thread
From: Joel Reicher @ 2024-08-12 10:13 UTC (permalink / raw)
  To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor

Heime <heimeborgia@protonmail.com> writes:

> On Monday, August 12th, 2024 at 11:41 AM, Joel Reicher 
> <joel.reicher@gmail.com> wrote:
>
>> Heime heimeborgia@protonmail.com writes:
>>
>>> I made this interactive function that adds items to imenu 
>>> menubar.
>>>
>>> But I want a rescan to happen automatically rather than having 
>>> to do it after I call the function.
>>
>> I think you mean you want your function to do an imenu rescan?
>
> Yes, the function changes imenu-generic-expression and I want it 
> to do a rescan so the user does not have to manually do it.

So add a rescan call to your function?

What am I missing?

Cheers,

        - Joel



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: imenu rescan automatically
  2024-08-12 10:13     ` Joel Reicher
@ 2024-08-12 10:21       ` Heime
  2024-08-12 10:50         ` Joel Reicher
  0 siblings, 1 reply; 12+ messages in thread
From: Heime @ 2024-08-12 10:21 UTC (permalink / raw)
  To: Joel Reicher; +Cc: Heime via Users list for the GNU Emacs text editor


On Monday, August 12th, 2024 at 10:13 PM, Joel Reicher <joel.reicher@gmail.com> wrote:

> Heime heimeborgia@protonmail.com writes:
> 
> > On Monday, August 12th, 2024 at 11:41 AM, Joel Reicher
> > joel.reicher@gmail.com wrote:
> > 
> > > Heime heimeborgia@protonmail.com writes:
> > > 
> > > > I made this interactive function that adds items to imenu
> > > > menubar.
> > > > 
> > > > But I want a rescan to happen automatically rather than having
> > > > to do it after I call the function.
> > > 
> > > I think you mean you want your function to do an imenu rescan?
> > 
> > Yes, the function changes imenu-generic-expression and I want it
> > to do a rescan so the user does not have to manually do it.
> 
> 
> So add a rescan call to your function?
> 
> What am I missing? - Joel

What is the function that achieves this ?  Have not found a rescan
function type name.





^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: imenu rescan automatically
  2024-08-12 10:21       ` Heime
@ 2024-08-12 10:50         ` Joel Reicher
  2024-08-12 11:27           ` Heime
  0 siblings, 1 reply; 12+ messages in thread
From: Joel Reicher @ 2024-08-12 10:50 UTC (permalink / raw)
  To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor

Heime <heimeborgia@protonmail.com> writes:

> On Monday, August 12th, 2024 at 10:13 PM, Joel Reicher 
> <joel.reicher@gmail.com> wrote:
>
>> Heime heimeborgia@protonmail.com writes:
>>
>>> Yes, the function changes imenu-generic-expression and I want 
>>> it to do a rescan so the user does not have to manually do it.
>>
>> So add a rescan call to your function?
>>
>> What am I missing?
>
> What is the function that achieves this ?  Have not found a 
> rescan function type name.

(imenu-flush-cache)

Flush the current imenu cache.
This forces a full rescan of the buffer to recreate the index 
alist next time ‘imenu’ is invoked.

I think that will do what you want.

Cheers,

        - Joel



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: imenu rescan automatically
  2024-08-12 10:50         ` Joel Reicher
@ 2024-08-12 11:27           ` Heime
  2024-08-12 11:57             ` Joel Reicher
  0 siblings, 1 reply; 12+ messages in thread
From: Heime @ 2024-08-12 11:27 UTC (permalink / raw)
  To: Joel Reicher; +Cc: Heime via Users list for the GNU Emacs text editor

On Monday, August 12th, 2024 at 10:50 PM, Joel Reicher <joel.reicher@gmail.com> wrote:

> Heime heimeborgia@protonmail.com writes:
> 
> > On Monday, August 12th, 2024 at 10:13 PM, Joel Reicher
> > joel.reicher@gmail.com wrote:
> > 
> > > Heime heimeborgia@protonmail.com writes:
> > > 
> > > > Yes, the function changes imenu-generic-expression and I want
> > > > it to do a rescan so the user does not have to manually do it.
> > > 
> > > So add a rescan call to your function?
> > > 
> > > What am I missing?
> > 
> > What is the function that achieves this ? Have not found a
> > rescan function type name.
> 
> 
> (imenu-flush-cache)
> 
> Flush the current imenu cache.
> This forces a full rescan of the buffer to recreate the index
> alist next time ‘imenu’ is invoked.
> 
> I think that will do what you want.
> 
> Cheers,
> 
> - Joel

When exactly should I call it ?  I want the imenu menubar to be automatically
updated.  Currently I have to press rescan on the  imenu menubar to update it.

   (when imenu-generic-expression
     (imenu-flush-cache)
     (imenu--make-index-alist t)
     (imenu-flush-cache)
     (imenu-add-to-menubar "Lumi")) )




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: imenu rescan automatically
  2024-08-12 11:27           ` Heime
@ 2024-08-12 11:57             ` Joel Reicher
  2024-08-12 12:14               ` Heime
  0 siblings, 1 reply; 12+ messages in thread
From: Joel Reicher @ 2024-08-12 11:57 UTC (permalink / raw)
  To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor

Heime <heimeborgia@protonmail.com> writes:

> On Monday, August 12th, 2024 at 10:50 PM, Joel Reicher 
> <joel.reicher@gmail.com> wrote:
>
>> (imenu-flush-cache)
>>
>> Flush the current imenu cache.
>> This forces a full rescan of the buffer to recreate the index 
>> alist next time ‘imenu’ is invoked.
>>
>> I think that will do what you want.
>
> When exactly should I call it ?  I want the imenu menubar to be 
> automatically updated.  Currently I have to press rescan on the 
> imenu menubar to update it.

I think for the kinds of things you are doing you need to get used 
to reading existing code. For example pressing rescan in the imenu 
does this...

...
      (and (equal result imenu--rescan-item)
	   (imenu--cleanup)
	   (setq result t imenu--index-alist nil))
...

And to explain my suggestion above, imenu-flush-cache is defined 
like so

(defun imenu-flush-cache ()
...
  (imenu--cleanup)
  (setq imenu--index-alist nil))

Cheers,

        - Joel



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: imenu rescan automatically
  2024-08-12 11:57             ` Joel Reicher
@ 2024-08-12 12:14               ` Heime
  2024-08-12 12:20                 ` Joel Reicher
  0 siblings, 1 reply; 12+ messages in thread
From: Heime @ 2024-08-12 12:14 UTC (permalink / raw)
  To: Joel Reicher; +Cc: Heime via Users list for the GNU Emacs text editor

On Monday, August 12th, 2024 at 11:57 PM, Joel Reicher <joel.reicher@gmail.com> wrote:

> Heime heimeborgia@protonmail.com writes:
> 
> > On Monday, August 12th, 2024 at 10:50 PM, Joel Reicher
> > joel.reicher@gmail.com wrote:
> > 
> > > (imenu-flush-cache)
> > > 
> > > Flush the current imenu cache.
> > > This forces a full rescan of the buffer to recreate the index
> > > alist next time ‘imenu’ is invoked.
> > > 
> > > I think that will do what you want.
> > 
> > When exactly should I call it ? I want the imenu menubar to be
> > automatically updated. Currently I have to press rescan on the
> > imenu menubar to update it.
> 
> 
> I think for the kinds of things you are doing you need to get used
> to reading existing code. For example pressing rescan in the imenu
> does this...
> 
> ...
> (and (equal result imenu--rescan-item)
> (imenu--cleanup)
> (setq result t imenu--index-alist nil))
> ...
> 
> And to explain my suggestion above, imenu-flush-cache is defined
> like so
> 
> (defun imenu-flush-cache ()
> ...
> (imenu--cleanup)
> (setq imenu--index-alist nil))

Well, I could not get anywhere.  Not even this

   (when imenu-generic-expression

     (imenu-flush-cache)
     (setq imenu--index-alist nil)
     (imenu--make-index-alist t)
     (imenu--cleanup)

     (imenu-add-to-menubar "Lumi")) )




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: imenu rescan automatically
  2024-08-12 12:14               ` Heime
@ 2024-08-12 12:20                 ` Joel Reicher
  2024-08-12 12:32                   ` Christopher Dimech
  0 siblings, 1 reply; 12+ messages in thread
From: Joel Reicher @ 2024-08-12 12:20 UTC (permalink / raw)
  To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor

Heime <heimeborgia@protonmail.com> writes:

> Well, I could not get anywhere.

Take the time to understand what the existing imenu code does. Ask 
questions.

Regards,

        - Joel



^ permalink raw reply	[flat|nested] 12+ messages in thread

* imenu rescan automatically
  2024-08-12 12:20                 ` Joel Reicher
@ 2024-08-12 12:32                   ` Christopher Dimech
  2024-08-12 13:02                     ` Joel Reicher
  0 siblings, 1 reply; 12+ messages in thread
From: Christopher Dimech @ 2024-08-12 12:32 UTC (permalink / raw)
  To: Joel Reicher; +Cc: Heime, Heime via Users list for the GNU Emacs text editor


> Sent: Tuesday, August 13, 2024 at 12:20 AM
> From: "Joel Reicher" <joel.reicher@gmail.com>
> To: "Heime" <heimeborgia@protonmail.com>
> Cc: "Heime via Users list for the GNU Emacs text editor" <help-gnu-emacs@gnu.org>
> Subject: Re: imenu rescan automatically
>
> Heime <heimeborgia@protonmail.com> writes:
>
> > Well, I could not get anywhere.
>
> Take the time to understand what the existing imenu code does. Ask
> questions. - Joel

So I can forget any useful code that words.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: imenu rescan automatically
  2024-08-12 12:32                   ` Christopher Dimech
@ 2024-08-12 13:02                     ` Joel Reicher
  0 siblings, 0 replies; 12+ messages in thread
From: Joel Reicher @ 2024-08-12 13:02 UTC (permalink / raw)
  To: Christopher Dimech
  Cc: Heime, Heime via Users list for the GNU Emacs text editor

Christopher Dimech <dimech@gmx.com> writes:

> So I can forget any useful code that words. 

For code to work it 'only' requires that the series of state 
changes executed by the machine leads to the desired final state.

It cannot and should not be underestimated how obfuscated that can 
be, and it is orthogonal almost to the point of being irrelevant 
to the way humans understand code.

An example from the UNIX fortune file:

        n = ((n >>  1) & 0x55555555) | ((n <<  1) & 0xaaaaaaaa);
        n = ((n >>  2) & 0x33333333) | ((n <<  2) & 0xcccccccc);
        n = ((n >>  4) & 0x0f0f0f0f) | ((n <<  4) & 0xf0f0f0f0);
        n = ((n >>  8) & 0x00ff00ff) | ((n <<  8) & 0xff00ff00);
        n = ((n >> 16) & 0x0000ffff) | ((n << 16) & 0xffff0000);

                -- C code which reverses the bits in a word.

If it works, but you don't understand it, it doesn't work.

Regards,

        - Joel



^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2024-08-12 13:02 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-11 16:51 imenu rescan automatically Heime
2024-08-11 23:41 ` Joel Reicher
2024-08-12  9:34   ` Heime
2024-08-12 10:13     ` Joel Reicher
2024-08-12 10:21       ` Heime
2024-08-12 10:50         ` Joel Reicher
2024-08-12 11:27           ` Heime
2024-08-12 11:57             ` Joel Reicher
2024-08-12 12:14               ` Heime
2024-08-12 12:20                 ` Joel Reicher
2024-08-12 12:32                   ` Christopher Dimech
2024-08-12 13:02                     ` Joel Reicher

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).