emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [O] how to bind keys in orgtbl-mode


From: Carsten Dominik
Subject: Re: [O] how to bind keys in orgtbl-mode
Date: Fri, 9 Dec 2011 23:24:37 +0100

On 9.12.2011, at 22:36, Uwe Brauer wrote:

> 
> 
> Hello 
> 
> 
> how can I bind keys in Orgtbl minor mode?
> 
> I would like to have the same binding as in org-mode
> 
>  (local-set-key [(control c) (control w)] 'org-table-wrap-region)

We could just add this to the standard orgtbl bindings - don't know why
this is not the case.  OK, I just did that.

>  (local-set-key [(control c) (control h)] 'org-table-insert-hline)

This one on the other hand violates Emacs conventions, so
we cannot do this by default.

> But I don't find a orgtbl-mode-hook.

Like Nick says, you need to set keys in orgtbl-mode-map.
You can use orgtbl-mode-hook to do this.  define-minor-mode
makes sure that a hook is run.

However, if you want to use them in a major mode that also
needs these keys (outside of tables), then you need to do
extra work to create magic commands that work inside
and outside tables, calling different commands in each
location.  This should do it:

(add-hook
 'orgtbl-mode-hook
 (lambda ()
   (org-defkey orgtbl-mode-map "\C-c\C-w"
               (orgtbl-make-binding 'org-table-wrap-region 1000 "\C-c\C-w"))
   (org-defkey orgtbl-mode-map "\C-c\C-h"
               (orgtbl-make-binding 'org-table-wrap-region 1001 "\C-c\C-h"))))

The 1000 and 1001 must be unique numbers not already used for this purpose
by orgtbl-mode, anything above 200 should be safe.


HTH

- Carsten



reply via email to

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