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

Can I select a piece of text that you are editing and change its color? I know that it is possible to create a color theme that will color certain types of text (for example, coloring functions in a particular programming language), but is it possible to change the color once for a selected piece of text in a specific emacs document without creating a theme? thanks in advance.

+6
source share
7 answers

The theme does not allow you to specify the color of arbitrary text in any case. It describes only the set of faces that will be used by font blocking.

To apply a face to an arbitrary part of the text, select the text , then M-: (add-text-properties (region-beginning) (region-end) '(face font-lock-warning-face))

See the faces section in the elisp tutorial on how to create a face.

Emacs also comes with a hi-lock package that can highlight regular expressions or strings containing regular expressions. See manual

+6
source

what about Mx highlight-phrase ?

+5
source

You may like enriched-mode .

+2
source

If you are in a buffer that is not controlled by font locking, you can use "facemenu".

For example, select some text, then use the mouse to press C-mouse-2 . Then you can select a face (some combination of text properties with a name). You can also choose random background or background colors.

If you are particularly old Emacs, I seem to remember something similar on Mg .

+1
source

Try set-background-color , set-foreground-color , set-cursor-color .
However, the changes will not be saved with the document.

Note:
When I try to perform these functions, they do not set the color of the area unless I go through the menu.

0
source

See http://www.emacswiki.org/emacs/HighlightTemporarily (and this should not be temporary).

You can β€œcolor” the text by dragging it with the mouse or by matching it with a regular expression and several other ways. The highlight.el library, in particular, allows you to "color" text in many ways.

0
source

I know that six years is quite a long time, but I came across this question, and after many studies I did not find anything almost objective, like what I eventually dug for myself.

To say the color, the first 200 characters in your buffer, run the command:

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

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

  • Enter an ESC-x eval expression.
  • Type or paste the above command into the mini-buffer after the prompt.
  • Press ENTER.
0
source

Source: https://habr.com/ru/post/898937/


All Articles