Emacs函数和命令之间的关系 [英] Relationship between Emacs functions and commands

查看:113
本文介绍了Emacs函数和命令之间的关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据我的理解,在Emacs中,我可以运行命令,例如 Mx (其中我认为代表 execute-extended-命令)。此命令 M-x 本身用于运行诸如 customize_face 的内容。在minibuffer中键入 M-x customize-face



我的问题是:



Q.1。 custom-face a 命令?或者是功能?而且我们说 customize-face 被传递给命令 Mx 作为参数



Q.2 所有Emacs命令是否具有关联的Emacs 功能? (即当我输入 M-x customize-face 我推测定义的函数被调用)。如果是这样,怎样才能从命令名中查找函数名? (和反向)

解决方案

是的,所有Emacs命令都是函数,但不是所有的功能都是Emacs命令。您可以通过 Mx 使用(交互式)

 (defun my-command()
这是docstring
(interactive)
(do-foo)
(do-bar))

现在您已经定义了 my-command 作为交互式,您可以立即使用 Mx my-command 访问它。 Emacs会自动为您的所有簿记提供名称。



这是所有您必须添加新的命令!然后,您可以将其绑定到如下所示的键:

 (global-set-key(kbdCc f)'我的命令)

此外,每个键绑定都与这样的交互式功能相关联。您可以使用 C-h k 键入哪个键,并输入您的键序列。这将为您提供将在该关键序列上调用的函数的文档。如果你运行了我给你的代码,那么做 Ch k Cc f 会给你一个包含(其中包括)你的文档字符串的缓冲区:

  Cc f运行命令my-command,它是一个交互式Lisp 
函数。

它绑定到C-c f。

(my-command)

这是docstring

所以:所有Emacs命令只是使用(交互式)定义的函数。 (实际上,Emacs的C核心还有一些原始的功能,但这并不是非常重要。)



命令和函数之间的这种简单而优雅的关系 - 很容易跟随任何一个方向 - 是使Emacs如此容易定制的一部分。如果您想知道您正常操作的功能是什么,您可以轻松查找它们,如果要添加更多命令,则只需在其中添加一行。


From what I understand, in Emacs I can run commands such as M-x (which by the way I believe stands for execute-extended-command). This command M-x itself is used to run things like customize_face e.g. by typing M-x customize-face in the minibuffer.

My questions are:

Q.1. Is customize-face a command? or is it a function? And do we say that customize-face is passed to the command M-x as an argument?

Q.2 Do all Emacs commands have an associated Emacs function? (i.e. when I enter M-x customize-face I presume a defined function is called). If so, how can I look up the function name from the command name? (and viceversa)

解决方案

Yes, all Emacs commands are functions, but not all functions are Emacs commands. You can make an arbitrary elisp function a command accessible via M-x using (interactive):

(defun my-command ()
 "This is the docstring"
 (interactive)
 (do-foo)
 (do-bar))

Now that you've defined my-command as interactive, you can immediately access it with M-x my-command. Emacs does all the bookkeeping with the name for you automatically.

This is all you have to do to add a new command! You can then bind it to a key with something like:

(global-set-key (kbd "C-c f") 'my-command)

Moreover, every key-binding is associated with an interactive function like this. You can find which function is called by which key using C-h k and entering your key sequence. This will give you the documentation for the function that would be called on that key sequence. If you ran the code I gave you, doing C-h k C-c f would give you a buffer containing (among other things) your doc-string:

C-c f runs the command my-command, which is an interactive Lisp
function.

It is bound to C-c f.

(my-command)

This is the docstring

So: all Emacs commands are just functions defined with (interactive). (Actually, there are also some primitive functions from Emacs's C core, but that isn't super important.)

This simple and elegant relationship between commands and functions--which is easy to follow in either direction--is part of what makes Emacs so easy to customize. If you ever wonder what functions your normal actions called, you can easily look them up, and if you want to add more commands, you just have one extra line in your function.

这篇关于Emacs函数和命令之间的关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆