受到堆栈溢出问题的启发Emacs 中惯用的文本批处理? https://stackoverflow.com/questions/2879746/idomatic-batch-processing-of-text-in-emacs我尝试了一个 Emacs shell 脚本,标题如下:
#!/usr/bin/emacs --script
我在其中放入了一些 Emacs Lisp 代码,并将其保存为文本文件 rcat。
由于 --script 选项不会阻止站点启动文件的加载,因此我有很多
Loading /etc/emacs/site-start.d/20apel.el (source)...
Loading /etc/emacs23/site-start.d/35elib-startup.el (source)...
Loading /etc/emacs23/site-start.d/50auctex.el (source)...
Bash shell (stdout) 中的消息。我可以通过打电话来阻止这种情况
rcat --no-site-file
or
rcat -Q
但不是通过更改脚本中的标题:
#!/usr/bin/emacs --script --no-site-file
有没有办法在这样的脚本文件中将附加选项传递给 Emacs,而不是稍后在命令行上执行?
许多 UNIX 变体只允许在 shebang 行上给程序使用单个参数。悲伤,但却是事实。如果你使用#!/usr/bin/env emacs
以免依赖于位置emacs
可执行文件,你根本不能传递参数。
链接脚本 https://stackoverflow.com/questions/6238331/emacs-shell-scripts-how-to-put-initial-options-into-the-script/6240904#6240904在某些系统上是可能的,但也并非在所有系统上都支持。
您可以沿着历史悠久的路线编写多语言脚本:既是 shell 脚本又是 Emacs Lisp 脚本的脚本(如 Perl 的if $running_under_some_shell http://perldoc.perl.org/perlrun.html#*-S*, 例如)。它确实看起来很黑客,但它确实有效。
Elisp 评论开头为;
,它在 shell 中分隔两个命令。所以我们可以使用一个;
接下来是切换到 Emacs 的 shell 指令,实际的 Lisp 代码从下一行开始。不过,大多数 shell 不喜欢空命令,因此我们需要找到 shell 和 Emacs 都将其视为无操作的内容,并将其放在;
。 shell 无操作命令是:
;你可以写它":"
就 shell 而言,Emacs 将其解析为顶层常量,这也是一个无操作。
#! /bin/sh
":"; exec emacs --no-site-file --script "$0" -- "$@" # -*-emacs-lisp-*-
(print (+ 2 2))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)