Improve robustness of image banner feature

Check for support for PNG image format
Fallback on text banner if the PNG file cannot be displayed or
the path is wrong
This commit is contained in:
syl20bnr 2015-03-08 22:09:09 -04:00
parent 4d0ace039a
commit a9aa68fff3
3 changed files with 31 additions and 19 deletions

View File

@ -18,10 +18,11 @@
Paths must have a trailing slash (ie. `~/.mycontribs/')")
(defvar dotspacemacs-startup-banner 'random
"Specify the startup banner. If the value is an integer then the
banner with the corresponding index is used, if the value is `random'
then the banner is chosen randomly among the available banners, if
the value is nil then no banner is displayed.")
"Specify the startup banner. If the value is an integer then the
text banner with the corresponding index is used, if the value is
`random' then the banner is chosen randomly among the available banners,
if the value is a string then it must be a path to a .PNG file,
if the value is nil then no banner is displayed.")
(defvar dotspacemacs-configuration-layers '()
"List of configuration layers to load. If it is the symbol `all' instead

View File

@ -17,17 +17,7 @@
Doge special banner can be reachable via `999', `doge' or `random*'.
`random' ignore special banners whereas `random*' does not."
(let ((banner (cond
((eq 'random dotspacemacs-startup-banner)
(spacemacs//choose-random-banner))
((eq 'random* dotspacemacs-startup-banner)
(spacemacs//choose-random-banner t))
((eq 'doge dotspacemacs-startup-banner)
(spacemacs//get-banner-path 999))
((integerp dotspacemacs-startup-banner)
(spacemacs//get-banner-path dotspacemacs-startup-banner))
((string-match "\\.png\\'" dotspacemacs-startup-banner)
dotspacemacs-startup-banner)))
(let ((banner (spacemacs//choose-banner))
(buffer-read-only nil))
(when banner
(spacemacs/message (format "Banner: %s" banner))
@ -43,7 +33,27 @@ Doge special banner can be reachable via `999', `doge' or `random*'.
(spacemacs/insert-buttons)
(spacemacs//redisplay))))
(defun spacemacs//choose-random-banner (&optional all)
(defun spacemacs//choose-banner ()
"Return the full path of a banner based on the dotfile value."
(cond
((eq 'random dotspacemacs-startup-banner)
(spacemacs//choose-random-text-banner))
((eq 'random* dotspacemacs-startup-banner)
(spacemacs//choose-random-text-banner t))
((eq 'doge dotspacemacs-startup-banner)
(spacemacs//get-banner-path 999))
((integerp dotspacemacs-startup-banner)
(spacemacs//get-banner-path dotspacemacs-startup-banner))
((string-match "\\.png\\'" dotspacemacs-startup-banner)
(if (image-type-available-p 'png)
(if (file-exists-p dotspacemacs-startup-banner)
dotspacemacs-startup-banner
(spacemacs/message (format "Warning: could not find banner %s"
dotspacemacs-startup-banner))
(spacemacs//get-banner-path 1))
(spacemacs//get-banner-path 1)))))
(defun spacemacs//choose-random-text-banner (&optional all)
"Return the full path of a banner chosen randomly.
If ALL is non-nil then truly all banners can be selected."

View File

@ -26,9 +26,10 @@ before layers configuration."
;; spacemacs settings.
(setq-default
;; Specify the startup banner. If the value is an integer then the
;; banner with the corresponding index is used, if the value is `random'
;; then the banner is chosen randomly among the available banners, if
;; the value is nil then no banner is displayed.
;; text banner with the corresponding index is used, if the value is
;; `random' then the banner is chosen randomly among the available banners,
;; if the value is a string then it must be a path to a .PNG file,
;; if the value is nil then no banner is displayed.
dotspacemacs-startup-banner 'random
;; List of themes, the first of the list is loaded when spacemacs starts.
;; Press <SPC> T n to cycle to the next theme in the list (works great