I'm new to emacs, and have a rookie question. I can bind a key to a particular function by (global-set-key (kbd "C-c a b c") 'some-command)
, where some-command
is a function. How can I invoke two functions (say some-command
and some-other-command
) with one key binding? Thanks a lot!
相关问题
- Symbol's function definition is void: declare-
- How can I set the SVN password with Emacs 23.1 bui
- Emacs shell: save commit message
- emacs bind key to the insertion of another
- Emacs - set mark on edit location
相关文章
- In IntelliJ IDEA, how can I create a key binding t
- ess-rdired: I get this error “no ESS process is as
- Emacs/xterm color annoyance on Linux
- Does learning one Lisp help in learning the other?
- Pipe less to Emacs
- Capturing the output of “diff” with org-babel
- emacs terminal mode: how to copy and paste efficie
- How to permanently enable the hs-minor-mode in ema
You can define your own function which call the two functions, and bind the key to your own function. Or use a simple lambda:
I recommend never binding lambda expressions to keys, for the simple reason that when you ask Emacs what that key does, it will end up telling you something like this (to use the accepted code, when byte-compiled, as an example):
If you never byte-compile your code, it's less cryptic, but still unformatted:
Which, while still readable in the case of a small function like this, gets rapidly incomprehensible for larger functions.
Compared with:
Which you get if you name the function (which encourages you to document it more than an anonymous function does).
Finally, as abo-abo points out, this also means you can easily visit the definition of that function at any time, to view or edit/re-evaluate the code, either by following the link provided in the help buffer (to
foo.el
in my example), or by using M-xfind-function
(enter the name of the function), or M-xfind-function-on-key
(type the key sequence it's bound to).You can define another functon with
defun
in which you invoke the others withfuncall
orapply
so, when you call this third function (which you can also bind) it will invoke the others.Define a command that calls each of the functions (commands) that you want, conditionally. Use the prefix arg to distinguish which to call. So if the new, dispatching command is bound to, say,
C-o
, thenC-u C-o
would call one of the functions andC-o
(without a prefix arg) would call the other.You will want to do
C-h f interactive
, to see how to define a command that recognizes a prefix argument etc. Consult the Elisp manual also - usei interactive
to find where it teaches this.This is an easy and fun exercise. Learning to define your own simple commands is a good way to start to talk to Emacs in its own language.