Function: emoji--define-transient

emoji--define-transient is a byte-compiled function defined in emoji.el.gz.

Signature

(emoji--define-transient &optional ALIST INHIBIT-DERIVED END-FUNCTION)

Source Code

;; Defined in /usr/src/emacs/lisp/international/emoji.el.gz
(defun emoji--define-transient (&optional alist inhibit-derived
                                          end-function)
  (unless alist
    (setq alist (cons "Emoji" emoji--labels)))
  (let* ((mname (pop alist))
         (name (intern (format "emoji--command-%s" mname)))
         (emoji--done-derived (or emoji--done-derived
                                  (make-hash-table :test #'equal)))
         (has-subs (consp (cadr alist)))
         (layout
          (if has-subs
              ;; Define sub-maps.
              (cl-loop for entry in
                       (emoji--compute-prefix
                        (if (equal mname "Emoji")
                            (cons (list "Recent") alist)
                          alist))
                       collect (list
                                (car entry)
                                (emoji--compute-name (cdr entry))
                                (if (equal (cadr entry) "Recent")
                                    (emoji--recent-transient end-function)
                                  (emoji--define-transient
                                   (cons (concat mname " > " (cadr entry))
                                         (cddr entry))))))
            ;; Insert an emoji.
            (cl-loop for glyph in alist
                     for i in (append (number-sequence ?a ?z)
                                      (number-sequence ?A ?Z)
                                      (number-sequence ?0 ?9)
                                      (number-sequence ?! ?/))
                     collect (let ((this-glyph glyph))
                               (list
                                (string i)
                                (emoji--fontify-glyph
                                 glyph inhibit-derived)
                                (let ((derived
                                       (and (not inhibit-derived)
                                            (not (gethash glyph
                                                          emoji--done-derived))
                                            (gethash glyph emoji--derived))))
                                  (if derived
                                      ;; We have a derived glyph, so add
                                      ;; another level.
                                      (progn
                                        (setf (gethash glyph
                                                       emoji--done-derived)
                                              t)
                                        (emoji--define-transient
                                         (cons (concat mname " " glyph)
                                               (cons glyph derived))
                                         t end-function))
                                    ;; Insert the emoji.
                                    (lambda ()
                                      (interactive nil not-a-mode)
                                      ;; Allow switching to the correct
                                      ;; buffer.
                                      (when end-function
                                        (funcall end-function))
                                      (emoji--add-recent this-glyph)
                                      (insert this-glyph)))))))))
         (args (apply #'vector mname
                      (emoji--columnize layout
                                        (if has-subs 2 8)))))
    ;; There's probably a better way to do this...
    (setf (symbol-function name)
          (lambda ()
            (interactive nil not-a-mode)
            (transient-setup name)))
    (pcase-let ((`(,class ,slots ,suffixes ,docstr ,_body)
                 (transient--expand-define-args (list args))))
       (put name 'interactive-only t)
       (put name 'function-documentation docstr)
       (put name 'transient--prefix
            (apply (or class 'transient-prefix) :command name
                   (cons :variable-pitch (cons t slots))))
       (put name 'transient--layout
            (transient-parse-suffixes name suffixes)))
    name))