Changing the color of a specific piece of text in emacs without creating a theme - 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.

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

how about M-x highlight-phrase ?

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:
Type ESC-x eval-expression.
Type or paste the above command in the mini-buffer after the prompt.
Press ENTER.

You might like to look at enriched-mode.

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.

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.

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.

Related

How to change default face for embolden text in Emacs?

I do love thin fonts, so I have following customisation in my .emacs:
(set-frame-font "NK57 Monospace-14:weight=light" t)
This works as expected, however this does not tells Emacs that it should render embolden text with lighter weight too, e.g. to use medium instead of regular weight, so there is dramatically difference in weights, see picture below.
How can I tweak this?
Well, it is possible to customise default bold face using customize-face command as was mentioned by lawlist (i.e. Easy Customization).
However, this is not enough in most cases, because of some packages or themes could introduce another customisations, which overrides default one (e.g. font-lock-function-name-face, font-lock-keyword-face) and could be found in face customisation menu too.

Customizing the Emacs Monokai Theme to have a more Sublime Text 2 look

I am using Emacs Prelude. I didn't find most of the custom themes comfortable. I really liked Sublime Text 2's Monokai theme, so I installed the Monokai theme ported for Emacs. Though it is more or less similar to Sublime Text 2's Monokai, there are some differences which I want to correct, so as get my Emacs Monokai more close to Sublime's Monokai.
For example I don't want every Python keyword to be the bold pinkish. I would be prefer keywords like class,def to have a blue color than the pink ones and I would prefer the function arguments to have an orange color.
The Emacs Monokai theme seems to color the variable name to an orange color, which I don't want. How do I implement this? I checked the monokai-theme.el file, but I don't know what variable to edit and what variable to add to give the features in color changes I mentioned above.
I suppose you're referring to this version of Monokai?
You'll be able to make some of your changes, but without doing a huge amount of work some of them won't be feasible. This theme uses font-lock to identify many of the things to be coloured, and font-lock identifies all Python keywords the same way.
Have a look through the various font-lock variables in that file. This will give you a good idea of what you can easily change. For example, if you want to change variables from orange to something else, change
'(font-lock-variable-name-face
(:foreground monokai-orange))
to use one of the other monokai- colour variables, or define your own.
If you're trying to figure out how a particular character is recognized by Emacs, move your cursor over that character and do C-u C-x = (C-u M-x what-cursor-position). This will show, among other things, the face for that character.

Color whole section line in org-mode depending on tag

The question says it all. I would like to change the background color of all sections labeled with a particular tag (e.g. :WORK:) in my org-mode file. I found out how to change the colors of the TODO states, but I wasn't successful in changing the color of the whole line. Can that be done? Thanks a lot in advance for your help.
You can use font-lock-add-keywords:
(font-lock-add-keywords 'org-mode
'(("^.*:write:.*$" . font-lock-keyword-face)))
See C-h f font-lock-add-keywords RET for details.
There is no such code that's ready to copy or use, AFAICT. Though, I'm sure it can be done, but will require hand-made code.
However, if you'd be interested to have such highlighting in the agenda buffer, you should check out some post of John Wiegley, a couple of years ago.

Emacs Gnus Faces (Fonts)

The slrn newsreader has an attractive interface with different colours for the author, subject and date columns when browsing list of articles in a newsgroup. I am looking for the Emacs font/face variables for these fields in gnus, but have not been able to find them. The gnus manual for faces does not list the available faces and none of the faces list in Emacs (M-x customize-face gnus-... looks relevant. I am using gnus 5.13 in Emacs 23.2.1.
(This question is not related to displaying "faces" (icons/avatars) in Emacs or gnus.)
Solved: See my answer below.
I think they're scattered a bit in the gnus codebase. The faces used in the article buffer are probably in gnus-art.el, etc.
It sounds like your biggest problem is that there are specific faces that you can't find the symbol for. You can always do M-x describe-face to see what is under the cursor to solve that problem.
Also, (face-list) returns a list of all defined faces. You could scan that list looking for things that look like likely candidates for the particular faces you're interested in.
The format string for various elements in gnus can be customized by modifying the appropriate variable. The variable for the summary line is gnus-summary-format-line. I am not using the default value for this variable, but instead am using the value %U%R%z %(%&user-date; %-15,15f %* %B%s%)\n.
As described here, a new face can be applied to any (sub)section of a format line by bracketing the section with %1{ and %}, where the 1 in this example corresponds to gnus-face-1. gnus-face-1 in my installation defaults to "italics", so adding the following to my ~/.emacs file results in the author in the summary line appearing in italics:
(setq gnus-summary-line-format "%U%R%z %(%&user-date; %1{%-15,15f%} %* %B%s%)\n")
I go with M-x list-faces-display (which opens a new buffer with all the currently defined face variables fontified to the color that they're set to, in alphabetic order) when I want to see what faces I need to change to get a mode working.
Then I setq them, using either the format from color-theme or from the new emacs built-in theme format, depending on which version of emacs I'm in.

Emacs - color of directories in dired

I have search the web. I have tried color-theme (perhaps I need to create my own, but really I have my emacs set up the way I want it except for this ONE thing, and I could not find a color theme that was acceptable to me).
I just want to change the color of the directories in dired-mode. I have several custom colors changed in my .emacs, like:
(set-face-foreground 'font-lock-comment-face "yellow" )
But I just don't know what face to change for the directories in dired mode.
Can anyone help?
Thanks!
If you move point to the place that's displaying the color you want to change and run M-x describe-face, it will tell you the face for the text at point and that face's properties.
For me, it's dired-directory, not font-lock-comment-face.
Well, I managed to list the faces by doing M-x list-faces-display, and then I found the faces that had the dark blue that I didn't want, and, although none of the face descriptions said anything remotely like "Directory Name in dired", I just changed all of the faces that had unreadable colors, and my problems were solved!
(set-face-foreground 'dired-directory "yellow" )
The easiest way is to run:
M-x customize-face dired-directory
You'll then be presented with a menu of attributes you can customize. Select Save for future sessions and your .emacs will automatically be updated to make the change permanent.
diredful (dired colorful) worked for me.
https://www.emacswiki.org/emacs/Diredful
https://github.com/emacsmirror/diredful
To match directories:
Pattern: d.*
Select regexp on whole line (so it matches the permissions containing the 'd')
Check apply to Dirctories
Style the colors.
if you are using an older version of emacs (i tested emacs 21) try "list-text-properties-at" instead of "describe-face". for me, it shows the directory face as "font-lock-function-name-face".