3

I want to bind

(defun switch-to-next-frame ()
  "Select the next frame on current display, and raise it."
  (interactive)
  (other-frame 1)
  )

to M-s in emacs? I tried:

(global-unset-key "\M-s")

but it doesn't work. The problem is - M-s is a prefix key.

Edit 2:

I made myself terribly unclear. I wanted to bind to switch-to-next-frame to M-s. I tried:

 (global-set-key (kbd "M-s") 'switch-to-next-frame)

it didn't work: emacs was doing M-s- when I had been pressing M-s. I thought - the problem was the M-s being a prefix key. I tired to unbind it - but it didn't work out. Then I came here and asked this question. As I found out later - the problem was with my .emacs - when I commented out icicles it all started to work as expected.

Edit 3:

Actually dired is realy using M-s a prefix key:

M-s a           Prefix Command
M-s f           Prefix Command
M-s f C-s       dired-isearch-filenames
M-s f ESC       Prefix Command
M-s a C-s       dired-do-isearch
M-s a ESC       Prefix Command
M-s f C-M-s     dired-isearch-filenames-regexp
M-s a C-M-s     dired-do-isearch-regexp

So binding to M-s is a realy bad idea.

Drew
  • 29,895
  • 7
  • 74
  • 104
Adobe
  • 12,967
  • 10
  • 85
  • 126

1 Answers1

1

The following should work:

(global-set-key [(meta s)] 'switch-to-next-frame)
N.N.
  • 8,336
  • 12
  • 54
  • 94
Luke Girvin
  • 13,221
  • 9
  • 64
  • 84
  • 1
    I think it's better to use the kbd macro. It's much more readable: `(global-set-key (kbd "M-s") 'switch-to-next-frame)` – Tom Mar 09 '12 at 17:17
  • 3
    @Tom surely you jest. You may be used to reading the kbd format, but vector format is more readable. – event_jr Mar 09 '12 at 18:41
  • 1
    The "M-s" part is the same format what Emacs prints when C-h k, etc. is used, so you can use the same format in keybindings, you don't have to write [(meta s)] – Tom Mar 09 '12 at 20:21
  • 2
    Compare `[(shift meta x)]` and `[(super meta x)]` to `(kbd "S-M-x")` and `(kbd "s-M-x")`. Which one is more readable? – Sean Mar 10 '12 at 03:46
  • Well... at least my question stimulated this discussion. I'll take the side of Tom: i prefer kbd for `C-h k` speaks this way. – Adobe Mar 10 '12 at 09:47
  • Those vectors are more readable, but `kbd` offers consistency, and *never* having to wonder how to represent a key/chord; the latter of which is such a huge win that I always recommend it in favour of the alternatives. – phils Mar 10 '12 at 10:20