From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Philip Kaludercic Newsgroups: gmane.emacs.devel Subject: Re: [ELPA] Add new 'show-font' package? Date: Thu, 05 Sep 2024 10:18:50 +0000 Message-ID: <87jzfqjtdh.fsf@posteo.net> References: <87msknu635.fsf@protesilaos.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10469"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Protesilaos Stavrou Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Sep 05 12:19:46 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sm9ab-0002XX-LV for ged-emacs-devel@m.gmane-mx.org; Thu, 05 Sep 2024 12:19:45 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sm9Zw-0006lg-JY; Thu, 05 Sep 2024 06:19:04 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sm9Zs-0006lT-66 for emacs-devel@gnu.org; Thu, 05 Sep 2024 06:19:00 -0400 Original-Received: from mout02.posteo.de ([185.67.36.66]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sm9Zp-0004kX-61 for emacs-devel@gnu.org; Thu, 05 Sep 2024 06:18:59 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 70300240104 for ; Thu, 5 Sep 2024 12:18:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1725531531; bh=Mc+t4GzGLp49ASjmz+68rcoFgihalzPtvn01a1UO+aU=; h=From:To:Cc:Subject:Autocrypt:OpenPGP:Date:Message-ID:MIME-Version: Content-Type:From; b=cIOgpuAmJ+Y8bXden5PNpreOXk5mNcnBKp7j234fahEsoYsmpkZh9YMvwtOqV1LGv fJFIoYGPa1u7FZsWHCPmx/3+YzIot0VMzpRSXm3dlMneP6UlUkSCnWsIH7ZJoyZTWp Dt4NyjZsqNzUv+JtIY6iiqknsZxt7rkJllFTyHGPzy8gsfolTvtiWnFwTRmK/GeBrj /HfuGIOBCkDiffDD5URDlDE/m0dE6bhjHUkWFdiL7/0JRg0Tmx0FkUWP3WEy1MQC1Z CAa6Wcn2ywDoLaLO5NpwNmEmLUDErLNZptiWNLycNHfgHs4myvOcXFyjCZSY4ACuSc YB0A5u9wUbTgw== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4WzwLf6kQpz6txv; Thu, 5 Sep 2024 12:18:50 +0200 (CEST) In-Reply-To: <87msknu635.fsf@protesilaos.com> (Protesilaos Stavrou's message of "Wed, 04 Sep 2024 12:21:50 +0300") Autocrypt: addr=philipk@posteo.net; keydata= mDMEZBBQQhYJKwYBBAHaRw8BAQdAHJuofBrfqFh12uQu0Yi7mrl525F28eTmwUDflFNmdui0QlBo aWxpcCBLYWx1ZGVyY2ljIChnZW5lcmF0ZWQgYnkgYXV0b2NyeXB0LmVsKSA8cGhpbGlwa0Bwb3N0 ZW8ubmV0PoiWBBMWCAA+FiEEDg7HY17ghYlni8XN8xYDWXahwukFAmQQUEICGwMFCQHhM4AFCwkI BwIGFQoJCAsCBBYCAwECHgECF4AACgkQ8xYDWXahwulikAEA77hloUiSrXgFkUVJhlKBpLCHUjA0 mWZ9j9w5d08+jVwBAK6c4iGP7j+/PhbkxaEKa4V3MzIl7zJkcNNjHCXmvFcEuDgEZBBQQhIKKwYB BAGXVQEFAQEHQI5NLiLRjZy3OfSt1dhCmFyn+fN/QKELUYQetiaoe+MMAwEIB4h+BBgWCAAmFiEE Dg7HY17ghYlni8XN8xYDWXahwukFAmQQUEICGwwFCQHhM4AACgkQ8xYDWXahwukm+wEA8cml4JpK NeAu65rg+auKrPOP6TP/4YWRCTIvuYDm0joBALw98AMz7/qMHvSCeU/hw9PL6u6R2EScxtpKnWof z4oM OpenPGP: id=philipk@posteo.net; url="https://keys.openpgp.org/vks/v1/by-email/philipk@posteo.net"; preference=signencrypt Received-SPF: pass client-ip=185.67.36.66; envelope-from=philipk@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:323390 Archived-At: --=-=-= Content-Type: text/plain Protesilaos Stavrou 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 > 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: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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 =20 ;; This file is NOT part of GNU Emacs. @@ -49,7 +49,7 @@ (const :tag "Grumpy wizards make toxic brew for the evil queen a= nd jack" wizards) (const :tag "A quick movement of the enemy will jeopardize six g= unboats" gunboats) (const :tag "Prot may find zesty owls join quiet vixens as the n= ight beckons" prot) - string) + (string :tag "A custom pangram")) :group 'show-font) =20 (defcustom show-font-character-sample @@ -101,8 +101,7 @@ x=C3=97X .,=C2=B7=C2=B0;:=C2=A1!=C2=BF?`'=E2=80=98=E2= =80=99 =C3=84A=C3=83=C3=80 TODO "Regular expression to match font file extensions.") =20 (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.") =20 (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 c= ommand name? (error "Cannot find `fc-list' executable; will not find installed font= s")) (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 thi= s 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'? =20 (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) ?=3D) '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")))))) =20 -(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. =20 +;; 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)) =20 --=-=-= Content-Type: text/plain Some general comments: It would be nice to have a command to select a font. -- Philip Kaludercic on siskin --=-=-=--