* [ELPA] Add new 'show-font' package? @ 2024-09-04 9:21 Protesilaos Stavrou 2024-09-05 10:18 ` Philip Kaludercic 0 siblings, 1 reply; 21+ messages in thread From: Protesilaos Stavrou @ 2024-09-04 9:21 UTC (permalink / raw) To: emacs-devel [-- Attachment #1: Type: text/plain, Size: 712 bytes --] 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 [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-elpa-packages-show-font-Add-new-package.patch --] [-- Type: text/x-diff, Size: 883 bytes --] 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") -- 2.45.2 ^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [ELPA] Add new 'show-font' package? 2024-09-04 9:21 [ELPA] Add new 'show-font' package? Protesilaos Stavrou @ 2024-09-05 10:18 ` Philip Kaludercic 2024-09-05 10:24 ` Eli Zaretskii 2024-09-06 5:43 ` Protesilaos Stavrou 0 siblings, 2 replies; 21+ messages in thread From: Philip Kaludercic @ 2024-09-05 10:18 UTC (permalink / raw) To: Protesilaos Stavrou; +Cc: emacs-devel [-- Attachment #1: Type: text/plain, Size: 1754 bytes --] 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: [-- Attachment #2: Type: text/plain, Size: 5219 bytes --] 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)) [-- Attachment #3: Type: text/plain, Size: 112 bytes --] Some general comments: It would be nice to have a command to select a font. -- Philip Kaludercic on siskin ^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [ELPA] Add new 'show-font' package? 2024-09-05 10:18 ` Philip Kaludercic @ 2024-09-05 10:24 ` Eli Zaretskii 2024-09-06 5:35 ` Protesilaos Stavrou 2024-09-06 5:43 ` Protesilaos Stavrou 1 sibling, 1 reply; 21+ messages in thread From: Eli Zaretskii @ 2024-09-05 10:24 UTC (permalink / raw) To: Philip Kaludercic; +Cc: info, emacs-devel > From: Philip Kaludercic <philipk@posteo.net> > Cc: emacs-devel@gnu.org > Date: Thu, 05 Sep 2024 10:18:50 +0000 > > + (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")) Do we really need fc-list? can't we use the built-in x-family-fonts instead? ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [ELPA] Add new 'show-font' package? 2024-09-05 10:24 ` Eli Zaretskii @ 2024-09-06 5:35 ` Protesilaos Stavrou 2024-09-06 6:12 ` Eli Zaretskii 0 siblings, 1 reply; 21+ messages in thread From: Protesilaos Stavrou @ 2024-09-06 5:35 UTC (permalink / raw) To: Eli Zaretskii, Philip Kaludercic; +Cc: emacs-devel > From: Eli Zaretskii <eliz@gnu.org> > Date: Thu, 5 Sep 2024 13:24:48 +0300 > >> From: Philip Kaludercic <philipk@posteo.net> >> Cc: emacs-devel@gnu.org >> Date: Thu, 05 Sep 2024 10:18:50 +0000 >> >> + (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")) > > Do we really need fc-list? can't we use the built-in x-family-fonts > instead? I thought that function was only for X. It also is defined in a file which again has X in its name. If it works everywhere, then I am happy to use it. -- Protesilaos Stavrou https://protesilaos.com ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [ELPA] Add new 'show-font' package? 2024-09-06 5:35 ` Protesilaos Stavrou @ 2024-09-06 6:12 ` Eli Zaretskii 2024-09-06 6:23 ` Protesilaos Stavrou 0 siblings, 1 reply; 21+ messages in thread From: Eli Zaretskii @ 2024-09-06 6:12 UTC (permalink / raw) To: Protesilaos Stavrou; +Cc: philipk, emacs-devel > From: Protesilaos Stavrou <info@protesilaos.com> > Cc: emacs-devel@gnu.org > Date: Fri, 06 Sep 2024 08:35:10 +0300 > > > From: Eli Zaretskii <eliz@gnu.org> > > Date: Thu, 5 Sep 2024 13:24:48 +0300 > > > >> From: Philip Kaludercic <philipk@posteo.net> > >> Cc: emacs-devel@gnu.org > >> Date: Thu, 05 Sep 2024 10:18:50 +0000 > >> > >> + (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")) > > > > Do we really need fc-list? can't we use the built-in x-family-fonts > > instead? > > I thought that function was only for X. It also is defined in a file > which again has X in its name. If it works everywhere, then I am happy > to use it. x-family-fonts is defined in xfaces.c, which is not specific to X. That function is supported by every font back-end that Emacs can use, so it is platform-independent. The only disadvantage in using it is that it will only know about font families that are installed. If you intend to support fonts that are not installed, you will need something else. But then fc-list doesn't know about uninstalled fonts, either. Also, fc-list is unlikely to be installed on systems that do not run X Window System, anyway. ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [ELPA] Add new 'show-font' package? 2024-09-06 6:12 ` Eli Zaretskii @ 2024-09-06 6:23 ` Protesilaos Stavrou 2024-09-06 7:16 ` Eli Zaretskii 0 siblings, 1 reply; 21+ messages in thread From: Protesilaos Stavrou @ 2024-09-06 6:23 UTC (permalink / raw) To: Eli Zaretskii; +Cc: philipk, emacs-devel > From: Eli Zaretskii <eliz@gnu.org> > Date: Fri, 6 Sep 2024 09:12:05 +0300 > [... 15 lines elided] >> > Do we really need fc-list? can't we use the built-in x-family-fonts >> > instead? >> >> I thought that function was only for X. It also is defined in a file >> which again has X in its name. If it works everywhere, then I am happy >> to use it. > > x-family-fonts is defined in xfaces.c, which is not specific to X. > That function is supported by every font back-end that Emacs can use, > so it is platform-independent. Very well! I am experimenting with it right now. It seems to do what I want. All I need is to figure out how to get/guess the name of a font based on the file name (ideally without depending on an external program that may not be installed on the user's end). > The only disadvantage in using it is that it will only know about font > families that are installed. If you intend to support fonts that are > not installed, you will need something else. But then fc-list doesn't > know about uninstalled fonts, either. Also, fc-list is unlikely to be > installed on systems that do not run X Window System, anyway. Yes, I know. It is why I had a TODO for how to make this work on all systems. But with x-family-fonts we are good to go. -- Protesilaos Stavrou https://protesilaos.com ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [ELPA] Add new 'show-font' package? 2024-09-06 6:23 ` Protesilaos Stavrou @ 2024-09-06 7:16 ` Eli Zaretskii 2024-09-06 7:23 ` Protesilaos Stavrou 0 siblings, 1 reply; 21+ messages in thread From: Eli Zaretskii @ 2024-09-06 7:16 UTC (permalink / raw) To: Protesilaos Stavrou; +Cc: philipk, emacs-devel > From: Protesilaos Stavrou <info@protesilaos.com> > Cc: philipk@posteo.net, emacs-devel@gnu.org > Date: Fri, 06 Sep 2024 09:23:43 +0300 > > > x-family-fonts is defined in xfaces.c, which is not specific to X. > > That function is supported by every font back-end that Emacs can use, > > so it is platform-independent. > > Very well! I am experimenting with it right now. It seems to do what I > want. All I need is to figure out how to get/guess the name of a font > based on the file name (ideally without depending on an external program > that may not be installed on the user's end). Why do you need that? IME, users don't care about file names of the fonts. ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [ELPA] Add new 'show-font' package? 2024-09-06 7:16 ` Eli Zaretskii @ 2024-09-06 7:23 ` Protesilaos Stavrou 2024-09-06 10:47 ` Eli Zaretskii 0 siblings, 1 reply; 21+ messages in thread From: Protesilaos Stavrou @ 2024-09-06 7:23 UTC (permalink / raw) To: Eli Zaretskii; +Cc: philipk, emacs-devel > From: Eli Zaretskii <eliz@gnu.org> > Date: Fri, 6 Sep 2024 10:16:30 +0300 > [... 11 lines elided] >> All I need is to figure out how to get/guess the name of a font >> based on the file name (ideally without depending on an external program >> that may not be installed on the user's end). > > Why do you need that? IME, users don't care about file names of the > fonts. Imagine the user has just downloaded a font in "~/Downloads" and tries to visit it. The idea is to get the font family out of this file and check if it exists on the system. If it exists, then we perform the preview of the font, otherwise we inform the user that the font called FONT is not installed (and then suggest to install it, but I will do that later). -- Protesilaos Stavrou https://protesilaos.com ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [ELPA] Add new 'show-font' package? 2024-09-06 7:23 ` Protesilaos Stavrou @ 2024-09-06 10:47 ` Eli Zaretskii 2024-09-06 10:59 ` Protesilaos Stavrou 0 siblings, 1 reply; 21+ messages in thread From: Eli Zaretskii @ 2024-09-06 10:47 UTC (permalink / raw) To: Protesilaos Stavrou; +Cc: philipk, emacs-devel > From: Protesilaos Stavrou <info@protesilaos.com> > Cc: philipk@posteo.net, emacs-devel@gnu.org > Date: Fri, 06 Sep 2024 10:23:49 +0300 > > > From: Eli Zaretskii <eliz@gnu.org> > > Date: Fri, 6 Sep 2024 10:16:30 +0300 > > > [... 11 lines elided] > > >> All I need is to figure out how to get/guess the name of a font > >> based on the file name (ideally without depending on an external program > >> that may not be installed on the user's end). > > > > Why do you need that? IME, users don't care about file names of the > > fonts. > > Imagine the user has just downloaded a font in "~/Downloads" and tries > to visit it. That is only relevant to fonts that are not yet installed, which is a separate use case, and IMO needs a different handling and perhaps also different UI. For now, AFAIU you are working on fonts that are already installed, and for those most users will not know the file names (nor will care about them). > The idea is to get the font family out of this file and check if it > exists on the system. If it exists, then we perform the preview of > the font, otherwise we inform the user that the font called FONT is > not installed (and then suggest to install it, but I will do that > later). This concept surprises me, since the tools and commands which I've seen that allow users to preview a font show the list of installed fonts, and then allow selecting a font from that list. In which case the font's file name is not very relevant. Moreover, some font files can have several different font families, in which case a file name will not unequivocally determine the font. ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [ELPA] Add new 'show-font' package? 2024-09-06 10:47 ` Eli Zaretskii @ 2024-09-06 10:59 ` Protesilaos Stavrou 2024-09-06 11:40 ` Eli Zaretskii 0 siblings, 1 reply; 21+ messages in thread From: Protesilaos Stavrou @ 2024-09-06 10:59 UTC (permalink / raw) To: Eli Zaretskii; +Cc: philipk, emacs-devel > From: Eli Zaretskii <eliz@gnu.org> > Date: Fri, 6 Sep 2024 13:47:17 +0300 > >> From: Protesilaos Stavrou <info@protesilaos.com> >> Cc: philipk@posteo.net, emacs-devel@gnu.org >> Date: Fri, 06 Sep 2024 10:23:49 +0300 >> >> > From: Eli Zaretskii <eliz@gnu.org> >> > Date: Fri, 6 Sep 2024 10:16:30 +0300 >> >> > [... 11 lines elided] >> >> >> All I need is to figure out how to get/guess the name of a font >> >> based on the file name (ideally without depending on an external program >> >> that may not be installed on the user's end). >> > >> > Why do you need that? IME, users don't care about file names of the >> > fonts. >> >> Imagine the user has just downloaded a font in "~/Downloads" and tries >> to visit it. > > That is only relevant to fonts that are not yet installed, which is a > separate use case, and IMO needs a different handling and perhaps also > different UI. For now, AFAIU you are working on fonts that are > already installed, and for those most users will not know the file > names (nor will care about them). This is not intended for fonts that are already installed on the system. It is for users who download a font from some website and then store it locally. We then want a major mode to preview the font instead of showing unreadable characters. If there is a function that can read FILE and infer the font name (or names) from it, then we can check if the font[s] are available and preview them accordingly. Else print a message that the fonts are not available on the system. >> The idea is to get the font family out of this file and check if it >> exists on the system. If it exists, then we perform the preview of >> the font, otherwise we inform the user that the font called FONT is >> not installed (and then suggest to install it, but I will do that >> later). > > This concept surprises me, since the tools and commands which I've seen > that allow users to preview a font show the list of installed fonts, > and then allow selecting a font from that list. In which case the > font's file name is not very relevant. Moreover, some font files can > have several different font families, in which case a file name will > not unequivocally determine the font. I already have all the code ready in my local repository. There are two commands to work with installed fonts (per 'x-family-fonts'): - show-font-select-preview :: Use minibuffer completion to select a font family and then display a buffer rendered in that family. - show-font-list :: Produce a buffer that has a short preview of each installed font, accompanied by the name of the font. Now all I am missing is the case with the file that I noted above. Then the prototype is feature complete and I can work on further refinements. -- Protesilaos Stavrou https://protesilaos.com ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [ELPA] Add new 'show-font' package? 2024-09-06 10:59 ` Protesilaos Stavrou @ 2024-09-06 11:40 ` Eli Zaretskii 2024-09-06 13:40 ` Protesilaos Stavrou 0 siblings, 1 reply; 21+ messages in thread From: Eli Zaretskii @ 2024-09-06 11:40 UTC (permalink / raw) To: Protesilaos Stavrou; +Cc: philipk, emacs-devel > From: Protesilaos Stavrou <info@protesilaos.com> > Cc: philipk@posteo.net, emacs-devel@gnu.org > Date: Fri, 06 Sep 2024 13:59:36 +0300 > > >> Imagine the user has just downloaded a font in "~/Downloads" and tries > >> to visit it. > > > > That is only relevant to fonts that are not yet installed, which is a > > separate use case, and IMO needs a different handling and perhaps also > > different UI. For now, AFAIU you are working on fonts that are > > already installed, and for those most users will not know the file > > names (nor will care about them). > > This is not intended for fonts that are already installed on the system. > It is for users who download a font from some website and then store it > locally. We then want a major mode to preview the font instead of > showing unreadable characters. This seems to be in contradiction to what you said originally: that you first want to handle installed fonts. A font that is not yet installed will not appear in x-family-fonts, so you need something else entirely. > If there is a function that can read FILE and infer the font name (or > names) from it, then we can check if the font[s] are available and > preview them accordingly. Else print a message that the fonts are not > available on the system. Emacs doesn't access font files directly, it uses system facilities for that. So the answer to your question is NO, not using Emacs APIs related to fonts. > > This concept surprises me, since the tools and commands which I've seen > > that allow users to preview a font show the list of installed fonts, > > and then allow selecting a font from that list. In which case the > > font's file name is not very relevant. Moreover, some font files can > > have several different font families, in which case a file name will > > not unequivocally determine the font. > > I already have all the code ready in my local repository. There are two > commands to work with installed fonts (per 'x-family-fonts'): > > - show-font-select-preview :: Use minibuffer completion to select a > font family and then display a buffer rendered in that family. > > - show-font-list :: Produce a buffer that has a short preview of each > installed font, accompanied by the name of the font. > > Now all I am missing is the case with the file that I noted above. Then > the prototype is feature complete and I can work on further refinements. If you are now talking only about uninstalled fonts, the way to handle them in Emacs will be quite complicated, I think, and will be highly-dependent on the font back-end. I'm not even sure this is possible on all supported system (e.g., I don't know how to do that on MS-Windows, I think it's impossible there). You may need to tell users to install a font temporarily for previewing it. ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [ELPA] Add new 'show-font' package? 2024-09-06 11:40 ` Eli Zaretskii @ 2024-09-06 13:40 ` Protesilaos Stavrou 2024-09-06 13:56 ` Eli Zaretskii 0 siblings, 1 reply; 21+ messages in thread From: Protesilaos Stavrou @ 2024-09-06 13:40 UTC (permalink / raw) To: Eli Zaretskii; +Cc: philipk, emacs-devel > From: Eli Zaretskii <eliz@gnu.org> > Date: Fri, 6 Sep 2024 14:40:07 +0300 > [... 14 lines elided] >> This is not intended for fonts that are already installed on the system. >> It is for users who download a font from some website and then store it >> locally. We then want a major mode to preview the font instead of >> showing unreadable characters. > > This seems to be in contradiction to what you said originally: that > you first want to handle installed fonts. A font that is not yet > installed will not appear in x-family-fonts, so you need something > else entirely. The "something else" is why I am relying on 'fc-list' and 'fc-scan'. I am keeping this dependency for the time being and will let users of other platforms tell me what the equivalent programs are on their system. >> If there is a function that can read FILE and infer the font name (or >> names) from it, then we can check if the font[s] are available and >> preview them accordingly. Else print a message that the fonts are not >> available on the system. > > Emacs doesn't access font files directly, it uses system facilities > for that. So the answer to your question is NO, not using Emacs APIs > related to fonts. I see, thank you! I will keep using external programs then. >> > This concept surprises me, since the tools and commands which I've seen >> > that allow users to preview a font show the list of installed fonts, >> > and then allow selecting a font from that list. In which case the >> > font's file name is not very relevant. Moreover, some font files can >> > have several different font families, in which case a file name will >> > not unequivocally determine the font. >> >> I already have all the code ready in my local repository. There are two >> commands to work with installed fonts (per 'x-family-fonts'): >> >> - show-font-select-preview :: Use minibuffer completion to select a >> font family and then display a buffer rendered in that family. >> >> - show-font-list :: Produce a buffer that has a short preview of each >> installed font, accompanied by the name of the font. >> >> Now all I am missing is the case with the file that I noted above. Then >> the prototype is feature complete and I can work on further refinements. > > If you are now talking only about uninstalled fonts, the way to handle > them in Emacs will be quite complicated, I think, and will be > highly-dependent on the font back-end. I'm not even sure this is > possible on all supported system (e.g., I don't know how to do that on > MS-Windows, I think it's impossible there). You may need to tell > users to install a font temporarily for previewing it. These are for installed fonts that we find with 'x-family-fonts'. I followed your suggestion and have now built on top of that function. Indeed, it is hard to preview a font that is not installed on the system. For those cases, we show the relevant warning and then provide the means to install that file by copying to the OS-dependent path (I implemented this earlier). * * * @Philip I made lots of changes since our last exchange earlier today. I think the package is ready for the release of version 0.1.0. I just need to write a manual for it. Is there anything else left before I push to elpa.git (I completely rewrote the file handler and there is no external code now)? -- Protesilaos Stavrou https://protesilaos.com ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [ELPA] Add new 'show-font' package? 2024-09-06 13:40 ` Protesilaos Stavrou @ 2024-09-06 13:56 ` Eli Zaretskii 0 siblings, 0 replies; 21+ messages in thread From: Eli Zaretskii @ 2024-09-06 13:56 UTC (permalink / raw) To: Protesilaos Stavrou; +Cc: philipk, emacs-devel > From: Protesilaos Stavrou <info@protesilaos.com> > Cc: philipk@posteo.net, emacs-devel@gnu.org > Date: Fri, 06 Sep 2024 16:40:09 +0300 > > > This seems to be in contradiction to what you said originally: that > > you first want to handle installed fonts. A font that is not yet > > installed will not appear in x-family-fonts, so you need something > > else entirely. > > The "something else" is why I am relying on 'fc-list' and 'fc-scan'. I > am keeping this dependency for the time being and will let users of > other platforms tell me what the equivalent programs are on their > system. Does fc-list show fonts that are not installed? > Indeed, it is hard to preview a font that is not installed on the > system. For those cases, we show the relevant warning and then provide > the means to install that file by copying to the OS-dependent path (I > implemented this earlier). On some systems, installation of a font does not boil down to copying the font's file. ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [ELPA] Add new 'show-font' package? 2024-09-05 10:18 ` Philip Kaludercic 2024-09-05 10:24 ` Eli Zaretskii @ 2024-09-06 5:43 ` Protesilaos Stavrou 2024-09-06 6:15 ` Eli Zaretskii 2024-09-06 6:33 ` Philip Kaludercic 1 sibling, 2 replies; 21+ messages in thread From: Protesilaos Stavrou @ 2024-09-06 5:43 UTC (permalink / raw) To: Philip Kaludercic; +Cc: emacs-devel > From: Philip Kaludercic <philipk@posteo.net> > Date: Thu, 5 Sep 2024 10:18:50 +0000 > > Protesilaos Stavrou <info@protesilaos.com> writes: > [... 48 lines elided] > A few comments on the code here: > [... 32 lines elided] Thank you, Philip! I will incorporate those. > (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? It does. I plan to change it, anyway. I needed something there to let me develop the core functionality. All I want though is to produce an empty buffer when I visit the file. If this proves difficult, then I will arrange for an alternative: to generate a new buffer and deal with it as I need to. > [... 44 lines elided] > Some general comments: It would be nice to have a command to select a > font. You mean to select a font to preview? This can be done, for sure, though I will need to decouple the preview/presentation from the file-visiting part. In other words, the user selects a font and then we do 'set-face-attribute' of its family across the buffer that we generate. This way, we do not need to know where the font is installed and to visit that file (though that is fine as well). -- Protesilaos Stavrou https://protesilaos.com ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [ELPA] Add new 'show-font' package? 2024-09-06 5:43 ` Protesilaos Stavrou @ 2024-09-06 6:15 ` Eli Zaretskii 2024-09-06 6:29 ` Protesilaos Stavrou 2024-09-06 6:33 ` Philip Kaludercic 1 sibling, 1 reply; 21+ messages in thread From: Eli Zaretskii @ 2024-09-06 6:15 UTC (permalink / raw) To: Protesilaos Stavrou; +Cc: philipk, emacs-devel > From: Protesilaos Stavrou <info@protesilaos.com> > Cc: emacs-devel@gnu.org > Date: Fri, 06 Sep 2024 08:43:09 +0300 > > > Some general comments: It would be nice to have a command to select a > > font. > > You mean to select a font to preview? This can be done, for sure, though > I will need to decouple the preview/presentation from the file-visiting > part. In other words, the user selects a font and then we do > 'set-face-attribute' of its family across the buffer that we generate. > This way, we do not need to know where the font is installed and to > visit that file (though that is fine as well). Did you plan on including support for showing non-ASCII fonts? That is, fonts whose sole purpose is to display non-ASCII characters of some script(s)? Because if you did (and I think it's important to Emacs users), then it would require different techniques, probably working with fontsets instead of set-face-attribute, because the latter only allows you to set the font for ASCII characters. ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [ELPA] Add new 'show-font' package? 2024-09-06 6:15 ` Eli Zaretskii @ 2024-09-06 6:29 ` Protesilaos Stavrou 2024-09-06 7:17 ` Eli Zaretskii 0 siblings, 1 reply; 21+ messages in thread From: Protesilaos Stavrou @ 2024-09-06 6:29 UTC (permalink / raw) To: Eli Zaretskii; +Cc: philipk, emacs-devel > From: Eli Zaretskii <eliz@gnu.org> > Date: Fri, 6 Sep 2024 09:15:05 +0300 > >> From: Protesilaos Stavrou <info@protesilaos.com> >> Cc: emacs-devel@gnu.org >> Date: Fri, 06 Sep 2024 08:43:09 +0300 >> >> > Some general comments: It would be nice to have a command to select a >> > font. >> >> You mean to select a font to preview? This can be done, for sure, though >> I will need to decouple the preview/presentation from the file-visiting >> part. In other words, the user selects a font and then we do >> 'set-face-attribute' of its family across the buffer that we generate. >> This way, we do not need to know where the font is installed and to >> visit that file (though that is fine as well). > > Did you plan on including support for showing non-ASCII fonts? Eventually yes. Though I need to consolidate the core functionality. > That is, fonts whose sole purpose is to display non-ASCII characters > of some script(s)? Because if you did (and I think it's important to > Emacs users), then it would require different techniques, probably > working with fontsets instead of set-face-attribute, because the > latter only allows you to set the font for ASCII characters. You mean to use 'set-fontset-font'? I will need to read more about the technicalities. -- Protesilaos Stavrou https://protesilaos.com ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [ELPA] Add new 'show-font' package? 2024-09-06 6:29 ` Protesilaos Stavrou @ 2024-09-06 7:17 ` Eli Zaretskii 0 siblings, 0 replies; 21+ messages in thread From: Eli Zaretskii @ 2024-09-06 7:17 UTC (permalink / raw) To: Protesilaos Stavrou; +Cc: philipk, emacs-devel > From: Protesilaos Stavrou <info@protesilaos.com> > Cc: philipk@posteo.net, emacs-devel@gnu.org > Date: Fri, 06 Sep 2024 09:29:57 +0300 > > > From: Eli Zaretskii <eliz@gnu.org> > > Date: Fri, 6 Sep 2024 09:15:05 +0300 > > > > Did you plan on including support for showing non-ASCII fonts? > > Eventually yes. Though I need to consolidate the core functionality. > > > That is, fonts whose sole purpose is to display non-ASCII characters > > of some script(s)? Because if you did (and I think it's important to > > Emacs users), then it would require different techniques, probably > > working with fontsets instead of set-face-attribute, because the > > latter only allows you to set the font for ASCII characters. > > You mean to use 'set-fontset-font'? Yes, and then using the fontset (if it is not the default). ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [ELPA] Add new 'show-font' package? 2024-09-06 5:43 ` Protesilaos Stavrou 2024-09-06 6:15 ` Eli Zaretskii @ 2024-09-06 6:33 ` Philip Kaludercic 2024-09-06 6:45 ` Protesilaos Stavrou 1 sibling, 1 reply; 21+ messages in thread From: Philip Kaludercic @ 2024-09-06 6:33 UTC (permalink / raw) To: Protesilaos Stavrou; +Cc: emacs-devel Protesilaos Stavrou <info@protesilaos.com> writes: >> From: Philip Kaludercic <philipk@posteo.net> >> Date: Thu, 5 Sep 2024 10:18:50 +0000 >> >> Protesilaos Stavrou <info@protesilaos.com> writes: > >> [... 48 lines elided] > >> A few comments on the code here: > >> [... 32 lines elided] > > Thank you, Philip! I will incorporate those. 1+ >> [... 44 lines elided] > >> Some general comments: It would be nice to have a command to select a >> font. > > You mean to select a font to preview? This can be done, for sure, though > I will need to decouple the preview/presentation from the file-visiting > part. In other words, the user selects a font and then we do > 'set-face-attribute' of its family across the buffer that we generate. > This way, we do not need to know where the font is installed and to > visit that file (though that is fine as well). Is it not possible to look up file name of the font one selects using e.g. `completing-read' and opening that with show-font? -- Philip Kaludercic on siskin ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [ELPA] Add new 'show-font' package? 2024-09-06 6:33 ` Philip Kaludercic @ 2024-09-06 6:45 ` Protesilaos Stavrou 2024-09-06 7:20 ` Eli Zaretskii 0 siblings, 1 reply; 21+ messages in thread From: Protesilaos Stavrou @ 2024-09-06 6:45 UTC (permalink / raw) To: Philip Kaludercic; +Cc: emacs-devel > From: Philip Kaludercic <philipk@posteo.net> > Date: Fri, 6 Sep 2024 06:33:26 +0000 > [... 20 lines elided] >>> Some general comments: It would be nice to have a command to select a >>> font. >> >> You mean to select a font to preview? This can be done, for sure, though >> I will need to decouple the preview/presentation from the file-visiting >> part. In other words, the user selects a font and then we do >> 'set-face-attribute' of its family across the buffer that we generate. >> This way, we do not need to know where the font is installed and to >> visit that file (though that is fine as well). > > Is it not possible to look up file name of the font one selects using > e.g. `completing-read' and opening that with show-font? I was thinking of the scenario where you have something like this: (completing-read "Preview font: " '("Hack" "Source Code Pro" "Iosevka Comfy")) Here we would not have file paths to visit them and enable the major mode there. But we could still produce a bespoke "*show-font*" buffer and then fontify it using the selected font family. [ The names of fonts would come from 'x-family-fonts'. ] -- Protesilaos Stavrou https://protesilaos.com ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [ELPA] Add new 'show-font' package? 2024-09-06 6:45 ` Protesilaos Stavrou @ 2024-09-06 7:20 ` Eli Zaretskii 2024-09-06 7:31 ` Philip Kaludercic 0 siblings, 1 reply; 21+ messages in thread From: Eli Zaretskii @ 2024-09-06 7:20 UTC (permalink / raw) To: Protesilaos Stavrou; +Cc: philipk, emacs-devel > From: Protesilaos Stavrou <info@protesilaos.com> > Cc: emacs-devel@gnu.org > Date: Fri, 06 Sep 2024 09:45:39 +0300 > > I was thinking of the scenario where you have something like this: > > (completing-read "Preview font: " '("Hack" "Source Code Pro" "Iosevka Comfy")) I think it should offer completion on font family names, not on file names. ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [ELPA] Add new 'show-font' package? 2024-09-06 7:20 ` Eli Zaretskii @ 2024-09-06 7:31 ` Philip Kaludercic 0 siblings, 0 replies; 21+ messages in thread From: Philip Kaludercic @ 2024-09-06 7:31 UTC (permalink / raw) To: Eli Zaretskii; +Cc: Protesilaos Stavrou, emacs-devel Eli Zaretskii <eliz@gnu.org> writes: >> From: Protesilaos Stavrou <info@protesilaos.com> >> Cc: emacs-devel@gnu.org >> Date: Fri, 06 Sep 2024 09:45:39 +0300 >> >> I was thinking of the scenario where you have something like this: >> >> (completing-read "Preview font: " '("Hack" "Source Code Pro" "Iosevka Comfy")) > > I think it should offer completion on font family names, not on file > names. My reason for suggesting file names was just that the current implementation works that way (i.e. a major mode for font files). -- Philip Kaludercic on siskin ^ permalink raw reply [flat|nested] 21+ messages in thread
end of thread, other threads:[~2024-09-06 13:56 UTC | newest] Thread overview: 21+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-09-04 9:21 [ELPA] Add new 'show-font' package? Protesilaos Stavrou 2024-09-05 10:18 ` Philip Kaludercic 2024-09-05 10:24 ` Eli Zaretskii 2024-09-06 5:35 ` Protesilaos Stavrou 2024-09-06 6:12 ` Eli Zaretskii 2024-09-06 6:23 ` Protesilaos Stavrou 2024-09-06 7:16 ` Eli Zaretskii 2024-09-06 7:23 ` Protesilaos Stavrou 2024-09-06 10:47 ` Eli Zaretskii 2024-09-06 10:59 ` Protesilaos Stavrou 2024-09-06 11:40 ` Eli Zaretskii 2024-09-06 13:40 ` Protesilaos Stavrou 2024-09-06 13:56 ` Eli Zaretskii 2024-09-06 5:43 ` Protesilaos Stavrou 2024-09-06 6:15 ` Eli Zaretskii 2024-09-06 6:29 ` Protesilaos Stavrou 2024-09-06 7:17 ` Eli Zaretskii 2024-09-06 6:33 ` Philip Kaludercic 2024-09-06 6:45 ` Protesilaos Stavrou 2024-09-06 7:20 ` Eli Zaretskii 2024-09-06 7:31 ` Philip Kaludercic
Code repositories for project(s) associated with this external index https://git.savannah.gnu.org/cgit/emacs.git https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.