all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Buffer specific binding
@ 2015-08-25 21:04 Ian Zimmerman
  2015-08-26  7:44 ` Tassilo Horn
  0 siblings, 1 reply; 3+ messages in thread
From: Ian Zimmerman @ 2015-08-25 21:04 UTC (permalink / raw)
  To: help-gnu-emacs

What's the best way to bind a key to a command _only in a specific
buffer_?  AFAIK local-set-key will set it in the mode keymap so all
buffers in the same mode will see the change or addition; I'd like to
avoid that.

I know one answer: make a specialized mode (inherited from the real
one).  Any other way?

-- 
Please *no* private copies of mailing list or newsgroup messages.
Rule 420: All persons more than eight miles high to leave the court.




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

* Re: Buffer specific binding
  2015-08-25 21:04 Buffer specific binding Ian Zimmerman
@ 2015-08-26  7:44 ` Tassilo Horn
  2015-08-26 18:34   ` Ian Zimmerman
  0 siblings, 1 reply; 3+ messages in thread
From: Tassilo Horn @ 2015-08-26  7:44 UTC (permalink / raw)
  To: Ian Zimmerman; +Cc: help-gnu-emacs

Ian Zimmerman <itz@buug.org> writes:

> What's the best way to bind a key to a command _only in a specific
> buffer_?  AFAIK local-set-key will set it in the mode keymap so all
> buffers in the same mode will see the change or addition; I'd like to
> avoid that.
>
> I know one answer: make a specialized mode (inherited from the real
> one).  Any other way?

I guess you could define a new keymap with the new bindings which has
the current local map as parent, and then use you new keymap as local
map.

  (let ((map (make-sparse-keymap)))
    (set-keymap-parent map (current-local-map))
    (define-key map (kbd "C-c c")
                (lambda ()
                  (interactive)
                  (message "Hey there!")))
    (use-local-map map))

I guess you can easily wrap that into some function
`iz/define-buffer-local-keys' and then call that conveniently from a
file local variable section:

;; Local Variables:
;; eval: (iz/define-buffer-local-keys
;;         (kbd "C-c c") #'iz/do-this
;;         (kbd "C-c C") #'iz/do-that)
;; End:


HTH,
Tassilo



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

* Re: Buffer specific binding
  2015-08-26  7:44 ` Tassilo Horn
@ 2015-08-26 18:34   ` Ian Zimmerman
  0 siblings, 0 replies; 3+ messages in thread
From: Ian Zimmerman @ 2015-08-26 18:34 UTC (permalink / raw)
  To: help-gnu-emacs

On 2015-08-26 09:44 +0200, Tassilo Horn wrote:

>   (let ((map (make-sparse-keymap)))
>     (set-keymap-parent map (current-local-map))
>     (define-key map (kbd "C-c c")
>                 (lambda ()
>                   (interactive)
>                   (message "Hey there!")))
>     (use-local-map map))
> 
> I guess you can easily wrap that into some function
> `iz/define-buffer-local-keys' and then call that conveniently from a
> file local variable section:
> 
> ;; Local Variables:
> ;; eval: (iz/define-buffer-local-keys
> ;;         (kbd "C-c c") #'iz/do-this
> ;;         (kbd "C-c C") #'iz/do-that)
> ;; End:

Yes, this works great.  Thanks!

-- 
Please *no* private copies of mailing list or newsgroup messages.
Rule 420: All persons more than eight miles high to leave the court.




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

end of thread, other threads:[~2015-08-26 18:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-25 21:04 Buffer specific binding Ian Zimmerman
2015-08-26  7:44 ` Tassilo Horn
2015-08-26 18:34   ` Ian Zimmerman

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.