49 Customization

Table of Contents

1 49 Customization

1.1 49.1 Easy Customization Interface

1.1.1 49.1.7 Custom Themes

"Custom themes" are collections of settings that can be enabled or disabled as a unit. You can use Custom themes to switch easily between various collections of settings, and to transfer such collections from one computer to another.

"订制主题"是可以作为一个单元启用或禁用的设置集合。可以通过订制主题在多种设置集合之间轻松切换,并将这些集合从一台计算机移动到另一台。

A Custom theme is stored as an Emacs Lisp source file. If the name of the Custom theme is NAME, the theme file is named ‘NAME-theme.el’. *Note Creating Custom Themes::, for the format of a theme file and how to make one.

订制主题存储为 Emacs Lisp 源码文件。如果订制主题是 NAME,主题文件名为‘NAME-theme.el’。参阅 Creating Custom Themes 了解主题文件格式以及如何制作。

Type ‘M-x customize-themes’ to switch to a buffer named ‘*Custom Themes*’, which lists the Custom themes that Emacs knows about. By default, Emacs looks for theme files in two locations: the directory specified by the variable ‘custom-theme-directory’ (which defaults to ‘~/.emacs.d/’), and a directory named ‘etc/themes’ in your Emacs installation (see the variable ‘data-directory’). The latter contains several Custom themes which are distributed with Emacs, which customize Emacs’s faces to fit various color schemes. (Note, however, that Custom themes need not be restricted to this purpose; they can be used to customize variables too.)

输入‘M-x customize-themes’切换到名为‘*Custom Themes*’的 buffer,列出 Emacs 已知的订制主题。默认情况下 Emacs 在两个位置查找主题文件:变量‘custom-theme-directory’指定的目录(默认是‘~/.emacs.d/’),和 Emacs 安装目录下名为‘etc/themes’的文件夹(参看变量‘data-directory’)。后者包含了几个伴随 Emacs 分发的主题,这些订制 Emacs 的 face 来适应各种颜色主题。(请注意,订制主题并不只限于这个目的,它们还可以订制各种变量。)

If you want Emacs to look for Custom themes in some other directory, add the directory name to the list variable ‘custom-theme-load-path’. Its default value is ‘(custom-theme-directory t)’; here, the symbol ‘custom-theme-directory’ has the special meaning of the value of the variable ‘custom-theme-directory’, while ‘t’ stands for the built-in theme directory ‘etc/themes’. The themes listed in the ‘*Custom Themes*’ buffer are those found in the directories specified by ‘custom-theme-load-path’.

如果想 Emacs 在其他目录中查找主题文件,将目录名添加到列表变量‘custom-theme-load-path’中。它的默认值是‘(custom-theme-directory t)’。这里符号‘custom-theme-directory’有变量‘custom-theme-directory’的特殊意义,t 代表内置主题目录‘etc/themes’。‘*Custom Themes*’ buffer 中列出的主题就是‘custom-theme-load-path’所指的目录中找到的。

In the ‘*Custom Themes*’ buffer, you can activate the checkbox next to a Custom theme to enable or disable the theme for the current Emacs session. When a Custom theme is enabled, all of its settings (variables and faces) take effect in the Emacs session. To apply the choice of theme(s) to future Emacs sessions, type ‘C-x C-s’ (‘custom-theme-save’) or use the ‘[Save Theme Settings]’ button.

‘*Custom Themes*’buffer 中,可以激活自定义主题旁边的复选框,为当前 Emacs 会话启用或禁用主题。主题的所有设置(变量和 faces)就会在当前 Emacs 会话中生效。为了,输入‘C-x C-s’ (‘custom-theme-save’) or 或使用‘[Save Theme Settings]’按钮将选中的主题用到以后的 Emacs 会话中。

When you first enable a Custom theme, Emacs displays the contents of the theme file and asks if you really want to load it. Because loading a Custom theme can execute arbitrary Lisp code, you should only say yes if you know that the theme is safe; in that case, Emacs offers to remember in the future that the theme is safe (this is done by saving the theme file’s SHA-256 hash to the variable ‘custom-safe-themes’; if you want to treat all themes as safe, change its value to ‘t’). Themes that come with Emacs (in the ‘etc/themes’ directory) are exempt from this check, and are always considered safe.

当第一次启用主题时,Emacs 显示主题文件的内容,并询问是否真的想要加载它。因为加载主题的时候可以执行任意的 Lisp 代码,如果明白主题是安全的,应该只回答 yes;这中情况下,Emacs 会记住该主题是安全的(这会将主题文件按的 SHA-256 哈希保存在变量‘custom-safe-themes’中;如果想将所有的主题都当作安全的,将该变量的值修改为 t)。Emacs 内置的主题(在‘etc/themes’目录中)不会进行这种检查,它们总是被认为是安全的。

Setting or saving Custom themes actually works by customizing the variable ‘custom-enabled-themes’. The value of this variable is a list of Custom theme names (as Lisp symbols, e.g., ‘tango’). Instead of using the ‘*Custom Themes*’ buffer to set ‘custom-enabled-themes’, you can customize the variable using the usual customization interface, e.g., with ‘M-x customize-option’. Note that Custom themes are not allowed to set ‘custom-enabled-themes’ themselves.

变量‘custom-enabled-themes’可以设置或保存订制主题。该变量的值是订制主题名字的列表(作为 lisp 符号)。除了使用‘*Custom Themes*’ buffer 设置‘custom-enabled-themes’,还可以使用常用的订制接口来修改该变量,比如使用‘M-x customize-option’。请注意不允许订制主题本身设置‘custom-enabled-themes’。

Any customizations that you make through the customization buffer take precedence over theme settings. This lets you easily override individual theme settings that you disagree with. If settings from two different themes overlap, the theme occurring earlier in ‘custom-enabled-themes’ takes precedence. In the customization buffer, if a setting has been changed from its default by a Custom theme, its ‘State’ display shows ‘THEMED’ instead of ‘STANDARD’.

通过订制 buffer 所做的设置将会优先于主题设置。这可以简单覆盖不想用的独立主题。如果两个不同的主题重叠,变量‘custom-enabled-themes’先出现的主题会优先使用。在订制 buffer 中,如果一个设置被订制主题修改为非默认值,它的‘state‘将会显示为’THEMED‘,而不是’STANDARD‘。

You can enable a specific Custom theme in the current Emacs session by typing ‘M-x load-theme’. This prompts for a theme name, loads the theme from the theme file, and enables it. If a theme file has been loaded before, you can enable the theme without loading its file by typing ‘M-x enable-theme’. To disable a Custom theme, type ‘M-x disable-theme’.

可以在当前 Emacs 会话中键入‘M-x load-theme’启用指定的订制主题。这将会提示输入一个主题名,从主题文件加载主题,并启用它。如果之前加载过主题文件,可以通过‘M-x enable-theme’直接启用主题,而不需要加载主题文件。输入‘M-x disable-theme’禁用主题文件。

To see a description of a Custom theme, type ‘?’ on its line in the ‘*Custom Themes*’ buffer; or type ‘M-x describe-theme’ anywhere in Emacs

在‘*Custom Themes*’ buffer 中,在订制主题的行上输入?可以查看订制主题的描述信息,或者 Emacs 中任何地方输入‘M-x describe-theme’。

Author: lsl

Created: 2016-08-07 Sun 19:10

Validate