Skip to content

Commit

Permalink
Merge pull request #27 from astoff/astoff-multiple-files
Browse files Browse the repository at this point in the history
Allow `helm-dictionary-database` to be an alist
  • Loading branch information
tmalsburg committed Jun 1, 2016
2 parents d6839ff + acf4835 commit 9e80ea2
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions helm-dictionary.el
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,13 @@
:group 'helm)

(defcustom helm-dictionary-database "/usr/share/trans/de-en"
"The file containing the dictionary."
"The file containing the dictionary, or an alist of offline
dictionaries where the key of each entry is the name of the
dictionary and the value is the file."
:group 'helm-dictionary
:type 'file)
:type '(choice
(file)
(alist :key-type string :value-type: file)))

(defcustom helm-dictionary-online-dicts
'(("translate.reference.com de->eng" .
Expand Down Expand Up @@ -237,13 +241,20 @@ browser in `helm-browse-url-default-browser-alist'"
(replace-regexp-in-string
" *{.+}\\| *\\[.+\\]" "" (cdr entry))))


(defvar helm-source-dictionary
(helm-build-in-file-source "Search dictionary" helm-dictionary-database
(defun helm-dictionary-build (name file)
(helm-build-in-file-source name file
:candidate-transformer 'helm-dictionary-transformer
:action '(("Insert source language term" . helm-dictionary-insert-l1term)
("Insert target language term" . helm-dictionary-insert-l2term))))


(defvar helm-source-dictionary
(mapcar
(lambda (x) (helm-dictionary-build (car x) (cdr x)))
(if (stringp helm-dictionary-database)
(list (cons "Search dictionary" helm-dictionary-database))
helm-dictionary-database)))

(defvar helm-source-dictionary-online
(helm-build-sync-source "Look up online"
:match (lambda (_candidate) t)
Expand All @@ -260,7 +271,7 @@ browser in `helm-browse-url-default-browser-alist'"
;;;###autoload
(defun helm-dictionary ()
(interactive)
(helm :sources '(helm-source-dictionary helm-source-dictionary-online)
(helm :sources (append helm-source-dictionary (list helm-source-dictionary-online))
:full-frame t
:candidate-number-limit 500
:buffer "*helm dictionary*"))
Expand Down

0 comments on commit 9e80ea2

Please sign in to comment.