0

我使用custom-create-theme 创建了一个emacs-23 自定义主题。它在 X(Linux gnome 桌面)下运行良好。但是,在 tty(在 gnome-terminal 中)下运行时,某些颜色是错误的。

问题不是颜色的准确性(尽管在这两种情况下匹配它们会很好),而是有些颜色太差以至于无法使用。例如,在 X 下显示为绿色的函数名称在 tty 下是不可见的,尽管在 X 下显示为金色的关键字在 tty 下也显示为金色(或至少某种黄色)。

也许在 tty 下的颜色不能完全匹配,所以类似的东西被替换了?如果是这样,这似乎并不总是有效。

我怎样才能解决这个问题?是否可以在“自定义”GUI 或 ~/.emacs.d/my-theme.el 文件中指定某些面孔仅适用于 X 上显示的帧,而其他面孔仅适用于 tty 或其他相似的?

(我有兴趣得到这个,内置的 emacs 主题系统工作而不是使用一些外部颜色主题系统。)

4

2 回答 2

1

如果框架上的颜色不可用,emacs 应该尝试选择“接近”的东西,但这在有限的颜色显示器上通常是非常错误的。您应该询问 emacs 它认为它在 gnome-terminal 中有多少颜色,或者使用M-x list-colors-display(实际查看颜色)或(display-color-cells)在暂存缓冲区中运行。如果它说您只有 8 个,您可能需要考虑在启动 emacs 之前将TERM环境变量更改为类似的值xterm-256color(尽管我不确定这在 gnome-terminal 中的实际效果如何;我使用 xterm)。

所以这可能有助于 emacs 能够找到更接近的颜色,但如果它仍然是错误的,你会想要做一些更激烈的事情,比如根据窗口系统设置颜色。

如果您不使用守护程序模式,则可以使用类似

(if window-system
    (set-face-foreground 'font-lock-function-name-face "LightSkyBlue"))

如果您使用M-x describe-face,它会询问您要描述哪张脸,默认为当前所在的那张脸。您可以从那里获得名称(通常是颜色)。

如果您使用的是守护程序模式,那么您需要为每个帧设置不同的颜色,在这种情况下,您需要在新的帧挂钩中设置帧的颜色,更像是:

(defun set-new-frame-colors (frame)
   "Set colors based on frame type."
   (if (window-system frame)
       (set-face-forgeground 'font-lock-function-name-face "LightSkyBlue" frame)
       (set-face-forgeground 'font-lock-function-name-face "blue" frame)))
(add-hook 'after-make-frame-functions 'set-new-frame-colors)

(window-system frame)或者,您可以检查并根据系统支持的颜色数量来代替检查(length (defined-colors frame)),以便您可以为 8 色和 256 色终端提供不同的颜色。

于 2010-02-11T23:30:44.093 回答
0

You can tell whether or not the current frame is associated with a graphical window by examining the variable window-system. The link has the documentation, but it looks like:

window-system is a variable defined in `C source code'.
Its value is nil

Documentation:
Name of window system through which the selected frame is displayed.
The value is a symbol--for instance, `x' for X windows.
The value is nil if the selected frame is on a text-only-terminal.

So, you can wrap the current theme inside an

(if window-system
    ;; current theme configuration
)

and then when in an xterm, create a new one that you like, and put that in the else (or another if statement, or unless and when)

于 2009-11-13T22:07:18.120 回答