如题目的要求,主要是用于在mutt中读一些邮件。
网上之前有人问过类似的问题。
提供的方法是
emacs FILE --eval '(setq buffer-read-only t)'
很奇怪的一点是,这个办法似乎不能将emacs换成emacsclient。用emacsclient以这种方式打开比如1107.yml
的话,会出现如下的错误。
*ERROR*: Symbol’s value as variable is void: 1107\.yml
似乎文件名在此时无法正确地传递给emacs,大家有什么办法吗?
‘–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.
当emacsclient
带eval执行的时候是被当作解释器的,和emacs的行为不一样
原回答的下面有啊:
emacsclient --create-frame --eval '(view-file "test.txt")'
而且你得到的错误和 emacsclient 也没有关系吧,应该只是缺少双引号,导致 emacs 将其解析为变量而不是字符串了。
和emacsclient有关系,只要–eval给出后,所有的参数都会被解释为被评估的对象。
emacsclient FILE
可以直接打开
emacsclient FILE -c -e '(read-only-mode)'
也会产生
*ERROR*: Symbol’s value as variable is void: FILE
而emacs没有这个限制,放在前后都一样。
稍微能用的的做法是
emacsclient --eval '(progn (view-file "FILE") (read-only-mode))'
可以写个sh,替换FILE
谢谢你的解释!不过用你或者hsingko的办法好像还是和直接用emacs打开有所区别。执行这条命令之后,会立刻返回,而不像用emacs一样会等待emacs执行的结果。
至少这个焦点切换问题可以利用论坛下面帖子的方法解决。
找到了,是用 select-frame-set-input-focus 实现了
这样的话,就用不着自己想办法用外部程序打开 Emacs 窗口了
(defun open-emacs-window ()
"打开 Emacs 窗口."
(select-frame-set-input-focus (selected-frame)))
~$ emacsclient --eval '(dired ".")' --eval '(open-emacs-window)'
~$ emacsclient --eval '(org-agenda-list)' --eval '(open-emacs-window)'
下面这条命令会卡住,直到窗口退出吧?
emacsclient --create-frame --eval '(view-file "test.txt")'
加个 -n
选项之后,命令行倒是会立刻得到结果。
我少打了,要加个-c,我的问题
emacsclient -c -e '(progn (view-file "FILE") (read-only-mode))'