改变Emacs’背景颜色
我有一个函数可以将 Emacs 的颜色主题设置为我自己定义的主题。在此函数中,我执行以下操作:
(set-face-attribute 'default cur-frame :foreground fg-color :background bg-color)
然后为 default-frame-alist
、initial-frame-alist
和 special 设置背景颜色、前景色和光标颜色-显示框架列表
。
所有这些在我的 Mac 上都运行良好。但是当我在 Linux 上使用它时,对于所有已打开的框架来说,它看起来都很好,但在新创建的框架上,它看起来像这样:
如果使用 set-background-color
/ set-foreground-color
函数而不是 (set-background-color
>set-face-attribute '默认...)。但如果我这样做,我必须手动重置每个已打开的帧的颜色。
我在 Mac 和 Ubuntu 上使用 Emacs 版本 23.3。
为了澄清起见,这是我使用的主题文件:
I have a function that sets Emacs' color theme to a theme defined by myself. In this function I do:
(set-face-attribute 'default cur-frame :foreground fg-color :background bg-color)
I then set the background color, foreground color, and cursor color for default-frame-alist
, initial-frame-alist
and special-display-frame-alist
.
All of this works fine on my Mac. But when I use this on Linux, it looks fine for all frames that have already been opened, but on newly created frames it looks like this:
I do not have this problem with new frames if use the set-background-color
/ set-foreground-color
functions instead of (set-face-attribute 'default ...
). But if I do that I have to manually reset the colors for every frame that's already open.
I am using Emacs version 23.3 on both Mac and Ubuntu.
For clarification, this is the theme file I use:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
set-face-attribute
顾名思义,设置脸部的属性(即与字体相关的属性),而不是框架的属性。使用(add-to-list 'default-frame-alist '(background-color . "lightgray"))
和类似的方法来更改与框架相关的属性。
set-face-attribute
sets, as the name suggest, the attributes of a face (i.e., font-related properties), not the attributes of the frame. Use(add-to-list 'default-frame-alist '(background-color . "lightgray"))
and similar to change frame-related properties.
像这样的东西应该可以帮助您维护每个操作系统的设置。
something like this should help you maintain settings per OS.
看来还是用
style来定脸比较好,这样就不会出现这个问题了。
It seems that it's better to use
style to set faces, this way it will not have that problem.
Emacs 在较新的 Emacs 版本中使用1)(或不覆盖)Gtk3.0 主题背景。使用例如
set-background-color
或default-frame-alist
更改背景仅在我调整窗口大小之前有效,之后 Gtk 主题背景再次“闪耀”。我还没有弄清楚如何让 emacs 始终在 Gtk 主题背景上绘制,但至少我找到了一种方法如何更改 Gtk 主题背景颜色,仅适用于 Emacs: https://superuser.com/questions/699501/ emacs-showing-grey-background-where-there-are-no-characters/937749#937749
所以这个并不能完全解决切换主题时改变背景颜色的问题,但至少可以摆脱打开新框架时遇到的黑白对比。
1)至少在我的机器上:)
Emacs uses1) (or does not paint over) the Gtk3.0 theme background in more recent Emacs versions. Changing background using e.g.
set-background-color
ordefault-frame-alist
only works until I resize the window, after which the Gtk theme background "shines through" again.I have not yet been able to figure out how to get emacs to always paint over the Gtk theme background, but at least I have found a way how to change the Gtk theme background color, for Emacs only: https://superuser.com/questions/699501/emacs-showing-grey-background-where-there-are-no-characters/937749#937749
So this does not fully solve changing the background color when you switch themes, but at least you can get rid of the black-white contrast you experience when opening new frames.
1) on my machine at least :)