unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Jean Louis <bugs@gnu.support>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: help-gnu-emacs@gnu.org
Subject: Re: How not to share `local-set-key' with all other buffers in the same major mode?
Date: Fri, 2 Apr 2021 19:16:07 +0300	[thread overview]
Message-ID: <YGdDR/UwT3ezYAIS@protected.localdomain> (raw)
In-Reply-To: <jwva6qg26en.fsf-monnier+emacs@gnu.org>

* Stefan Monnier <monnier@iro.umontreal.ca> [2021-04-02 15:56]:
> > 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.
> 
> To avoid it, you can use something like:
> 
>     (use-local-map
>      (let ((map (make-sparse-keymap)))
>        (set-keymap-parent map (current-local-map))
>        map))
> 
> before doing your `local-set-key`.

Thank you. I made a function, and now it works nicely this way:

(defun hyperscope-view-local-map (id column)
  (interactive)
  (let ((map (make-sparse-keymap)))
    ;;(set-keymap-parent map (make-composed-keymap view-mode-map))
    (define-key map "q" 'quit-window)
    (define-key map "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"))))))
    (define-key map "e" (lambda ()
			  (interactive)
			  (hyperscope-edit-with-mode id column)
			  (kill-this-buffer)
			  (hyperscope-view-with-mode id column)))
    (use-local-map map)))

When I wish now to use the map, I just provide one line:

(hyperscope-view-local-map id column)


-- 
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/




      reply	other threads:[~2021-04-02 16:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

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=YGdDR/UwT3ezYAIS@protected.localdomain \
    --to=bugs@gnu.support \
    --cc=help-gnu-emacs@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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.
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).