diff options
| author | Craig Jennings <c@cjennings.net> | 2026-06-15 23:29:35 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-06-15 23:29:35 -0500 |
| commit | c0c6e72684387f990fda1096e842f1f100ddb3e5 (patch) | |
| tree | c5a310db35ffb543df2773d3c239642b15bfe3d2 /modules/system-utils.el | |
| parent | 07738d4f58f463c20ab70b5f336b2911f5f9d521 (diff) | |
| download | dotemacs-c0c6e72684387f990fda1096e842f1f100ddb3e5.tar.gz dotemacs-c0c6e72684387f990fda1096e842f1f100ddb3e5.zip | |
feat(system-utils): tint the *scratch* background a shade lighter
A buffer-local face remap lightens the *scratch* default background by cj/scratch-background-lighten percent (default 5) so it reads as the scratch buffer, applied on emacs-startup-hook. The colour math is display-dependent (verified live); the pure helper's guard contract is unit-tested.
Diffstat (limited to 'modules/system-utils.el')
| -rw-r--r-- | modules/system-utils.el | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/modules/system-utils.el b/modules/system-utils.el index 7cf958674..b3e038ef0 100644 --- a/modules/system-utils.el +++ b/modules/system-utils.el @@ -157,12 +157,39 @@ detached from Emacs." ;; Set scratch buffer to org-mode (setopt initial-major-mode 'org-mode) -;; Move cursor to end of scratch buffer on startup +;; Tint the *scratch* background a shade lighter than the default so it reads +;; as the scratch buffer at a glance. Buffer-local face remap, recomputed from +;; whatever theme is loaded. +(require 'color) + +(defcustom cj/scratch-background-lighten 5 + "Percent to lighten the *scratch* background above the default background. +Aesthetic; tune to taste." + :type 'integer + :group 'convenience) + +(defun cj/--scratch-lightened-background (bg) + "Return BG lightened by `cj/scratch-background-lighten' percent. +Return nil when BG is not a usable color string (e.g. `unspecified')." + (when (and (stringp bg) (color-name-to-rgb bg)) + (color-lighten-name bg cj/scratch-background-lighten))) + +(defun cj/scratch-apply-background () + "Remap the *scratch* buffer background a shade lighter than the default." + (when (get-buffer "*scratch*") + (with-current-buffer "*scratch*" + (let ((lighter (cj/--scratch-lightened-background + (face-attribute 'default :background nil t)))) + (when lighter + (face-remap-add-relative 'default :background lighter)))))) + +;; Move cursor to end of scratch buffer on startup, and tint its background (add-hook 'emacs-startup-hook (lambda () (when (get-buffer "*scratch*") (with-current-buffer "*scratch*" - (goto-char (point-max)))))) + (goto-char (point-max)))) + (cj/scratch-apply-background))) ;;; --------------------------------- Dictionary -------------------------------- |
