在命令行上评估emacs lisp表达式 [英] Evaluate emacs lisp expression on command line

查看:119
本文介绍了在命令行上评估emacs lisp表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是emacs的新手。我正在使用redhat linux上的emacs-24.1,并尝试评估一个elisp表达式。我想要emacs要做的是评估elisp表达式而不启动emacs本身。我正在尝试不同的事情

  emacs --eval'(+ 2 3)'

我不知道emacs是否正在评估表达式,但是结果没有显示在控制台上,而emacs窗口出现。接下来我试过这个

  emacsclient --eval'(+ 2 3)'

Emacs客户端正在期待服务器。它找不到服务器,因此抛出一个错误(找不到套接字,启动服务器等)。所以我启动了一个服务器(服务器名称是SERVER)并再次运行emacsclient

  emacsclient --server-file = SERVER -e '(+ 2 3)'

这一次,emacs评估了表达式,并将结果打印在控制台上。这是因为emacs正在使用现有的服务器来评估表达式。现在,当服务器未运行时,我遇到问题。

  emacsclient --server-file = ANOTHER_SERVER -e'(+ 2 3)'-a emacs 

这一次,控制台上没有任何错误。 Emacs正在启动一个新窗口,因为-a(我的.emacs有(server-start)命令,server-name设置为ANOTHER_SERVER)。但是emacs正在尝试编辑文件(+ 2 3)。它显示在模式行上。我很困惑。 emacsclient --help向我显示这个

  -e,--eval将FILE参数评估为ELisp表达式

和emacs手册说这个。

 ' -  e'
'--eval'
告诉Emacs来评估一些Emacs Lisp代码,而不是访问一些文件。
当给出此选项时,emacsclient的参数将被解释为一个
表达式列表,用于评估,而不是作为要访问的文件列表。

我不知道如何继续这个。正如我所说,我的目标是评估一个elisp表达式,而不启动emacs。有可能吗?

解决方案

经过一番测试,您可以使用批处理将emacs转储到stderr的任何消息。然后,您可以调用消息将事情打印到stderr,您将可以看到它们。你的例子将成为 emacs --batch --eval'(message(number-to-string(+ 2 3)))',结果将被打印到stderr。



如果您要将输出重定向到文件,则需要使用 2> 而不是>


I'm a newbie to emacs. I'm working with emacs-24.1 on redhat linux, and trying to evaluate an elisp expression. What I want emacs to do is to evaluate the elisp expression without launching emacs itself. I'm trying different things

emacs --eval '(+ 2 3)'

I do not know if emacs is evaluating the expression, but the result is not shown on console and emacs window comes up. Next I tried this

emacsclient --eval '(+ 2 3)'

Emacs client is expecting a server. It could not find the server and hence throwing an error (can't find socket. start server etc). So I launched a server (server-name is SERVER) and ran emacsclient again

emacsclient --server-file=SERVER -e '(+ 2 3)'

This time, emacs evaluated the expression and printed the result on console. That is because emacs is using the existing server to evaluate the expression. Now I get a problem when the server is not running.

emacsclient --server-file=ANOTHER_SERVER -e '(+ 2 3)' -a emacs

This time, I'm not getting any error on console. Emacs is launching a new window, because of -a (my .emacs has (server-start) command in it and server-name set to ANOTHER_SERVER). But emacs then is trying to edit the file (+ 2 3). It is shown on the mode line. I'm confused. emacsclient --help showed me this

-e, --eval              Evaluate the FILE arguments as ELisp expressions

and emacs manual says this.

'-e'
'--eval'
Tell Emacs to evaluate some Emacs Lisp code, instead of visiting some files.
When this option is given, the arguments to emacsclient are interpreted as a
list of expressions to evaluate, not as a list of files to visit.

I do not know how to proceed on this. As I said, my goal is to evaluate an elisp expression without launching emacs. Is it possible?

解决方案

After a bit of testing it looks like you can use --batch to have emacs dump any messages to stderr. Then you can call message to print things to stderr where you'll be able to see them. Your example would become emacs --batch --eval '(message (number-to-string (+ 2 3)))' and the result would be printed to stderr.

If you're trying to redirect the output to a file you'll need to redirect stderr instead of stdout by using 2> instead of just >.

这篇关于在命令行上评估emacs lisp表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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