Changing the color of a specific piece of text in emacs without creating a theme

主宰稳场 提交于 2020-01-12 08:00:21

问题


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.


回答1:


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 manual




回答2:


how about M-x highlight-phrase ?




回答3:


You might like to look at enriched-mode.




回答4:


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.




回答5:


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.




回答6:


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.




回答7:


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:

(put-text-property 1 200 'face (cons 'foreground-color "red"))

If you need help executing this command in emacs, here is one possibility among many:

  1. Type ESC-x eval-expression.
  2. Type or paste the above command in the mini-buffer after the prompt.
  3. Press ENTER.


来源:https://stackoverflow.com/questions/7707002/changing-the-color-of-a-specific-piece-of-text-in-emacs-without-creating-a-theme

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!