diff --git a/modules/tools/lookup/README.org b/modules/tools/lookup/README.org index 05fdda993..b69d6b25e 100644 --- a/modules/tools/lookup/README.org +++ b/modules/tools/lookup/README.org @@ -10,6 +10,7 @@ - [[#prerequisites][Prerequisites]] - [[#macos][MacOS]] - [[#arch-linux][Arch Linux]] + - [[#nixos][NixOS]] - [[#features][Features]] - [[#jump-to-definition][Jump to definition]] - [[#find-references][Find references]] @@ -32,10 +33,11 @@ up definitions, references and documentation. + Documentation lookup for a variety of online sources (like devdocs.io, stackoverflow or youtube). + Integration with Dash.app docsets. -+ Support for online dictionaries and thesauruses. ++ Support for online (and offline) dictionaries and thesauruses. ** Module Flags + ~+dictionary~ Enable word definition and thesaurus lookup functionality. + + ~+offline~ Install and prefer offline dictionary/thesaurus. + ~+docsets~ Enable integration with Dash.app docsets. ** Plugins @@ -46,13 +48,13 @@ up definitions, references and documentation. * Prerequisites This module has several soft dependencies: -+ ~ripgrep~ as a last-resort fallback for - jump-to-definition/find-references. ++ ~ripgrep~ as a last-resort fallback for jump-to-definition/find-references. + ~sqlite3~ for Dash docset support. ++ ~wordnet~ for offline dictionary and thesaurus support. ** MacOS #+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 # folks have reported it will), install it through homebrew: @@ -65,6 +67,16 @@ export PATH="/usr/local/opt/sqlite/bin:$PATH" ** Arch Linux #+BEGIN_SRC sh 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 * Features diff --git a/modules/tools/lookup/autoload/lookup.el b/modules/tools/lookup/autoload/lookup.el index 3ee8f0cf4..352a1d4bc 100644 --- a/modules/tools/lookup/autoload/lookup.el +++ b/modules/tools/lookup/autoload/lookup.el @@ -321,12 +321,17 @@ Otherwise, falls back on `find-file-at-point'." (list (or (doom-thing-at-point-or-region 'word) (read-string "Look up in dictionary: ")) current-prefix-arg)) + (message "Looking up definition for %S" identifier) (cond ((and IS-MAC (require 'osx-dictionary nil t)) (osx-dictionary--view-result identifier)) - ((and +lookup-dictionary-enable-online (require 'define-word nil t)) - (message "Looking up definition of %S" identifier) + ((and +lookup-dictionary-prefer-offline + (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)) - ;; TODO Implement offline dictionary backend ((user-error "No dictionary backend is available")))) ;;;###autoload @@ -335,10 +340,13 @@ Otherwise, falls back on `find-file-at-point'." (interactive (list (doom-thing-at-point-or-region 'word) ; TODO actually use this 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) - (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")))) diff --git a/modules/tools/lookup/config.el b/modules/tools/lookup/config.el index 9116fb83e..59a5e93c4 100644 --- a/modules/tools/lookup/config.el +++ b/modules/tools/lookup/config.el @@ -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 this list.") -(defvar +lookup-dictionary-enable-online t +(defvar +lookup-dictionary-prefer-offline (featurep! +offline) "If non-nil, look up dictionaries online. Setting this to nil will force it to use offline backends, which may be less 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.") @@ -196,3 +196,7 @@ See https://github.com/magit/ghub/issues/81" (define-key! text-mode-map [remap +lookup/definition] #'+lookup/dictionary-definition [remap +lookup/references] #'+lookup/synonyms)) + + +;;;###package synosaurus +(setq synosaurus-choose-method 'default) ; use ivy/helm instead of ido diff --git a/modules/tools/lookup/packages.el b/modules/tools/lookup/packages.el index 288d779c7..e80c98361 100644 --- a/modules/tools/lookup/packages.el +++ b/modules/tools/lookup/packages.el @@ -24,7 +24,9 @@ (when (featurep! +dictionary) (if IS-MAC (package! osx-dictionary :pin "1b79ff64c7") - (package! define-word :pin "d8c76d503b")) - ;; Need for Google/DuckDuckGo auto-completion on `+lookup/online' - (package! powerthesaurus :pin "81a262ec0c") - (package! request :pin "4be823a89b")) + (package! define-word :pin "d8c76d503b") + (package! powerthesaurus :pin "81a262ec0c") + (package! request :pin "4be823a89b") + (when (featurep! +offline) + (package! wordnut :pin "feac531404") + (package! synosaurus :pin "14d34fc92a"))))