开发者

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-en开发者_高级运维d-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?


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)


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).


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)))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜