2

What I want to do is, when I find myself using a function that prompts me for a value, and this value is ALWAYS the right one, to be able to bind the function to a key and auto-accept the answer, simulating a RET in the minibuffer.

Take for instance "ido-switch-buffer". When entered, it prompts you for a buffer name, and proposes the last visited one.

(It can do a lot more, that's why I dont want to re-define it, I just want a wrapper around it)

Say I want to switch between the last visited two buffers, how would I say that in my .emacs ?

yPhil
  • 8,049
  • 4
  • 57
  • 83

2 Answers2

5

You can do this with:

(switch-to-buffer (other-buffer))
Michael Hoffman
  • 32,526
  • 7
  • 64
  • 86
  • That did the trick. Not the way I wanted, but the cat is skinned :) Thanks Michael ! – yPhil Dec 03 '11 at 00:14
  • 2
    @PhilippeCM Why did you accept this answer if it doesn't address your question in a general way like you wanted? huaiyuan actually gave you exactly what you wanted, you just mis-applied the solution as an infinite loop. – event_jr Dec 03 '11 at 02:45
3

You may bind any keyboard macro, which is essentially a sequence of keys, to a key. For example,

(global-set-key (kbd "C-c b") (kbd "C-x b <return>"))
huaiyuan
  • 26,129
  • 5
  • 57
  • 63
  • Mm.. Nope, not in this very case. `(global-set-key (kbd "C-") 'ido-switch-buffer) (global-set-key (kbd "C-") (kbd "C- "))` Only gives me `After 0 kbd macro iterations: Variable binding depth exceeds max-specpdl-size` – yPhil Dec 02 '11 at 23:19
  • And I'd really like to know how, in elisp parlance, you say "accept what the minibuffer proposes" – yPhil Dec 02 '11 at 23:21
  • The defined key should not be part of the defining sequence, which as you see will result in infinite recursion. – huaiyuan Dec 02 '11 at 23:28