Giter Site home page Giter Site logo

helm-dictionary's Introduction

MELPA

helm-dictionary

This helm source can be used to look up words in local (offline) dictionaries. It also provides short-cuts for various online dictionaries, which is useful in situations where the local dictionary doesn't have an entry for a word.

Dictionaries are available for a variety of language pairs; see below.

Install

Helm-dictionary can be installed via MELPA. Alternatively, put the file helm-dictionary.el in your Emacs-Lisp load path and add the following in your Emacs start-up file:

(require 'helm-dictionary)

Alternatively, you can use autoload:

(autoload 'helm-dictionary "helm-dictionary" "" t)

Configure local dictionaries

In order to specify a dictionary set the variable helm-dictionary-database to the file name of that dictionary.

A dictionary for German and English can be found in the Debian package trans-de-en. This package is also available in many distributions derived from Debian such as Ubuntu. Alternatively, this dictionary can also be downloaded here:

A dictionary for German and Spanish can be found here:

A variety of dictionaries with English as the source or target language can be found here:

These dictionaries were automatically created from the Wiktionary database. Their size and quality may vary. Also generated from Wiktionary are the following dictionaries with Russian as the source or target language:

Configure online web dictionaries

If the local dictionary doesn't have an entry for a word, it can be useful to try online dictionaries available on the web. Helm-dictionary has a dummy source that provides shortcuts for looking up the currently entered string in these online dictionaries. The variable helm-dictionary-online-dicts specifies which online dictionaries should be listed. The value of that variable is a list conses. The first element of each cons specifies the name of an online dictionary for display during searches. The second element is the URL used for retrieving search results from the respective dictionary. This URL has to contain a "%s" at the position where the search term should be inserted.

The browser specified in helm-dictionary-browser-function will be used to show results from online dictionaries. If this variable is nil (default), the value of the variable browse-url-browser-function will be used (the currently configured Emacs-wide default browser). If that variable is also nil, helm uses the first available browser in helm-browse-url-default-browser-alist.

Usage

Use the command M-x helm-dictionary to start a new search or bind helm-dictionary to a key. As usual, a search is case-insensitive unless the expression contains capital letters. Regular expressions can also be used as search terms. Specifically, you can use \b to denote word boundaries when you want to search for complete words, e.g., \bhouse\b when you only want the entry for the word house but not entries like household and workhouse.

You can use M-n to insert the word on which you called helm-dictionary (works in all helm sources).

There are two actions available: insert the currently selected term in the source language (left) or in the target language (right) at point, i.e., the cursor position at which helm-dictionary was called.

In the section Look up online, you can choose among several online dictionaries. If you select one of the entries listed in this section, a browser will be used to display search results from the respective dictionary.

helm-dictionary's People

Contributors

astoff avatar michael-heerdegen avatar purcell avatar syohex avatar thierryvolpiatto avatar tmalsburg avatar tmalsburg-test avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

helm-dictionary's Issues

Remove `helm-dictionary-word-at-point`

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.

helm-source-dictionary-online: should never be narrowed.

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.")

No such file or directory

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.

Some more thoughts

Hi,

after working a bit with the code, I have questions aboutt the following points:

  1. :candidate-number-limit 500. Is it useful/realistic to use such a huge number? Nobody can read 500 items in a reasonable amount of time. OTOH, it probably doesn't harm.
  2. (action . (("Insert German term" . helm-dictionary-insert-l1term)
    ("Insert English term" . helm-dictionary-insert-l2term)))

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?

  1. 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.

thing-at-point as default input

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.

wrong usage of helm-browse-url

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.

Alternate dictionary files

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.

Looking up words online

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.

Use candidates-files instead of candidates-process

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*")

check if dictionary file exists

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)

Always downcase helm-pattern

(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.

run with a single dictionary and provide default search term

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?

Doc: selected browser function

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:

  • use the value of `helm-dictionary-browser-function' if non-nil, else
  • use the value of `browse-url-browser-function' if non-nil, else
  • let helm find a suitable browser (via `helm-browse-url-default-browser-alist').

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.

More useful matching

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?

Upload to Melpa

Hello,

I don't see this package in M-x package-list-packages. Can we upload it to Melpa?

action hard coded to german/english

Action names are hardcoded to german/english:

(action . (("Insert German term"  . helm-dictionary-insert-l1term)
               ("Insert English term" . helm-dictionary-insert-l2term)))

Error in emacs 25

Calling helm-dictionary in emacs-25 fails with this error:

slot-missing: Invalid slot name: "#<helm-source-sync helm-source-sync>", :multimatch

unefficient code in helm-dictionary-transformer and error handling

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.

Autoload missing helm-net and helm-plugin

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

Use cl-lib

Please use cl-lib.
Now helm is using cl-lib.
Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.