unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Ergus via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: 54074@debbugs.gnu.org
Subject: bug#54074: 29.0.50; Feature request emacs keymap-set and minor-modes
Date: Sun, 20 Feb 2022 23:09:31 +0100	[thread overview]
Message-ID: <20220220220931.524xf6jeihqkhay3@Ergus> (raw)
In-Reply-To: <87czjhmior.fsf@gnus.org>

On Sun, Feb 20, 2022 at 08:39:16PM +0100, Lars Ingebrigtsen wrote:
>Ergus <spacibba@aol.com> writes:
>
>> Recently I have seen that many packages have a pattern where a global
>> minor mode adds a set of keybindings to another (like isearch or
>> minibuffer). The issue comes when they want to disable the mode, because
>> sometimes they need to iterate or loop over, and then emacs looses the
>> previous binding unless they also adds more code to remember it when set
>> and then bring it back when unset.

Hi Lars.. thanks for replying!

>
>I'm not sure I understand the use case.  Isn't the way to do this just
>to have my-mode add itself to isearch-mode-hook, and then have my-mode
>have a minor mode keymap with the prefix it uses?
>
Yes this is actually the common way to do it, but it is cumbersome with
no reason for simpler cases... and when more than one keymap can be
affected.

Basically I mean to have a way to add an entry: (keymap …) to another...

Because from the manual:

"If an element of a keymap is itself a keymap, it counts as if this inner
keymap were inlined in the outer keymap."

So, simpler cleaner and eventually not needing execute or start a mode
every time in a hook...

Now keymap-set allows to add a command or keymap to a prefix in another,
but not just append a keymap as is with no prefix and then remove it
completely in a clean way...


>> Something similar happens to some variables that are modified in minor
>> modes and then should be restored... this forces sometimes to restart
>> emacs... (for example completion-styles in fido-mode or some hooks that
>> are always added and then need to be removed... all these is very
>> mechanic and increases code and sources of errors...).
>>
>> The best approach for this one is to save the original value in an alist
>> and assign with a wrapper around setq...  and use a loop when disabling
>> the mode to restore the original values.... it is not perfect, but works
>> in many cases...
>
>I don't think there's any general mechanism that's possible for this.
>Any package may mogrify any variable (destructively or not), and only
>the package can know what it has to do to bring things back to normal
>when the package is switched off.
>

The common is just to save and the restore... isn't it the typical idea
behind a mode? Right now the modes cleanup is a source of issues and
code replication here and there for many mechanical thinks like
add-hook/remove-hook, set variable, unset them, and so on... when the
general idea is that all that may follow the same philosophy than
keybindings set-unset...

Best,
Ergus





  parent reply	other threads:[~2022-02-20 22:09 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <87ley5iclc.fsf.ref@aol.com>
2022-02-20 19:04 ` bug#54074: 29.0.50; Feature request emacs keymap-set and minor-modes Ergus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-20 19:39   ` Lars Ingebrigtsen
2022-02-20 21:18     ` Ergus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-20 22:09     ` Ergus via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2022-02-21 21:22     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-22 13:22       ` Lars Ingebrigtsen
2022-02-22 14:07         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-22 14:31           ` Lars Ingebrigtsen
2022-02-22 15:39             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-23 12:12               ` Lars Ingebrigtsen
2022-02-20 22:34   ` bug#54074: [External] : " Drew Adams
2022-02-21 21:05     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-21  8:28   ` Juri Linkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220220220931.524xf6jeihqkhay3@Ergus \
    --to=bug-gnu-emacs@gnu.org \
    --cc=54074@debbugs.gnu.org \
    --cc=larsi@gnus.org \
    --cc=spacibba@aol.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).