Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run with a single dictionary and provide default search term #31

Open
mooseyboots opened this issue Mar 18, 2022 · 3 comments
Open

run with a single dictionary and provide default search term #31

mooseyboots opened this issue Mar 18, 2022 · 3 comments

Comments

@mooseyboots
Copy link

mooseyboots commented Mar 18, 2022

i have various dictionaries specified in helm-dictionary-database and i'm interested in being able to choose which one of them to use when i run helm-dictionary. i'm mainly interested in this to speed it up. i have dicts for different languages but usually only want to search for a term in one of them at a time.

i'd also like to feed it a default input string, so i can call it from a function and provide the search term.

i came up with this:

(defun helm-dictionary (&optional dictionary query)
  (interactive)
  (let ((helm-source-dictionary
         (if dictionary
           (helm-dictionary-build (car dictionary) (cdr 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 (or query (thing-at-point 'word))))
        (helm :sources (append helm-source-dictionary (list helm-source-dictionary-online))
              :full-frame t
              :default input
              :candidate-number-limit 500
              :buffer "*helm dictionary*")))

then i call it like so:

  (let ((query (fetch-query-string-from-somewhere)))
    (helm-dictionary (assoc "de-en" helm-dictionary-database) query)))

the dictionary arg seems to work right, though i'm not sure if thats the best way to do it?

and for now the query argument isn't respected by helm's :default. i then tried again without my new arg, and, at least for me, it also doesn't seem to use (thing-at-point 'word) either. helm-dictionary opens with no default input. am i missing something there?

@mooseyboots mooseyboots changed the title run with a single dictionary run with a single dictionary and provide default search term Mar 18, 2022
@mooseyboots
Copy link
Author

mooseyboots commented Mar 18, 2022

ah, i just saw #30. switching back to :default input to :input input in this case seems to work.

let binding helm-maybe-use-default-as-input from my caller function doesn't seem to work but maybe i can live with that.

now i wonder how i can hand helm-dictionary my query string surrounded by \b to narrow the search down, as concatenating converts the \b to ^H, which returns zero results.

@tmalsburg
Copy link
Member

Perhaps you just have to use \\b when concatenating?

@mooseyboots
Copy link
Author

that works! thanks.

i also asked helm about the use of :resume. it would be great if it would work without an input, as then the performance issue re loading lots of dictionaries each time would be solved, but alas, thierry says it can't be done.

an updated version of my modified helm-dict is here:
mooseyboots@de34f04.

works for me: when i'm viewing results in emacs-leo i can now instantly run helm-dictionary with just one dictionary enabled and search for the same term.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants