在不创建主题的情况下更改 emacs 中特定文本的颜色
是否可以选择您正在编辑的一段文本并更改其颜色?我知道可以创建一个颜色主题来为某些类型的文本着色(例如某种编程语言中的着色函数),但是是否可以对特定 emacs 中的选定文本片段进行一次性颜色更改不创建主题的文档?提前致谢。
Is it possible to select a piece of text you're editing and change its color? I know it's possible to create a color theme that will color certain kinds of text (like for example coloring functions in a certain programming language), but is it possible to do a one time color change to a selected piece of text in a specific emacs document without creating a theme? thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
在任何情况下,主题都不允许您指定任意文本的颜色。它仅描述了字体锁定使用的一组面孔。
要将面应用到任意一段文本,请选择文本,然后M-:
(add-text-properties (region-beginning) (region- end) '(face font-lock-warning-face))
有关如何创建面的信息,请参阅 elisp 手册的 faces 部分。
Emacs 还附带了 hi-lock 包,它可以突出显示正则表达式或包含正则表达式的行。请参阅手册
A theme doesn't allow you to specify the color of arbitrary text in any case. It only describes a set of face to be used by font-lock.
To apply a face to an arbitrary piece of text, select the text, then M-:
(add-text-properties (region-beginning) (region-end) '(face font-lock-warning-face))
See the faces section of the elisp manual on how to create a face.
Emacs also comes with the
hi-lock
package, which can highlight regexps or lines containing regexps. See manualMx 高亮短语
怎么样?how about
M-x highlight-phrase
?我知道六年是一个相当长的时间,但我偶然发现了这个问题,经过大量研究,我没有发现任何东西比我最终为自己挖掘出的东西更客观。
例如,要为缓冲区中的前 200 个字符着色,请执行以下命令:
如果您需要在 emacs 中执行此命令的帮助,这里是众多可能性中的一种:
I know six years is a pretty long time, but I stumbled across this question and, after a lot of research, I did not find anything nearly as objective as what I eventually dug out for myself.
To color say, the first 200 characters in your buffer, execute the command:
If you need help executing this command in emacs, here is one possibility among many:
您可能想查看 enriched-mode 。
You might like to look at enriched-mode.
如果您所在的缓冲区不受字体锁定控制,则可以使用“facemenu”。
例如,突出显示一段文本,然后用鼠标按
C-mouse-2
。然后,您可以选择一个面(文本属性与名称的某种组合)。您还可以选择随机的前景或背景颜色。如果你对 Emacs 特别老的话,我好像记得
Mg
上有类似的东西。If you are in a buffer that isn't controlled by font-lock, you can use 'facemenu'.
For example, highlight a bit of text, then with the mouse, press
C-mouse-2
. You can then select a face (some combination of text properties with a name). You can also pick random forground or background colors.If you Emacs is particularly old, I seem to remember something similar on
M-g
.尝试
set-background-color
、set-foreground-color
、set-cursor-color
。但更改不会与文档一起保存。
注:
当我尝试这些功能时,除非我浏览菜单,否则它们不会设置该区域的颜色。
Try
set-background-color
,set-foreground-color
,set-cursor-color
.Changes won't be saved with the document though.
Note:
When I try those functions, they don't set the region's color unless I go through the menus.
请参阅 http://www.emacswiki.org/emacs/HighlightTemporarily (并且它不必是临时的)。
您可以通过用鼠标滑动文本或将其与正则表达式匹配以及其他几种方式来为文本“着色”。库
highlight.el
特别可以让您为文本“着色”在很多方面。See http://www.emacswiki.org/emacs/HighlightTemporarily (and it need not be temporary).
You can "color" text by swiping it with the mouse, or matching it with a regexp, and several other ways. Library
highlight.el
, in particular, lets you "color" text in many ways.