Created
December 3, 2017 20:27
-
-
Save gonewest818/ca6cbe8732ba1dd4b968c73f22d9a480 to your computer and use it in GitHub Desktop.
elisp to "dim" faces except in the current window - work in progress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; This buffer is for text that is not saved, and for Lisp evaluation. | |
;; To create a file, visit it with C-x C-f and enter text in its buffer. | |
(setq face-remapping-alist nil) | |
(with-selected-window (get-buffer-window "*eshell*") | |
(setq face-remapping-alist nil) | |
(redraw-display)) | |
;; ====================================================================== | |
(defvar dimmer-face-remaps (make-hash-table)) | |
(defvar dimmer-last-buffer nil) | |
(defvar dimmer-percent 0.80) | |
(defvar dimmer-invert nil) | |
(defun dimmer-face-color (f pct &optional invert) | |
(when-let ((fg (face-foreground f))) | |
(if invert | |
(apply 'color-rgb-to-hex | |
(mapcar (lambda (x) (- 1 (* (- 1 x) pct))) | |
(color-name-to-rgb fg))) | |
(apply 'color-rgb-to-hex | |
(mapcar (lambda (x) (* x pct)) | |
(color-name-to-rgb fg)))))) | |
;; (dimmer-face-color 'default 0.1 t) | |
;; (dimmer-face-color 'hiwin-face 0.5) | |
(defun dimmer-dim-window (name pct &optional invert) | |
(let ((win (get-buffer-window name)) | |
(cookies nil)) | |
(unless (gethash win dimmer-face-remaps) | |
(with-selected-window win | |
(puthash win | |
(dolist (f (face-list) cookies) | |
(when-let ((c (dimmer-face-color f pct invert))) | |
(setq cookies | |
(cons (face-remap-add-relative f :foreground c) cookies)))) | |
dimmer-face-remaps))))) | |
(defun dimmer-restore-window (name) | |
(let ((win (get-buffer-window name))) | |
(when-let ((cookies (gethash win dimmer-face-remaps))) | |
(with-selected-window win | |
(dolist (c cookies) | |
(face-remap-remove-relative c))) | |
(remhash win dimmer-face-remaps)))) | |
;; (dimmer-dim-window "hiwin.el" 0.70) | |
;; (gethash (get-buffer-window "*eshell*") dimmer-face-remaps) | |
;; (dimmer-restore-window "hiwin.el") | |
;;;###autoload | |
(defun dimmer-activate () | |
(interactive) | |
(add-hook 'post-command-hook 'dimmer-command-hook)) | |
;;;###autoload | |
(defun dimmer-deactivate () | |
(interactive) | |
(remove-hook 'post-command-hook 'dimmer-command-hook) | |
(dimmer-delete-all)) | |
(defun fih () | |
(message (concat "focus in: " (buffer-name (window-buffer (selected-window)))))) | |
(defun foh () | |
(message (concat "focus out: " (buffer-name (window-buffer (selected-window)))))) | |
;; (add-hook 'focus-in-hook 'fih) | |
;; (add-hook 'focus-out-hook 'foh) | |
(defun dimmer-command-hook () | |
(unless (eq (current-buffer) dimmer-last-buffer) | |
(let ((current (current-buffer)) | |
(previous dimmer-last-buffer)) | |
(setq dimmer-last-buffer current) | |
(when current | |
(dimmer-restore-window (buffer-name current))) | |
(when previous | |
(dimmer-dim-window (buffer-name previous) dimmer-percent dimmer-invert))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment