No longer use transient in isearch-emoji-by-name

* 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'.
This commit is contained in:
Jonas Bernoulli 2023-02-01 20:25:15 +01:00
parent 0c125fcc67
commit 58dc03ba7e
No known key found for this signature in database
GPG key ID: 230C2EFBB326D927
2 changed files with 28 additions and 28 deletions

View file

@ -245,6 +245,7 @@ the name is not known."
(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 @@ We prefer the earliest unique letter."
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 @@ We prefer the earliest unique letter."
(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

View file

@ -2774,25 +2774,21 @@ With argument, add COUNT copies of the character."
(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