Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

terminal

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.

like image 209
Hendeca Avatar asked Oct 09 '11 22:10

Hendeca


People also ask

How do I change the color of text in Emacs?

To customize colors for color syntax highlighting, see the section on font-lock . To change the foreground or background color in Emacs through the windowing interface, you can use the menu commands Foreground Color->Other and Background Color->Other in the Edit->Text Properties menu.

How do I change the color theme in Emacs?

set a theme Alt + x load-theme , then press Tab to show a list of available themes. Alternatively, Alt + x customize-themes to set a color theme.

How do you make Emacs colorful?

Call customize-themes to set a color theme. emacs M-x customize-themes. Click to see the change immediately. Alternatively, call load-theme , then press Tab ↹ to show a list of available themes.


1 Answers

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

like image 139
event_jr Avatar answered Nov 11 '22 06:11

event_jr