[英]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.