Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
add comment

1 Answer 1

up vote 4 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)) ...

or

(defun my-end-of-line ()
  "Invoke end-of-line with -1."
  (interactive)
  (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
add comment

Your Answer

 
discard

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.