Binding a key to a command and automatically using the (interactive) default values for its interactive arguments

81 views Asked by At

I would like F5 to switch to the most recently used buffer. This functionality is accomplished by running M-x icicle-buffer and then hitting enter to not specify the buffer I want to switch to -- (the default behavior of icicle is to switch to the most recent buffer.)

I have tried editing my .emacs thus:

(defun most-recent-buffer-please ()
  (interactive)
  (icicle-buffer " "))

(global-set-key [(f5)] 'most-recent-buffer-please)

but when I evaluate this lisp, and then hit F5, I get an error that starts with Wrong number of arguments followed by a lot of gibberish characters. What am I doing wrong?

1

There are 1 answers

0
lawlist On

A function can have mandatory and/or optional arguments, or no arguments at all. When writing elisp, it is usually a good idea to find out what arguments are available for certain functions by typing M-x describe-function RET [name of the function] RET. Drew (the author of Icicles) has indicated in his comment underneath the original question that the function icicle-buffer is not designed to be used in conjunction with any arguments -- therefore, adding " " causes the error message that the original poster experienced.

To switch to the previous buffer, Emacs already has a built-in function called previous-buffer. Since the original poster has indicated a preference for the f5 key, the following is an example of how to configure that keyboard shortcut so that it triggers previous-buffer -- brackets are sufficient and the parentheses used by the original poster around f5 can be omitted:

 (global-set-key [f5] 'previous-buffer)