Closed thierryvolpiatto closed 10 years ago
Here some code that can simplify helm-dictionary:
(defun helm-dict-transformer (candidates) "Formats entries retrieved from the data base." (loop for i in candidates for headerp = (string-match "\\`#" i) for entry = (split-string i " :: ") for l1terms = (split-string (car entry) " | ") for l2terms = (split-string (cadr entry) " | ") for filtered-helm-pattern = (replace-regexp-in-string "\\\\$" "" helm-pattern) for width = (save-excursion (with-helm-window (window-width))) unless headerp append (loop for l1term in l1terms for l2term in l2terms if (or (string-match filtered-helm-pattern l1term) (string-match filtered-helm-pattern l2term)) collect (cons (concat (truncate-string-to-width l1term (- (/ width 2) 1) 0 ?\s) " " (truncate-string-to-width l2term (- (/ width 2) 1) 0 ?\s)) (cons l1term l2term))))) (defvar helm-source-dict '((name . "test dict") (candidate-transformer . helm-dict-transformer) (candidates-file . helm-dictionary-database) (action . (("Insert initial term" . helm-dictionary-insert-l1term) ("Insert translation term" . helm-dictionary-insert-l2term))))) (helm :sources 'helm-source-dict :buffer "*helm test*")
This would fix also previous issue.
I merged the branch candidates-file into master. Thanks, Thierry for the great suggestions.
Here some code that can simplify helm-dictionary: