help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How not to share `local-set-key' with all other buffers in the same


From: Jean Louis
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
User-agent: Mutt/2.0.6 (2021-03-06)

* 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 via email to

[Prev in Thread] Current Thread [Next in Thread]