diff --git a/show-font.el b/show-font.el index 4ecd184..519d838 100644 --- a/show-font.el +++ b/show-font.el @@ -6,7 +6,7 @@ ;; Maintainer: Protesilaos Stavrou ;; URL: https://github.com/protesilaos/show-font ;; Version: 0.0.0 -;; Package-Requires: ((emacs "28.1")) +;; Package-Requires: ((emacs "28.1")) ;any reason for 28.1? ;; Keywords: convenience, writing, font ;; This file is NOT part of GNU Emacs. @@ -49,7 +49,7 @@ (const :tag "Grumpy wizards make toxic brew for the evil queen and jack" wizards) (const :tag "A quick movement of the enemy will jeopardize six gunboats" gunboats) (const :tag "Prot may find zesty owls join quiet vixens as the night beckons" prot) - string) + (string :tag "A custom pangram")) :group 'show-font) (defcustom show-font-character-sample @@ -101,8 +101,7 @@ x×X .,·°;:¡!¿?`'‘’ ÄAÃÀ TODO "Regular expression to match font file extensions.") (defconst show-font-latin-alphabet - '("a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" - "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z") + (eval-when-compile (mapcar #'string (number-sequence ?a ?z))) "The latin alphabet as a list of strings.") (defun show-font-pangram-p (string &optional characters) @@ -123,6 +122,9 @@ that all of them occur at least once in STRING." ;; mechanics of file handling yet. The idea of what I want is to get ;; an empty buffer. Then I add contents there without making it ;; appear modified. + +;; This constitutes a significant contribution, does it not? + (defun show-font-handler (operation &rest args) "Handle the given I/O `file-name-handler-alist' OPERATION with ARGS. Determine how to render the font file contents in a buffer." @@ -154,8 +156,10 @@ matched against the output of the `fc-scan' executable." (unless (executable-find "fc-scan") (error "Cannot find `fc-scan' executable; will not render font")) (when-let ((f (or file buffer-file-name)) - (_ (string-match-p show-font-extensions-regexp f)) - (output (shell-command-to-string (format "fc-scan -f \"%%{%s}\" %s" attribute f)))) + ((string-match-p show-font-extensions-regexp f)) + (output (shell-command-to-string (format "fc-scan -f \"%%{%s}\" %s" + (shell-quote-argument attribute) + (shell-quote-argument f))))) (if (string-match-p "," output) (car (split-string output ",")) output))) @@ -163,7 +167,7 @@ matched against the output of the `fc-scan' executable." (defun show-font--get-installed-fonts (&optional attribute) "Get list of font families available on the system. With optional ATTRIBUTE use it instead of \"family\"." - (unless (executable-find "fc-list") + (unless (executable-find "fc-list") ;perhaps add a user option for the command name? (error "Cannot find `fc-list' executable; will not find installed fonts")) (process-lines "fc-list" @@ -189,6 +193,9 @@ With optional ATTRIBUTE use it instead of \"family\"." "Prot may find zesty owls join quiet vixens as the night beckons") (t "No string or acceptable symbol value for `show-font-pangram', but this will do..."))) +;; Instead of duplicating the strings here and in the documentation, +;; why not add a defconst with the panagrams that you use to simplify +;; this function and generate the type for `show-font-pangram'? (defun show-font--prepare-text () "Prepare pangram text at varying font heights." @@ -219,10 +226,11 @@ With optional ATTRIBUTE use it instead of \"family\"." (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" + ;; Why not use `make-separator-line' here? (mapconcat #'identity (nreverse list-of-lines) "\n") "\n" (mapconcat #'identity (nreverse list-of-blocks) "\n") "\n")))))) -(defmacro show-font-with-unmodified-buffer (&rest body) +(defmacro show-font-with-unmodified-buffer (&rest body) ;isn't this `with-silent-modifications'? "Run BODY while not making the buffer appear modified." `(progn ,@body @@ -241,7 +249,7 @@ buffer." ;;;###autoload (define-derived-mode show-font-mode special-mode "Show Font" "Major mode to preview a font file's character set." - (set-buffer-multibyte t) + (set-buffer-multibyte t) ;is this safe? (setq-local truncate-lines t buffer-undo-list t auto-save-default nil @@ -252,6 +260,10 @@ buffer." ;; FIXME 2024-08-25: Do we want to autoload this or does it belong ;; somewhere else? It seems wrong like this. +;; This seems fine to me. What I found more peculiar is the autoload +;; in front of show-font-extensions-regexp, even if I understand the +;; technical reasons for it. + ;;;###autoload (add-to-list 'file-name-handler-alist (cons show-font-extensions-regexp #'show-font-handler))