emacs-emojify

fork of https://github.com/iqbalansari/emacs-emojify
Log | Files | Refs | LICENSE

commit c2708194d9778b044dbd75b1cc70e9b9159821ff
parent 96b728c1b89b8476778f517b8714b31110db07fa
Author: Iqbal Ansari <iqbalansari02@yahoo.com>
Date:   Mon, 13 Mar 2017 14:47:49 +0530

Use a hash-table as the collection or `emojify-completing-read`

Earlier we used a list as the collection this restricts the information that the
`predicate` argument for `emojify-completing-read` has access to for filtering
the candidates, using that hash-table with display string and the emoji data
allows provides all the data about the emoji to the predicate.

Diffstat:
Memojify.el | 35++++++++++++++++++++++++++---------
1 file changed, 26 insertions(+), 9 deletions(-)

diff --git a/emojify.el b/emojify.el @@ -1506,6 +1506,31 @@ Borrowed from apropos.el" ;; Inserting emojis +(defvar emojify--completing-candidates-cache nil + "Cached values for completing read candidates calculated for `emojify-completing-read'.") + +(defun emojify--get-completing-read-candidates () + "Get the candidates to be used for `emojify-completing-read'. + +The candidates are calculated according to currently active +`emojify-emoji-styles' and cached" + (let ((styles (mapcar #'symbol-name emojify-emoji-styles))) + (unless (and emojify--completing-candidates-cache + (equal styles (car emojify--completing-candidates-cache))) + (setq emojify--completing-candidates-cache + (cons styles + (let ((emojis (ht-create #'equal))) + (emojify-emojis-each (lambda (key value) + (when (seq-position styles (ht-get value "style")) + (ht-set! emojis + (format "%s - %s (%s)" + key + (ht-get value "name") + (ht-get value "style")) + value)))) + emojis)))) + (cdr emojify--completing-candidates-cache))) + (defun emojify--completing-read-minibuffer-setup-hook () "Enables `emojify-mode' in minbuffer while inserting emojis. @@ -1531,15 +1556,7 @@ HIST, DEF, INHERIT-INPUT-METHOD correspond to the arguments for (styles (mapcar #'symbol-name emojify-emoji-styles)) (line-spacing 7) (completion-ignore-case t) - (candidates (let (emojis) - (emojify-emojis-each (lambda (key value) - (when (seq-position styles (ht-get value "style")) - (push (format "%s - %s (%s)" - key - (ht-get value "name") - (ht-get value "style")) - emojis)))) - emojis)) + (candidates (emojify--get-completing-read-candidates)) ;; Vanilla Emacs completion and Icicles use the completion list mode to display candidates ;; the following makes sure emojify is enabled in the completion list (completion-list-mode-hook (cons #'emojify--completing-read-minibuffer-setup-hook