unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* binding a key for keyword completion in all modes
@ 2009-02-26  2:20 Xah Lee
  2009-02-26  3:01 ` David Golden
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Xah Lee @ 2009-02-26  2:20 UTC (permalink / raw)
  To: help-gnu-emacs

this is a problem that annoys me, i wonder how you guys solve it.

the default shortcut for completion is Meta+Tab. However, that key is
after Alt+Tab, and in Mac and Windows and Linux, that combo is taken
by OS to switch apps. (i don't want to have emacs override that)

What i have always been doing is pressing Esc then Tab, but that is
really annoying, especially if you use this often.

How do you solve this?

also, how to bind a key to completion in any lang's mode? the problem
for me is, each lang mode usually uses a different name for
completion, e.g. lisp-complete-symbol, python-complete-symbol, etc. Is
there a way to solve this? Must i add hook to every mode?

Thanks.

  Xah
∑ http://xahlee.org/^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: binding a key for keyword completion in all modes
  2009-02-26  2:20 binding a key for keyword completion in all modes Xah Lee
@ 2009-02-26  3:01 ` David Golden
  2009-02-26  8:13 ` Tassilo Horn
  2009-02-26 19:58 ` Marc Tfardy
  2 siblings, 0 replies; 8+ messages in thread
From: David Golden @ 2009-02-26  3:01 UTC (permalink / raw)
  To: help-gnu-emacs

Xah Lee wrote:


> (i don't want to have emacs override that) 
> 
> What i have always been doing is pressing Esc then Tab, but that is
> really annoying, especially if you use this often.
> 
> How do you solve this?
> 

On my own systems I use super-tab for app switching* and therefore let
emacs have alt-tab, but on occasion it helps to know that C-M-i
typically works the same in emacs - C-i being conventionally a tab
character of course, but OS / window manager level stuff tends not to
grab it like the tab key.

* I tend to place "system-wide" window manager shortcuts consistently on
super-<something> rather than the horrible defaults that can get in the
way of emacs use.










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

* Re: binding a key for keyword completion in all modes
  2009-02-26  2:20 binding a key for keyword completion in all modes Xah Lee
  2009-02-26  3:01 ` David Golden
@ 2009-02-26  8:13 ` Tassilo Horn
       [not found]   ` <87skm012ln.fsf@mundaneum.com>
  2009-02-26 19:58 ` Marc Tfardy
  2 siblings, 1 reply; 8+ messages in thread
From: Tassilo Horn @ 2009-02-26  8:13 UTC (permalink / raw)
  To: help-gnu-emacs

Xah Lee <xahlee@gmail.com> writes:

Hi Xah,

> the default shortcut for completion is Meta+Tab. However, that key is
> after Alt+Tab, and in Mac and Windows and Linux, that combo is taken
> by OS to switch apps. (i don't want to have emacs override that)
>
> What i have always been doing is pressing Esc then Tab, but that is
> really annoying, especially if you use this often.
>
> How do you solve this?

I reverve super-* for window manager keys, so emacs can use very C and M
binding.  I don't know if that's possible on windows and mac, too.

> also, how to bind a key to completion in any lang's mode? the problem
> for me is, each lang mode usually uses a different name for
> completion, e.g. lisp-complete-symbol, python-complete-symbol, etc.

I think it's more or less a convention that each language mode binds its
symbol completion command to M-TAB.

> Is there a way to solve this?

Maybe something like this will do the trick?

  (global-set-key (kbd "C-TAB")
                  (lambda () (key-binding (kbd "M-TAB")))

Now when you hit C-TAB the command normally bound to M-TAB will be
called.

Bye,
Tassilo
-- 
When Richard Stallman pipes to more, he gets less


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

* Re: binding a key for keyword completion in all modes
  2009-02-26  2:20 binding a key for keyword completion in all modes Xah Lee
  2009-02-26  3:01 ` David Golden
  2009-02-26  8:13 ` Tassilo Horn
@ 2009-02-26 19:58 ` Marc Tfardy
  2 siblings, 0 replies; 8+ messages in thread
From: Marc Tfardy @ 2009-02-26 19:58 UTC (permalink / raw)
  To: help-gnu-emacs

Xah Lee schrieb:
 > this is a problem that annoys me, i wonder how you guys solve it.
 >
 > the default shortcut for completion is Meta+Tab. However, that key is
 > after Alt+Tab, and in Mac and Windows and Linux, that combo is taken
 > by OS to switch apps. (i don't want to have emacs override that)
 >
 > What i have always been doing is pressing Esc then Tab, but that is
 > really annoying, especially if you use this often.
 >
 > How do you solve this?


On windows you can use:
(w32-register-hot-key [A-tab])
and M-TAB do completion in Emacs.

I start Emacs in "normal" behavior, so ALT-TAB do task switch, but
in my .emacs I have this small piece of code:

;; Disable Alt+Tab as task switch with ESC C-TAB
(define-key esc-map (kbd "C-<tab>")
  (lambda ()
    (interactive)
    (message "ALT-TAB task switch disabled.")
    (w32-register-hot-key [A-tab])))

If required I press "ESC C-TAB" and Emacs take over the M-TAB (ALT-TAB).


Windows task switch works still with ALT-ESC (but in slightly
another way).

regards
Marc




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

* Re: binding a key for keyword completion in all modes
       [not found]         ` <87ocwkavg0.fsf@thinkpad.tsdh.de>
@ 2009-03-03 23:35           ` Xah Lee
  2009-03-04 12:04             ` TomSW
  0 siblings, 1 reply; 8+ messages in thread
From: Xah Lee @ 2009-03-03 23:35 UTC (permalink / raw)
  To: help-gnu-emacs

On Mar 2, 5:46 am, Tassilo Horn <tass...@member.fsf.org> wrote:
> XahLee<xah...@gmail.com> writes:
>
> HiXah,
>
> >> Ah, the interactive was missing as well as the funcall, and the C-TAB
> >> was wrong, too.  Here's a tested version. ;-)
>
> >> --8<---------------cut here---------------start------------->8---
> >> (global-set-key (kbd "<C-tab>")
> >>                 (lambda ()
> >>                   (interactive)
> >>                   (funcall (key-binding (kbd "M-TAB")))))
> >> --8<---------------cut here---------------end--------------->8---
>
> > Thanks Tassilo. It's wonderful.
>
> But don't forget to use Teemu's advice to use `call-interactively' here
> instead of funcall.

umm... there seems to be a problem with this solution.

Suppose i defined Meta+t for Meta+Tab.
When i do Alt+x describe-key on Meta+t, i get

M-t runs the command #[nil "\300\301\302!!\207" [call-interactively
key-binding [134217737]] 3 nil nil]
  which is an interactive compiled Lisp function.
It is bound to M-t.
(anonymous)

Is there a more robust solution?

  Xah
∑ http://xahlee.org/^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: binding a key for keyword completion in all modes
  2009-03-03 23:35           ` Xah Lee
@ 2009-03-04 12:04             ` TomSW
  2009-03-04 22:18               ` Xah Lee
  0 siblings, 1 reply; 8+ messages in thread
From: TomSW @ 2009-03-04 12:04 UTC (permalink / raw)
  To: help-gnu-emacs

> M-t runs the command #[nil "\300\301\302!!\207" [call-interactively
> key-binding [134217737]] 3 nil nil]
>   which is an interactive compiled Lisp function.
> It is bound to M-t.
> (anonymous)
>
> Is there a more robust solution?

Yes. If Alt-Tab is bound, it will be bound to an interactive command,
which you can bind Ctrl-Tab to directly:

(let ((binding (or (key-binding (kbd "<M-tab>"))
                        (key-binding (kbd "M-TAB")))))
              (when binding
                (local-set-key (kbd "<C-tab>") binding)))))

This will give better results with describe-key.

Regards,
Tom SW



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

* Re: binding a key for keyword completion in all modes
  2009-03-04 12:04             ` TomSW
@ 2009-03-04 22:18               ` Xah Lee
  2009-03-04 23:17                 ` TomSW
  0 siblings, 1 reply; 8+ messages in thread
From: Xah Lee @ 2009-03-04 22:18 UTC (permalink / raw)
  To: help-gnu-emacs

On Mar 4, 4:04 am, TomSW <tom.weissm...@gmail.com> wrote:
> > M-t runs the command #[nil "\300\301\302!!\207" [call-interactively
> > key-binding [134217737]] 3 nil nil]
> >   which is an interactive compiled Lisp function.
> > It is bound to M-t.
> > (anonymous)
>
> > Is there a more robust solution?
>
> Yes. If Alt-Tab is bound, it will be bound to an interactive command,
> which you can bind Ctrl-Tab to directly:
>
> (let ((binding (or (key-binding (kbd "<M-tab>"))
>                         (key-binding (kbd "M-TAB")))))
>               (when binding
>                 (local-set-key (kbd "<C-tab>") binding)))))
>
> This will give better results with describe-key.

Thanks. This does not seems to solve it though still.

if i have

(local-set-key (kbd "<C-tab>") (or (key-binding (kbd "<M-tab>"))
                                (key-binding (kbd "M-TAB"))))

then the key is changed for local buffer. If i use global-set-key,
then it's wrong because a specifical completion command name is used
for all. e.g. I get ispell-complete-word for all.

just to make message more clear and independent of the thread, what i
wanted is to set Ctrl+Tab for command completion that works in all
major modes, and avoding adding a custome hook to each and every mode.

Right now i adopted this implementation.

; keyword completion, because Alt+Tab is used by OS
(global-set-key (kbd "M-t") 'call-command-completion)

(defun call-keyword-completion ()
  "Call the function with keyboard shortcut M-TAB."
  (interactive)
  (call-interactively (key-binding (kbd "M-TAB")))
)

  Xah
∑ http://xahlee.org/^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: binding a key for keyword completion in all modes
  2009-03-04 22:18               ` Xah Lee
@ 2009-03-04 23:17                 ` TomSW
  0 siblings, 0 replies; 8+ messages in thread
From: TomSW @ 2009-03-04 23:17 UTC (permalink / raw)
  To: help-gnu-emacs

On Mar 4, 11:18 pm, Xah Lee <xah...@gmail.com> wrote:

> just to make message more clear and independent of the thread, what i
> wanted is to set Ctrl+Tab for command completion that works in all
> major modes, and avoding adding a custome hook to each and every mode.

It depends what you call a "custom hook". The code to rebind C-tab
works whatever the mode, but it still needs to be run for every new
buffer: in my experience most worthwhile modes need a bit of tweaking
so adding an extra function call to emacs-mode-hook, nxml-mode-hook,
etc. isn't a big deal.

I believe the best solution will involve local-set-key and a suitable
hook: maybe you can find a hook called for every new buffer after the
major mode has loaded. Another possibility is to define a global minor
mode that just applies your keybinding changes: I think this will be
invoked after any major mode but I'm not certain.

Regards,
Tom


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

end of thread, other threads:[~2009-03-04 23:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-26  2:20 binding a key for keyword completion in all modes Xah Lee
2009-02-26  3:01 ` David Golden
2009-02-26  8:13 ` Tassilo Horn
     [not found]   ` <87skm012ln.fsf@mundaneum.com>
     [not found]     ` <87r61j62k0.fsf@thinkpad.tsdh.de>
     [not found]       ` <58e57903-4b47-443c-b84d-e41662071482@e36g2000prg.googlegroups.com>
     [not found]         ` <87ocwkavg0.fsf@thinkpad.tsdh.de>
2009-03-03 23:35           ` Xah Lee
2009-03-04 12:04             ` TomSW
2009-03-04 22:18               ` Xah Lee
2009-03-04 23:17                 ` TomSW
2009-02-26 19:58 ` Marc Tfardy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).