[英]Open emacs application in a specific mode for given path
我在命令行上使用 emacs,我使用以下命令在 magit 模式下打开当前的 git 目录:
emacs -nw -f magit-status --eval "(call-interactively #'delete-other-windows)"
我改用 emacs 应用程序而不是在命令行中打开它。 我正在使用以下命令别名:
alias emacs='open -a /Applications/Emacs.app $1'
因为这个 magit 命令不再起作用。 有没有办法用 Emacs 应用程序实现相同的功能?
另外,按照评论中的建议尝试了这个功能:
function magit() {
open -a /Applications/Emacs.app --args -f magit-status $1
}
问候,
帕万。
当开始一个新的 Emacs 会话时,函数
function magit() {
open -a Emacs --args --file "$1" -f magit-status
}
会做你想做的。 也就是说,将文件加载到缓冲区(通过find-file
)并在该缓冲区上运行magit-status
函数。 请注意,该顺序取决于 Emacs 命令行。 虽然open -a Emacs myfile --args -f magit-status
和open -a Emacs --args -f magit-status myfile
从open
的角度来看是正确的,但从 Emacs 的角度来看它们是不正确的。 ( magit-status
不执行任何操作,然后打开myfile
。不是您想要的。)
如果您想对当前正在运行的 Emacs 会话执行此操作,则不能。 线索在open
的联机帮助页中。
--args All remaining arguments are passed to the opened application in the argv parameter to main(). These argu- ments are not opened or interpreted by the open tool.
main()
已经执行了,所以你不能再向它传递参数,所以--args
被有效地忽略了。 因此,您必须对 Emacs 服务器和emacsclient
发挥创意。
如果您有一个与关联服务器的开放 Emacs 会话(例如通过server-start
),您可以执行以下操作来“加载和执行”文件
# my emacs will load *.log files in `fundamental-mode`
# this will load them in `text-mode`
$ emacsclient -e '(find-file "/tmp/foo.log")' -e '(text-mode)'
# or
$ emacsclient -e '(progn (find-file "/tmp/foo.log") (text-mode))'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.