Confused when setting an Emacs face - emacs

(set-face-attribute 'diredp-dir-heading nil
'(t (:foreground blue
:background dark1)))
What should be the right statements to set this face? Bow//

Face attributes :foreground and :background must have string values.
So try "blue" instead of blue etc.
The error message you see is saying that you asked Emacs to evaluate blue, which means find its value as a variable. Emacs tried that and found that the symbol blue has no value as a variable. The string "blue", on the other hand, evaluates to itself, and a string is exactly the kind of value that is needed here.

Related

Applying custom face in emacs

I wanted to make a derived mode for python-mode to add custom keywords and color. So I retreived the part of the code that defines the face of the keywords and added my own keywords.
If I use an already existing face it works just fine. But I want to use custom faces so it doesn't change color if in the same time of other faces.
I search how to define a face and end up with this:
(defface printr-face
'((t :foreground "red" :weight bold))
"Face for printr function"
:group 'python-print-color-faces)
the part of the code I try to apply it (inside the variable "python-font-lock-keywords") look like this:
(,(rx symbol-start (or "printr") symbol-end) . printr-face)
The printr-face does appear in the list when I use
M-x list-faces-display.
But the face isn't applied. M-x describe-face see it as default.
What am I doing wrong? How can I use my newly defined face ?
When adding new faces to new keywords, you need to add the keywords, too:
(font-lock-add-keywords
'my-mode
'(("regex1" 1 'my-face1)
("regex2" 1 'my-face2))
1)
choroba was in the right.
Also I missed a set a parenthesis in the defface:
(defface printr-face `((t (:foreground "red" :weight bold))) "Face for printr function"
:group 'python-print-color)
(I forgot to encapsulated the :forground :weight)
then
(font-lock-add-keywords
'python-print-color-mode
'(("printr" . 'printr)
("printg" . 'printg)))
Note that I had to use "." instead of "1" to make it work. Not sure what the "1" should have done but it wasn't working for me.

How to override override modeline customization from org-faces.el?

org-faces.el contains this code
(org-copy-face 'mode-line 'org-mode-line-clock
"Face used for clock display in mode line.")
;; ...snip...
(provide 'org-faces)
;;; org-faces.el ends here
Which makes the right side of my modeline (the org clock display) have the same face as 'mode-line. Using my .emacs I'd like to change this behavior so that the org clock display uses the same face as 'mode-line-inactive.
I tried adding this to .emacs:
(require 'org-faces) ;;necessary?
(org-copy-face 'mode-line-inactive 'org-mode-line-clock
"Face used for clock display in mode line."
:background "blue")
(provide 'org-faces) ;;necessary?
but the modeline is unchanged after evaluating .emacs. Where am I going wrong? I'm pretty new to Lisp. Thanks for any help.
You should redefine the face, as I do for "org-todo":
(set-face-attribute 'org-todo nil
:weight 'bold :box '(:line-width 1 :color "#D8ABA7")
:foreground "#D8ABA7" :background "#FFE6E4")
You may (or must, maybe, depending on where you place the above lines) leave the requiring of org-faces, but clearly not the provide line.
Alternatively, use a color theme that improves Org's use (such as my Emacs Leuven theme, see https://github.com/fniessen/emacs-leuven-theme), eventually customizing it to suit your taste.
This seems to work:
(eval-after-load "org-faces"
'(set-face-attribute 'org-mode-line-clock nil
:inherit nil))
That is, make the org-mode-line-clock no longer inherit attributes from the mode-line face. It seems like it gets the attributes from mode-line or mode-line-inactive as appropriate, when displayed in the mode line.

Getting Faces to Share Background Color in Emacs

I'm in the process of configuring linum, hlinum, and hl-line for Emacs 24, and something I'm running into some trouble with is getting the hlinum highlight to match/inherit the background color of the line highlight.
In my Elisp file responsible for face customizations, I have the following:
(eval-after-load 'hl-line
'(progn
(set-face-attribute 'hl-line nil
:background "#222222")))
(eval-after-load 'hlinum
'(progn
(set-face-attribute 'linum-highlight-face nil
:inherit 'hl-line)))
However, the hlinum face remains unchanged. Specifying the linum-highlight-face background manually works, but I'd rather have it pick up on the color for hl-line.
How can I get linum-highlight-face to use the same background color as hl-line?
Related to this StackOverflow question, I added
:background 'unspecified
below the :inherit line for hlinum, and it used the same color.

Emacs 24: Mode-Line Style

I am trying to change the styling of the modeline in emacs 24.
I want to add an overline and an underline. Underline works fine, but overline is not working for some reason. Here is my code so far (added to .emacs):
(set-face-attribute 'mode-line nil
:foreground "gray0"
:background "cyan"
:overline "cyan"
:underline "cyan")
Any ideas on how to get the overline working?
Also is there a way to set the distance between the borders and text?
Thanks
If I remember correctly, the default mode-line spec has a non-nil :box spec, so it might solve your problem to add the line :box nil to your code listed above.

Change Emacs syntax highlighting colors

I'm running Emacs, editing files in C++ mode and PHP mode. I love syntax highlighting as a concept, but the default colors are a travesty. I can barely read some of them: way too dark. What is the easiest way to change their values? I can't seem to find anything about this on the web. I don't even mind changing the binary as I'm compiling my own Emacs. I just want to find the place where it says blue is #0000FF and change it to #AAAAFF for example.
I find it easiest to use color-theme for this sort of thing.
But if you don't want to do that, put the cursor over the offending text, and hit M-x customize-face. It should default to the face that the cursor is over.
See 49.1.6 Customizing Specific Items.
Two ways - you can install the package color-theme, which has lots of nice schemes to select and is easier to do it by hand. The by-hand looks like this (in your .emacs file)
(custom-set-faces
custom-set-faces was added by Custom.
If you edit it by hand, you could mess it up, so be careful.
Your init file should contain only one such instance.
If there is more than one, they won't work right.
'(default ((t (:inherit nil :stipple nil :background "lightyellow2" :foreground "gray20" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight bold :width normal :family "liberation mono"))))
'(background "blue")
'(font-lock-builtin-face ((((class color) (background dark)) (:foreground "Turquoise"))))
'(font-lock-comment-face ((t (:foreground "MediumAquamarine"))))
'(font-lock-constant-face ((((class color) (background dark)) (:bold t :foreground "DarkOrchid"))))
'(font-lock-doc-string-face ((t (:foreground "green2"))))
'(font-lock-function-name-face ((t (:foreground "SkyBlue"))))
'(font-lock-keyword-face ((t (:bold t :foreground "CornflowerBlue"))))
'(font-lock-preprocessor-face ((t (:italic nil :foreground "CornFlowerBlue"))))
'(font-lock-reference-face ((t (:foreground "DodgerBlue"))))
'(font-lock-string-face ((t (:foreground "LimeGreen"))))
...
etc. etc.
You can also type
`M-x customize-face RET`
which will give you all the customizations to set, ultimately end up in your .emacs file.
Put the cursor on a face ("color") that you want to change. Hit C-u C-x =. That will tell you which face(s) are present at that position, and it will let you click to customize it/them. Save your customizations.
If you don't care about color highlighting at all, or none of the previous answers work for you (or take too much time and effort to figure out), here is a very simple solution that will get rid of colors altogether.
Typing the following will get rid of colors:
M-x global-font-lock-mode
You can also do this as an interim step to allow you to actually see everything your screen to try any of the above answers. In my case, this was very useful because the color of certain key pieces of text which would allow me to change colors were themselves nearly invisible - for instance, the prompt of M-x.
If you want the change to be permanent, you can add this to your .emacs file:
(setq-default global-font-lock-mode nil)
Starting with Emacs 24.1, you can use M-x customize-themes to select a colour theme.
Emacs comes with a dozen or so themes with varying brightness and colourfulness, so you'll most likely find something that mostly matches your preferences.
You can also find more colour themes installable through MELPA at https://peach-melpa.org/ - no, that web site seems to be down. You can search for "theme" at melpa.org, but it doesn't show any screenshots.