|
;;; fancy-banner.el -*- lexical-binding: t; -*-
|
|
;;; Commentary:
|
|
;;
|
|
;; See https://github.com/tecosaur/emacs-config/blob/master/config.org
|
|
;;
|
|
;;; Code:
|
|
;;;
|
|
(setq +doom-dashboard--width 120)
|
|
|
|
(defvar fancy-splash-image-template
|
|
(expand-file-name "misc/splash-images/blackhole-lines-template.svg" doom-private-dir)
|
|
"Default template svg used for the splash image, with substitutions from ")
|
|
(defvar fancy-splash-image-nil
|
|
(expand-file-name "misc/splash-images/transparent-pixel.png" doom-private-dir)
|
|
"An image to use at minimum size, usually a transparent pixel")
|
|
|
|
(defvar fancy-splash-sizes
|
|
`((:height 400 :min-height 50 :padding (0 . 2))
|
|
(:height 350 :min-height 42 :padding (1 . 4))
|
|
(:height 300 :min-height 35 :padding (1 . 3))
|
|
(:height 250 :min-height 30 :padding (1 . 2))
|
|
(:height 0 :min-height 0 :padding (0 . 0) :file ,fancy-splash-image-nil))
|
|
"list of plists with the following properties
|
|
:height the height of the image
|
|
:min-height minimum `frame-height' for image
|
|
:padding `+doom-dashboard-banner-padding' to apply
|
|
:template non-default template file
|
|
:file file to use instead of template")
|
|
|
|
(setq fancy-splash-sizes
|
|
`((:height 400 :min-height 40 :padding (0 . 4) :template ,(expand-file-name "misc/splash-images/blackhole-lines-0.svg" doom-private-dir))
|
|
(:height 350 :min-height 32 :padding (1 . 4) :template ,(expand-file-name "misc/splash-images/blackhole-lines-0.svg" doom-private-dir))
|
|
(:height 300 :min-height 28 :padding (1 . 4) :template ,(expand-file-name "misc/splash-images/blackhole-lines-1.svg" doom-private-dir))
|
|
(:height 250 :min-height 26 :padding (1 . 3) :template ,(expand-file-name "misc/splash-images/blackhole-lines-2.svg" doom-private-dir))
|
|
(:height 200 :min-height 24 :padding (1 . 3) :template ,(expand-file-name "misc/splash-images/blackhole-lines-3.svg" doom-private-dir))
|
|
(:height 150 :min-height 22 :padding (1 . 2) :template ,(expand-file-name "misc/splash-images/blackhole-lines-4.svg" doom-private-dir))
|
|
(:height 100 :min-height 20 :padding (1 . 2) :template ,(expand-file-name "misc/splash-images/blackhole-lines-5.svg" doom-private-dir))
|
|
(:height 100 :min-height 14 :padding (1 . 2) :template ,(expand-file-name "misc/splash-images/emacs-e-template.svg" doom-private-dir))
|
|
(:height 0 :min-height 0 :padding (0 . 0) :file ,fancy-splash-image-nil)))
|
|
|
|
|
|
(defvar fancy-splash-template-colours
|
|
'(("$colour1" . keywords) ("$colour2" . type) ("$colour3" . base5) ("$colour4" . base8))
|
|
"list of colour-replacement alists of the form (\"$placeholder\" . 'theme-colour) which applied the template")
|
|
|
|
(unless (file-exists-p (expand-file-name "theme-splashes" doom-cache-dir))
|
|
(make-directory (expand-file-name "theme-splashes" doom-cache-dir) t))
|
|
|
|
(defun fancy-splash-filename (theme-name height)
|
|
(expand-file-name (concat (file-name-as-directory "theme-splashes")
|
|
theme-name
|
|
"-" (number-to-string height) ".svg")
|
|
doom-cache-dir))
|
|
|
|
(defun fancy-splash-clear-cache ()
|
|
"Delete all cached fancy splash images"
|
|
(interactive)
|
|
(delete-directory (expand-file-name "theme-splashes" doom-cache-dir) t)
|
|
(message "Cache cleared!"))
|
|
|
|
(defun fancy-splash-generate-image (template height)
|
|
"Read TEMPLATE and create an image if HEIGHT with colour substitutions as
|
|
described by `fancy-splash-template-colours' for the current theme"
|
|
(with-temp-buffer
|
|
(insert-file-contents template)
|
|
(re-search-forward "$height" nil t)
|
|
(replace-match (number-to-string height) nil nil)
|
|
(dolist (substitution fancy-splash-template-colours)
|
|
(goto-char (point-min))
|
|
(while (re-search-forward (car substitution) nil t)
|
|
(replace-match (doom-color (cdr substitution)) nil nil)))
|
|
(write-region nil nil
|
|
(fancy-splash-filename (symbol-name doom-theme) height) nil nil)))
|
|
|
|
(defun fancy-splash-generate-images ()
|
|
"Perform `fancy-splash-generate-image' in bulk"
|
|
(dolist (size fancy-splash-sizes)
|
|
(unless (plist-get size :file)
|
|
(fancy-splash-generate-image (or (plist-get size :file)
|
|
(plist-get size :template)
|
|
fancy-splash-image-template)
|
|
(plist-get size :height)))))
|
|
|
|
(defun ensure-theme-splash-images-exist (&optional height)
|
|
(unless (file-exists-p (fancy-splash-filename
|
|
(symbol-name doom-theme)
|
|
(or height
|
|
(plist-get (car fancy-splash-sizes) :height))))
|
|
(fancy-splash-generate-images)))
|
|
|
|
(defun get-appropriate-splash ()
|
|
(let ((height (frame-height)))
|
|
(cl-some (lambda (size) (when (>= height (plist-get size :min-height)) size))
|
|
fancy-splash-sizes)))
|
|
|
|
(setq fancy-splash-last-size nil)
|
|
(setq fancy-splash-last-theme nil)
|
|
(defun set-appropriate-splash (&rest _)
|
|
(let ((appropriate-image (get-appropriate-splash)))
|
|
(unless (and (equal appropriate-image fancy-splash-last-size)
|
|
(equal doom-theme fancy-splash-last-theme)))
|
|
(unless (plist-get appropriate-image :file)
|
|
(ensure-theme-splash-images-exist (plist-get appropriate-image :height)))
|
|
(setq fancy-splash-image
|
|
(or (plist-get appropriate-image :file)
|
|
(fancy-splash-filename (symbol-name doom-theme) (plist-get appropriate-image :height))))
|
|
(setq +doom-dashboard-banner-padding (plist-get appropriate-image :padding))
|
|
(setq fancy-splash-last-size appropriate-image)
|
|
(setq fancy-splash-last-theme doom-theme)
|
|
(+doom-dashboard-reload)))
|
|
|
|
(add-hook 'window-size-change-functions #'set-appropriate-splash)
|
|
(add-hook 'doom-load-theme-hook #'set-appropriate-splash)
|
|
|
|
(provide 'fancy-banner)
|
|
;; fancy-banner.el ends here
|