all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / 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

* Re: How not to share `local-set-key' with all other buffers in the same major mode?
  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
  1 sibling, 0 replies; 4+ messages in thread
From: Skip Montanaro @ 2021-04-02 12:44 UTC (permalink / raw)
  To: Jean Louis; +Cc: 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.
>

Would the minor view-mode do what you want?

https://www.gnu.org/software/emacs/manual/html_node/emacs/View-Mode.html

Skip

>


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

* Re: How not to share `local-set-key' with all other buffers in the same major mode?
  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
  1 sibling, 1 reply; 4+ messages in thread
From: Stefan Monnier @ 2021-04-02 12:55 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.

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


        Stefan




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

* Re: How not to share `local-set-key' with all other buffers in the same major mode?
  2021-04-02 12:55 ` Stefan Monnier
@ 2021-04-02 16:16   ` Jean Louis
  0 siblings, 0 replies; 4+ messages in thread
From: Jean Louis @ 2021-04-02 16:16 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: help-gnu-emacs

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




^ 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

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.