[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
scratch/emoji 754a985 1/3: Implement a textual insertion command variati
From: |
Lars Ingebrigtsen |
Subject: |
scratch/emoji 754a985 1/3: Implement a textual insertion command variation |
Date: |
Tue, 26 Oct 2021 16:36:13 -0400 (EDT) |
branch: scratch/emoji
commit 754a9852362a2398d7c6410d97596870f549b330
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
Implement a textual insertion command variation
---
lisp/play/emoji.el | 28 ++++++++++++++++++++++++----
1 file changed, 24 insertions(+), 4 deletions(-)
diff --git a/lisp/play/emoji.el b/lisp/play/emoji.el
index 753045c..2290b1b 100644
--- a/lisp/play/emoji.el
+++ b/lisp/play/emoji.el
@@ -42,11 +42,15 @@
(defvar emoji--names (make-hash-table :test #'equal))
;;;###autoload
-(defun emoji-insert ()
- "Choose and insert an emoji glyph."
- (interactive)
+(defun emoji-insert (&optional text)
+ "Choose and insert an emoji glyph.
+If TEXT (interactively, the prefix), use a textual search instead
+of a visual interface."
+ (interactive "P")
(emoji--init)
- (funcall (intern "emoji-command-Emoji")))
+ (if text
+ (emoji--choose-emoji)
+ (funcall (intern "emoji-command-Emoji"))))
(defvar emoji--insert-buffer)
@@ -394,6 +398,22 @@ We prefer the earliest unique letter."
collect (cons (concat (string prefix) "-group")
(seq-take bit 77))))))))
+(defun emoji--choose-emoji ()
+ (let ((names (make-hash-table :test #'equal)))
+ (dolist (section (emoji--flatten (cons "Emoji" emoji--labels)))
+ (dolist (char section)
+ (when-let ((name (or (gethash char emoji--names)
+ (get-char-code-property (aref char 0) 'name))))
+ (setf (gethash (downcase name) names) char))))
+ (let* ((name (completing-read "Emoji: " names nil t))
+ (glyph (gethash name names))
+ (variants (gethash glyph emoji--variants)))
+ (if (not variants)
+ (insert glyph)
+ (funcall
+ (emoji--define-transient
+ (cons "Choose Emoji" (cons glyph variants))))))))
+
(provide 'emoji)
;;; emoji.el ends here