tags:

views:

178

answers:

3

Hi!

I've seen questions here about moving the cursor from window to window with C-x o and M-- C-x o. Fine.

I want to map that to C-TAB and C-S-TAB.

This is what I added to my .emacs:

(global-set-key [C-tab] 'other-window)
(global-set-key [C-S-tab] '(other-window -1))

C-tabworks, but not C-S-tab.

The minibuffer tells me:

Wrong type argument: commandp, (other-window -1)

I tried without the parenthesis around other-window, but that wouldn't work either.

In short, I'm not sure how to pass optional arguments to functions in my .emacs.

Help, please?

Edit to add version: (emacs 22.3.1 on windows)

+5  A: 
(global-set-key [C-S-tab] 
    (lambda ()
      (interactive)
      (other-window -1)))

EDIT: Added in (interactive), per Gauthier and Peter Hart.

Matthew Flaschen
Right. `'(other-window -1)` is interpreted as a cons cell, and you can't call cons cells.
Charles Stewart
Sorry, this gives `Wrong type argument: commandp, (lambda nil (other-window -1))`(emacs 22.3.1 on windows)
Gauthier
It works if you add `(interactive)` after `lambda()`. Edit your answer and I'll set it as valid answer!That'd be nice if you could add a short explanation about why `(interactive)` is needed.
Gauthier
(interactive) is needed to make the function callable interactively (i.e. from the M-x prompt or an event). http://www.gnu.org/s/emacs/manual/html_node/elisp/Interactive-Call.html gives more information.
Peter Hart
+1  A: 

To elaborate on Matthew's answer a bit, I recently wrote a little helper macro for situations like this:

(defmacro global-set-key* (keys &rest body)
  `(global-set-key ,keys (lambda () (interactive) ,@body))

That way I can write things like:

(global-set-key* [(shift control n)] (next-line) (scroll-up 1))
(global-set-key* [(shift control p)] (previous-line) (scroll-down 1))
Sean
A: 

I'm on my mobile phone and i don't recall the exact key sequence but you can find it in my init.el file or by C-h k C-S-TAB so emacs tel you "<the key sequence your looking for> is not bind to anything" or something alike. http://pablo.rauzy.name/init.el.html :-)

EDIT: So i'm now on my computer, here is the simple way to do this :

(global-set-key [C-tab] 'next-buffer)
(global-set-key [C-S-iso-lefttab] 'previous-buffer)
p4bl0
Note the difference between selecting next buffer, and selecting next window.
Gauthier
Oh, my bad! But it still work, with `'other-window` instead of `'next-buffer` and `'(other-window -1)` instead of `'previous-buffer` :-)
p4bl0
That is what I tried (see original post), but it didn't work. See the solution.
Gauthier
Nope, because you used `tab` instead of `iso-lefttab` ;-).
p4bl0