修改 rst.el 中的颜色
在 Emacs 中,我使用深色背景和浅色文本的配色方案。当使用 .rst 文件时,我有一个使用 rst.el 的模式。然而,rst.el 用浅色背景颜色突出显示标题,这使得阅读上面的浅色文本变得不可能!
我认为这是 rst.el 中负责背景颜色的代码部分:
(defgroup rst-faces-defaults nil
"Values used to generate default faces for section titles on all levels.
Tweak these if you are content with how section title faces are built in
general but you do not like the details."
:group 'rst-faces
:version "21.1")
(defun rst-define-level-faces ()
"Define the faces for the section title text faces from the values."
;; All variables used here must be checked in `rst-set-level-default'
(let ((i 1))
(while (<= i rst-level-face-max)
(let ((sym (intern (format "rst-level-%d-face" i)))
(doc (format "Face for showing section title text at level %d" i))
(col (format ("gray10")))
(make-empty-face sym)
(set-face-doc-string sym doc)
(set-face-background sym col)
(set sym sym)
(setq i (1+ i))))))
(defun rst-set-level-default (sym val)
"Set a customized value affecting section title text face and recompute the
faces."
(custom-set-default sym val)
;; Also defines the faces initially when all values are available
(and (boundp 'rst-level-face-max)
(boundp 'rst-level-face-format-light)
(boundp 'rst-level-face-base-color)
(boundp 'rst-level-face-step-light)
(boundp 'rst-level-face-base-light)
(rst-define-level-faces)))
;; Faces for displaying items on several levels; these definitions define
;; different shades of grey where the lightest one (i.e. least contrasting) is
;; used for level 1
(defcustom rst-level-face-max 6
"Maximum depth of levels for which section title faces are defined."
:group 'rst-faces-defaults
:type '(integer)
:set 'rst-set-level-default)
(defcustom rst-level-face-base-color "grey"
"The base name of the color to be used for creating background colors in
ection title faces for all levels."
:group 'rst-faces-defaults
:type '(string)
:set 'rst-set-level-default)
(defcustom rst-level-face-base-light
(if (eq frame-background-mode 'dark)
85
15)
"The lightness factor for the base color. This value is used for level 1. The
default depends on whether the value of `frame-background-mode' is `dark' or
not."
:group 'rst-faces-defaults
:type '(integer)
:set 'rst-set-level-default)
(defcustom rst-level-face-format-light "%2d"
"The format for the lightness factor appended to the base name of the color.
This value is expanded by `format' with an integer."
:group 'rst-faces-defaults
:type '(string)
:set 'rst-set-level-default)
(defcustom rst-level-face-step-light
(if (eq frame-background-mode 'dark)
-7
7)
"The step width to use for the next color. The formula
`rst-level-face-base-light'
+ (`rst-level-face-max' - 1) * `rst-level-face-step-light'
must result in a color level which appended to `rst-level-face-base-color'
using `rst-level-face-format-light' results in a valid color such as `grey50'.
This color is used as background for section title text on level
`rst-level-face-max'."
:group 'rst-faces-defaults
:type '(integer)
:set 'rst-set-level-default)
(defcustom rst-adornment-faces-alist
(let ((alist '((t . font-lock-keyword-face)
(nil . font-lock-keyword-face)))
(i 1))
(while (<= i rst-level-face-max)
(nconc alist (list (cons i (intern (format "rst-level-%d-face" i)))))
(setq i (1+ i)))
alist)
"Provides faces for the various adornment types. Key is a number (for the
section title text of that level), t (for transitions) or nil (for section
title adornment). If you generally do not like how section title text faces are
set up tweak here. If the general idea is ok for you but you do not like the
details check the Rst Faces Defaults group."
:group 'rst-faces
:type '(alist
:key-type
(choice
(integer
:tag
"Section level (may not be bigger than `rst-level-face-max')")
(boolean :tag "transitions (on) / section title adornment (off)"))
:value-type (face))
:set-after '(rst-level-face-max))
我尝试将“灰色”更改为其他颜色,但它没有改变任何东西。有什么帮助吗?
In Emacs, I'm using a color scheme with a dark background and light text. When working with .rst files, I have a mode for that which uses rst.el. However, rst.el highlights headings with a light background color, which makes reading light text on it impossible!
I think that this is the section of code in rst.el that is responsible for the background colors:
(defgroup rst-faces-defaults nil
"Values used to generate default faces for section titles on all levels.
Tweak these if you are content with how section title faces are built in
general but you do not like the details."
:group 'rst-faces
:version "21.1")
(defun rst-define-level-faces ()
"Define the faces for the section title text faces from the values."
;; All variables used here must be checked in `rst-set-level-default'
(let ((i 1))
(while (<= i rst-level-face-max)
(let ((sym (intern (format "rst-level-%d-face" i)))
(doc (format "Face for showing section title text at level %d" i))
(col (format ("gray10")))
(make-empty-face sym)
(set-face-doc-string sym doc)
(set-face-background sym col)
(set sym sym)
(setq i (1+ i))))))
(defun rst-set-level-default (sym val)
"Set a customized value affecting section title text face and recompute the
faces."
(custom-set-default sym val)
;; Also defines the faces initially when all values are available
(and (boundp 'rst-level-face-max)
(boundp 'rst-level-face-format-light)
(boundp 'rst-level-face-base-color)
(boundp 'rst-level-face-step-light)
(boundp 'rst-level-face-base-light)
(rst-define-level-faces)))
;; Faces for displaying items on several levels; these definitions define
;; different shades of grey where the lightest one (i.e. least contrasting) is
;; used for level 1
(defcustom rst-level-face-max 6
"Maximum depth of levels for which section title faces are defined."
:group 'rst-faces-defaults
:type '(integer)
:set 'rst-set-level-default)
(defcustom rst-level-face-base-color "grey"
"The base name of the color to be used for creating background colors in
ection title faces for all levels."
:group 'rst-faces-defaults
:type '(string)
:set 'rst-set-level-default)
(defcustom rst-level-face-base-light
(if (eq frame-background-mode 'dark)
85
15)
"The lightness factor for the base color. This value is used for level 1. The
default depends on whether the value of `frame-background-mode' is `dark' or
not."
:group 'rst-faces-defaults
:type '(integer)
:set 'rst-set-level-default)
(defcustom rst-level-face-format-light "%2d"
"The format for the lightness factor appended to the base name of the color.
This value is expanded by `format' with an integer."
:group 'rst-faces-defaults
:type '(string)
:set 'rst-set-level-default)
(defcustom rst-level-face-step-light
(if (eq frame-background-mode 'dark)
-7
7)
"The step width to use for the next color. The formula
`rst-level-face-base-light'
+ (`rst-level-face-max' - 1) * `rst-level-face-step-light'
must result in a color level which appended to `rst-level-face-base-color'
using `rst-level-face-format-light' results in a valid color such as `grey50'.
This color is used as background for section title text on level
`rst-level-face-max'."
:group 'rst-faces-defaults
:type '(integer)
:set 'rst-set-level-default)
(defcustom rst-adornment-faces-alist
(let ((alist '((t . font-lock-keyword-face)
(nil . font-lock-keyword-face)))
(i 1))
(while (<= i rst-level-face-max)
(nconc alist (list (cons i (intern (format "rst-level-%d-face" i)))))
(setq i (1+ i)))
alist)
"Provides faces for the various adornment types. Key is a number (for the
section title text of that level), t (for transitions) or nil (for section
title adornment). If you generally do not like how section title text faces are
set up tweak here. If the general idea is ok for you but you do not like the
details check the Rst Faces Defaults group."
:group 'rst-faces
:type '(alist
:key-type
(choice
(integer
:tag
"Section level (may not be bigger than `rst-level-face-max')")
(boolean :tag "transitions (on) / section title adornment (off)"))
:value-type (face))
:set-after '(rst-level-face-max))
I've tried changing 'grey' to something else, but it doesn't change a thing. Any help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果你坚持使用代码,那么使用customize来设置一些东西,查看生成的代码并将其用作模型。但是,使用老式 .emacs 代码不再被认为是良好的形式。
If you insist on using code, then use customize to set some things, look at the generated code and use it as a model. However, it's no longer considered good form to do it with old-fashioned .emacs code.
抱歉挖出一个老问题。
要更改的字段是
第一级面基础光
。将值从默认值 85 更改为 ~51 可以使文本可读,但保持标题突出显示。它利用系统命名的
grey%2d
颜色来对基于背景的部分深度进行着色。Sorry to dig up an old question.
The field to change is
Rst Level Face Base Light
. Changing the value to ~51 from the default of 85 makes the text readable, but maintains highlighting of titles.It makes use of the systematically named
grey%2d
colors to shade the background based section depth.使用
并将
Rst Level Face Base Color
的值设置为黑色
可以使标题更易于阅读。请确保为所有未来会话设置该值。Using
and set the value of
Rst Level Face Base Color
toblack
make the titles easier to read. Be sure that you set the value for all future sessions.