branch: externals/show-font commit 97b3301dd3787a178ad8c1c88e42721f4fd92d69 Author: Protesilaos Stavrou <i...@protesilaos.com> Commit: Protesilaos Stavrou <i...@protesilaos.com>
Add error checking in show-font--prepare-text --- show-font.el | 46 +++++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/show-font.el b/show-font.el index 3f35623602..0ccb8f1614 100644 --- a/show-font.el +++ b/show-font.el @@ -192,23 +192,35 @@ With optional ATTRIBUTE use it instead of \"family\"." (defun show-font--prepare-text () "Prepare pangram text at varying font heights." - (let ((pangram (show-font--get-pangram)) - (faces '(show-font-small show-font-regular show-font-medium show-font-large)) - (list-of-lines nil) - (list-of-blocks nil) - (name (show-font--get-attribute "fullname")) - (family (show-font--get-attribute "family"))) - (dolist (face faces) - (push (propertize pangram 'face (list face :family family)) list-of-lines) - (push (propertize show-font-character-sample 'face (list face :family family)) list-of-blocks)) - (concat - (propertize name 'face (list 'show-font-title :family family)) "\n" - (propertize (make-string (length name) ?-) 'face (list 'show-font-title :family family)) "\n" - (propertize "Rendered with parent family:" 'face (list 'show-font-regular :family family)) "\n" - (propertize family 'face (list 'show-font-subtitle :family family)) "\n" - (propertize (make-string (length family) ?=) 'face (list 'show-font-subtitle :family family)) "\n\n" - (mapconcat #'identity (nreverse list-of-lines) "\n") "\n" - (mapconcat #'identity (nreverse list-of-blocks) "\n") "\n"))) + (let* ((pangram (show-font--get-pangram)) + (appeasement-message (concat "But here is a pangram to make you happy..." "\n\n" pangram))) + (cond + ((not (display-graphic-p)) + (concat (propertize "Fonts cannot be displayed in a terminal or TTY." 'face 'show-font-title) + "\n\n" appeasement-message)) + ((not (show-font--installed-p buffer-file-name)) + (concat (propertize "Cannot preview this font" 'face 'show-font-title) + "\n\n" + (propertize buffer-file-name 'face 'bold) + " is not installed" + "\n\n" appeasement-message)) + (t + (let ((faces '(show-font-small show-font-regular show-font-medium show-font-large)) + (list-of-lines nil) + (list-of-blocks nil) + (name (show-font--get-attribute "fullname")) + (family (show-font--get-attribute "family"))) + (dolist (face faces) + (push (propertize pangram 'face (list face :family family)) list-of-lines) + (push (propertize show-font-character-sample 'face (list face :family family)) list-of-blocks)) + (concat + (propertize name 'face (list 'show-font-title :family family)) "\n" + (propertize (make-string (length name) ?-) 'face (list 'show-font-title :family family)) "\n" + (propertize "Rendered with parent family:" 'face (list 'show-font-regular :family family)) "\n" + (propertize family 'face (list 'show-font-subtitle :family family)) "\n" + (propertize (make-string (length family) ?=) 'face (list 'show-font-subtitle :family family)) "\n\n" + (mapconcat #'identity (nreverse list-of-lines) "\n") "\n" + (mapconcat #'identity (nreverse list-of-blocks) "\n") "\n")))))) (defmacro show-font-with-unmodified-buffer (&rest body) "Run BODY while not making the buffer appear modified."