emacs-helm / helm-dictionary Goto Github PK
View Code? Open in Web Editor NEWHelm source for looking up dictionaries
Helm source for looking up dictionaries
As you told me this source should not match against helm-pattern.
Using dummy attr doesn't help here, here what you can do:
(defvar helm-source-dictionary-online
`((name . "Lookup online")
(match (lambda (_candidate) t))
(candidates . helm-dictionary-online-dicts)
(nohighlight)
(action
. (lambda (cand)
(let ((browse-url-browser-function
(or helm-dictionary-browser-function
browse-url-browser-function)))
(helm-browse-url (format cand (url-hexify-string helm-pattern)))))))
"Source for online lookup.")
(Proposed by Thierry.) I agree that it can be counter-intuitive when case matters (because it doesn't in most other search facilities). However, in some languages, e.g. German, it's very useful if you can search for upper-case letters. For example when you want to search for nouns. In German, you want to use "Test" to match the noun Test but "test" for matching things like the verb testen.
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?
Hi,
in the header and the doc of `helm-dictionary-browser-function', we should say more clearly how the browser function is selected. The docs are currently incomplete and inconsistent.
This is how it works:
Also the tag in
(const :tag "Currently configured default for Helm"
:value nil)
is misleading. We don't need to give a complete description in the :tag, we could just use "default" and explain in the docstring what that means.
Proposed by Thierry. I'm not sure about this. There's C-w which inserts the part of word-at-point to the left of the cursor but that doesn't seem useful to me because it will often be a partial word not the whole thing. Comments appreciated.
I'm not happy with making thing-at-point the default input. It's hardly ever what I want. (I use helm-dictionary mostly while writing, not reading.) I'd like to undo this. But I also want other users to be able to quickly search for the word under the cursor. Two options: we could offer a separate command helm-dictionary-at-point or we could introduce a defcustom that defines whether thing-at-point should be used by default. I prefer the former solution, because I could bind both helm-dictionary functions to keys and use them side-by-side. What do you think, @thierryvolpiatto.
Hi Titus and Michael,
just tried helm-dictionary, and I have an error because helm-dictionary-database
default value point to a non--existing file.
You should check for this in helm-dictionary-init
:
(when (file-exists-p helm-dictionary-database)
You misunderstand what helm-browse-url does, you should use:
(let ((browse-url-browser-function
(or helm-dictionary-browser-function
browse-url-browser-function)))
(helm-browse-url (format cand (url-hexify-string helm-pattern)))))))
and remove the helm-browse-url entry in helm-dictionary-browser-function
.
There are many free dictionaries with .dict
format here: http://abloz.com/huzheng/stardict-dic/
It would be nice if we have support for it. To get the raw text dictionary:
.dict
file.Calling helm-dictionary in emacs-25 fails with this error:
slot-missing: Invalid slot name: "#<helm-source-sync helm-source-sync>", :multimatch
Hi,
after working a bit with the code, I have questions aboutt the following points:
I think it's not good to hardcode language names, because this package can be used for dictionaries of other languages as well. Maybe we should call the actions "Insert from left|right side" or so?
helm-dictionary-word-at-point' - is this really useful? You can always use C-w (
helm-yank-text-at-point') to insert the current word. Defining an extra command seems a bit like overkill.Action names are hardcoded to german/english:
(action . (("Insert German term" . helm-dictionary-insert-l1term)
("Insert English term" . helm-dictionary-insert-l2term)))
Hello,
I don't see this package in M-x package-list-packages. Can we upload it to Melpa?
Hi,
while using this fine tool for a while now, I miss a matching feature from the rest of helm. When entering multiple words, I would like to see all lines that contain all of these words - in any order. E.g., when giving "soup eel", I want to see the entry for "eel soup". This would make it possible to narrow down a long list of candidates by giving more keywords without having to know how the exact dictionary entry looks like.
Do you agree that could be useful?
@thierryvolpiatto Is this possible at all with the current implementation? I guess it's just the match plugin that I'm missing. Any chance to get it work here?
It would be useful if helm-dictionary
could take an optional argument specifying the dictionary file. Then one could create different commands for different languages.
It would also be useful to allow helm-dictionary-database
to be a list of files; the word list in this case would be the concatenation of all dictionary files.
With helm-dictionary-20160309.910
, I get the following message when calling helm-dictionary: helm-p-candidates-file-init: Opening input file: no such file or directory, /usr/share/trans/de-en
It seems like helm-dictionary-database
is only accepting the default value (which is "/usr/share/trans/de-en"). Try changing helm-dictionary-database
to a different value and see if helm-dictionary uses that value instead? This may be related to the helm-plugin
's package.
You are computing all candidates with remove-if, then recomputing them a second time with the loop, inefficient.
(defun helm-dictionary-transformer (candidates)
"Formats entries retrieved from the data base."
(let ((cands (remove-if (lambda (i) (string-match "\\`#" i)) candidates)))
(loop for i in cands
Also please check as I done for existence of entry, (car entry), (cdr entry), i.e if one line doesn't have a " :: " separator, the loop fail.
Hi,
I think it woud be cool when you were able to browse online dictionaries on the fly from the minibuffer when using helm-dictionary. This could be achieved easily by providing a dummy source that doesn't do anything unless you expicitly consult it.
I could prepair a pull request if you are interrested.
Regards,
Michael.
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*")
Hi,
thanks for your work, I just discovered helm-dictionary and it looks quite useful. However, relying on your autoload, I had to add
(eval-after-load "helm-dictionary"
'(progn
(require 'helm-net)
(require 'helm-plugin)
...
to get it to work.
Best
Peter
These sources could query local and remote databases.
Please use cl-lib.
Now helm is using cl-lib.
Thanks.
... because of the temporary trailing backslashes.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.