与 tty 兼容的自定义主题设置面

发布于 2024-08-09 13:05:16 字数 459 浏览 12 评论 0原文

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

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

也许在 tty 下颜色无法完全匹配,因此类似的东西正在被替换?如果是这样,这似乎并不总是有效。

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

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

I have created an emacs-23 custom theme using customize-create-theme. It works fine under X (Linux gnome desktop). However, when running under a tty (within gnome-terminal) some of the colors are wrong.

It is not the accuracy of the colors which are a problem (although it would be nice to match them under both situations) but the fact that some are so off as to be unworkable. For example, function names which appear green under X are invisible under the tty, although keywords which appear gold under X also appear gold (or at least some kind of yellow) under the tty.

Perhaps under the tty colors can't be matched exactly and so something similar is being substituted? If so, this doesn't seem to work all the time.

How can I fix this? Is it possible to specify, either in the 'customize' GUI or in the ~/.emacs.d/my-theme.el file, that certain faces only apply to frames displayed on X and others are only for the tty, or something similar?

(I'm interested in getting this, the built-in emacs theming system working rather than using some external color theme system.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

帅哥哥的热头脑 2024-08-16 13:05:16

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

因此,这可能有助于 emacs 找到更接近的颜色,但如果仍然错误,您将需要做一些更彻底的事情,例如根据窗口系统设置颜色。

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

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

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

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

(defun set-new -frame-colors(框架)
   “根据框架类型设置颜色。”
   (if (窗口系统框架)
      (set-face-forgeground 'font-lock-function-name-face "LightSkyBlue" 框架)
      (set-face-forgeground'font-lock-function-name-face“蓝色”框架)))
(add-hook 'after-make-frame-functions 'set-new-frame-colors)

或者,您可以检查 ,而不是检查 (window-system frame) (长度(定义颜色帧)) 并基于系统支持的颜色数量,以便您可以为 8 色和 256 色终端设置不同的颜色。

If a color is unavailable on a frame, emacs should try and pick something "close", but that's often very wrong on limited color displays. You should ask emacs how many colors it thinks it has in gnome-terminal either using M-x list-colors-display (to actually view the colors) or run (display-color-cells) in the scratch buffer. If it says you only have 8, you might want to consider changing your TERM environment variable to something like xterm-256color before you start emacs (though I'm not sure how well this actually works in gnome-terminal; I use xterm).

So that might help emacs be able to find a color that's closer, but if it's still wrong, you'll want to do something more drastic, like set the colors based on the window system.

If you're not using daemon mode, you can use something like

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

If you use M-x describe-face, it will ask which face you want to describe, defaulting to the one currently at point. You can get the name (and usually the color) from there.

If you are using daemon mode, then you'll want different colors for each frame, in which case you'll need to set the color for the frame in the new frame hook, something more like:

(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)

Alternatively, instead of checking (window-system frame), you could check (length (defined-colors frame)) and base it on how many colors are supported by the system, so that you can have different colors for 8-color vs. 256-color terminals.

我们的影子 2024-08-16 13:05:16

您可以通过检查变量 窗口系统。该链接有文档,但看起来像:

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.

因此,您可以将当前主题包装在 an 中

(if window-system
    ;; current theme configuration
)

,然后在 xterm 中创建一个您喜欢的新主题,并将其放在 else 中(或另一个 if< /code> 语句,或 unlesswhen

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文