unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Jonas Bernoulli <jonas@bernoul.li>
To: 60740@debbugs.gnu.org
Cc: larsi@gnus.org
Subject: bug#60740: [PATCH 1/2] No longer use transient in isearch-emoji-by-name
Date: Thu,  2 Feb 2023 00:09:17 +0100	[thread overview]
Message-ID: <20230201230918.550-2-jonas@bernoul.li> (raw)
In-Reply-To: <20230201230918.550-1-jonas@bernoul.li>

* lisp/isearch.el (isearch-emoji-by-name): Use 'emoji--read-emoji'
and if that returns derivations, 'completing-read' to select one
of them.  This fixes bug#60740.
* lisp/international/emoji.el (emoji--init): Autoload.
(emoji--read-emoji): New function, which doesn't use transient
and returns a list of the glyph and all derivations, if any.
(emoji--choose-emoji): Use 'emoji--read-emoji'.
---
 lisp/international/emoji.el | 36 ++++++++++++++++++++----------------
 lisp/isearch.el             | 20 ++++++++------------
 2 files changed, 28 insertions(+), 28 deletions(-)

diff --git a/lisp/international/emoji.el b/lisp/international/emoji.el
index 2d17cf639b0..f75bd877991 100644
--- a/lisp/international/emoji.el
+++ b/lisp/international/emoji.el
@@ -245,6 +245,7 @@ emoji-list-help
           (error "Emoji name is unknown")
         (message "%s" name)))))
 
+;;;###autoload
 (defun emoji--init (&optional force inhibit-adjust)
   (when (or (not emoji--labels)
             force)
@@ -638,7 +639,7 @@ emoji--split-long-lists
                          collect (cons (concat (string prefix) "-group")
                                        (seq-take bit 77))))))))
 
-(defun emoji--choose-emoji ()
+(defun emoji--read-emoji ()
   ;; Use the list of names.
   (let* ((table
           (if (not emoji-alternate-names)
@@ -678,21 +679,24 @@ emoji--choose-emoji
 	       (complete-with-action action table string pred)))
            nil t)))
     (when (cl-plusp (length name))
-      (let* ((glyph (if emoji-alternate-names
-                        (cadr (split-string name "\t"))
-                      (gethash name emoji--all-bases)))
-             (derived (gethash glyph emoji--derived)))
-        (if (not derived)
-            ;; Simple glyph with no derivations.
-            (progn
-              (emoji--add-recent glyph)
-              (insert glyph))
-          ;; Choose a derived version.
-          (let ((emoji--done-derived (make-hash-table :test #'equal)))
-            (setf (gethash glyph emoji--done-derived) t)
-            (funcall
-             (emoji--define-transient
-              (cons "Choose Emoji" (cons glyph derived))))))))))
+      (let ((glyph (if emoji-alternate-names
+                       (cadr (split-string name "\t"))
+                     (gethash name emoji--all-bases))))
+        (cons glyph (gethash glyph emoji--derived))))))
+
+(defun emoji--choose-emoji ()
+  (pcase-let ((`(,glyph ,derived)) (emoji--read-emoji))
+    (if (not derived)
+        ;; Simple glyph with no derivations.
+        (progn
+          (emoji--add-recent glyph)
+          (insert glyph))
+      ;; Choose a derived version.
+      (let ((emoji--done-derived (make-hash-table :test #'equal)))
+        (setf (gethash glyph emoji--done-derived) t)
+        (funcall
+         (emoji--define-transient
+          (cons "Choose Emoji" (cons glyph derived))))))))
 
 (defvar-keymap emoji-zoom-map
   "+" #'emoji-zoom-increase
diff --git a/lisp/isearch.el b/lisp/isearch.el
index 22e27764127..bfa71756146 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -2774,25 +2774,21 @@ isearch-char-by-name
 					   (mapconcat 'isearch-text-char-description
 						      string ""))))))))
 
-(defvar emoji--derived)
 (defun isearch-emoji-by-name (&optional count)
   "Read an Emoji name and add it to the search string COUNT times.
 COUNT (interactively, the prefix argument) defaults to 1.
 The command accepts Unicode names like \"smiling face\" or
 \"heart with arrow\", and completion is available."
   (interactive "p")
+  (emoji--init)
   (with-isearch-suspended
-   (let ((emoji (with-temp-buffer
-                  ;; Derived emoji not supported yet (bug#60740).
-                  ;; So first load `emoji--labels', then `emoji--init'
-                  ;; will not fill `emoji--derived' that is set
-                  ;; to an empty hash table below.
-                  (ignore-errors (require 'emoji-labels))
-                  (let ((emoji--derived (make-hash-table :test #'equal)))
-                    (emoji-search))
-                  (if (and (integerp count) (> count 1))
-                      (apply 'concat (make-list count (buffer-string)))
-                    (buffer-string)))))
+   (pcase-let* ((`(,glyph . ,derived) (emoji--read-emoji))
+                (emoji (if derived
+                           (completing-read "Select derivation: "
+                                            (cons glyph derived) nil t)
+                         glyph)))
+     (when (and (integerp count) (> count 1))
+       (setq emoji (apply 'concat (make-list count emoji))))
      (when emoji
        (setq isearch-new-string (concat isearch-string emoji)
              isearch-new-message (concat isearch-message
-- 
2.39.1






  reply	other threads:[~2023-02-01 23:09 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <83leli3nly.fsf@gnu.org>
2023-02-01 23:09 ` bug#60740: [PATCH 0/2] emoji changes Jonas Bernoulli
2023-02-01 23:09   ` Jonas Bernoulli [this message]
2023-02-01 23:09   ` bug#60740: [PATCH 2/2] Rewrite emoji's usage of transient Jonas Bernoulli
2023-02-04  8:30   ` bug#60740: [PATCH 0/2] emoji changes Eli Zaretskii
2023-02-04 12:05     ` Jonas Bernoulli
2023-02-04 12:29       ` Eli Zaretskii
2023-02-05 14:40         ` Jonas Bernoulli
2023-02-05 14:53           ` Eli Zaretskii
2023-02-05 15:02           ` Eli Zaretskii
2023-02-05 16:29             ` Jonas Bernoulli
2023-02-05 16:53               ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230201230918.550-2-jonas@bernoul.li \
    --to=jonas@bernoul.li \
    --cc=60740@debbugs.gnu.org \
    --cc=larsi@gnus.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).