all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Disabling minor mode after setting imenu-generic-expression
@ 2024-08-27 19:00 Heime
  2024-08-28  5:15 ` Yuri Khan
  0 siblings, 1 reply; 6+ messages in thread
From: Heime @ 2024-08-27 19:00 UTC (permalink / raw)
  To: Heime via Users list for the GNU Emacs text editor

Have set 'imenu-generic-expression' for a buffer when it is in 'emacs-lisp-mode'
using '(eq major-mode'.  But how do I revert back to the initial sate after disabling
the minor mode ?  What should 'tema-disable-function' do  exactly ?

(defun tema-expr-elisp ()

  (setq imenu-generic-expression
    `( ("defun"
          ,(concat "^\\s-*"
                   "(\\(defun\\|define-minor-mode\\)\\s-+"
                   "\\(\\(\\sw\\|\\s_\\)+\\)") 2) )) )

;;;###autoload
(define-minor-mode tema-minor-mode
  "DESC."
  :init-value nil
  :lighter " Tema"

  (if tema-minor-mode
      (progn
        ;; Apply the configuration for the current buffer if the major mode matches
        (cond
          ((eq major-mode 'sh-mode) (tema-expr-sh))
          ((eq major-mode 'emacs-lisp-mode) (tema-expr-elisp))))
    (tema-disable-function) ))





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

* Re: Disabling minor mode after setting imenu-generic-expression
  2024-08-27 19:00 Heime
@ 2024-08-28  5:15 ` Yuri Khan
  2024-08-28  9:09   ` Heime
  2024-08-29  1:21   ` Stefan Monnier via Users list for the GNU Emacs text editor
  0 siblings, 2 replies; 6+ messages in thread
From: Yuri Khan @ 2024-08-28  5:15 UTC (permalink / raw)
  To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor

On Wed, 28 Aug 2024 at 02:01, Heime <heimeborgia@protonmail.com> wrote:
>
> Have set 'imenu-generic-expression' for a buffer when it is in 'emacs-lisp-mode'
> using '(eq major-mode'.  But how do I revert back to the initial sate after disabling
> the minor mode ?  What should 'tema-disable-function' do  exactly ?

You have been asking this question every day for the last week (I
might be exaggerating a bit) and got no answers. This should cue you
to the idea that the functionality you seek is not well suited to be a
minor mode.

You have also not explained why you want different imenu settings at
different times, so your question is an instance of XY problem — you
have a need that you are not telling us, you have a feeling that it
might be solved in a particular way, and you’re asking about that way.



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

* Re: Disabling minor mode after setting imenu-generic-expression
  2024-08-28  5:15 ` Yuri Khan
@ 2024-08-28  9:09   ` Heime
  2024-08-29  1:21   ` Stefan Monnier via Users list for the GNU Emacs text editor
  1 sibling, 0 replies; 6+ messages in thread
From: Heime @ 2024-08-28  9:09 UTC (permalink / raw)
  To: Yuri Khan; +Cc: Heime via Users list for the GNU Emacs text editor

On Wednesday, August 28th, 2024 at 5:15 PM, Yuri Khan <yuri.v.khan@gmail.com> wrote:

> On Wed, 28 Aug 2024 at 02:01, Heime heimeborgia@protonmail.com wrote:
> 
> > Have set 'imenu-generic-expression' for a buffer when it is in 'emacs-lisp-mode'
> > using '(eq major-mode'. But how do I revert back to the initial sate after disabling
> > the minor mode ? What should 'tema-disable-function' do exactly ?
> 
> 
> You have been asking this question every day for the last week (I
> might be exaggerating a bit) and got no answers. This should cue you
> to the idea that the functionality you seek is not well suited to be a
> minor mode.

I already have a minor-mode and I want to add this functionality to it.
There should be nothing bad about doing this.

The imenu-generic-expression is customarily set by the major-mode, but I want
to change it, and then revert back when the mode is disabled. 

 
> You have also not explained why you want different imenu settings at
> different times. 

I want to have matching regexp types in a buffer that I want to match
besides the standard "(defun" thing, but which would not always be needed.  

> So your question is an instance of XY problem — you have a need that 
> you are not telling us, you have a feeling that it might be solved in 
> a particular way, and you’re asking about that way.

I do not see it the way you describe.




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

* Disabling minor mode after setting imenu-generic-expression
@ 2024-08-28 23:22 Heime
  0 siblings, 0 replies; 6+ messages in thread
From: Heime @ 2024-08-28 23:22 UTC (permalink / raw)
  To: Heime via Users list for the GNU Emacs text editor

Have set 'imenu-generic-expression' for a buffer when it is in 'emacs-lisp-mode'
using '(eq major-mode'.  Customarily, it is the major mode sets the default value
to 'imenu-generic-expression'.  I want to save the original value, so that when 
I deactivate the minor mode, I reset 'imenu-generic-expression' to any previous
value before the minor mode changed it.

How can I do so ?

(defun tema-expr-elisp ()

(setq imenu-generic-expression
  `( ("defun"
        ,(concat "^\\s-*"
                 "(\\(defun\\|define-minor-mode\\)\\s-+"
                 "\\(\\(\\sw\\|\\s_\\)+\\)") 2) )) )

;;;###autoload
(define-minor-mode tema-minor-mode
  "DESC."
  :init-value nil
  :lighter " Tema"

  (if tema-minor-mode
      (progn
        (cond
          ((eq major-mode 'sh-mode) (tema-expr-sh))
          ((eq major-mode 'emacs-lisp-mode) (tema-expr-elisp))))
    (tema-disable-function) ))




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

* Re: Disabling minor mode after setting imenu-generic-expression
  2024-08-28  5:15 ` Yuri Khan
  2024-08-28  9:09   ` Heime
@ 2024-08-29  1:21   ` Stefan Monnier via Users list for the GNU Emacs text editor
  2024-08-29 10:21     ` Heime
  1 sibling, 1 reply; 6+ messages in thread
From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2024-08-29  1:21 UTC (permalink / raw)
  To: help-gnu-emacs

> You have been asking this question every day for the last week (I
> might be exaggerating a bit) and got no answers. This should cue you
> to the idea that the functionality you seek is not well suited to be a
> minor mode.

In my case the lack of answer is because I don't understand
the question.
I read it as "After changing the name on my mailbox, how do I set it
back".  Presumably if you know how to change it in the first place, you
should know how to set it back (unless maybe you can change the name on
the mailbox but you can't read the name on the mailbox?).


        Stefan




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

* Re: Disabling minor mode after setting imenu-generic-expression
  2024-08-29  1:21   ` Stefan Monnier via Users list for the GNU Emacs text editor
@ 2024-08-29 10:21     ` Heime
  0 siblings, 0 replies; 6+ messages in thread
From: Heime @ 2024-08-29 10:21 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: help-gnu-emacs


On Thursday, August 29th, 2024 at 1:21 PM, Stefan Monnier via Users 
list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> wrote:

> > You have been asking this question every day for the last week (I
> > might be exaggerating a bit) and got no answers. This should cue you
> > to the idea that the functionality you seek is not well suited to be a
> > minor mode.
> 
> 
> In my case the lack of answer is because I don't understand
> the question.
> I read it as "After changing the name on my mailbox, how do I set it
> back". Presumably if you know how to change it in the first place, you
> should know how to set it back (unless maybe you can change the name on
> the mailbox but you can't read the name on the mailbox?). - Stefan

I could save the default set by the major mode before changing it.  But
will all the buffer local things, I am unsure what to use.  Currently,
I set the value with

(setq imenu-generic-expression

But when disabling the mode I want to revert to the original.



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

end of thread, other threads:[~2024-08-29 10:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-28 23:22 Disabling minor mode after setting imenu-generic-expression Heime
  -- strict thread matches above, loose matches on Subject: below --
2024-08-27 19:00 Heime
2024-08-28  5:15 ` Yuri Khan
2024-08-28  9:09   ` Heime
2024-08-29  1:21   ` Stefan Monnier via Users list for the GNU Emacs text editor
2024-08-29 10:21     ` Heime

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.