为什么某些Emacs功能不能通过`M-x'? [英] Why are some Emacs functions not available via `M-x`?

查看:135
本文介绍了为什么某些Emacs功能不能通过`M-x'?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

,它可以输入命令的名称并运行它。

  • M - :绑定到命令 eval-expression ,它允许您键入包含函数调用的任意S表达式,并对其进行评估。 / li>


    可以使用 M调用的功能:用于实现Emacs功能,自定义如您的 .emacs )和插件。函数参数通常通过调用S表达式中的函数传递。



    任何函数都可以作为命令,如果它有一个 interactive 在其定义中形成。 交互式表格描述了当作为命令调用时该函数应该如何获取其参数。例如,如果函数在其定义中具有(交互式bGive me a buffer:),则该函数将使用 M-x 进行调用。当用户使用 Mx 调用该功能时,Emacs将提示用户输入一个缓冲区名称(因为 b )和它们键入的名称将作为一个参数传递给函数。



    使函数成为一个命令的重点在于使最终用户更容易调用它,而不仅仅是为了Emacs Lisp程序员。命令(使用 Mx 运行)通过以下方式更容易以交互方式运行:




    • 您不必使用()包含命令名称,使其成为有效的S表达式。

    • 可以自动传递参数(如光标位置),或者您可以提示他们,以便您不必记住需要什么参数。

    • 当提示输入参数时,您可以自动完成,因为 interactive form的代码字符(如 b )指定要预期的输入类型。



    您不能使用 Mx 调用函数 set-face-attribute 的原因是它的定义不包含交互式表单,因此 set-face-attribute 不是一个命令。您必须将其称为简单函数,在S表达式中。您可以使用 M - :的minibuffer或其他任何其他评估代码的方法



    < hr>

    Emacs Mini手册→概念→命令对于正常功能和命令之间的差异有一个简短的,不同的措辞。 Emacs功能和命令之间的关系解释了这个答案中的一些细节。


    This Stack Overflow answer told me that I can set Emacs’s font size with set-face-attribute:

    (set-face-attribute 'default nil :height 100)
    

    The comments reveal that you can’t run set-face-attribute with M-x:

    Instead, you have to run it with M-::

    Why are some commands, like set-face-attribute, not available via M-x?

    解决方案

    • M-x is bound to the command execute-extended-command, which lets you type the name of a command and runs it.
    • M-: is bound to the command eval-expression, which lets you type an arbitrary S-expression containing function calls and evaluates it.

    Functions, which you can call with M-:, are used to implement Emacs features, customizations (such as in your .emacs), and plugins. Function arguments are normally passed by calling the function in an S-expression.

    Any function can also be a command if it has an interactive form in its definition. The interactive form describes how the function should get its arguments when called as a command. For example, if the function has (interactive "bGive me a buffer: ") in its definition, then the function will be callable with M-x. When the user calls the function with M-x, Emacs will prompt the user for a buffer name (because of the b), and the name they type will be passed as an argument to the function.

    The point of making a function a command is to make calling it easy for end-users, not just for Emacs Lisp programmers. Commands (run with M-x) are easier to run interactively in these ways:

    • You don’t have to surround the command name with () to make it a valid S-expression.
    • Arguments can be passed automatically (such as the cursor position), or you can be prompted for them so you don’t have to remember what arguments are needed.
    • When prompted for an argument, you can auto-complete it, because the interactive form’s code characters (like b) specify what type of input to expect.

    The reason you can’t call the function set-face-attribute with M-x is that its definition does not contain an interactive form, and so set-face-attribute is not a command. You must call it as a plain function, in S-expressions. You can do that from the minibuffer with M-:, or from other places with any of the other ways of evaluating code.


    Emacs Mini Manual → Concepts → Command has a short, differently-worded explanation of the difference between normal functions and commands. Relationship between Emacs functions and commands explains some details not in this answer.

    这篇关于为什么某些Emacs功能不能通过`M-x'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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