emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

scratch/emoji 95254d0: Introduce a new variable inhibit-loading-fonts


From: Lars Ingebrigtsen
Subject: scratch/emoji 95254d0: Introduce a new variable inhibit-loading-fonts
Date: Fri, 29 Oct 2021 10:48:01 -0400 (EDT)

branch: scratch/emoji
commit 95254d0103548304b6e9fd0e6dce03d9ca866cbd
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Introduce a new variable inhibit-loading-fonts
---
 lisp/play/emoji.el | 70 ++++++++++++++++++++++++++++++++++++++++++++----------
 src/fontset.c      | 15 ++++++++++--
 2 files changed, 70 insertions(+), 15 deletions(-)

diff --git a/lisp/play/emoji.el b/lisp/play/emoji.el
index c0c3dcc..91ff9c1 100644
--- a/lisp/play/emoji.el
+++ b/lisp/play/emoji.el
@@ -167,6 +167,35 @@ character) under point is."
                  'help-echo (emoji--name glyph))))
       (insert "\n\n"))))
 
+(defun emoji--pick-read-affixation (names)
+  (mapcar
+   (lambda (name)
+     (list name (char-to-string
+                 (char-from-name
+                  (concat "EMOJI MODIFIER FITZPATRICK TYPE-" name)))))
+   names))
+
+(defun emoji--pick-read-tone (prompt initial-input history)
+  (let* ((names '("1-2" "3" "4" "5" "6"))
+         (str (completing-read
+               prompt
+               (lambda (string pred action)
+                 (if (eq action 'metadata)
+                     `(metadata
+                      (affixation-function . ,'emoji--pick-read-affixation))
+                   (complete-with-action action names string pred)))
+               nil t initial-input history)))
+    (char-to-string
+     (char-from-name (concat "EMOJI MODIFIER FITZPATRICK TYPE-" str)))))
+
+(transient-define-infix emoji-pick:--skin-tone ()
+  :description "Skin tone"
+  :class 'transient-option
+  :shortarg "-s"
+  :argument ""
+  :prompt "Skin tone: "
+  :reader #'emoji--pick-read-tone)
+
 (defun emoji--fontify-glyph (glyph &optional inhibit-derived)
   (propertize glyph 'face
               (if (and (not inhibit-derived)
@@ -254,15 +283,21 @@ character) under point is."
   (if (consp (caddr alist))
       (dolist (child (cdr alist))
         (emoji--adjust-displayable child))
-    (setcdr alist (seq-filter
-                   (lambda (glyph)
-                     ;; Store all the emojis for later retrieval by
-                     ;; the search feature.
-                     (when-let ((name (emoji--name glyph)))
-                       (setf (gethash (downcase name) emoji--all-bases) glyph))
-                     ;; Say whether we should include in graphical displays.
-                     (not (symbolp (char-displayable-p (elt glyph 0)))))
-                   (cdr alist)))))
+    (let ((inhibit-loading-fonts nil))
+      (setcdr
+       alist
+       (seq-filter
+        (lambda (glyph)
+          ;; Store all the emojis for later retrieval by
+          ;; the search feature.
+          (when-let ((name (emoji--name glyph)))
+            (setf (gethash (downcase name) emoji--all-bases) glyph))
+          ;; Say whether we should include in graphical displays.
+          (let ((symp (symbolp (char-displayable-p (elt glyph 0)))))
+            (unless symp
+              (setq inhibit-loading-fonts t))
+            (not symp)))
+        (cdr alist))))))
 
 (defun emoji--parse-emoji-test ()
   (setq emoji--labels nil)
@@ -433,16 +468,25 @@ character) under point is."
               (cl-loop for entry in
                        (emoji--compute-prefix
                         (if (equal mname "Emoji")
-                            (cons (list "Recent") alist)
+                            (nconc
+                             (list (list "Recent")
+                                   ;;(list "Variations")
+                                   )
+                             alist)
                           alist))
                        collect (list
                                 (car entry)
                                 (emoji--compute-name (cdr entry))
-                                (if (equal (cadr entry) "Recent")
-                                    (emoji--recent-transient end-function)
+                                (cond
+                                 ((equal (cadr entry) "Recent")
+                                  (emoji--recent-transient end-function))
+                                 ((equal (cadr entry) "Variations")
+                                  ;;(emoji-pick:--skin-tone)
+                                  )
+                                 (t
                                   (emoji--define-transient
                                    (cons (concat mname " > " (cadr entry))
-                                         (cddr entry))))))
+                                         (cddr entry)))))))
             ;; Insert an emoji.
             (cl-loop for glyph in alist
                      for i in (append (number-sequence ?a ?z)
diff --git a/src/fontset.c b/src/fontset.c
index 7d4bd65..0c6100c 100644
--- a/src/fontset.c
+++ b/src/fontset.c
@@ -657,8 +657,11 @@ fontset_find_font (Lisp_Object fontset, int c, struct face 
*face,
             the support of the character C.  That checking is costly,
             and even without the checking, the found font supports C
             in high possibility.  */
-         font_entity = font_find_for_lface (f, face->lface,
-                                            FONT_DEF_SPEC (font_def), -1);
+         if (! inhibit_loading_fonts)
+           font_entity = font_find_for_lface (f, face->lface,
+                                              FONT_DEF_SPEC (font_def), -1);
+         else
+           font_entity = Qnil;
          if (NILP (font_entity))
            {
              /* Record that no font matches the spec.  */
@@ -2172,6 +2175,14 @@ fontsets, if the default font can display the character.
 Set this to nil to make Emacs honor the fontsets instead.  */);
   use_default_font_for_symbols = 1;
 
+  DEFVAR_BOOL ("inhibit-loading-fonts", inhibit_loading_fonts,
+              doc: /*
+If non-nil, inhibit loading fonts.
+This is not meant to be used generally, but only in specific
+circumstances for certain characters where attempting to load fonts is
+known to be inefficient and futile.  */);
+  inhibit_loading_fonts = 0;
+
   DEFVAR_LISP ("ignore-relative-composition", Vignore_relative_composition,
               doc: /*
 Char table of characters which are not composed relatively.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]