Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
share|improve this question
up vote 5 down vote accepted

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))
share|improve this answer
@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 posting your answer, you agree to the privacy policy and terms of service.

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