Skip to content

Commit

Permalink
add optional args DICT and QUERY to helm-dictionary
Browse files Browse the repository at this point in the history
this allows helm-dictionary to be called from other functions, specifying
a dictionary to use, and a search query.

if an incorrect dictionary is given, we just ignore it.

if a query is given, it is handed to :input, so it will instantly narrow the sources.
  • Loading branch information
mousebot committed Mar 18, 2022
1 parent b316a1d commit de34f04
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions helm-dictionary.el
Original file line number Diff line number Diff line change
Expand Up @@ -259,18 +259,25 @@ browser in `helm-browse-url-default-browser-alist'"
"Source for online look-up.")

;;;###autoload
(defun helm-dictionary ()
(defun helm-dictionary (&optional dict query)
"Load helm-dictionary.
Optionally, use only dictionary DICT and provide input QUERY."
(interactive)
(let ((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)))
(input (thing-at-point 'word)))
(if (and dict
(member dict
helm-dictionary-database))
(helm-dictionary-build (car dict) (cdr dict))
(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))))
(input (or query (thing-at-point 'word))))
(helm :sources (append helm-source-dictionary (list helm-source-dictionary-online))
:full-frame t
:default input
:input (when query input)
:candidate-number-limit 500
:buffer "*helm dictionary*")))

Expand Down

0 comments on commit de34f04

Please sign in to comment.