pseudosudo
pseudosudo

Reputation: 1980

having two functions executed with one keyboard combo

I'm trying to have C-<return> map to move-end-of-line then newline-and-indent

In my .emacs I have been playing around with the following:

(global-set-key (kbd "C-<return>") '(progn (move-end-of-line) (newline-and-indent)))

And

(defun c-ret()
    '(move-end-of-line newline-and-indent))
(global-set-key (kbd "C-<return>") 'c-ret)

but neither work.

Pointers?

Upvotes: 2

Views: 160

Answers (3)

Anton Tarasenko
Anton Tarasenko

Reputation: 8465

If you want a one-line solution, this will work too:

(global-set-key (kbd "C-<return>") (lambda () (interactive) (move-end-of-line nil) (newline-and-indent)))

Upvotes: 1

jlf
jlf

Reputation: 3539

You can do this without writing any code yourself. See http://www.emacswiki.org/emacs/KeyboardMacrosTricks for instructions on capturing a sequence of commands as a keyboard macro, naming it, and saving it in your .emacs. You can then give the new command a key binding of your choice with e.g. (global-set-key (kbd "C-c i") 'new-command-name).

Upvotes: 2

Paul Nathan
Paul Nathan

Reputation: 40319

You are quoting the commands.

That implies that they won't be executed. You also need the (interactive) to signify to emacs that it's callable from the keyboard.

Then, you need to have your parameters to your functions correct.

Further, I think your nomenclature for return is wrong.

Your basic misunderstanding here is knowing how eLisp works. That's okay, it's an arcane programming language.

' a.k.a QUOTE is pretty much a Lisp-specific special instruction. It says, "Don't evaluate what comes after me", and returns the unevaluated parameter.

So '(foo bar) is desugared into (QUOTE (FOO BAR)), which returns (FOO BAR).

Try this:

(defun c-ret()
    (interactive)
    (move-end-of-line nil)
    (newline-and-indent))

(global-set-key (kbd "C-RET") 'c-ret)

Upvotes: 6

Related Questions