Make startup banner scalable (from dotfile)

The default logo is rather big. Users might prefer to use the screen size for
other information (while still showing a banner).

This commit adds a configuration variable `dotspacemacs-startup-banner-scale`
to the dotfile
This commit is contained in:
Daniel Nicolai 2022-02-19 18:45:22 +01:00 committed by Maxi Wolff
parent 51686e5f12
commit a485b5a84b
2 changed files with 62 additions and 9 deletions

View File

@ -27,6 +27,7 @@
(defvar dotspacemacs-filepath)
(defvar dotspacemacs-show-startup-list-numbers)
(defvar dotspacemacs-startup-banner)
(defvar dotspacemacs-startup-banner-scale)
(defvar dotspacemacs-startup-buffer-show-icons)
(defvar spacemacs-badge-official-png)
(defvar spacemacs-banner-directory)
@ -261,15 +262,52 @@ If ALL is non-nil then truly all banners can be selected."
"Return the full path to banner with index INDEX."
(concat spacemacs-banner-directory (format "%03d-banner.txt" index)))
(defun spacemacs-buffer//banner-fit-height-size ()
"Calculate height of startup banner to fit buffer contents.
Returns height in units of line height with a minimum of 1."
;; first determine number of lines occupied by startup list
(let* ((startup-list-line-height
;; the all-the-icons package is not available here yet, but we don't
;; require icons for just counting the lines in the
;; `dotspacemacs-startup-lists'
(let ((icons dotspacemacs-startup-buffer-show-icons)
lines)
(setq dotspacemacs-startup-buffer-show-icons nil)
(setq lines (with-temp-buffer
(spacemacs-buffer//do-insert-startupify-lists)
(line-number-at-pos)))
;; (count-lines (point-min) (point-max)))
(setq dotspacemacs-startup-buffer-show-icons icons)
lines))
;; We determine the maximum available banner height by subtracting the
;; number of lines in the home buffer contents (excl. logo and
;; startup-list), i.e. `26', and the number of lines in the startup
;; list from the total available text lines
(image-height (- (window-text-height) 26 startup-list-line-height)))
;; return image-height with minimum of 3 line heights
(max image-height 3)))
(defun spacemacs-buffer//insert-image-banner (banner)
"Display an image banner.
BANNER: the path to an ascii banner file."
(when (file-exists-p banner)
(let* ((title spacemacs-buffer-logo-title)
(spec (create-image banner))
(size (image-size spec))
;; we must use the scaled size for determining the correct
;; left-margin size
(unscaled-size (image-size spec)) ;; size in 'canonical character units'
(height (cdr unscaled-size)) ;; return size in units of line heights
(scale (pcase dotspacemacs-startup-banner-scale
('auto (let ((factor (/ (float (spacemacs-buffer//banner-fit-height-size))
height)))
;; return factor with maximum of 1
(min factor 1)))
(factor factor)))
(size (cons (* scale (car unscaled-size)) (* scale (cdr unscaled-size))))
(width (car size))
(left-margin (max 0 (floor (- spacemacs-buffer--window-width width) 2))))
;; we scale the image by simply setting the scale property in the image-spec
(plist-put (cdr spec) :scale scale)
(insert (make-string left-margin ?\s))
(insert-image spec)
(insert "\n\n")
@ -1219,7 +1257,8 @@ SEQ, START and END are the same arguments as for `cl-subseq'"
(defun spacemacs-buffer//insert-errors ()
(when (spacemacs-buffer//insert-string-list
(spacemacs-buffer||propertize-heading
(all-the-icons-material "error" :face 'font-lock-keyword-face)
(when dotspacemacs-startup-buffer-show-icons
(all-the-icons-material "error" :face 'font-lock-keyword-face))
"Errors:" "e")
spacemacs-buffer--errors)
(spacemacs-buffer||add-shortcut "e" "Errors:")
@ -1228,7 +1267,8 @@ SEQ, START and END are the same arguments as for `cl-subseq'"
(defun spacemacs-buffer//insert-warnings ()
(when (spacemacs-buffer//insert-string-list
(spacemacs-buffer||propertize-heading
(all-the-icons-material "warning" :face 'font-lock-keyword-face)
(when dotspacemacs-startup-buffer-show-icons
(all-the-icons-material "warning" :face 'font-lock-keyword-face))
"Warnings:" "w")
spacemacs-buffer--warnings)
(spacemacs-buffer||add-shortcut "w" "Warnings:")
@ -1249,7 +1289,8 @@ SEQ, START and END are the same arguments as for `cl-subseq'"
(spacemacs//subseq spacemacs-buffer//recent-files-list 0 list-size))
(when (spacemacs-buffer//insert-file-list
(spacemacs-buffer||propertize-heading
(all-the-icons-octicon "history" :face 'font-lock-keyword-face :v-adjust -0.05)
(when dotspacemacs-startup-buffer-show-icons
(all-the-icons-octicon "history" :face 'font-lock-keyword-face :v-adjust -0.05))
"Recent Files:" "r")
spacemacs-buffer//recent-files-list)
(spacemacs-buffer||add-shortcut "r" "Recent Files:"))
@ -1260,7 +1301,8 @@ SEQ, START and END are the same arguments as for `cl-subseq'"
(unless projectile-mode (projectile-mode))
(when (spacemacs-buffer//insert-files-by-dir-list
(spacemacs-buffer||propertize-heading
(all-the-icons-octicon "rocket" :face 'font-lock-keyword-face :v-adjust -0.05)
(when dotspacemacs-startup-buffer-show-icons
(all-the-icons-octicon "rocket" :face 'font-lock-keyword-face :v-adjust -0.05))
"Recent Files by Project:" "R")
(mapcar (lambda (group)
(cons (car group)
@ -1276,7 +1318,8 @@ SEQ, START and END are the same arguments as for `cl-subseq'"
(defun spacemacs-buffer//insert-todos (list-size)
(when (spacemacs-buffer//insert-todo-list
(spacemacs-buffer||propertize-heading
(all-the-icons-octicon "check" :face 'font-lock-keyword-face :v-adjust -0.05)
(when dotspacemacs-startup-buffer-show-icons
(all-the-icons-octicon "check" :face 'font-lock-keyword-face :v-adjust -0.05))
"To-Do:" "d")
(spacemacs//subseq (spacemacs-buffer//todo-list)
0 list-size))
@ -1286,7 +1329,8 @@ SEQ, START and END are the same arguments as for `cl-subseq'"
(defun spacemacs-buffer//insert-agenda (list-size)
(when (spacemacs-buffer//insert-todo-list
(spacemacs-buffer||propertize-heading
(all-the-icons-octicon "calendar" :face 'font-lock-keyword-face :v-adjust -0.05)
(when dotspacemacs-startup-buffer-show-icons
(all-the-icons-octicon "calendar" :face 'font-lock-keyword-face :v-adjust -0.05))
"Agenda:" "c")
(spacemacs//subseq (spacemacs-buffer//agenda-list)
0 list-size))
@ -1299,7 +1343,8 @@ SEQ, START and END are the same arguments as for `cl-subseq'"
(require 'bookmark)
(when (spacemacs-buffer//insert-bookmark-list
(spacemacs-buffer||propertize-heading
(all-the-icons-octicon "bookmark" :face 'font-lock-keyword-face :v-adjust -0.05)
(when dotspacemacs-startup-buffer-show-icons
(all-the-icons-octicon "bookmark" :face 'font-lock-keyword-face :v-adjust -0.05))
"Bookmarks:" "b")
(spacemacs//subseq (bookmark-all-names)
0 list-size))
@ -1310,7 +1355,8 @@ SEQ, START and END are the same arguments as for `cl-subseq'"
(unless projectile-mode (projectile-mode))
(when (spacemacs-buffer//insert-file-list
(spacemacs-buffer||propertize-heading
(all-the-icons-octicon "rocket" :face 'font-lock-keyword-face :v-adjust -0.05)
(when dotspacemacs-startup-buffer-show-icons
(all-the-icons-octicon "rocket" :face 'font-lock-keyword-face :v-adjust -0.05))
"Projects:" "p")
(spacemacs//subseq (projectile-relevant-known-projects)
0 list-size))

View File

@ -180,6 +180,13 @@ It should only modify the values of Spacemacs settings."
;; If the value is nil then no banner is displayed. (default 'official)
dotspacemacs-startup-banner 'official
;; Scale factor controls the scaling (size) of the startup banner. Default
;; value is `auto' for scaling the logo automatically to fit all buffer
;; contents, to a maximum of the full image height and a minimum of 3 line
;; heights. If set to a number (int or float) it is used as a constant
;; scaling factor for the default logo size.
dotspacemacs-startup-banner-scale 'auto
;; List of items to show in startup buffer or an association list of
;; the form `(list-type . list-size)`. If nil then it is disabled.
;; Possible values for list-type are: