tools/lookup: add +offline feature
For offline dictionary/thesaurus lookup, using wordnut and synosaurus.
This commit is contained in:
parent
7cf197d8ae
commit
038e52d709
4 changed files with 46 additions and 20 deletions
|
@ -10,6 +10,7 @@
|
||||||
- [[#prerequisites][Prerequisites]]
|
- [[#prerequisites][Prerequisites]]
|
||||||
- [[#macos][MacOS]]
|
- [[#macos][MacOS]]
|
||||||
- [[#arch-linux][Arch Linux]]
|
- [[#arch-linux][Arch Linux]]
|
||||||
|
- [[#nixos][NixOS]]
|
||||||
- [[#features][Features]]
|
- [[#features][Features]]
|
||||||
- [[#jump-to-definition][Jump to definition]]
|
- [[#jump-to-definition][Jump to definition]]
|
||||||
- [[#find-references][Find references]]
|
- [[#find-references][Find references]]
|
||||||
|
@ -32,10 +33,11 @@ up definitions, references and documentation.
|
||||||
+ Documentation lookup for a variety of online sources (like devdocs.io,
|
+ Documentation lookup for a variety of online sources (like devdocs.io,
|
||||||
stackoverflow or youtube).
|
stackoverflow or youtube).
|
||||||
+ Integration with Dash.app docsets.
|
+ Integration with Dash.app docsets.
|
||||||
+ Support for online dictionaries and thesauruses.
|
+ Support for online (and offline) dictionaries and thesauruses.
|
||||||
|
|
||||||
** Module Flags
|
** Module Flags
|
||||||
+ ~+dictionary~ Enable word definition and thesaurus lookup functionality.
|
+ ~+dictionary~ Enable word definition and thesaurus lookup functionality.
|
||||||
|
+ ~+offline~ Install and prefer offline dictionary/thesaurus.
|
||||||
+ ~+docsets~ Enable integration with Dash.app docsets.
|
+ ~+docsets~ Enable integration with Dash.app docsets.
|
||||||
|
|
||||||
** Plugins
|
** Plugins
|
||||||
|
@ -46,13 +48,13 @@ up definitions, references and documentation.
|
||||||
* Prerequisites
|
* Prerequisites
|
||||||
This module has several soft dependencies:
|
This module has several soft dependencies:
|
||||||
|
|
||||||
+ ~ripgrep~ as a last-resort fallback for
|
+ ~ripgrep~ as a last-resort fallback for jump-to-definition/find-references.
|
||||||
jump-to-definition/find-references.
|
|
||||||
+ ~sqlite3~ for Dash docset support.
|
+ ~sqlite3~ for Dash docset support.
|
||||||
|
+ ~wordnet~ for offline dictionary and thesaurus support.
|
||||||
|
|
||||||
** MacOS
|
** MacOS
|
||||||
#+BEGIN_SRC sh
|
#+BEGIN_SRC sh
|
||||||
brew install ripgrep
|
brew install ripgrep wordnet
|
||||||
|
|
||||||
# An older version of sqlite is included in MacOS. If it causes you problems (and
|
# An older version of sqlite is included in MacOS. If it causes you problems (and
|
||||||
# folks have reported it will), install it through homebrew:
|
# folks have reported it will), install it through homebrew:
|
||||||
|
@ -65,6 +67,16 @@ export PATH="/usr/local/opt/sqlite/bin:$PATH"
|
||||||
** Arch Linux
|
** Arch Linux
|
||||||
#+BEGIN_SRC sh
|
#+BEGIN_SRC sh
|
||||||
sudo pacman -S sqlite ripgrep
|
sudo pacman -S sqlite ripgrep
|
||||||
|
sudo yay -S wordnet-cli
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
** NixOS
|
||||||
|
#+BEGIN_SRC nix
|
||||||
|
environment.systemPackages = with pkgs; [
|
||||||
|
ripgrep
|
||||||
|
sqlite
|
||||||
|
wordnet
|
||||||
|
];
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
|
||||||
* Features
|
* Features
|
||||||
|
|
|
@ -321,12 +321,17 @@ Otherwise, falls back on `find-file-at-point'."
|
||||||
(list (or (doom-thing-at-point-or-region 'word)
|
(list (or (doom-thing-at-point-or-region 'word)
|
||||||
(read-string "Look up in dictionary: "))
|
(read-string "Look up in dictionary: "))
|
||||||
current-prefix-arg))
|
current-prefix-arg))
|
||||||
|
(message "Looking up definition for %S" identifier)
|
||||||
(cond ((and IS-MAC (require 'osx-dictionary nil t))
|
(cond ((and IS-MAC (require 'osx-dictionary nil t))
|
||||||
(osx-dictionary--view-result identifier))
|
(osx-dictionary--view-result identifier))
|
||||||
((and +lookup-dictionary-enable-online (require 'define-word nil t))
|
((and +lookup-dictionary-prefer-offline
|
||||||
(message "Looking up definition of %S" identifier)
|
(require 'wordnut nil t))
|
||||||
|
(unless (executable-find wordnut-cmd)
|
||||||
|
(user-error "Couldn't find %S installed on your system"
|
||||||
|
wordnut-cmd))
|
||||||
|
(wordnut-search identifier))
|
||||||
|
((require 'define-word nil t)
|
||||||
(define-word identifier nil arg))
|
(define-word identifier nil arg))
|
||||||
;; TODO Implement offline dictionary backend
|
|
||||||
((user-error "No dictionary backend is available"))))
|
((user-error "No dictionary backend is available"))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
|
@ -335,10 +340,13 @@ Otherwise, falls back on `find-file-at-point'."
|
||||||
(interactive
|
(interactive
|
||||||
(list (doom-thing-at-point-or-region 'word) ; TODO actually use this
|
(list (doom-thing-at-point-or-region 'word) ; TODO actually use this
|
||||||
current-prefix-arg))
|
current-prefix-arg))
|
||||||
(unless (require 'powerthesaurus nil t)
|
|
||||||
(user-error "No dictionary backend is available"))
|
|
||||||
(unless +lookup-dictionary-enable-online
|
|
||||||
;; TODO Implement offline synonyms backend
|
|
||||||
(user-error "No offline dictionary implemented yet"))
|
|
||||||
(message "Looking up synonyms for %S" identifier)
|
(message "Looking up synonyms for %S" identifier)
|
||||||
(powerthesaurus-lookup-word-dwim))
|
(cond ((and +lookup-dictionary-prefer-offline
|
||||||
|
(require 'synosaurus nil t))
|
||||||
|
(unless (executable-find synosaurus-wordnet--command)
|
||||||
|
(user-error "Couldn't find %S installed on your system"
|
||||||
|
synosaurus-wordnet--command))
|
||||||
|
(synosaurus-choose-and-replace))
|
||||||
|
((require 'powerthesaurus nil t)
|
||||||
|
(powerthesaurus-lookup-word-dwim))
|
||||||
|
((user-error "No thesaurus backend is available"))))
|
||||||
|
|
|
@ -85,15 +85,15 @@ If the argument is interactive (satisfies `commandp'), it is called with
|
||||||
argument: the identifier at point. See `set-lookup-handlers!' about adding to
|
argument: the identifier at point. See `set-lookup-handlers!' about adding to
|
||||||
this list.")
|
this list.")
|
||||||
|
|
||||||
(defvar +lookup-dictionary-enable-online t
|
(defvar +lookup-dictionary-prefer-offline (featurep! +offline)
|
||||||
"If non-nil, look up dictionaries online.
|
"If non-nil, look up dictionaries online.
|
||||||
|
|
||||||
Setting this to nil will force it to use offline backends, which may be less
|
Setting this to nil will force it to use offline backends, which may be less
|
||||||
than perfect, but available without an internet connection.
|
than perfect, but available without an internet connection.
|
||||||
|
|
||||||
Used by `+lookup/word-definition' and `+lookup/word-synonyms'.
|
Used by `+lookup/dictionary-definition' and `+lookup/synonyms'.
|
||||||
|
|
||||||
For `+lookup/word-definition', this is ignored on Mac, where Emacs users
|
For `+lookup/dictionary-definition', this is ignored on Mac, where Emacs users
|
||||||
Dictionary.app behind the scenes to get definitions.")
|
Dictionary.app behind the scenes to get definitions.")
|
||||||
|
|
||||||
|
|
||||||
|
@ -196,3 +196,7 @@ See https://github.com/magit/ghub/issues/81"
|
||||||
(define-key! text-mode-map
|
(define-key! text-mode-map
|
||||||
[remap +lookup/definition] #'+lookup/dictionary-definition
|
[remap +lookup/definition] #'+lookup/dictionary-definition
|
||||||
[remap +lookup/references] #'+lookup/synonyms))
|
[remap +lookup/references] #'+lookup/synonyms))
|
||||||
|
|
||||||
|
|
||||||
|
;;;###package synosaurus
|
||||||
|
(setq synosaurus-choose-method 'default) ; use ivy/helm instead of ido
|
||||||
|
|
|
@ -24,7 +24,9 @@
|
||||||
(when (featurep! +dictionary)
|
(when (featurep! +dictionary)
|
||||||
(if IS-MAC
|
(if IS-MAC
|
||||||
(package! osx-dictionary :pin "1b79ff64c7")
|
(package! osx-dictionary :pin "1b79ff64c7")
|
||||||
(package! define-word :pin "d8c76d503b"))
|
(package! define-word :pin "d8c76d503b")
|
||||||
;; Need for Google/DuckDuckGo auto-completion on `+lookup/online'
|
(package! powerthesaurus :pin "81a262ec0c")
|
||||||
(package! powerthesaurus :pin "81a262ec0c")
|
(package! request :pin "4be823a89b")
|
||||||
(package! request :pin "4be823a89b"))
|
(when (featurep! +offline)
|
||||||
|
(package! wordnut :pin "feac531404")
|
||||||
|
(package! synosaurus :pin "14d34fc92a"))))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue