如何在仅限命令行版本的Emacs中执行.emacs文件中的代码?

3
我在Mac上运行Carbon Emacs,我的GUI emacs设置了非常令人愉悦的配色方案。不幸的是,在终端窗口中运行"emacs"时,它看起来很糟糕,因为它解析了我根文件夹中相同的.emacs文件。所以,是否有一种方法可以有条件地执行我的.emacs文件中的代码,以便我可以为命令行和“GUI” emacs选择不同的配色方案?谢谢!
2个回答

10
你可以使用window-system变量来判断是否在窗口环境中运行Emacs。例如,您可以将以下内容添加到您的.emacs.el文件中:
(when window-system
  (setq default-frame-alist
    (append
      '((background-color . "#102e4e")
        (background-mode  . dark)
        ...))))

这是window-system变量的文档(在Emacs中输入C-h v window-system RET可以查看):

所选帧显示的窗口系统名称。
值为符号,例如对于 X 窗口系统为“x”。
如果所选帧在纯文本终端上,则值为 nil。


0

Mac电脑自带一个非常老的emacs版本。因此,当您在终端中时,它会首先找到该版本:

Valideres-MacBook-Pro:be james$ which emacs
/usr/bin/emacs
Valideres-MacBook-Pro:be james$ emacs --version  
GNU Emacs 22.1.1
Copyright (C) 2007 Free Software Foundation, Inc.
GNU Emacs comes with ABSOLUTELY NO WARRANTY.
You may redistribute copies of Emacs
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING.
Valideres-MacBook-Pro:be james$ /Applications/Emacs.app/Contents/MacOS/Emacs --version
GNU Emacs 25.1.1
Copyright (C) 2016 Free Software Foundation, Inc.
GNU Emacs comes with ABSOLUTELY NO WARRANTY.
You may redistribute copies of GNU Emacs
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING.
Valideres-MacBook-Pro:be james$ /Applications/Emacs.app/Contents/MacOS/Emacs -nw ~/code/tmp/greatstuff.lsp

Emacs真的很棒,因为桌面版也可以在终端中运行。只需传入“-nw”选项即可选择“无窗口”模式。所以对我来说,我会输入:

/Applications/Emacs.app/Contents/MacOS/Emacs -nw ~/code/tmp/greatstuff.lsp

我可以获取桌面的颜色主题、现代包和所有新功能,但是它是在终端中。您可以进行一些操作系统链接以使新版本成为默认值(我无法折腾)。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接