My personal configuration files for Doom emacs
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
5.7 KiB

  1. ;;; fancy-banner.el -*- lexical-binding: t; -*-
  2. ;;; Commentary:
  3. ;;
  4. ;; See https://github.com/tecosaur/emacs-config/blob/master/config.org
  5. ;;
  6. ;;; Code:
  7. ;;;
  8. (setq +doom-dashboard--width 120)
  9. (defvar fancy-splash-image-template
  10. (expand-file-name "misc/splash-images/blackhole-lines-template.svg" doom-private-dir)
  11. "Default template svg used for the splash image, with substitutions from ")
  12. (defvar fancy-splash-image-nil
  13. (expand-file-name "misc/splash-images/transparent-pixel.png" doom-private-dir)
  14. "An image to use at minimum size, usually a transparent pixel")
  15. (defvar fancy-splash-sizes
  16. `((:height 400 :min-height 50 :padding (0 . 2))
  17. (:height 350 :min-height 42 :padding (1 . 4))
  18. (:height 300 :min-height 35 :padding (1 . 3))
  19. (:height 250 :min-height 30 :padding (1 . 2))
  20. (:height 0 :min-height 0 :padding (0 . 0) :file ,fancy-splash-image-nil))
  21. "list of plists with the following properties
  22. :height the height of the image
  23. :min-height minimum `frame-height' for image
  24. :padding `+doom-dashboard-banner-padding' to apply
  25. :template non-default template file
  26. :file file to use instead of template")
  27. (setq fancy-splash-sizes
  28. `((:height 400 :min-height 40 :padding (0 . 4) :template ,(expand-file-name "misc/splash-images/blackhole-lines-0.svg" doom-private-dir))
  29. (:height 350 :min-height 32 :padding (1 . 4) :template ,(expand-file-name "misc/splash-images/blackhole-lines-0.svg" doom-private-dir))
  30. (:height 300 :min-height 28 :padding (1 . 4) :template ,(expand-file-name "misc/splash-images/blackhole-lines-1.svg" doom-private-dir))
  31. (:height 250 :min-height 26 :padding (1 . 3) :template ,(expand-file-name "misc/splash-images/blackhole-lines-2.svg" doom-private-dir))
  32. (:height 200 :min-height 24 :padding (1 . 3) :template ,(expand-file-name "misc/splash-images/blackhole-lines-3.svg" doom-private-dir))
  33. (:height 150 :min-height 22 :padding (1 . 2) :template ,(expand-file-name "misc/splash-images/blackhole-lines-4.svg" doom-private-dir))
  34. (:height 100 :min-height 20 :padding (1 . 2) :template ,(expand-file-name "misc/splash-images/blackhole-lines-5.svg" doom-private-dir))
  35. (:height 100 :min-height 14 :padding (1 . 2) :template ,(expand-file-name "misc/splash-images/emacs-e-template.svg" doom-private-dir))
  36. (:height 0 :min-height 0 :padding (0 . 0) :file ,fancy-splash-image-nil)))
  37. (defvar fancy-splash-template-colours
  38. '(("$colour1" . keywords) ("$colour2" . type) ("$colour3" . base5) ("$colour4" . base8))
  39. "list of colour-replacement alists of the form (\"$placeholder\" . 'theme-colour) which applied the template")
  40. (unless (file-exists-p (expand-file-name "theme-splashes" doom-cache-dir))
  41. (make-directory (expand-file-name "theme-splashes" doom-cache-dir) t))
  42. (defun fancy-splash-filename (theme-name height)
  43. (expand-file-name (concat (file-name-as-directory "theme-splashes")
  44. theme-name
  45. "-" (number-to-string height) ".svg")
  46. doom-cache-dir))
  47. (defun fancy-splash-clear-cache ()
  48. "Delete all cached fancy splash images"
  49. (interactive)
  50. (delete-directory (expand-file-name "theme-splashes" doom-cache-dir) t)
  51. (message "Cache cleared!"))
  52. (defun fancy-splash-generate-image (template height)
  53. "Read TEMPLATE and create an image if HEIGHT with colour substitutions as
  54. described by `fancy-splash-template-colours' for the current theme"
  55. (with-temp-buffer
  56. (insert-file-contents template)
  57. (re-search-forward "$height" nil t)
  58. (replace-match (number-to-string height) nil nil)
  59. (dolist (substitution fancy-splash-template-colours)
  60. (goto-char (point-min))
  61. (while (re-search-forward (car substitution) nil t)
  62. (replace-match (doom-color (cdr substitution)) nil nil)))
  63. (write-region nil nil
  64. (fancy-splash-filename (symbol-name doom-theme) height) nil nil)))
  65. (defun fancy-splash-generate-images ()
  66. "Perform `fancy-splash-generate-image' in bulk"
  67. (dolist (size fancy-splash-sizes)
  68. (unless (plist-get size :file)
  69. (fancy-splash-generate-image (or (plist-get size :file)
  70. (plist-get size :template)
  71. fancy-splash-image-template)
  72. (plist-get size :height)))))
  73. (defun ensure-theme-splash-images-exist (&optional height)
  74. (unless (file-exists-p (fancy-splash-filename
  75. (symbol-name doom-theme)
  76. (or height
  77. (plist-get (car fancy-splash-sizes) :height))))
  78. (fancy-splash-generate-images)))
  79. (defun get-appropriate-splash ()
  80. (let ((height (frame-height)))
  81. (cl-some (lambda (size) (when (>= height (plist-get size :min-height)) size))
  82. fancy-splash-sizes)))
  83. (setq fancy-splash-last-size nil)
  84. (setq fancy-splash-last-theme nil)
  85. (defun set-appropriate-splash (&rest _)
  86. (let ((appropriate-image (get-appropriate-splash)))
  87. (unless (and (equal appropriate-image fancy-splash-last-size)
  88. (equal doom-theme fancy-splash-last-theme)))
  89. (unless (plist-get appropriate-image :file)
  90. (ensure-theme-splash-images-exist (plist-get appropriate-image :height)))
  91. (setq fancy-splash-image
  92. (or (plist-get appropriate-image :file)
  93. (fancy-splash-filename (symbol-name doom-theme) (plist-get appropriate-image :height))))
  94. (setq +doom-dashboard-banner-padding (plist-get appropriate-image :padding))
  95. (setq fancy-splash-last-size appropriate-image)
  96. (setq fancy-splash-last-theme doom-theme)
  97. (+doom-dashboard-reload)))
  98. (add-hook 'window-size-change-functions #'set-appropriate-splash)
  99. (add-hook 'doom-load-theme-hook #'set-appropriate-splash)
  100. (provide 'fancy-banner)
  101. ;; fancy-banner.el ends here