summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2021-12-19 20:21:15 +0100
committerLars Ingebrigtsen <larsi@gnus.org>2021-12-19 20:21:15 +0100
commit6aac4caaff7c3217b917f3a08a114ab68f082740 (patch)
tree33400cd89c5f13637c012f8934579d25948f8ccc
parentdf3fde6fa5366d02fb41d98962df0b2e1148d5b2 (diff)
downloademacs-6aac4caaff7c3217b917f3a08a114ab68f082740.tar.gz
Further tweaks to the emoji segmentation
* lisp/international/emoji.el (emoji--parse-emoji-test): Ensure that we key off of the "person" variants, even if they come after the gendered variations (which is the case for a handful of glyphs).
-rw-r--r--lisp/international/emoji.el51
1 files changed, 35 insertions, 16 deletions
diff --git a/lisp/international/emoji.el b/lisp/international/emoji.el
index 4375a6344c5..205a803a25e 100644
--- a/lisp/international/emoji.el
+++ b/lisp/international/emoji.el
@@ -305,6 +305,7 @@ the name is not known."
(setq emoji--names (make-hash-table :test #'equal))
(let ((derivations (make-hash-table :test #'equal))
(case-fold-search t)
+ (glyphs nil)
group subgroup)
(while (not (eobp))
(cond
@@ -318,27 +319,40 @@ the name is not known."
(let* ((codes (match-string 1))
(qualification (match-string 2))
(name (match-string 3))
- (base (emoji--base-name name derivations))
(glyph (mapconcat
(lambda (code)
(string (string-to-number code 16)))
(split-string codes))))
- ;; Special-case flags.
- (when (equal base "flag")
- (setq base name))
- ;; Register all glyphs to that we can look up their names
- ;; later.
- (setf (gethash glyph emoji--names) name)
- ;; For the interface, we only care about the fully qualified
- ;; emojis.
- (when (equal qualification "fully-qualified")
- (when (equal base name)
- (emoji--add-to-group group subgroup glyph))
- ;; Create mapping from base glyph name to name of
- ;; derived glyphs.
- (setf (gethash base derivations)
- (nconc (gethash base derivations) (list glyph)))))))
+ (push (list name qualification group subgroup glyph) glyphs))))
(forward-line 1))
+ ;; We sort the data so that the "person foo" variant comes
+ ;; first, so that that becomes the key.
+ (setq glyphs
+ (sort (nreverse glyphs)
+ (lambda (g1 g2)
+ (and (equal (nth 2 g1) (nth 2 g2))
+ (equal (nth 3 g1) (nth 3 g2))
+ (< (emoji--score (car g1))
+ (emoji--score (car g2)))))))
+ ;; Get the derivations.
+ (cl-loop for (name qualification group subgroup glyph) in glyphs
+ for base = (emoji--base-name name derivations)
+ do
+ ;; Special-case flags.
+ (when (equal base "flag")
+ (setq base name))
+ ;; Register all glyphs to that we can look up their names
+ ;; later.
+ (setf (gethash glyph emoji--names) name)
+ ;; For the interface, we only care about the fully qualified
+ ;; emojis.
+ (when (equal qualification "fully-qualified")
+ (when (equal base name)
+ (emoji--add-to-group group subgroup glyph))
+ ;; Create mapping from base glyph name to name of
+ ;; derived glyphs.
+ (setf (gethash base derivations)
+ (nconc (gethash base derivations) (list glyph)))))
;; Finally create the mapping from the base glyphs to derived ones.
(setq emoji--derived (make-hash-table :test #'equal))
(maphash (lambda (_k v)
@@ -346,6 +360,11 @@ the name is not known."
(cdr v)))
derivations))))
+(defun emoji--score (string)
+ (if (string-match-p "person\\|people" string)
+ 0
+ 1))
+
(defun emoji--add-to-group (group subgroup glyph)
;; "People & Body" is very large; split it up.
(cond