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.
Related
I wish to change the appearance of something in a *helm ag* buffer. None of my usual tricks for discovering which face is being used at some point (my favourite being M-x customize-face with the point in the region of interest) work, as there is no (obvious) way of getting control of a cursor in helm buffers.
My questions are:
Teach me to fish, feed me for life: How can I discover the faces used in a buffer in which I cannot place the cursor?
Give me a fish, feed me for a day: Which face is used in the *helm ag* buffer to highlight the pattern match on the currently selected line?
Update
In the case of *helm-ag* buffers created by the helm-ag command, the relevant face is helm-match. However, in *helm ag* buffers (no dash!) created by the helm-do-grep-ag command, the helm-match face seems to have no effect, as described in the further information below.
Further information
Here is a picture of an emacs session in which no custom themes have been enabled.
In the lower left there is a *helm ag* buffer searching for defun. The third line in the buffer is selected. The match (defun) is highlighted in all other lines, but not on the selected one.
On the right are some face customization buffers for likely candidates. helm-match has been set to have a red foreground, but this is not reflected in the *helm-ag* buffer. This seems to suggest that helm-match is not the fish I'm looking for.
A similar approach to #elethan's #3:
Call list-faces-display, which will show you a list of all faces
in alphabetical order.
Search for "helm".
First here is your "fish": I think the face you are referring to is helm-match.
Here are few different strategies that I would personally try if I needed to find a given face and can't place point on the text with that face:
Use M-x describe-face, guess at what the first part of the name is likely to be (in this case helm), and scan through the likely candidates that start with that.
Go to the code where that face is likely defined (in this case helm-ag.el which you can find with M-x describe-function RET helm-ag), and search for face in that file to find a likely match.
Do M-x customize-face and enter and 'all faces', look for helm-* faces and try to find a name and face (since you can see a sample of the face in this buffer) that matches the one you are looking for.
Probably none of these methods is as direct as you are hoping for, and there may be a quicker solution, but this is what I would do (and have done). In this case I found the face with method #2.
Update:
Here is a screenshot from my setup:
Notice that for me the relevant face is helm-match which inherits from match in replace.el. Also, note that the difference between the way the match appears in the highlighted/selected line compared to the other lines is not due to a different face, but caused by how the background color of the line highlighting affects the color, as can be seen when I highlight the sample text here:
Update 2:
It turns out OP was using helm-ag-do-grep which is defined in a different file - helm-grep.el. Here is the face-setting portion of that code:
;;; Faces
;;
;;
(defgroup helm-grep-faces nil
"Customize the appearance of helm-grep."
:prefix "helm-"
:group 'helm-grep
:group 'helm-faces)
(defface helm-grep-match
'((((background light)) :foreground "#b00000")
(((background dark)) :foreground "gold1"))
"Face used to highlight grep matches."
:group 'helm-grep-faces)
(defface helm-grep-file
'((t (:foreground "BlueViolet"
:underline t)))
"Face used to highlight grep results filenames."
:group 'helm-grep-faces)
(defface helm-grep-lineno
'((t (:foreground "Darkorange1")))
"Face used to highlight grep number lines."
:group 'helm-grep-faces)
(defface helm-grep-finish
'((t (:foreground "Green")))
"Face used in mode line when grep is finish."
:group 'helm-grep-faces)
(defface helm-grep-cmd-line
'((t (:inherit diff-added)))
"Face used to highlight grep command line when no results."
:group 'helm-grep-faces)
I think helm-grep-match is what you are looking for. If not, the face in question is likely to be in the above code snippet, and all of those faces should be customizable using customize-face. This code also tracked down using method #2 described above.
ag itself uses colours to highlight matches. Helm uses these colours and ignores helm-grep-match unless helm-grep-ag-command contains the --nocolors option.
There are therefore two approaches:
Set the colours you want with the --color-match option to ag in helm-grep-ag-command.
Disable ag's match highlighting with the --nocolor opiton in helm-grep-ag-command and set Emacs' helm-match or helm-grep-match (not entirely sure which one is the right one here) to specify the match colours. As this second option uses elisp to deal with the colouring, it's likely to be slower than the first.
In both cases, match highlighting will be overriden by helm-selection, so the only way to get any highlighting of the match on the selected line is to have helm-selection not specify either the background or the foreground, thereby leaving the opportuinity for the match highlighting to be seen.
Reference: https://github.com/emacs-helm/helm/issues/1660#
In emacs lisp mode, I want to highlight all function calls one color, and all quoted symbols another color. For example, in (foo 1 2 'bar), foo should be highlighted color 1 and 'bar should be highlighted color 2.
I was able to do this with the code below, however, it is also highlighting the first symbol in a list when the list is quoted. For example, in '(nil a b c), nil should not be highlighted as a function call, and all items in that list should be highlighted as quoted symbols (color 2).
(defface font-lock-func-face
'((nil (:foreground "#6fc2ef"))
(t (:bold t :italic t)))
"Font Lock mode face used for function calls."
:group 'font-lock-highlighting-faces)
(defface font-lock-quoted-face
'((nil (:foreground "#e1a3ee"))
(t (:bold t :italic t)))
"Font Lock mode face used for function calls."
:group 'font-lock-highlighting-faces)
(font-lock-add-keywords
'emacs-lisp-mode
'(("(\\s-*\\(\\_<\\(?:\\sw\\|\\s_\\)+\\)\\_>"
1 'font-lock-func-face)))
(font-lock-add-keywords
'emacs-lisp-mode
'(("'[-a-zA-Z_][-a-zA-Z0-9_]*\\>" 0 'font-lock-quoted-face)))
There's also an image of what I'm looking at here: http://imgur.com/Iluku05
First part of the answer: The package lisp-extra-font-lock highlights, among else, quoted expressions.
It also highlights:
variables in the parameter lists of functions and variables bound by let, pcase etc. It distinguish between normal local variables and global variables defined by a defvar by using different colors.
Back-quoted expressions (and un-highlights all ,- and ,#-escaped subexpressions)
For example:
Second part of the answer:
If you use the lisp-extra-font-lock package, your rule for highlighting functions work as you posted it, if you add it as the last rule, after you have enabled the package. That way it will not overwrite any other highlight:
(font-lock-add-keywords
'emacs-lisp-mode
'(("(\\s-*\\(\\_<\\(?:\\sw\\|\\s_\\)+\\)\\_>"
1 'font-lock-func-face))
'append) ;; <-- Add after all other rules
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.
I installed Prelude on my emacs24. I'm using ubuntu 12.04
It worked perfectly the first time I used it, but all the next times it doesn't.
On my current line the font color is gray so it's hard to see what I write. Previously it was a Bold case, keeping any color the line had for reserved words.
How can I fix this?
or also the empty lines with spaces are all yellow
I've been trying to fix it on the:
~/.emacs.d/elpa/zenburn-theme-20130716.1457/zenburn-theme.el
file but I can't find a solution... I think the problem could be between this lines:
;;;;; hl-line-mode
`(hl-line-face ((,class (:background ,zenburn-bg-05))
(t :weight bold)))
`(hl-line ((,class (:background ,zenburn-bg-05)) ; old emacsen
(t :weight bold)))
Thanks!
You can change the background and foreground to whatever you want, or turn it off completely. You can add bold or underline or overline or slant, or whatever floats your boat. One of my very first projects was to take the settings from color-theme and put it into my .emacs file and I haven't used a specific color theme since. Oh, and of course you want to open your .emacs or init file to see if there are any settings that conflict with the color theme you are using.
(global-hl-line-mode 1) ;; highlight current line -- see hl-line.el
(custom-set-faces
'(highlight ((t (:background "grey80" :foreground "black" :bold t)))) ;; highlight current line
)
Important:
Add to .bashrc file:
export TERM=xterm-256color
and I found the perfect configuration for me. Here it goes:
;;;;; hl-line-mode
(custom-set-faces
'(highlight ((t (:background "grey20" :foreground nil :bold t)))) ;; highligh\
t current line
)
This way you keep every color for reserved words all bold and a gray background for the current line. Everything will be beautiful =)
I use the volatitle-highlights-mode(VHL) to hightlights last edit region. But the background color of the VHL is much too light in color for the solarized-theme. So I want change the background color of the VHL.
I found the snippets from the VHL, as follow:
(defface vhl/default-face
(cond
((or vhl/.xemacsp
(vhl/.face-inheritance-possible-p))
'((((class color) (background light))
(:background "yellow1"))
(((class color) (background dark))
(:background "SkyBlue4"))
(t :inverse-video t)))
(t
'((t
:inherit secondary-selection
))))
"Face used for volatile highlights."
:group 'volatile-highlights)
this snippets specify the color of the VHL background, so how can I customize the background color in my .emacs.d to override the default VHL background color.
Snippets welcome! Thanks.
You can also just use M-x customize-face RET vhl/default-face. It does not matter how the face is defined: you can still use Customize to customize it.
The code above looks strange: It seems to check whether face inheritance is possible and, if not, try to inherit from the secondary-selection face (!!)
Anyway, the easiest thing to do is use customize-face, like wvxvw suggested in the comments to your question. I don't quite understand your response to his answer: setting a face that doesn't exist won't cause any error. However, if you're worried, you can cut the (custom-set-face .... ) form that appears in your .emacs and stick it in a file in .emacs.d: the warning about only using one instance in your .emacs is so that the customize infrastructure knows how to edit the file.