[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [ELPA] Add new 'show-font' package?
From: |
Philip Kaludercic |
Subject: |
Re: [ELPA] Add new 'show-font' package? |
Date: |
Thu, 05 Sep 2024 10:18:50 +0000 |
Protesilaos Stavrou <info@protesilaos.com> writes:
> Hello everyone,
>
> I am working on a new package called 'show-font'. It is a major mode for
> ".ttf" and ".otf" files (font files). It previews the current font, if
> available on the system, else it produces a helpful message that the
> font is not installed and thus cannot be previewed.
>
> These are early days. My immediate goals include the following:
>
> - Make it work on other operating systems beside GNU/Llinux.
> - Let users install a font file (OS-dependent).
> - Preview a font that is not installed on the system.
>
> I attach the patch I want to commit to elpa.git. Please let me know if
> you have any thoughts about this.
>
> All the best,
> Protesilaos (or simply "Prot")
>
> --
> Protesilaos Stavrou
> https://protesilaos.com
>
> From 6d0b5b4555c3ad80840c7260a276904c48fdf84e Mon Sep 17 00:00:00 2001
> Message-ID:
> <6d0b5b4555c3ad80840c7260a276904c48fdf84e.1725441140.git.info@protesilaos.com>
> From: Protesilaos Stavrou <info@protesilaos.com>
> Date: Wed, 4 Sep 2024 12:11:37 +0300
> Subject: [PATCH] * elpa-packages (show-font): Add new package
>
> ---
> elpa-packages | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/elpa-packages b/elpa-packages
> index 6bac9fb..7434a5d 100644
> --- a/elpa-packages
> +++ b/elpa-packages
> @@ -680,6 +680,8 @@
> (shell-command+ :url "https://git.sr.ht/~pkal/shell-command-plus")
> (shell-quasiquote :url nil)
> (shen-mode :url nil)
> + (show-font :url "https://github.com/protesilaos/show-font"
> + :readme "README.md")
> (sisu-mode :url nil)
> (site-lisp :url "https://git.sr.ht/~pkal/site-lisp")
> (sketch-mode :url
> "https://github.com/dalanicolai/sketch-mode")
A few comments on the code here:
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 <info@protesilaos.com>
;; 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))
Some general comments: It would be nice to have a command to select a
font.
--
Philip Kaludercic on siskin
- [ELPA] Add new 'show-font' package?, Protesilaos Stavrou, 2024/09/04
- Re: [ELPA] Add new 'show-font' package?,
Philip Kaludercic <=
- Re: [ELPA] Add new 'show-font' package?, Eli Zaretskii, 2024/09/05
- Re: [ELPA] Add new 'show-font' package?, Protesilaos Stavrou, 2024/09/06
- Re: [ELPA] Add new 'show-font' package?, Eli Zaretskii, 2024/09/06
- Re: [ELPA] Add new 'show-font' package?, Protesilaos Stavrou, 2024/09/06
- Re: [ELPA] Add new 'show-font' package?, Eli Zaretskii, 2024/09/06
- Re: [ELPA] Add new 'show-font' package?, Protesilaos Stavrou, 2024/09/06
- Re: [ELPA] Add new 'show-font' package?, Eli Zaretskii, 2024/09/06
- Re: [ELPA] Add new 'show-font' package?, Protesilaos Stavrou, 2024/09/06
- Re: [ELPA] Add new 'show-font' package?, Eli Zaretskii, 2024/09/06
- Re: [ELPA] Add new 'show-font' package?, Protesilaos Stavrou, 2024/09/06