I want to create a keybinding for funcion end-of-line+ and pass a value of -1 to i. The function is declared as:

  • (end-of-line+ &optional n)

The first of the following snippets below, works (without an arg). but the other attempts (with an arg) fail... I haven't been able to find an example of a keybinding with args. What's the right way to do this?

(global-set-key (kbd  "C-s-E") 'end-of-line+)     ;; Okay!

(global-set-key (kbd  "C-s-E") 'end-of-line+ -1)   ;; Fails 
(global-set-key (kbd  "C-s-E") 'end-of-line+ '-1)  ;; Fails
(global-set-key (kbd  "C-s-E") '(end-of-line+ -1)) ;; Fails

The idea is just to construct a new function to express your wanted custom behavior (and bind the key to it).

Either with lambda ("anonymous", in place) or with defun (in this case, you give it a name, and you can refer to it with the name).

To define an interactive "command", you need to prepend (interactive) to the body.

For example:

... (lambda() (interactive) (end-of-line+ -1)) ...


(defun my-end-of-line ()
  "Invoke end-of-line with -1."
  (end-of-line+ -1))
  • @imz: Thanks, that got it working. I went with defun, and I'll have more of a look at the lambda later. I'd better read up on it first.. By the way, it does require (interactive) – Peter.O Jul 25 '11 at 16:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.