Overlays -- how to prevent bold faces from trumping non-bold faces - emacs

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.)

Related

Emacs 26.3 scrollbar refuses to move up if not moved up immediately

On Fedora Release 31. Using Xming on Windows 7 as X server. EDIT: also Emacs 24.3 running on RHEL7 with MobaXterm 12.2 4204, whether in -Q mode or not
The scrollbar I'm seeing is a medium-dark rectangle (the scrollbar "elevator") with rounded left-hand corners and square right-hand corners, in a light-gray vertical area (the scrollbar "track"). When I mouse over the rectangle it switches to dark gray.
When I click it, it turns blue. After about 1/2 second, if not moved, it narrows about 2 pixels on the right [EDIT: on the 24.3/RHEL7/MobaXterm setup, narrows on both sides], and refuses to move. Moving the mouse will sometimes get one scroll of the window contents, and sometimes not.
If I click it and move it slightly in that 1/2 second, it will move, and continue to be movable even if I hold still for a while. But I have to move it substantially (at least half its height, it seems, in a 2000 line file) or it will then freeze at the 1/2 second mark.
Here's my current .emacs file:
(defun switch-to-next-buffer-frank ()
(interactive)
(switch-to-buffer (other-buffer)))
(defun switch-to-prev-window ()
(interactive)
(other-window -1))
(defun scroll-one-line-up (&optional arg)
"Scroll the selected window up (forward in the text) one line (or N lines)."
(interactive "p")
(scroll-up (or arg 1)))
(defun scroll-one-line-down (&optional arg)
"Scroll the selected window down (backward in the text) one line (or N)."
(interactive "p")
(scroll-down (or arg 1)))
(global-set-key [(control ?z)] 'scroll-one-line-up)
(global-set-key [(meta ?z)] 'scroll-one-line-down)
(global-set-key [(meta ?g)] 'goto-line)
(global-set-key [(control ?x)(k)] 'kill-this-buffer)
(global-set-key [(control meta ?l)] 'switch-to-next-buffer)
(global-set-key [(control shift meta ?l)] 'switch-to-prev-buffer)
(global-set-key [(control tab)] 'other-window)
(global-set-key [(control shift iso-lefttab)] 'switch-to-prev-window)
(modify-syntax-entry ?_ "w")
(setq scroll-bar-mode 'left)
(setq scroll-bar-adjust-thumb-portion nil)
(setq gutter-buffers-tab-visible-p nil)
(setq inhibit-startup-screen t)
(setq mouse-yank-at-point t)
(setq inhibit-startup-buffer-menu t)
(tool-bar-mode -1)
(delete-selection-mode 1)
;(setq inhibit-splash-screen t)
;(setq inhibit-startup-message t)
;(setq initial-scratch-message nil)
;(delete-selection-mode 1)
;
;(defun ask-user-about-supersession-threat (fn)
; "blatantly ignore files that changed on disk"
; )
(custom-set-variables
;; custom-set-variables 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.
'(ansi-color-faces-vector
[default default default italic underline success warning error])
'(ansi-color-names-vector
["#3F3F3F" "#CC9393" "#7F9F7F" "#F0DFAF" "#8CD0D3" "#DC8CC3" "#93E0E3" "#DCDCCC"])
'(background-color "#000000")
'(background-mode dark)
'(company-quickhelp-color-background "#4F4F4F")
'(company-quickhelp-color-foreground "#DCDCCC")
'(cursor-color "#ffffff")
'(custom-enabled-themes (quote (manoj-dark)))
'(custom-safe-themes
(quote
("54f2d1fcc9bcadedd50398697618f7c34aceb9966a6cbaa99829eb64c0c1f3ca" "4138944fbed88c047c9973f68908b36b4153646a045648a22083bd622d1e636d" "8885761700542f5d0ea63436874bf3f9e279211707d4b1ca9ed6f53522f21934" "59e82a683db7129c0142b4b5a35dbbeaf8e01a4b81588f8c163bd255b76f4d21" default)))
'(fci-rule-color "#383838")
'(font-use-system-font t)
'(foreground-color "#00ff00")
'(gutter-buffers-tab-visible-p nil t)
'(indent-tabs-mode nil)
'(nrepl-message-colors
(quote
("#CC9393" "#DFAF8F" "#F0DFAF" "#7F9F7F" "#BFEBBF" "#93E0E3" "#94BFF3" "#DC8CC3")))
'(pdf-view-midnight-colors (quote ("#DCDCCC" . "#383838")))
'(query-user-mail-address nil)
'(tool-bar-mode nil)
'(user-mail-address "fsheeran#gmail.com")
'(vc-annotate-background "#2B2B2B")
'(vc-annotate-color-map
(quote
((20 . "#BC8383")
(40 . "#CC9393")
(60 . "#DFAF8F")
(80 . "#D0BF8F")
(100 . "#E0CF9F")
(120 . "#F0DFAF")
(140 . "#5F7F5F")
(160 . "#7F9F7F")
(180 . "#8FB28F")
(200 . "#9FC59F")
(220 . "#AFD8AF")
(240 . "#BFEBBF")
(260 . "#93E0E3")
(280 . "#6CA0A3")
(300 . "#7CB8BB")
(320 . "#8CD0D3")
(340 . "#94BFF3")
(360 . "#DC8CC3"))))
'(vc-annotate-very-old-color "#DC8CC3"))
(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 (:foreground "#00ff00" :background "#000000" :size "10pt" :family "DejaVu Sans Mono" :foundry "PfEd" :slant normal :weight normal :height 144 :width normal))))
'(font-lock-builtin-face ((t (:foreground "#00ccff"))))
'(font-lock-comment-delimiter-face ((t (:foreground "#ffff00" :slant normal))))
'(font-lock-comment-face ((t (:foreground "#ffff00" :slant normal))))
'(font-lock-constant-face ((t (:foreground "#00ff99" :weight normal))))
'(font-lock-function-name-face ((t (:foreground "#00ff00" :weight normal :height 1.0))))
'(font-lock-preprocessor-face ((t (:foreground "#ff4040"))))
'(font-lock-string-face ((t (:foreground "#00ffee"))))
'(font-lock-type-face ((t (:foreground "#33ccff"))))
'(font-lock-variable-name-face ((t (:foreground "#66ff00"))))
'(italic ((t nil)))
'(mode-line ((t (:background "#445555" :foreground "#ffffff" :box (:line-width 2 :color "#445555") :height 1.0))))
'(mode-line-buffer-id ((t (:background "#445555" :foreground "#55ff55" :weight normal :height 1.0))))
'(mode-line-emphasis ((t (:weight normal))))
'(mode-line-highlight ((t (:box (:line-width 2 :color "#445555")))))
'(mode-line-inactive ((t (:background "#445555" :foreground "#ffffff" :box (:line-width 2 :color "#445555") :weight normal :height 1.0))))
'(scroll-bar ((t (:background "#334444" :foreground "#ddffff")))))
Here's a screenshot: of emacs -Q 24.3/RHEL7/MobaXterm:
Then here is the same window after I've held the top scrollbar about 1 second without moving after clicking down:

How to color entries in emacs's ibuffer by buffer type?

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.

How to display text with different colors in mode-line

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).

only highlight "*", not the entire heading line in org-mode, emacs

How can I only highlight the * star, not the entire heading line, to keep texts in same color? In the great emacs org-mode
thanks guys
excample (replace * by #, for cann't bold * in stack-overflow)
(not below)
# heading text
this is text body
(but below)
# heading text
this is text body
Updated Answer
See the variable org-level-color-stars-only, which contains a doc-string that states: "Non-nil means fontify only the stars in each headline. When nil, the entire headline is fontified. Changing it requires restart of `font-lock-mode' to become effective also in regions already fontified."
USAGE:  (setq org-level-color-stars-only t)
Previous Answer
You can remove or add stars as you see fit -- this example uses two (2) stars together. If you do just one star, then that would also affect two (2) and three (3) stars together. Maybe one of our forum local regexp experts could please give us the code for one star (but not more than one star) :)
(defvar bumble-bee (make-face 'bumble-bee))
(set-face-attribute 'bumble-bee nil :background "black" :foreground "yellow")
(font-lock-add-keywords 'org-mode (list
(list (concat "\\*\\*")
'(0 bumble-bee t))
))
These control the title of tasks -- you could set them all the same or make them different. Anything you don't want, just set to nil or set to the same color as whatever your regular font is.
(custom-set-faces
'(org-level-1 ((t (:foreground "orange" :bold t))))
'(org-level-2 ((t (:foreground "black" :bold t))))
'(org-level-3 ((t (:foreground "pink" :bold t))))
'(org-level-4 ((t (:foreground "cyan" :bold t))))
)
The other components of the first line are usually: org-tag; org-tag-faces; org-todo-keyword-faces; org-priority-faces; and org-warning:
(setq org-todo-keyword-faces '(
("Active" . (:foreground "red"))
("Next Action" . (:foreground "ForestGreen"))
("Reference" . (:foreground "purple"))
("Someday" . (:foreground "gray65"))
("None" . (:foreground "green"))
("Delegated" . (:foreground "cyan")) ))
(setq org-tag-faces '(
("TODO" . org-warning)
))
(setq org-priority-faces '(
(?A . (:foreground "firebrick" :weight bold))
(?B . (:foreground "orange"))
(?C . (:foreground "green"))
(?D . (:foreground "purple"))
(?E . (:foreground "blue")) ))
(custom-set-faces
'(org-tag ((t (:background "gray97" :foreground "gray50"
:box (:line-width 1 :color "black") :weight regular))))
'(org-warning ((t (:foreground "black"))))
)

Custom background for active window

How can I configure a different background color for the active window in Emacs?
Try Yoshida's hiwin-mode (visible active window mode): https://github.com/yoshida-mediba/hiwin-mode
If by "window" you mean Emacs' definition of windows, i.e., panes, not really.
If by "window" you mean everyone else's conception of windows, which Emacs calls frames, then yes. Here's an example:
(defadvice handle-switch-frame (around switch-frame-set-background)
(set-background-color "white")
ad-do-it
(set-background-color "yellow"))
(ad-activate 'handle-switch-frame)
(defadvice delete-frame (after delete-frame-set-background)
(set-background-color "yellow"))
(ad-activate 'delete-frame)
Here is an alternative using the modeline inactive color matching the background so the only modeline with color is the active window. I have a hooks for the minibuffer enter and exit, and also when switching windows. I use bold for certain modeline things like read only and the file name, so that the a different color doesn't stand out when switching windows. When I enter the minibuffer, the active window modeline turns to inactive until I exit the minibuffer, or when I switch from an active minibuffer (leaving it open) to another window. I had to set the modeline background box to match also.
(set-face-attribute 'default nil :background "black" :foreground "white"
:font "Courier" :height 180)
(set-face-attribute 'mode-line nil
:height 160 ;; affects everything
:foreground "black" :background "gray70")
(set-face-attribute 'mode-line-inactive nil
:foreground "gray70" :background "black" :box '(:line-width 1 :color "black"))
(defun enter-minibuffer-setup ()
(whitespace-mode t)
(set-face-attribute 'mode-line nil
:height 160 :foreground "gray70" :background "black" :box '(:line-width 1 :color "black"))
(set-face-attribute 'minibuffer-prompt nil :background "black" :foreground "cyan")
(set (make-local-variable 'face-remapping-alist)
'((default :background "black" :foreground "yellow"))) )
(defun exit-minibuffer-setup ()
(cond
((or save-as-variable multi-extract-variable multi-attach-variable)
(set-face-attribute 'mode-line nil :height 160 :foreground "black" :background "#eab700"))
(t (set-face-attribute 'mode-line nil :height 160 :foreground "black" :background "gray70" :box nil)))
(set-face-attribute 'minibuffer-prompt nil :background "black" :foreground "cyan"))
(add-hook 'minibuffer-setup-hook 'enter-minibuffer-setup)
(add-hook 'minibuffer-exit-hook 'exit-minibuffer-setup)
(defun lawlist-minibuffer-conditions ()
(cond
((minibufferp)
(set-face-attribute 'mode-line nil
:height 160 :foreground "gray70" :background "black" :box '(:line-width 1 :color "black"))
(set-face-attribute 'minibuffer-prompt nil :background "black" :foreground "cyan"))
(t
(set-face-attribute 'mode-line nil
:height 160 :foreground "black" :background "gray70")
(set-face-attribute 'minibuffer-prompt nil :background "black" :foreground "gray70")) ))
(defun lawlist-forward-window ()
(interactive)
(other-window 1)
(lawlist-minibuffer-conditions))
(defun lawlist-backward-window ()
(interactive)
(other-window -1)
(lawlist-minibuffer-conditions))
ALTERNATIVE ANSWER (similar concept):  set-face-attribute is too slow for changing faces during redisplay. The preferred method for adjusting faces in that context is with the function face-remap-add-relative; however, that function is a little complicated to use because faces stack up one behind the other and get shadowed. So, I'll need to revise the following draft alternative answer (in the future) to incorporate face-remap-add-relative -- in the meantime, I'm setting the face-remapping-alist manually (which admittedly is not the preferred method according to the manual / doc-string).
(defvar modeline-selected-window nil)
(let ((default-background (face-background 'default nil 'default)))
(set-face-attribute 'mode-line-inactive nil :background default-background :box nil))
(defun modeline-record-selected-window ()
(setq modeline-selected-window (selected-window)))
(defun modeline-update-function ()
(cond
((minibufferp)
(let ((default-background (face-background 'default nil 'default)))
(with-selected-window (minibuffer-window)
(setq-local face-remapping-alist '(
(default :foreground "blue")
(minibuffer-prompt :foreground "red"))))
(setq-default face-remapping-alist `((mode-line ,'mode-line-inactive)))))
(t
(with-selected-window (minibuffer-window)
(when (local-variable-p 'face-remapping-alist)
(kill-local-variable 'face-remapping-alist)))
(setq-default face-remapping-alist nil))))
(defun modeline-set-format ()
(setq mode-line-format '(
(:eval
(if (eq modeline-selected-window (selected-window))
(propertize "SELECTED WINDOW" 'face 'font-lock-warning-face)
(propertize "NOT-SELECTED WINDOW" 'face 'font-lock-keyword-face)))))
;; next two lines make the affect immediately apparent
(setq modeline-selected-window (selected-window))
(force-mode-line-update))
(define-minor-mode modeline-mode
"This is a minor-mode for `modeline-mode`."
:init-value nil
:lighter " ML"
:keymap nil
:global t
:group nil
(cond
(modeline-mode
(add-hook 'post-command-hook 'modeline-record-selected-window)
(add-hook 'buffer-list-update-hook 'modeline-update-function)
(add-hook 'text-mode-hook 'modeline-set-format)
(when (called-interactively-p 'any)
(message "Globally turned ON `modeline-mode`.")))
(t
(remove-hook 'post-command-hook 'modeline-record-selected-window)
(remove-hook 'buffer-list-update-hook 'modeline-update-function)
(remove-hook 'text-mode-hook 'modeline-set-format)
(when (called-interactively-p 'any)
(message "Globally turned OFF `modeline-mode`.") ))))
(modeline-mode 1) ;; globally turn on minor-mode
If what you are trying to achieve is to highlight the current buffer/frame, the way I do that is through Highlight-Current-Line. It shows you the line where the cursor is, but a side effect of that is that it also shows you which buffer/frame you are in. You could configure it to highlight the entire buffer, or look into the code to see how they do it.
Crosshairs mode is your best bet, I think. It not only draws attention to the active window, but it also shows you immediately where the cursor is in an obvious way. You can easily toggle it on/off (I bind it to C-+.)
You can also use crosshairs-toggle-when-idle as an alternative. It does not show the crosshairs until a delay has past. It too is a toggle.
You can of course use crosshairs together with an in-your-face mode-line face.
I was using hiwin-mode as suggested in this topic but there is an open issue with shell buffers (when inactive, the text becomes invisible).
Therefore, another option which I'm enjoying so far is auto-dim-other-buffers mode.