Coder Social home page Coder Social logo

define-word's People

Contributors

abo-abo avatar andersjohansson avatar cute-jumper avatar dalanicolai avatar duianto avatar edwargix avatar freesteph avatar manuel-uberti avatar stefanv avatar syohex 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

define-word's Issues

Font size...

Hey, is it possible to define bigger size for the formated list?

Thanks!

Fails on resolving plural words

When looking up the singular form of a plural word that doesn't have a matching verb form, define-word will fail with "define-word: Wrong type argument: stringp, ("Fetching singular...")" You can see this behavior by looking up the word "pears", which will fail while the word "pear" resolves correctly. This is caused by the apparently spurious '("Fetching singular...") at line 135. When I delete the '("Fetching singular..."), define-word handles the plural forms correctly.

Where I could find the en-en-withforms-enwiktionary.txt

I was looking to use define-word with an offline dictionary when I saw the define-word-offline-dict-directory variable in the source code. I searched online for the required file en-en-withforms-enwiktionary.txt but couldn't find it. Any help?

german umlauts not displayed properly (openthesaurus)

When using openthesaurus and getting an explanation with an umlaut, emacs display it like

m\303\244nnlicher Vorname

I'm guessing it's something to do with encoding, not sure if I have to specify that somewhere

define-word variant with return value

Hi there, it'd be nice to have a variant of define-word that returns non-nil if a definition is found and nil otherwise. Rationale: I'd like to use define-word to build a function for adding words to my local ispell dictionary.

Clever definitions by ignoring plural/tense ...

Hey, wordnik returns some "dumb" definitions as:

pangs > Plural form of pang...

I think that most users wants

pang definition: A sudden sharp spasm of pain. See Synonyms at pain...

So I propose a variable that ignores plural and tense definition by trimming words as pangs to pang, loathed to loath!

I know some issues will arise as words that ends with s (malicious) but I still think there might be a solution to it...

What yall think about it?

Thanks!

define-word results using wordnik stopped working

Recently define-word using wordnik it stopped returning definitions. I did a little digging, and it turns out that it works when you visit the url with Chrome, but not if you just try to download it with curl, or url-retrieve in Emacs. Adding a "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_5_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36" with curl's -H option made it work. So I added a let in my advice for define-word that binds url request-extra-headers to an alist with "User-Agent" as the key and "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_5_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36" as the value, and it works again.

It might be a good idea to add a simpler way to add a User-Agent: header around define-word--to-string's call to url-retrieve-synchronously.

My solution looks something like this (simplified from my actual advice, which does other things too):

(defadvice define-word (around your-around-define-word activate)
  "Dynamically bind tkb-define-word-word to the word passed in."
  (let ((url-request-extra-headers
         '(("User-Agent" . "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_5_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36"))))
    ad-do-it))

wrong type argument on Windows (7 x64 built GNU Emacs & Spacemacs)

I'm on windows (official GNU windows built Emacs (24.*) and the latest Spacemacs, and while I'm trying to use either define-word or define-word-at-point I'm always getting:

error in process filter: apply: Wrong type argument: char-or-string-p, nil
error in process filter: Wrong type argument: char-or-string-p, nil

instead of any other results.

I'm behind a company proxy, but accessing them from (Spac)emacs is working, e.g. I can upgrade both Spacemacs, and other installed packages just fine.

Maximum result length is inflexible

Please consider making the maximum length of results configurable, instead of a constant 10. It would be great if the length could be configurable as either some fraction of the frame height at invocation or some number of lines.

getting error in process filter

This is my setup:

  ;; Dictionary
  (use-package define-word
    :ensure t
    :bind (
           ("M-#"   . define-word-at-point)
           ("C-M-#" . define-word)
           )
    )

But When doing M-# I get this error:

error in process filter: "http://wordnik.com/words/interrupts" bad request

Not enough arguments for format string Error

Hi. For some words, define-word would return "Not enough arguments for format string" error. For other words, the definition is not nicely parsed.

M-x define-word road RET

Error:

Debugger entered--Lisp error: (error "Not enough arguments for format string")
message(#("noun An open, generally public way for the passage of vehicles, people, and animals.\nnoun The surface of a road; a roadbed.\nnoun A course or path.\nnoun A railroad.\nnoun Nautical A roadstead.\nidiom (down the road) In the future; at a later date.\nidiom (on the road) On tour, as a theatrical company.\nidiom (on the road) Traveling, especially as a salesperson.\nidiom (on the road) Wandering, as a vagabond.\nnoun The tour or route of a theatrical company. See <internalXref urlencoded="on%20the%20road">on the road." 0 5 (face define-word-face-1) 5 93 (face define-word-face-2) 94 99 (face define-word-face-1) 99 141 (face define-word-face-2) 142 147 (face define-word-face-1) 147 173 (face define-word-face-2) 174 179 (face define-word-face-1) 179 199 (face define-word-face-2) 200 205 (face define-word-face-1) 205 234 (face define-word-face-2) 235 241 (face define-word-face-1) 241 307 (face define-word-face-2) 308 314 (face define-word-face-1) 314 380 (face define-word-face-2) 381 387 (face define-word-face-1) 387 459 (face define-word-face-2) 460 466 (face define-word-face-1) 466 524 (face define-word-face-2) 525 530 (face define-word-face-1) 530 656 (face define-word-face-2)))
funcall(message #("noun An open, generally public way for the passage of vehicles, people, and animals.\nnoun The surface of a road; a roadbed.\nnoun A course or path.\nnoun A railroad.\nnoun Nautical A roadstead.\nidiom (down the road) In the future; at a later date.\nidiom (on the road) On tour, as a theatrical company.\nidiom (on the road) Traveling, especially as a salesperson.\nidiom (on the road) Wandering, as a vagabond.\nnoun The tour or route of a theatrical company. See <internalXref urlencoded="on%20the%20road">on the road." 0 5 (face define-word-face-1) 5 93 (face define-word-face-2) 94 99 (face define-word-face-1) 99 141 (face define-word-face-2) 142 147 (face define-word-face-1) 147 173 (face define-word-face-2) 174 179 (face define-word-face-1) 179 199 (face define-word-face-2) 200 205 (face define-word-face-1) 205 234 (face define-word-face-2) 235 241 (face define-word-face-1) 241 307 (face define-word-face-2) 308 314 (face define-word-face-1) 314 380 (face define-word-face-2) 381 387 (face define-word-face-1) 387 459 (face define-word-face-2) 460 466 (face define-word-face-1) 466 524 (face define-word-face-2) 525 530 (face define-word-face-1) 530 656 (face define-word-face-2)))
(let* ((service (or service (if choose-service (intern (completing-read "Service: " define-word-services)) define-word-default-service))) (results (define-word--to-string word service))) (funcall (define-word-displayfn service) (cond ((not results) "0 definitions found") ((define-word--expand "Plural form of \(.\)\.$" results service)) ((define-word--expand "Past participle of \(.\)\.$" results service)) ((define-word--expand "Present participle of \(.*\)\.$" results service)) (t results))))
define-word("road" nil nil)
funcall-interactively(define-word "road" nil nil)
call-interactively(define-word nil nil)
command-execute(define-word)

M-x define-word test RET
define_word

I am on Arch Linux with emacs 26.2. Version: define-word-20190128.1559. Thanks!

Auto-fetch singular forms

Try define-word-at-point on something like organizations. It will just say Plural form of organization. It would be nice if the package could recognize this response and fetch the definition for organization and display it as well.

The behavior I'm imagining is similar to looking up 'protected' macros with texdef, e.g.

$ texdef -t latex LaTeX

\LaTeX:
macro:->\protect \LaTeX  


\LaTeX :
\long macro:->L\kern -.36em{\sbox \z@ T\vbox to\ht \z@ {\hbox {\check@mathfonts \fontsize \sf@size \z@ \math@fontsfalse \selectfont A}\vss }}\kern -.15em\TeX 

Error in define-word--parse-wordnik

Seems like the \ character causes some problems fordefine-word--parse-wordnik, such that calling define-word on the word "backslash" yields an error. With Emacs 29:

  1. emacs -Q -l ~/.emacs.d/elpa/define-word-20220104.1848/define-word.el
  2. M-x toggle-debug-on-error
  3. M-x define-word RET backslash RET
Debugger entered--Lisp error: (error "Invalid use of ‘\\’ in replacement text")
  replace-match(#("\\" 0 1 (face link)))
  (let ((match (match-string 1))) (replace-match (propertize match 'face face)))
  (while (re-search-forward regexp nil t) (let ((match (match-string 1))) (replace-match (propertize match 'face face))))
  define-word--regexp-to-face("<xref>\\(.*?\\)</xref>" link)
  (while (consp --cl-var--) (progn (setq --cl-var-- (car --cl-var--)) (setq regexp (car-safe (prog1 --cl-var-- (setq --cl-var-- (cdr --cl-var--))))) (setq face (car --cl-var--))) (define-word--regexp-to-face regexp face) (setq --cl-var-- (cdr --cl-var--)))
  (let* ((--cl-var-- define-word--tag-faces) (regexp nil) (face nil) (--cl-var--)) (while (consp --cl-var--) (progn (setq --cl-var-- (car --cl-var--)) (setq regexp (car-safe (prog1 --cl-var-- (setq --cl-var-- (cdr --cl-var--))))) (setq face (car --cl-var--))) (define-word--regexp-to-face regexp face) (setq --cl-var-- (cdr --cl-var--))) nil)
  (progn (insert str) (let* ((--cl-var-- define-word--tag-faces) (regexp nil) (face nil) (--cl-var--)) (while (consp --cl-var--) (progn (setq --cl-var-- (car --cl-var--)) (setq regexp (car-safe (prog1 --cl-var-- (setq --cl-var-- ...)))) (setq face (car --cl-var--))) (define-word--regexp-to-face regexp face) (setq --cl-var-- (cdr --cl-var--))) nil) (buffer-string))
  (unwind-protect (progn (insert str) (let* ((--cl-var-- define-word--tag-faces) (regexp nil) (face nil) (--cl-var--)) (while (consp --cl-var--) (progn (setq --cl-var-- (car --cl-var--)) (setq regexp (car-safe (prog1 --cl-var-- ...))) (setq face (car --cl-var--))) (define-word--regexp-to-face regexp face) (setq --cl-var-- (cdr --cl-var--))) nil) (buffer-string)) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))
  (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (insert str) (let* ((--cl-var-- define-word--tag-faces) (regexp nil) (face nil) (--cl-var--)) (while (consp --cl-var--) (progn (setq --cl-var-- (car --cl-var--)) (setq regexp (car-safe ...)) (setq face (car --cl-var--))) (define-word--regexp-to-face regexp face) (setq --cl-var-- (cdr --cl-var--))) nil) (buffer-string)) (and (buffer-name temp-buffer) (kill-buffer temp-buffer))))
  (let ((temp-buffer (generate-new-buffer " *temp*" t))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (insert str) (let* ((--cl-var-- define-word--tag-faces) (regexp nil) (face nil) (--cl-var--)) (while (consp --cl-var--) (progn (setq --cl-var-- ...) (setq regexp ...) (setq face ...)) (define-word--regexp-to-face regexp face) (setq --cl-var-- (cdr --cl-var--))) nil) (buffer-string)) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))))
  define-word--convert-html-tag-to-face(#("noun <i></i>  A backward virgule ( &#92;).\nnoun <i..." 0 5 (face define-word-face-1) 5 42 (face define-word-face-2) 43 48 (face define-word-face-1) 48 106 (face define-word-face-2) 107 112 (face define-word-face-1) 112 267 (face define-word-face-2) 268 273 (face define-word-face-1) 273 480 (face define-word-face-2)))
  (progn (define-word--convert-html-tag-to-face (define-word--join-results results)))
  (if (setq results (nreverse results)) (progn (define-word--convert-html-tag-to-face (define-word--join-results results))))
  (let (results beg part) (while (re-search-forward "<li><abbr[^>]*>\\([^<]*\\)</abbr>" nil t) (setq part (match-string 1)) (if (= 0 (length part)) nil (setq part (concat part " "))) (skip-chars-forward " ") (setq beg (point)) (if (re-search-forward "</li>") (progn (setq results (cons (concat (propertize part ... ...) (propertize ... ... ...)) results))))) (if (setq results (nreverse results)) (progn (define-word--convert-html-tag-to-face (define-word--join-results results)))))
  (progn (let (results beg part) (while (re-search-forward "<li><abbr[^>]*>\\([^<]*\\)</abbr>" nil t) (setq part (match-string 1)) (if (= 0 (length part)) nil (setq part (concat part " "))) (skip-chars-forward " ") (setq beg (point)) (if (re-search-forward "</li>") (progn (setq results (cons (concat ... ...) results))))) (if (setq results (nreverse results)) (progn (define-word--convert-html-tag-to-face (define-word--join-results results))))))
  (unwind-protect (progn (let (results beg part) (while (re-search-forward "<li><abbr[^>]*>\\([^<]*\\)</abbr>" nil t) (setq part (match-string 1)) (if (= 0 (length part)) nil (setq part (concat part " "))) (skip-chars-forward " ") (setq beg (point)) (if (re-search-forward "</li>") (progn (setq results (cons ... results))))) (if (setq results (nreverse results)) (progn (define-word--convert-html-tag-to-face (define-word--join-results results)))))) (set-match-data saved-match-data t))
  (let ((saved-match-data (match-data))) (unwind-protect (progn (let (results beg part) (while (re-search-forward "<li><abbr[^>]*>\\([^<]*\\)</abbr>" nil t) (setq part (match-string 1)) (if (= 0 (length part)) nil (setq part (concat part " "))) (skip-chars-forward " ") (setq beg (point)) (if (re-search-forward "</li>") (progn (setq results ...)))) (if (setq results (nreverse results)) (progn (define-word--convert-html-tag-to-face (define-word--join-results results)))))) (set-match-data saved-match-data t)))
  define-word--parse-wordnik()
  funcall(define-word--parse-wordnik)
  (progn (url-insert-buffer-contents buffer url) (funcall parser))
  (unwind-protect (progn (url-insert-buffer-contents buffer url) (funcall parser)) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))
  (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (url-insert-buffer-contents buffer url) (funcall parser)) (and (buffer-name temp-buffer) (kill-buffer temp-buffer))))
  (let ((temp-buffer (generate-new-buffer " *temp*" t))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (url-insert-buffer-contents buffer url) (funcall parser)) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))))
  (let* ((url (format retriever (downcase word))) (buffer (url-retrieve-synchronously url t t))) (let ((temp-buffer (generate-new-buffer " *temp*" t))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (url-insert-buffer-contents buffer url) (funcall parser)) (and (buffer-name temp-buffer) (kill-buffer temp-buffer))))))
  (if (functionp retriever) (funcall retriever word) (let* ((url (format retriever (downcase word))) (buffer (url-retrieve-synchronously url t t))) (let ((temp-buffer (generate-new-buffer " *temp*" t))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (url-insert-buffer-contents buffer url) (funcall parser)) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))))))
  (let* ((servicedata (assoc service define-word-services)) (retriever (nth 1 servicedata)) (parser (nth 2 servicedata)) (url-user-agent (if (eq (nth 0 servicedata) 'wordnik) "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_5_2) App..." url-user-agent))) (if (functionp retriever) (funcall retriever word) (let* ((url (format retriever (downcase word))) (buffer (url-retrieve-synchronously url t t))) (let ((temp-buffer (generate-new-buffer " *temp*" t))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (url-insert-buffer-contents buffer url) (funcall parser)) (and (buffer-name temp-buffer) (kill-buffer temp-buffer))))))))
  define-word--to-string("backslash" wordnik)
  (let* ((service (or service (if choose-service (intern (completing-read "Service: " define-word-services)) define-word-default-service))) (results (define-word--to-string word service))) (funcall (define-word-displayfn service) (cond ((not results) "0 definitions found") ((define-word--expand "Plural form of \\(.*\\)\\.$" results service)) ((define-word--expand "Past participle of \\(.*\\)\\.$" results service)) ((define-word--expand "Present participle of \\(.*\\)\\.$" results service)) (t results))))
  define-word("backslash" nil nil)
  funcall-interactively(define-word "backslash" nil nil)
  command-execute(define-word record)
  execute-extended-command(nil "define-word" nil)
  funcall-interactively(execute-extended-command nil "define-word" nil)
  command-execute(execute-extended-command)

Using other thesaurus services, e.g. for german

Thanks a lot for this nice package. It works nicely with english words using wordnik. But I could not figure out how to use it for a german thesaurus like Openthesaurus. How do I have to customize define-word-services?

I tried to add a new service using the url https://www.openthesaurus.de/synonyme/%s but it gives me only the message 0 definitions found.

Redefining display function to output to a buffer instead of messages

Hi define-word developers,

Thanks very much for an extremely useful addition to emacs. I have a slight problem in that my messages buffer at present is a bit crowded (treemacs woes, but that's for another issue), and so I keep missing my define-word text. I thought I would do a quick hack and place them on a dedicated buffer (akin to what is desired in [1]), but sadly I failed miserably; my elisp is rather limited, I'm afraid. At any rate, here's what I tried.

I started by defining a function that I thought could do the displaying:

(defun my/display-word (&rest args)
  "Create a buffer for display word instead of using messages."
  (interactive)
  (let
      ((buffer (generate-new-buffer "Define Word")))
    (set-buffer buffer)
    (set-buffer-major-mode buffer)
    (apply 'insert args)
    (display-buffer buffer))
  )

This seems to work vaguely correctly, i.e.:

(my/display-word "ab" "ba")

Produces the intended result. I then tried to map this via define-word-displayfn-alist but this is where I got stuck. I tried a few variations:

(setq define-word-displayfn-alist
      '((define-word-default-service . 'my/display-word)))
(add-to-list 'define-word-displayfn-alist
             '("wordnik" . 'my/display-word))
(add-to-list 'define-word-displayfn-alist
             '(define-word-default-service . 'my/display-word))

But on all cases, if I call:

(cdr (assoc define-word-default-service define-word-displayfn-alist))

I keep getting nil. I also tested this by calling:

(define-word-displayfn define-word-default-service)

Which seems to always return message, ignoring my alist association. I think I am somehow incorrectly setting up the alist; I wonder if I am passing a "reference" to the variable define-word-default-service rather than its value. Also, I don't understand why adding the string directly has no effect. A bit lost as you can see :-) Could you please shed some light on what I am doing wrong?

Many thanks for your time.

[1] https://emacs.stackexchange.com/questions/45490/changing-display-function-in-define-word-package

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.