I have code to change default color theme. I prefer this way because I add more classes then default font-lock.
(defmacro /construct-face (name comment &rest args)
"Define face and specify attributes."
(list 'progn
(list 'defface name nil comment)
(nconc (list 'set-face-attribute (list 'quote name) nil) args)))
(/construct-face ⋅function-name "Face to highlight functions."
:foreground "SlateBlue")
(setq font-lock-function-name-face '⋅function-name)
(/construct-face ⋅comment "Face to display comments"
:foreground "gray20"
:bold t)
(setq font-lock-comment-face '⋅comment)
Weirdness is that comment colors became gray, but function's names did not became purple. What is the difference and what should I try to check?
Because it is not "gray20" but "grey20", I made this mistake yesterday as well, but with grey10.
Related
How can I color entries in ibuffer accoding to the buffer type ?
Based on which mode the buffer is - for example python mode is blue, lisp mode is yellow etc ...
Is this possible ?
Building on the comment from #lawlist, here's some sample code you could use and tweak to your liking:
(setq ibuffer-fontification-alist
'((1 (eq major-mode 'c++-mode) yellow-face)
(1 (eq major-mode 'fundamental-mode) green-face)
(1 (member major-mode '(shell-mode sh-mode)) purple-face)
(1 (eq major-mode 'tcl-mode) brown-face)))
(defface yellow-face '((t :foreground "yellow")) "")
(defface green-face '((t :foreground "green")) "")
(defface purple-face '((t :foreground "black")) "")
(defface brown-face '((t :foreground "brown")) "")
Obviously you can use existing faces, or create new ones (like in this example). See the manual for faces for more information.
Trying to get the line numbering right aligned with a separator space and the same background color as the line highlighting in Spacemacs was quite complicated. Specialy when it came to do both at the same time in linum and linum-relative.
I don't know if this code is ok, but it manages so far:
(defun dotspacemacs/user-config ()
"Configuration function for user code.
This function is called at the very end of Spacemacs initialization after
layers configuration. You are free to put any user code."
(global-linum-mode t)
(unless window-system
(add-hook 'linum-before-numbering-hook
(lambda ()
(setq-local my-linum-format-fmt
(let ((w (length (number-to-string
(count-lines (point-min) (point-max))))))
(concat "%" (number-to-string w) "d"))))
(set-face-attribute 'linum nil
:background (face-background 'hl-line nil t))))
(defface my-linum-hl
`((t :inherit linum :background ,(face-background 'hl-line nil t)))
"Face for the current line number."
:group 'linum)
(defun my-linum-format-func (line)
(concat
(propertize (format my-linum-format-fmt line) 'face 'my-linum-hl)
(propertize " " 'face 'my-linum-hl)))
(unless window-system
(setq linum-format 'my-linum-format-func))
;; linum-relative
(linum-relative-toggle)
(unless window-system
(setq-local my-linum-relative-format-fmt
(let ((w (length (number-to-string
(count-lines (point-min) (point-max))))))
(concat "%" (number-to-string w) "s "))))
(unless window-system
(setq linum-relative-format my-linum-relative-format-fmt))
)
Problem is: The numbers background color don't change to the correct one when I change the theme while inside Emacs. The color remains the same. How do I make emacs update the linum and linum-relative background color after a color theme change?
I want to display parts of my mode line with different colors but it isn't working as expected and I can't find a good web reference for this. I can change the text to bold or italic but not change the colors as required.
The simplest possible example is to display a simple mode line with the buffer-file-name in white rather than the default face color.
(custom-set-variables
'(mode-line-format
(quote
("%e" mode-line-front-space
"[" mode-name "] %l:%i"
"\t"
propertize buffer-file-name 'font-lock-face '(:foreground "white")))))
Thanks to legosica for pointing out that I should have included other examples of what I've tried ...
Replacing 'font-lock-face with 'face:
propertize buffer-file-name 'face '(:foreground "white")))))
Follow Up
Thanks to TacticalCoder I now have exactly what I want - multiple fonts and colours in my modeline. The reason why setting 'face '(:foreground "white") didn't work is that it needed to be wrapped in '(:eval ...).
I ended up with this ...
(setq-default mode-line-format
(list
mode-line-front-space ; +-- just like in the default mode-line-format
'(:eval (propertize (concat "\t[" mode-name "] %l:%i\t") 'face '(:foreground "black" :height 0.9 :weight normal)
'help-echo (buffer-file-name)))
'(:eval (propertize (file-name-directory buffer-file-name) 'face 'info-title-4
'help-echo (buffer-file-name)))
'(:eval (propertize (file-name-nondirectory buffer-file-name) 'face 'info-title-3
'help-echo (buffer-file-name)))
))
Combined with ...
(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.
'(info-title-3 ((t (:inherit info-title-4 :foreground "white" :height 1.2))))
'(info-title-4 ((t (:inherit info-title-4 :foreground "black"))))
'(mode-line ((t (:background "#6483af" :foreground "#001122" :box (:line-width 3 :color "#6483af") :weight ultra-bold :height 118 :family "Monospace")))))
... I get a nice simple mode-line that demonstrates most of what I want. More work to do but thanks to TacticalCoder, I'm back on track.
Here's a tiny part of the custom modeline I'm using (I don't remember where I found it), modified as you asked to show the buffer name in another color. In this example I'm using font-lock-warning-face (which is 'red' in my color scheme):
This is not a complete modeline by any mean:
(setq-default mode-line-format
(list
mode-line-front-space ; +-- just like in the default mode-line-format
mode-line-mule-info ; |
mode-line-client ; |
;; the buffer name; the file name as a tool tip if you hover the mouse on it
'(:eval (propertize "%b " 'face 'font-lock-warning-face
'help-echo (buffer-file-name)))
'(:eval (propertize (if overwrite-mode "OVERWRITE" "")
'face 'font-lock-warning-face
'help-echo (concat "Buffer is in "
(if overwrite-mode "overwrite" "insert") " mode")))
"%-" ; fill what's left with '-'
))
Does that work for you? I did also put the part where OVERWRITE appears in font-lock-warning-face in case you turn overwrite on (I kinda hate being in overwrite mode, so I want it to be very obvious).
I'm looking for some assistance, please, to control bold faces in conjunction with overlays. With the standard font-lock method, it is generally sufficient to place :bold nil in the other face to prevent it from being trumped. However, that same concept doesn't seem to apply when dealing with overlays. When dealing with overlays, what else can be done to prevent bold from bleeding through to other faces?
For example: when two overlays overlap, how can I prevent tab-face bold from trumping hr-underscore-face?
(defface tab-face
'((t (:foreground "cyan" :bold t)))
"Face for `tab-face`."
:group 'lawlist-ruler-faces)
(defface hr-underscore-face
'((t (:underline "yellow" :bold nil)))
"Face for `hr-underscore-face`."
:group 'lawlist-ruler-faces)
EDIT (June 19, 2014): Added sample .emacs configuration to reproduce issue, and two screenshots. The path to the ispell-program-name would need to be set according to the user's own setup.
;; GNU Emacs 24.4.50.1 (x86_64-apple-darwin10.8.0,
;; NS appkit-1038.36 Version 10.6.8 (Build 10K549)) of 2014-06-01 on MP.local
(set-face-attribute 'default nil
:background "black" :foreground "white" :font "Courier" :height 180)
(tool-bar-mode -1)
(require 'ispell)
(require 'flyspell)
(setq-default ispell-program-name
"/Users/HOME/.0.data/.0.emacs/elpa/bin/aspell")
(custom-set-faces
'(flyspell-incorrect ((t (:foreground "yellow" :weight bold ))))
'(highlight ((t (:underline "yellow" :weight normal)))))
(defun zoom ()
(interactive)
(setq buffer-face-mode-face `(:height 575))
(buffer-face-mode 1))
(defun test-number-one ()
(interactive)
(switch-to-buffer (get-buffer-create "test-number-ONE"))
(zoom)
(turn-on-flyspell)
(setq flyspell-mark-duplications-flag nil)
(setq flyspell-duplicate-distance 0)
(hl-line-mode 1)
(insert
"This is `test-number-one`."
"\n"
"\n"
"Aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz"
"\n"
"\n"
"Aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz"))
(defun test-number-two ()
(interactive)
(switch-to-buffer (get-buffer-create "test-number-TWO"))
(zoom)
(hl-line-mode 1)
(insert
"This is `test-number-two`."
"\n"
"\n"
"Aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz"
"\n"
"\n"
"Aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz"))
In example number one, the underline is bold. [However, I'd like to learn how to make the underline consistently have a normal weight (even though the :foreground of the text is bold).]
(source: lawlist.com)
In example number two, the underline is normal.
(source: lawlist.com)
:bold is a compatibility alias. For finer control, use :weight, e.g.
(defface hr-underscore-face
'((t (:underline "yellow" :weight normal)))
"Face for `hr-underscore-face`."
:group 'lawlist-ruler-faces)
I don't see the problem you report, even with the code you posted (though I agree with #Stefan about :weight normal).
Evaluating your code I get this, which shows the yellow underline throughout the buffer and bold text only on a piece of the last line:
What am I missing? (This is with the buffer in Text mode and font-lock-mode turned off.)
Is there a way to dynamically change the color of the mode-line depending on specific conditions e.g. change color if I'm in narrowed view and to a different color if the buffer is read-only
Thank you very much!
You can use a post-command-hook and then just evaluate whatever you need and set the mode-line face color. I do this to change between 3 colors depending on which evil-mode state I'm in and if the buffer has any unsaved changes.
(lexical-let ((default-color (cons (face-background 'mode-line)
(face-foreground 'mode-line))))
(add-hook 'post-command-hook
(lambda ()
(let ((color (cond ((minibufferp) default-color)
((evil-insert-state-p) '("#e80000" . "#ffffff"))
((evil-emacs-state-p) '("#af00d7" . "#ffffff"))
((buffer-modified-p) '("#006fa0" . "#ffffff"))
(t default-color))))
(set-face-background 'mode-line (car color))
(set-face-foreground 'mode-line (cdr color))))))
I use this code. It colors the buffer-modified indicator on the left orange if it's read-only and red if it's modified. When you narrow a buffer it colors the line number indicator yellow. Obviously you might want to change the format yourself.
(defface my-narrow-face
'((t (:foreground "black" :background "yellow3")))
"todo/fixme highlighting."
:group 'faces)
(defface my-read-only-face
'((t (:foreground "black" :background "orange3")))
"Read-only buffer highlighting."
:group 'faces)
(defface my-modified-face
'((t (:foreground "gray80" :background "red4")))
"Modified buffer highlighting."
:group 'faces)
(setq-default
mode-line-format
'(" "
(:eval (let ((str (if buffer-read-only
(if (buffer-modified-p) "%%*" "%%%%")
(if (buffer-modified-p) "**" "--"))))
(if buffer-read-only
(propertize str 'face 'my-read-only-face)
(if (buffer-modified-p)
(propertize str 'face 'my-modified-face)
str))))
(list 'line-number-mode " ")
(:eval (when line-number-mode
(let ((str "L%l"))
(if (/= (buffer-size) (- (point-max) (point-min)))
(propertize str 'face 'my-narrow-face)
str))))
" %p"
(list 'column-number-mode " C%c")
" " mode-line-buffer-identification
" " mode-line-modes))