0

I want to build a helm-source from a large hash-table, is there a smarter/faster way to to this, than the way described below?

(setq tab #s(hash-table
             size 16
             test equal
             data ("asdf"  "asdf"
                   "zxcv"  "zxcv"
                   "qwert"  "qwert")))

(setq l '(("asdf" . "asdf")
          ("zxcv" . "zxcv")
          ("qwert" . "qwert")))

;;; works as expected
(helm :sources (helm-build-sync-source "test"
                 :candidates l
                 :fuzzy-match t
                 :action (lambda (candidate) (insert candidate)))
      :buffer "*helm test*")

;;; does not work
(helm :sources (helm-build-sync-source "test"
                 :candidates tab
                 :fuzzy-match t
                 :action (lambda (candidate) (insert candidate)))
      :buffer "*helm test*")

I can build a function that transforms the hash-table:

(defun hash-to-alist (hash)
  (let (res)
    (maphash (lambda (key value)
               (push `(,key . ,value) res))
             hash)
    res))

(helm :sources (helm-build-sync-source "test"
                 :candidates (hash-to-alist tab) 
                 :fuzzy-match t
                 :action (lambda (candidate) (insert candidate)))
      :buffer "*helm test*")
0

This is fast enough on my computer:

(let ((utf8-hash-table (ucs-names)))
  (helm :sources
        `((name . "Unicode character by name")
          (candidates . ,(hash-table-keys utf8-hash-table))
          (action . (lambda (key) (insert (gethash key ,utf8-hash-table)))))))
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.