Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

emacs switch window to C-TAB and C-S-TAB

Tags:

emacs

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)

like image 994
Gauthier Avatar asked Feb 26 '10 13:02

Gauthier


3 Answers

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

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

like image 57
Matthew Flaschen Avatar answered Oct 16 '22 08:10

Matthew Flaschen


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)
like image 28
p4bl0 Avatar answered Oct 16 '22 06:10

p4bl0


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))
like image 38
Sean Avatar answered Oct 16 '22 08:10

Sean