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*")
gdkrmr
  • 175
  • 7

1 Answers1

1

This is fast enough on my computer:

(let ((utf8-hash-table (ucs-names)))
  (helm :sources
        (helm-build-sync-source "Unicode character by name"
          :candidates (hash-table-keys utf8-hash-table)
          :action (lambda (key) (insert (gethash key utf8-hash-table))))))
jagrg
  • 3,824
  • 4
  • 19
Edoot
  • 111
  • 1