I have defined a custom comment environment (through \usepackage{verbatim}):
\newenvironment{customComment}[1]
{
\noindent{\textsc{Commented bloc}: #1}}
\comment}
Commented block
{\endcomment}
What I want to do is to highlight the content of the \begin...\end{customComment} either:
as an already existing environment (font-lock-comment-face maybe but haven't found any working example); or
through a complete font/background etc. customization.
Already tried the defvar... solution from here and (for a similar command this time) this example.
Would be great if you found a solution that only needs editing the .emacs or adding a.el` (I've got a load of these customComments).
To the extent that the original poster (or anyone else) may be interested in highlighting the text that appears between opening/closing LaTeX codes, below are a few examples. The active ingredient is a regexp (\\(.\\|\n\\)+?\\), which could be something else that is also similar, but would need to effectively do the same thing. The following examples are set up to highlight text appearing between quotation marks that LaTeX artists frown upon, a bold command, an underline and a double underline using a tex package called ulem, bold and underline, and I threw in a begin/end document example so that the original poster (or anyone else) can combine the examples to make his / her own.
NOTE: As the definitions become more complex and tend to overlap other definitions, the order in which they appear may be critical -- i.e., one definition may trump another.
(font-lock-add-keywords 'latex-mode (list
(list (concat "\\(\"\\)\\(\\(.\\|\n\\)+?\\)\\(\"\\)")
'(1 lawlist-super-orange t)
'(2 lawlist-super-cyan t)
'(4 lawlist-super-orange t))
(list (concat "\\(\{\\)\\(\\\\bf\\)\\(\\(.\\|\n\\)+?\\)\\(\}\\)")
'(1 lawlist-regular t)
'(2 lawlist-purple t)
'(3 lawlist-bold t)
'(5 lawlist-regular t))
(list (concat "\\(\\\\uline\\|\\\\uuline\\)\\(\{\\)\\(\\(.\\|\n\\)+?\\)\\(\}\\)")
'(1 lawlist-green t)
'(2 lawlist-regular t)
'(3 lawlist-underline t)
'(5 lawlist-regular t))
(list (concat "\\(\{\\)\\(\\\\bf\\)\\(\\\\uline\\)\\(\{\\)\\(\\(.\\|\n\\)+?\\)\\(\}\\)\\(\}\\)")
'(1 lawlist-regular t)
'(2 lawlist-red t)
'(3 lawlist-blue t)
'(4 lawlist-regular t)
'(5 lawlist-bold-underline t)
'(7 lawlist-regular t)
'(8 lawlist-regular t))
(list (concat "\\(\\\\begin\\|\\\\end\\)\\(\{\\)\\(document\\)\\(\}\\)")
'(1 lawlist-super-orange t)
'(2 lawlist-super-SeaGreen t)
'(3 lawlist-super-HotPink1 t)
'(4 lawlist-super-SeaGreen t))
))
(defvar lawlist-regular (make-face 'lawlist-regular))
(set-face-attribute 'lawlist-regular nil
:background "white" :foreground "black")
(defvar lawlist-bold (make-face 'lawlist-bold))
(set-face-attribute 'lawlist-bold nil
:background "white" :foreground "black" :bold t)
(defvar lawlist-bold-underline (make-face 'lawlist-bold-underline))
(set-face-attribute 'lawlist-bold-underline nil
:background "white" :foreground "black" :bold t :underline "black")
(defvar lawlist-underline (make-face 'lawlist-underline))
(set-face-attribute 'lawlist-underline nil
:background "white" :foreground "black" :underline "black")
(defvar lawlist-bumble-bee (make-face 'lawlist-bumble-bee))
(set-face-attribute 'lawlist-bumble-bee nil
:background "black" :foreground "yellow" :bold t :underline "red")
(defvar lawlist-red (make-face 'lawlist-red))
(set-face-attribute 'lawlist-red nil
:background "white" :foreground "red" :bold t)
(defvar lawlist-blue (make-face 'lawlist-blue))
(set-face-attribute 'lawlist-blue nil
:background "white" :foreground "blue" :bold t)
(defvar lawlist-green (make-face 'lawlist-green))
(set-face-attribute 'lawlist-green nil
:background "white" :foreground "green3" :bold t)
(defvar lawlist-orange (make-face 'lawlist-orange))
(set-face-attribute 'lawlist-orange nil
:background "white" :foreground "orange" :bold t)
(defvar lawlist-purple (make-face 'lawlist-purple))
(set-face-attribute 'lawlist-purple nil
:background "white" :foreground "purple" :bold t)
(defvar lawlist-pink (make-face 'lawlist-pink))
(set-face-attribute 'lawlist-pink nil
:background "white" :foreground "pink" :bold t)
(defvar lawlist-super-orange (make-face 'lawlist-super-orange))
(set-face-attribute 'lawlist-super-orange nil
:background "white" :foreground "orange" :bold t :underline nil)
(defvar lawlist-super-cyan (make-face 'lawlist-super-cyan))
(set-face-attribute 'lawlist-super-cyan nil
:background "white" :foreground "cyan" :bold t :underline nil)
(defvar lawlist-super-blue (make-face 'lawlist-super-blue))
(set-face-attribute 'lawlist-super-blue nil
:background "white" :foreground "blue" :bold t :underline nil)
(defvar lawlist-super-red (make-face 'lawlist-super-red))
(set-face-attribute 'lawlist-super-red nil
:background "white" :foreground "red" :bold t :underline nil)
(defvar lawlist-super-purple (make-face 'lawlist-super-purple))
(set-face-attribute 'lawlist-super-purple nil
:background "white" :foreground "purple" :bold t :underline nil)
(defvar lawlist-super-HotPink1 (make-face 'lawlist-super-HotPink1))
(set-face-attribute 'lawlist-super-HotPink1 nil
:background "white" :foreground "HotPink1" :bold t :underline nil)
(defvar lawlist-super-SeaGreen (make-face 'lawlist-super-SeaGreen))
(set-face-attribute 'lawlist-super-SeaGreen nil
:background "white" :foreground "SeaGreen" :bold t :underline nil)
In the tex-mode that's built into Emacs you could do that by adding your environment to tex-verbatim-environments.
Related
The following function named my-modeline-face-function causes Emacs to pause for approximately one-half to one full second, and I'm looking for some suggestions please to significantly increase the speed.
It doesn't seem like much, but this function is used a lot. For example, every time I enable multiple-cursors mode (aka mc-mode), I end up twiddling my thumbs before I can get down to business -- the same thing happens when exiting multiple-cursors mode.
Adding (redisplay t) at the tail end of the function does nothing to increase the speed.
Using (force-mode-line-update) following this function does not increase the speed.
(defun my-modeline-face-function ()
(cond
((minibufferp)
(set-face-attribute 'mode-line nil :height 140 :foreground "gray70"
:background "black" :box '(:line-width 1 :color "black"))
(set-face-attribute 'minibuffer-prompt nil :background "black"
:foreground "cyan" :bold t)
(set (make-local-variable 'face-remapping-alist)
'((default :background "black" :foreground "yellow"))))
(save-as-variable
(set-face-attribute 'mode-line nil :height 140
:foreground "black" :background "#eab700" :box nil))
(insert-variable
(set-face-attribute 'mode-line nil :height 140
:foreground "black" :background "orange" :box nil))
((or multi-extract-variable multi-attach-variable)
(set-face-attribute 'mode-line nil :height 140
:foreground "black" :background "magenta" :box nil))
(open-with-variable
(set-face-attribute 'mode-line nil :height 140
:foreground "black" :background "ForestGreen" :box nil))
(mc-mode
(set-face-attribute 'mode-line nil :height 140
:foreground "black" :background "cyan" :box nil))
(isearch-mode
(set-face-attribute 'mode-line nil :height 140
:foreground "black" :background "yellow" :box nil))
((eq major-mode 'lawlist-calculator-mode)
(set-face-attribute 'mode-line nil :height 140
:foreground "black" :background "firebrick" :box nil))
(t
(set-face-attribute 'mode-line nil :height 140
:foreground "black" :background "gray70" :box nil)
(set-face-attribute 'minibuffer-prompt nil
:background "black" :foreground "white"))) )
EDIT (August 5, 2014):
● Using a measure-time macro (i.e., http://lists.gnu.org/archive/html/help-gnu-emacs/2008-06/msg00087.html ), I verified that the run-time for the function internal-set-lisp-face-attribute within set-face-attribute occurs within mere fractions of a second. However, it takes up to one full second for me to see the visual effect. The same holds true whether it is the initial call of the function or subsequent calls within the same buffer.
● As to the first call of face-remapping-alist within a buffer, the visual effect takes up to one full second for me to see. However, subsequent calls using the face-remapping-alist within that same buffer occur within fractions of the second. I have not been able to eliminate the time needed to see the visual effect following the first call. This may be as good as it gets -- i.e., up to one full second for the first call, and light speed for subsequent calls within that same buffer.
(defun my-modeline-face-function ()
(cond
((minibufferp)
(set 'face-remapping-alist '(
(mode-line modeline-inactive-face)
(minibuffer-prompt minibuffer-prompt-active-face))) )
(save-as-variable
(set 'face-remapping-alist '((mode-line save-as-modeline-face))))
(insert-variable
(set 'face-remapping-alist '((mode-line insert-modeline-face))))
((or multi-extract-variable multi-attach-variable)
(set 'face-remapping-alist '((mode-line multi-attach-extract-modeline-face))))
(open-with-variable
(set 'face-remapping-alist '((mode-line open-with-modeline-face))))
(mc-mode
(set 'face-remapping-alist '((mode-line mc-modeline-face))))
(isearch-mode
(set 'face-remapping-alist '((mode-line isearch-modeline-face))))
((eq major-mode 'lawlist-calculator-mode)
(set 'face-remapping-alist '((mode-line lawlist-calculator-modeline-face))))
(t
(set 'face-remapping-alist '(
(mode-line modeline-active-face)
(minibuffer-prompt minibuffer-prompt-inactive-face))) )))
Changing faces dynamically is going to be slow because the redisplay code is written under the assumption that faces don't change (if they change, we basically redo a lot of work). Using face-remapping-alist will result in much better performance because the redisplay code does expect it to change and know how to cache the result.
I'm looking for some assistance, please, further modifying the following already modified excerpt from the highlight-parentheses library: https://github.com/nschum/highlight-parentheses.el [Fn 1.]
GOAL: The goal is to use something like mapcar or dolist to automatically replace INSERT-FACE-HERE with a different face from the variable my-parens-faces each time while does a loop. The visual effect will be a rainbow coloring of parentheses based on the level of nesting.
I am removing the overlays with a post-command-hook and a function similar to remove-overlays, and then subsequently adding new overlays with the parens function below. I will not be moving any overlays -- just creating and deleting. The final version will use variables for the faces and target specific overlays for removal, but here is a sample of what it will look like: (add-hook 'post-command-hook (lambda () (remove-overlays) (parens)))
Each time while does a loop, I want to insert a different face from the variable my-parens-faces -- going in order, like dolist. For example:
while doing loop # 1: (:foreground "black" :background "cyan")
while doing loop # 2: (:foreground "blue" :background "purple")
while doing loop # 3: (:foreground "green" :background "blue")
while doing loop # 4: (:foreground "yellow" :background "purple")
while doing loop # 5: (:foreground "orange" :background "yellow")
while doing loop # 6: (:foreground "red" :background "green")
while doing loop # 7: (:foreground "pink" :background "brown")
while doing loop # 8: (:foreground "blue" :background "beige")
(defun parens ()
(let* (pos1 pos2)
(save-excursion
(condition-case err
(while (setq pos1 (cadr (syntax-ppss pos1)))
(overlay-put (make-overlay pos1 (1+ pos1)) 'face 'INSERT-FACE-HERE)
(when (setq pos2 (scan-sexps pos1 1))
(overlay-put (make-overlay (1- pos2) pos2) 'face 'INSERT-FACE-HERE)))
(error nil)) )))
(defvar my-parens-faces '(
(:foreground "black" :background "cyan")
(:foreground "blue" :background "purple")
(:foreground "green" :background "blue")
(:foreground "yellow" :background "purple")
(:foreground "orange" :background "yellow")
(:foreground "red" :background "green")
(:foreground "pink" :background "brown")
(:foreground "blue" :background "beige")))
[Footnote number 1: Reference to the highlight-parentheses library is not needed to answer this question, but the reference is being included so that proper attribute is made to the author (i.e., Nikolaj Schumacher) who inspired the parens function in this question.]
(defvar parens-mode-command-exclusions '(mwheel-scroll scroll-up scroll-down)
"List of functions that are excluded from triggering the function `parens'.")
(defvar parens-mode-syntax-table
(let ((st (make-syntax-table)))
st)
"Syntax table used while executing the function `parens'.")
(defgroup parens nil
"Faces for highlighting parentheses in `parens-mode'."
:group 'parens)
(defface parens-one-face
'((t (:foreground "magenta")))
"Face for `parens-one-face'."
:group 'parens)
(defface parens-two-face
'((t (:foreground "red")))
"Face for `parens-two-face'."
:group 'parens)
(defface parens-three-face
'((t (:foreground "yellow")))
"Face for `parens-three-face'."
:group 'parens)
(defface parens-four-face
'((t (:foreground "green")))
"Face for `parens-four-face'."
:group 'parens)
(defface parens-five-face
'((t (:foreground "cyan")))
"Face for `parens-five-face'."
:group 'parens)
(defface parens-six-face
'((t (:foreground "orange")))
"Face for `parens-six-face'."
:group 'parens)
(defface parens-seven-face
'((t (:foreground "purple")))
"Face for `parens-seven-face'."
:group 'parens)
(defface parens-eight-face
'((t (:foreground "blue")))
"Face for `parens-eight-face'."
:group 'parens)
(defface parens-nine-face
'((t (:foreground "brown")))
"Face for `parens-nine-face'."
:group 'parens)
(defface parens-ten-face
'((t (:foreground "white")))
"Face for `parens-ten-face'."
:group 'parens)
(defvar parens-overlays-exist-p nil
"Simple test to see whether the parens overlays have been placed.")
(make-variable-buffer-local 'parens-overlays-exist-p)
(defun parens ()
"Portions of this function were borrowed from the library
`highlight-parentheses` written by Nikolaj Schumacher.
https://github.com/nschum/highlight-parentheses.el"
(unless (memq this-command parens-mode-command-exclusions)
(with-syntax-table parens-mode-syntax-table
(let* (
(pt (point))
(pos1 (if
(or
(= pt (point-min))
(eq (preceding-char) 40) ;; open-parentheses
(eq (preceding-char) 91) ;; open-squre-bracket
(eq (preceding-char) 123)) ;; open-wavy-bracket
pt
(1- pt)))
pos2
selected-face
(i 0) )
(remove-parens-overlays)
(save-excursion
(condition-case nil
(while (setq pos1 (cadr (syntax-ppss pos1)))
(if (= i 10)
(setq i 1)
(setq i (1+ i)))
(cond
((= i 1)
(setq selected-face 'parens-one-face))
((= i 2)
(setq selected-face 'parens-two-face))
((= i 3)
(setq selected-face 'parens-three-face))
((= i 4)
(setq selected-face 'parens-four-face))
((= i 5)
(setq selected-face 'parens-five-face))
((= i 6)
(setq selected-face 'parens-six-face))
((= i 7)
(setq selected-face 'parens-seven-face))
((= i 8)
(setq selected-face 'parens-eight-face))
((= i 9)
(setq selected-face 'parens-nine-face))
((= i 10)
(setq selected-face 'parens-ten-face)) )
(overlay-put (make-overlay pos1 (1+ pos1)) 'face selected-face)
(when (setq pos2 (scan-sexps pos1 1))
(overlay-put (make-overlay (1- pos2) pos2) 'face selected-face)))
(error nil) ))
(setq parens-overlays-exist-p t)))))
(defun remove-parens-overlays ()
(when parens-overlays-exist-p
(dolist (face '(
parens-one-face
parens-two-face
parens-three-face
parens-four-face
parens-five-face
parens-six-face
parens-seven-face
parens-eight-face
parens-nine-face
parens-ten-face))
(remove-overlays nil nil 'face face))
(setq parens-overlays-exist-p nil)))
(defun turn-off-parens-mode ()
(parens-mode -1))
(define-minor-mode parens-mode
"A minor-mode for highlighting parentheses."
:init-value nil
:lighter " ‹›"
:keymap nil
:global nil
:group 'parens
(cond
(parens-mode
(add-hook 'post-command-hook 'parens t t)
(add-hook 'change-major-mode-hook 'turn-off-parens-mode nil t)
(when (called-interactively-p 'any)
(message "Turned ON `parens-mode`.")))
(t
(remove-hook 'post-command-hook 'parens t)
(remove-hook 'change-major-mode-hook 'turn-off-parens-mode t)
(remove-parens-overlays)
(when (called-interactively-p 'any)
(message "Turned OFF `parens-mode`.")))))
Within the same frame and with an active minibuffer, can anyone think of a way to have switch to other-window behave similar to a minibuffer-exit-hook (without completely exiting the minibuffer)?
Essentially, I'd like to have the main windows show an inactive modeline color when focus is in the minibuffer, and then update the modline to active (for a window that has focus) when I move from the semi-active minibuffer to another window using other-window.
For example, there are two windows open in the same frame (side by side) -- Window # 1 are my notes -- Window # 2 is a Big Brother Database display of a record that I want to modify. So I open the minibuffer to input my record modification and then switch back and forth between my notes in Window # 1 and the minibuffer to copy and paste the relevant portions. When using other-window to jump between the three areas, it is still difficult to know whether focus is in the minibuffer or another window.
Window # 1 (notes) | Window # 2 (bbdb record display)
|
___________________________|_____________________________________
Name: lawlist . . .
(defun enter-minibuffer-setup ()
(set-face-attribute 'mode-line nil
:height 160 :foreground "gray70" :background "black")
(set (make-local-variable 'face-remapping-alist)
'((default :background "gray10" :foreground "yellow"))))
(defun exit-minibuffer-setup ()
(set-face-attribute 'mode-line nil
:height 160 :foreground "black" :background "gray70"))
(add-hook 'minibuffer-setup-hook 'enter-minibuffer-setup)
(add-hook 'minibuffer-exit-hook 'exit-minibuffer-setup)
One option would be to "advise" the other-window function to execute some form when switching to the minibuffer.
For example, the following code will turn the minibuffer prompt green when you cycle back to it using other-window, and if you land on a non minibuffer window it turns the prompt grey:
(defadvice other-window (after adv-other-window-minibuffer
(COUNT &optional ALL-FRAMES))
"Make minibuffer prompt green when switched to"
(if (minibufferp)
(set-face-attribute 'minibuffer-prompt nil
:foreground "green" :background "black")
(set-face-attribute 'minibuffer-prompt nil
:foreground "dark grey" :background "black")))
(ad-activate 'other-window)
Of course you are not limited to just setting the minibuffer prompt, but it's not clear to me exactly what effect your are trying to achieve.
Updated draft -- borrowing (minibufferp) from #Carl Groner
(defun enter-minibuffer-setup ()
(set-face-attribute 'mode-line nil
:height 160 :foreground "gray70" :background "black")
(set (make-local-variable 'face-remapping-alist)
'((default :background "black" :foreground "yellow")))
(set-face-attribute 'minibuffer-prompt nil
:background "black" :foreground "cyan"))
(defun exit-minibuffer-setup ()
(set-face-attribute 'mode-line nil
:height 160 :foreground "black" :background "gray70")
(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")
(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))
I want to define a bunch of faces for different characters like below:
(defface char-face-a
'((((type tty) (class color)) (:background "yellow" :foreground "black"))
(((type tty) (class mono)) (:inverse-video t))
(((class color) (background dark)) (:background "yellow" :foreground "black"))
(((class color) (background light)) (:background "yellow" :foreground "black"))
(t (:background "gray")))
"Face for marking up A's"
:group 'char-faces)
(defface char-face-b
'((((type tty) (class color)) (:background "red" :foreground "black"))
(((type tty) (class mono)) (:inverse-video t))
(((class color) (background dark)) (:background "red" :foreground "black"))
(((class color) (background light)) (:background "red" :foreground "black"))
(t (:background "gray")))
"Face for marking up B's"
:group 'char-faces)
...
...
Is there anyway to avoid explicitly write all the defface definitions and make the code less redundant? (I know make-face, but it seems deprecated and can't set attributes according to different terminal types as defface does.)
make-face is not at all deprecated, AFAICT.
defface can make use of inheritance -- see face attribute :inherit.
Dunno whether that helps in your particular context.
How about a macro and a loop that operates on a mapping of suffixes <-> colors:
(defmacro brian-def-char-face (letter backgrnd foregrnd)
`(defface ,(intern (concat "brian-char-face-"
letter))
'((((type tty) (class color))
(:background
,backgrnd
:foreground
,foregrnd))
(((type tty) (class color)) (:inverse-video t))
(((class color) (background dark))
(:foreground
,foregrnd
:background
,backgrnd))
(((class color) (background light))
(:foreground
,foregrnd
:background
,backgrnd))
(t (:background "gray")))
,(concat "Face for marking up " (upcase letter) "'s")))
(let ((letcol-alist '((s . (white black))
(t . (black yellow))
(u . (green pink)))))
(loop for elem in letcol-alist
for l = (format "%s" (car elem))
for back = (format "%s" (cadr elem))
for fore = (format "%s" (caddr elem))
do
(eval (macroexpand `(brian-def-char-face ,l ,back ,fore)))))
Gives you new faces:
brian-char-face-s, brian-char-face-t, and brian-char-face-u
Now you just need to maintain the list of letter<->color mappings, and possibly extend the macro to support other face properties (if desired).
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.