all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* swapping the bindings of TAB and M-i ?
@ 2007-05-16 22:21 poppyer
  2007-05-17 10:17 ` Daniel Jensen
  0 siblings, 1 reply; 4+ messages in thread
From: poppyer @ 2007-05-16 22:21 UTC (permalink / raw)
  To: help-gnu-emacs

hi, all,

	I would like to swap TAB and M-i, i.e.
use TAB to do tab-to-tab-stop; and M-i to indent codes.
However, the "indent" of current TAB binding is mode-specific.
Is there any easy way to do such kind of swap without re-bind the keys
mode by mode?

thanks,
poppyer
-- 

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

* Re: swapping the bindings of TAB and M-i ?
  2007-05-16 22:21 swapping the bindings of TAB and M-i ? poppyer
@ 2007-05-17 10:17 ` Daniel Jensen
  2007-05-17 12:33   ` poppyer
  0 siblings, 1 reply; 4+ messages in thread
From: Daniel Jensen @ 2007-05-17 10:17 UTC (permalink / raw)
  To: help-gnu-emacs

poppyer <poppyer2001@gmail.com> writes:

> 	I would like to swap TAB and M-i, i.e.
> use TAB to do tab-to-tab-stop; and M-i to indent codes.
> However, the "indent" of current TAB binding is mode-specific.
> Is there any easy way to do such kind of swap without re-bind the keys
> mode by mode?

You can add the following function to the hooks for the major modes you
want to change. There are ways to do this for every mode, but you
probably don't want to do that.

(defun swap-indent-bindings ()
  (let ((tab-binding (key-binding "\C-i")))
    (local-set-key "\C-i" (key-binding "\M-i"))
    (local-set-key "\M-i" tab-binding)))

(add-hook 'text-mode-hook 'swap-indent-bindings) ; and so on

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

* Re: swapping the bindings of TAB and M-i ?
  2007-05-17 10:17 ` Daniel Jensen
@ 2007-05-17 12:33   ` poppyer
  2007-05-18  8:49     ` Daniel Jensen
  0 siblings, 1 reply; 4+ messages in thread
From: poppyer @ 2007-05-17 12:33 UTC (permalink / raw)
  To: help-gnu-emacs

Thanks daniel, that is exactly what I want.

However, is there something like any-major-mode-hook? That would be a
perfect solution adding to this.

daniel@bigwalter.net (Daniel Jensen) writes:

> poppyer <poppyer@gmail.com> writes:
> 
> > 	I would like to swap TAB and M-i, i.e.
> > use TAB to do tab-to-tab-stop; and M-i to indent codes.
> > However, the "indent" of current TAB binding is mode-specific.
> > Is there any easy way to do such kind of swap without re-bind the keys
> > mode by mode?
> 
> You can add the following function to the hooks for the major modes you
> want to change. There are ways to do this for every mode, but you
> probably don't want to do that.
> 
> (defun swap-indent-bindings ()
>   (let ((tab-binding (key-binding "\C-i")))
>     (local-set-key "\C-i" (key-binding "\M-i"))
>     (local-set-key "\M-i" tab-binding)))
> 
> (add-hook 'text-mode-hook 'swap-indent-bindings) ; and so on

-- 

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

* Re: swapping the bindings of TAB and M-i ?
  2007-05-17 12:33   ` poppyer
@ 2007-05-18  8:49     ` Daniel Jensen
  0 siblings, 0 replies; 4+ messages in thread
From: Daniel Jensen @ 2007-05-18  8:49 UTC (permalink / raw)
  To: help-gnu-emacs

poppyer <poppyer@gmail.com> writes:

> daniel@bigwalter.net (Daniel Jensen) writes:
>
>> You can add the following function to the hooks for the major modes you
>> want to change. There are ways to do this for every mode, but you
>> probably don't want to do that.
>> 
>> (defun swap-indent-bindings ()
>>   (let ((tab-binding (key-binding "\C-i")))
>>     (local-set-key "\C-i" (key-binding "\M-i"))
>>     (local-set-key "\M-i" tab-binding)))
>> 
>> (add-hook 'text-mode-hook 'swap-indent-bindings) ; and so on
>
> Thanks daniel, that is exactly what I want.
>
> However, is there something like any-major-mode-hook? That would be a
> perfect solution adding to this.

There is no such hook. It might be possible to create a global minor
mode to do it, or to use keyboard translations, but I haven't tried to
do that. The quickest solution that comes to mind is to put an advice on
use-local-map:

(defadvice use-local-map (after swap-bindings-in-local-map activate)
  (swap-indent-bindings))

I wouldn't do this. It's really ugly and it messes with modes that use
TAB for something unrelated to text indenting. I suggest you stick with
explicitly changing the modes that you want to change.

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

end of thread, other threads:[~2007-05-18  8:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-16 22:21 swapping the bindings of TAB and M-i ? poppyer
2007-05-17 10:17 ` Daniel Jensen
2007-05-17 12:33   ` poppyer
2007-05-18  8:49     ` Daniel Jensen

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.