unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* How not to share `local-set-key' with all other buffers in the same major mode?
@ 2021-04-02  8:32 Jean Louis
  2021-04-02 12:44 ` Skip Montanaro
  2021-04-02 12:55 ` Stefan Monnier
  0 siblings, 2 replies; 4+ messages in thread
From: Jean Louis @ 2021-04-02  8:32 UTC (permalink / raw)
  To: Help GNU Emacs

I would like to use editing modes as temporary view modes where I
would like to set a key like "q" or "i" temporarily, like this for
example:

(local-set-key "q" 'quit-window)

And I use it in read only mode. The binding goes in the current
buffer’s local map, which in most cases is shared with all other
buffers in the same major mode.

If the mode is Markdown then next time I enter in writeable buffer the
same key "q" remains and I need to unset it. So it is not convenient.

Would a solution for that be to make a new mode map and then invoke
new mode map when I wish to view it with special keys? All invoking I
do through functions, not manually.

Another matter is that I do dynamic `local-set-key' like following:

  (local-set-key "i" `(lambda ()
				(interactive)
				(hyperscope-view-with-mode ,id
				 ,(cond ((string= column "hlinks_description") "hlinks_text")
					((string= column "hlinks_text") "hlinks_description")
					(t (error "Cannot find column"))))))

So then if I wish to see some database entry in the buffer, I press
"i" and I see first "hlinks_description", but if I press "i" again I
will see "hlinks_text". This is very handy.

Is it possible to invoke mode dynamically, like to define a function
that defines mode, and that I call that function which would then call
the mode with specified parameters which in turn change the key
bindings as how I wish?

Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

Sign an open letter in support of Richard M. Stallman
https://rms-support-letter.github.io/






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

end of thread, other threads:[~2021-04-02 16:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-04-02  8:32 How not to share `local-set-key' with all other buffers in the same major mode? Jean Louis
2021-04-02 12:44 ` Skip Montanaro
2021-04-02 12:55 ` Stefan Monnier
2021-04-02 16:16   ` Jean Louis

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