mirror of
https://gitlab.com/dwt1/dotfiles.git
synced 2026-04-23 19:40:24 +10:00
Updating Doom Emacs.
This commit is contained in:
@@ -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]]
|
||||
@@ -24,33 +25,51 @@
|
||||
- [[#commands][Commands]]
|
||||
|
||||
* Description
|
||||
Integrates with code navigation and documentation tools to help you quickly look
|
||||
up definitions, references and documentation.
|
||||
This module adds code navigation and documentation lookup tools to help you
|
||||
quickly look up definitions, references, documentation, dictionary definitions
|
||||
or synonyms.
|
||||
|
||||
+ Jump-to-definition and find-references implementations that just work.
|
||||
+ Powerful xref integration for languages that support it.
|
||||
+ Documentation lookup for a variety of online sources (like devdocs.io,
|
||||
stackoverflow or youtube).
|
||||
+ Search online providers like devdocs.io, stackoverflow, google, duckduckgo or
|
||||
youtube (duckduckgo and google have live suggestions).
|
||||
+ Integration with Dash.app docsets.
|
||||
+ 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.
|
||||
+ ~+xwidget~ Enable integration with [[https://www.gnu.org/software/emacs/manual/html_node/emacs/Embedded-WebKit-Widgets.html][Embedded Webkit Widgets]].
|
||||
|
||||
** Plugins
|
||||
+ [[https://github.com/jacktasia/dumb-jump][dumb-jump]]
|
||||
+ [[https://github.com/alexmurray/ivy-xref][ivy-xref]] or [[https://github.com/brotzeit/helm-xref][helm-xref]]
|
||||
+ [[https://github.com/nathankot/counsel-dash][counsel-dash]] or [[https://github.com/areina/helm-dash][helm-dash]]
|
||||
+ [[https://github.com/tkf/emacs-request][request]]
|
||||
+ =+docsets=
|
||||
+ [[https://github.com/dash-docs-el/dash-docs][dash-docs]]
|
||||
+ [[https://github.com/nathankot/counsel-dash][counsel-dash]] or [[https://github.com/areina/helm-dash][helm-dash]]
|
||||
+ =+dictionary=
|
||||
+ if macOS
|
||||
+ [[https://github.com/xuchunyang/osx-dictionary.el][osx-dictionary]]* (on macOS)
|
||||
+ else
|
||||
+ [[https://github.com/abo-abo/define-word][define-word]]
|
||||
+ [[https://github.com/maxchaos/emacs-powerthesaurus][powerthesaurus]]
|
||||
+ =+offline=
|
||||
+ [[https://github.com/gromnitsky/wordnut][wordnut]]
|
||||
+ [[https://github.com/hpdeifel/synosaurus][synosaurus]]
|
||||
|
||||
* Prerequisites
|
||||
This module has several soft dependencies:
|
||||
|
||||
+ ~the_silver_searcher~ or ~ripgrep~ (recommended) as a last-resort fallback for
|
||||
jump-to-definition/find-references.
|
||||
+ ~sqlite3~ for Dash docset support.
|
||||
+ ~ripgrep~ as a last-resort fallback for jump-to-definition/find-references.
|
||||
+ ~sqlite3~ for Dash docset support (if you have =+docsets= enabled)
|
||||
+ ~wordnet~ for offline dictionary and thesaurus support (if you have
|
||||
=+dictionary +offline= enabled).
|
||||
|
||||
** MacOS
|
||||
#+BEGIN_SRC sh
|
||||
brew install the_silver_searcher 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:
|
||||
@@ -62,7 +81,17 @@ export PATH="/usr/local/opt/sqlite/bin:$PATH"
|
||||
|
||||
** Arch Linux
|
||||
#+BEGIN_SRC sh
|
||||
sudo pacman -S sqlite the_silver_searcher ripgrep
|
||||
sudo pacman -S sqlite ripgrep
|
||||
yay -S wordnet-cli
|
||||
#+END_SRC
|
||||
|
||||
** NixOS
|
||||
#+BEGIN_SRC nix
|
||||
environment.systemPackages = with pkgs; [
|
||||
ripgrep
|
||||
sqlite
|
||||
wordnet
|
||||
];
|
||||
#+END_SRC
|
||||
|
||||
* Features
|
||||
@@ -77,7 +106,7 @@ following sources before giving up:
|
||||
~:lookup~ setting (see "Configuration" section).
|
||||
2. Any available xref backends.
|
||||
3. ~dumb-jump~ (a text search with aides to reduce false positives).
|
||||
3. An ordinary project-wide text search with ripgrep or the_silver_searcher.
|
||||
3. An ordinary project-wide text search with ripgrep.
|
||||
5. If ~evil-mode~ is active, use ~evil-goto-definition~, which preforms a simple
|
||||
text search within the current buffer.
|
||||
|
||||
@@ -93,7 +122,7 @@ will try:
|
||||
1. Whatever ~:references~ function is registered for the current buffer with the
|
||||
~:lookup~ setting (see "Configuration" section).
|
||||
2. Any available xref backends.
|
||||
3. An ordinary project-wide text search with ripgrep or the_silver_searcher.
|
||||
3. An ordinary project-wide text search with ripgrep.
|
||||
|
||||
If there are multiple results, you will be prompted to select one.
|
||||
|
||||
|
||||
@@ -86,11 +86,12 @@ installed with `dash-docs-install-docset'."
|
||||
(interactive "P")
|
||||
(require 'dash-docs)
|
||||
(let ((dash-docs-common-docsets)
|
||||
(dash-docs-browser-func +lookup-open-url-fn)
|
||||
(dash-docs-docsets
|
||||
(if arg
|
||||
(dash-docs-installed-docsets)
|
||||
(cl-remove-if-not #'dash-docs-docset-path (or docsets dash-docs-docsets))))
|
||||
(query (or query (+lookup-symbol-or-region) "")))
|
||||
(query (doom-thing-at-point-or-region query)))
|
||||
(doom-log "Searching docsets %s" dash-docs-docsets)
|
||||
(cond ((featurep! :completion helm)
|
||||
(helm-dash query))
|
||||
|
||||
@@ -15,6 +15,12 @@ properties:
|
||||
|
||||
:definition FN
|
||||
Run when jumping to a symbol's definition. Used by `+lookup/definition'.
|
||||
:implementations FN
|
||||
Run when looking for implementations of a symbol in the current project. Used
|
||||
by `+lookup/implementations'.
|
||||
:type-definition FN
|
||||
Run when jumping to a symbol's type definition. Used by
|
||||
`+lookup/type-definition'.
|
||||
:references FN
|
||||
Run when looking for usage references of a symbol in the current project. Used
|
||||
by `+lookup/references'.
|
||||
@@ -46,6 +52,7 @@ change the current buffer or window or return non-nil when it succeeds.
|
||||
|
||||
If it doesn't change the current buffer, or it returns nil, the lookup module
|
||||
will fall back to the next handler in `+lookup-definition-functions',
|
||||
`+lookup-implementations-functions', `+lookup-type-definition-functions',
|
||||
`+lookup-references-functions', `+lookup-file-functions' or
|
||||
`+lookup-documentation-functions'.
|
||||
|
||||
@@ -57,35 +64,40 @@ This can be passed nil as its second argument to unset handlers for MODES. e.g.
|
||||
|
||||
(set-lookup-handlers! 'python-mode nil)
|
||||
|
||||
\(fn MODES &key DEFINITION REFERENCES DOCUMENTATION FILE XREF-BACKEND ASYNC)"
|
||||
\(fn MODES &key DEFINITION IMPLEMENTATIONS TYPE-DEFINITION REFERENCES DOCUMENTATION FILE XREF-BACKEND ASYNC)"
|
||||
(declare (indent defun))
|
||||
(dolist (mode (doom-enlist modes))
|
||||
(let ((hook (intern (format "%s-hook" mode)))
|
||||
(fn (intern (format "+lookup--init-%s-handlers-h" mode))))
|
||||
(cond ((null (car plist))
|
||||
(remove-hook hook fn)
|
||||
(unintern fn nil))
|
||||
((fset
|
||||
fn
|
||||
(lambda ()
|
||||
(cl-destructuring-bind (&key definition references documentation file xref-backend async)
|
||||
plist
|
||||
(cl-mapc #'+lookup--set-handler
|
||||
(list definition
|
||||
references
|
||||
documentation
|
||||
file
|
||||
xref-backend)
|
||||
(list '+lookup-definition-functions
|
||||
'+lookup-references-functions
|
||||
'+lookup-documentation-functions
|
||||
'+lookup-file-functions
|
||||
'xref-backend-functions)
|
||||
(make-list 5 async)
|
||||
(make-list 5 (or (eq major-mode mode)
|
||||
(and (boundp mode)
|
||||
(symbol-value mode))))))))
|
||||
(add-hook hook fn))))))
|
||||
(if (null (car plist))
|
||||
(progn
|
||||
(remove-hook hook fn)
|
||||
(unintern fn nil))
|
||||
(fset
|
||||
fn
|
||||
(lambda ()
|
||||
(cl-destructuring-bind (&key definition implementations type-definition references documentation file xref-backend async)
|
||||
plist
|
||||
(cl-mapc #'+lookup--set-handler
|
||||
(list definition
|
||||
implementations
|
||||
type-definition
|
||||
references
|
||||
documentation
|
||||
file
|
||||
xref-backend)
|
||||
(list '+lookup-definition-functions
|
||||
'+lookup-implementations-functions
|
||||
'+lookup-type-definition-functions
|
||||
'+lookup-references-functions
|
||||
'+lookup-documentation-functions
|
||||
'+lookup-file-functions
|
||||
'xref-backend-functions)
|
||||
(make-list 5 async)
|
||||
(make-list 5 (or (eq major-mode mode)
|
||||
(and (boundp mode)
|
||||
(symbol-value mode))))))))
|
||||
(add-hook hook fn)))))
|
||||
|
||||
|
||||
;;
|
||||
@@ -130,20 +142,24 @@ This can be passed nil as its second argument to unset handlers for MODES. e.g.
|
||||
|
||||
(defun +lookup--jump-to (prop identifier &optional display-fn arg)
|
||||
(let* ((origin (point-marker))
|
||||
(handlers (plist-get (list :definition '+lookup-definition-functions
|
||||
:references '+lookup-references-functions
|
||||
:documentation '+lookup-documentation-functions
|
||||
:file '+lookup-file-functions)
|
||||
prop))
|
||||
(handlers
|
||||
(plist-get (list :definition '+lookup-definition-functions
|
||||
:implementations '+lookup-implementations-functions
|
||||
:type-definition '+lookup-type-definition-functions
|
||||
:references '+lookup-references-functions
|
||||
:documentation '+lookup-documentation-functions
|
||||
:file '+lookup-file-functions)
|
||||
prop))
|
||||
(result
|
||||
(if arg
|
||||
(if-let*
|
||||
((handler (intern-soft
|
||||
(completing-read "Select lookup handler: "
|
||||
(delete-dups
|
||||
(remq t (append (symbol-value handlers)
|
||||
(default-value handlers))))
|
||||
nil t))))
|
||||
(if-let
|
||||
(handler
|
||||
(intern-soft
|
||||
(completing-read "Select lookup handler: "
|
||||
(delete-dups
|
||||
(remq t (append (symbol-value handlers)
|
||||
(default-value handlers))))
|
||||
nil t)))
|
||||
(+lookup--run-handlers handler identifier origin)
|
||||
(user-error "No lookup handler selected"))
|
||||
(run-hook-wrapped handlers #'+lookup--run-handlers identifier origin))))
|
||||
@@ -160,40 +176,29 @@ This can be passed nil as its second argument to unset handlers for MODES. e.g.
|
||||
(better-jumper-set-jump (marker-position origin)))
|
||||
result)))
|
||||
|
||||
;;;###autoload
|
||||
(defun +lookup-symbol-or-region (&optional initial)
|
||||
"Grab the symbol at point or selected region."
|
||||
(cond ((stringp initial)
|
||||
initial)
|
||||
((use-region-p)
|
||||
(buffer-substring-no-properties (region-beginning)
|
||||
(region-end)))
|
||||
((require 'xref nil t)
|
||||
;; A little smarter than using `symbol-at-point', though in most cases,
|
||||
;; xref ends up using `symbol-at-point' anyway.
|
||||
(xref-backend-identifier-at-point (xref-find-backend)))))
|
||||
|
||||
|
||||
;;
|
||||
;;; Lookup backends
|
||||
|
||||
(defun +lookup--xref-show (fn identifier)
|
||||
(defun +lookup--xref-show (fn identifier &optional show-fn)
|
||||
(let ((xrefs (funcall fn
|
||||
(xref-find-backend)
|
||||
identifier)))
|
||||
(when xrefs
|
||||
(xref--show-xrefs xrefs nil)
|
||||
(funcall (or show-fn #'xref--show-defs)
|
||||
(lambda () xrefs)
|
||||
nil)
|
||||
(if (cdr xrefs)
|
||||
'deferred
|
||||
t))))
|
||||
|
||||
(defun +lookup-xref-definitions-backend-fn (identifier)
|
||||
"Non-interactive wrapper for `xref-find-definitions'"
|
||||
(+lookup--xref-show 'xref-backend-definitions identifier))
|
||||
(+lookup--xref-show 'xref-backend-definitions identifier #'xref--show-defs))
|
||||
|
||||
(defun +lookup-xref-references-backend-fn (identifier)
|
||||
"Non-interactive wrapper for `xref-find-references'"
|
||||
(+lookup--xref-show 'xref-backend-references identifier))
|
||||
(+lookup--xref-show 'xref-backend-references identifier #'xref--show-xrefs))
|
||||
|
||||
(defun +lookup-dumb-jump-backend-fn (_identifier)
|
||||
"Look up the symbol at point (or selection) with `dumb-jump', which conducts a
|
||||
@@ -243,12 +248,36 @@ Each function in `+lookup-definition-functions' is tried until one changes the
|
||||
point or current buffer. Falls back to dumb-jump, naive
|
||||
ripgrep/the_silver_searcher text search, then `evil-goto-definition' if
|
||||
evil-mode is active."
|
||||
(interactive (list (+lookup-symbol-or-region)
|
||||
(interactive (list (doom-thing-at-point-or-region)
|
||||
current-prefix-arg))
|
||||
(cond ((null identifier) (user-error "Nothing under point"))
|
||||
((+lookup--jump-to :definition identifier nil arg))
|
||||
((error "Couldn't find the definition of %S" identifier))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +lookup/implementations (identifier &optional arg)
|
||||
"Jump to the implementations of IDENTIFIER (defaults to the symbol at point).
|
||||
|
||||
Each function in `+lookup-implementations-functions' is tried until one changes
|
||||
the point or current buffer."
|
||||
(interactive (list (doom-thing-at-point-or-region)
|
||||
current-prefix-arg))
|
||||
(cond ((null identifier) (user-error "Nothing under point"))
|
||||
((+lookup--jump-to :implementations identifier nil arg))
|
||||
((error "Couldn't find the implementations of %S" identifier))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +lookup/type-definition (identifier &optional arg)
|
||||
"Jump to the type definition of IDENTIFIER (defaults to the symbol at point).
|
||||
|
||||
Each function in `+lookup-type-definition-functions' is tried until one changes
|
||||
the point or current buffer."
|
||||
(interactive (list (doom-thing-at-point-or-region)
|
||||
current-prefix-arg))
|
||||
(cond ((null identifier) (user-error "Nothing under point"))
|
||||
((+lookup--jump-to :type-definition identifier nil arg))
|
||||
((error "Couldn't find the definition of %S" identifier))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +lookup/references (identifier &optional arg)
|
||||
"Show a list of usages of IDENTIFIER (defaults to the symbol at point)
|
||||
@@ -256,7 +285,7 @@ evil-mode is active."
|
||||
Tries each function in `+lookup-references-functions' until one changes the
|
||||
point and/or current buffer. Falls back to a naive ripgrep/the_silver_searcher
|
||||
search otherwise."
|
||||
(interactive (list (+lookup-symbol-or-region)
|
||||
(interactive (list (doom-thing-at-point-or-region)
|
||||
current-prefix-arg))
|
||||
(cond ((null identifier) (user-error "Nothing under point"))
|
||||
((+lookup--jump-to :references identifier nil arg))
|
||||
@@ -269,7 +298,7 @@ search otherwise."
|
||||
First attempts the :documentation handler specified with `set-lookup-handlers!'
|
||||
for the current mode/buffer (if any), then falls back to the backends in
|
||||
`+lookup-documentation-functions'."
|
||||
(interactive (list (+lookup-symbol-or-region)
|
||||
(interactive (list (doom-thing-at-point-or-region)
|
||||
current-prefix-arg))
|
||||
(cond ((+lookup--jump-to :documentation identifier #'pop-to-buffer arg))
|
||||
((user-error "Couldn't find documentation for %S" identifier))))
|
||||
@@ -290,33 +319,56 @@ Otherwise, falls back on `find-file-at-point'."
|
||||
(or (ffap-guesser)
|
||||
(ffap-read-file-or-url
|
||||
(if ffap-url-regexp "Find file or URL: " "Find file: ")
|
||||
(+lookup-symbol-or-region))))))
|
||||
(doom-thing-at-point-or-region))))))
|
||||
(require 'ffap)
|
||||
(cond ((not path)
|
||||
(call-interactively #'find-file-at-point))
|
||||
(cond ((and path
|
||||
buffer-file-name
|
||||
(file-equal-p path buffer-file-name)
|
||||
(user-error "Already here")))
|
||||
|
||||
((ffap-url-p path)
|
||||
(find-file-at-point path))
|
||||
((+lookup--jump-to :file path))
|
||||
|
||||
((not (+lookup--jump-to :file path))
|
||||
(let ((fullpath (doom-path path)))
|
||||
(when (and buffer-file-name (file-equal-p fullpath buffer-file-name))
|
||||
(user-error "Already here"))
|
||||
(let* ((insert-default-directory t)
|
||||
(project-root (doom-project-root))
|
||||
(ffap-file-finder
|
||||
(cond ((not (doom-glob fullpath))
|
||||
#'find-file)
|
||||
((ignore-errors (file-in-directory-p fullpath project-root))
|
||||
(lambda (dir)
|
||||
(let* ((default-directory dir)
|
||||
projectile-project-name
|
||||
projectile-project-root
|
||||
(projectile-project-root-cache (make-hash-table :test 'equal))
|
||||
(file (projectile-completing-read "Find file: "
|
||||
(projectile-current-project-files)
|
||||
:initial-input path)))
|
||||
(find-file (expand-file-name file (doom-project-root)))
|
||||
(run-hooks 'projectile-find-file-hook))))
|
||||
(#'doom-project-browse))))
|
||||
(find-file-at-point path))))))
|
||||
((stringp path) (find-file-at-point path))
|
||||
|
||||
((call-interactively #'find-file-at-point))))
|
||||
|
||||
|
||||
;;
|
||||
;;; Dictionary
|
||||
|
||||
;;;###autoload
|
||||
(defun +lookup/dictionary-definition (identifier &optional arg)
|
||||
"Look up the definition of the word at point (or selection)."
|
||||
(interactive
|
||||
(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-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))
|
||||
((user-error "No dictionary backend is available"))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +lookup/synonyms (identifier &optional _arg)
|
||||
"Look up and insert a synonym for the word at point (or selection)."
|
||||
(interactive
|
||||
(list (doom-thing-at-point-or-region 'word) ; TODO actually use this
|
||||
current-prefix-arg))
|
||||
(message "Looking up synonyms for %S" identifier)
|
||||
(cond ((and +lookup-dictionary-prefer-offline
|
||||
(require 'synosaurus-wordnet 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"))))
|
||||
|
||||
@@ -25,8 +25,8 @@ argument is non-nil)."
|
||||
(+lookup--online-provider (not current-prefix-arg))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +lookup/online (arg &optional query provider)
|
||||
"Looks up QUERY (a string) in you browser using PROVIDER.
|
||||
(defun +lookup/online (query provider)
|
||||
"Looks up QUERY (a string) in you browser usin PROVIDER.
|
||||
|
||||
PROVIDER should be a key of `+lookup-provider-url-alist'.
|
||||
|
||||
@@ -34,14 +34,13 @@ When used interactively, it will prompt for a query and, for the first time, the
|
||||
provider from `+lookup-provider-url-alist'. On consecutive uses, the last
|
||||
provider will be reused. If the universal argument is supplied, always prompt
|
||||
for the provider."
|
||||
(interactive "P")
|
||||
(let* ((provider (or provider (+lookup--online-provider arg)))
|
||||
(query (or query (+lookup-symbol-or-region)))
|
||||
(backend (cl-find-if (lambda (x) (or (stringp x) (fboundp x)))
|
||||
(cdr (assoc provider +lookup-provider-url-alist)))))
|
||||
(if (and (functionp backend)
|
||||
(commandp backend))
|
||||
(call-interactively backend)
|
||||
(interactive
|
||||
(list (if (use-region-p) (doom-thing-at-point-or-region))
|
||||
(+lookup--online-provider current-prefix-arg)))
|
||||
(let ((backend (cl-find-if (lambda (x) (or (stringp x) (fboundp x)))
|
||||
(cdr (assoc provider +lookup-provider-url-alist)))))
|
||||
(unless (and (functionp backend)
|
||||
(funcall backend query))
|
||||
(unless backend
|
||||
(user-error "%S is an invalid query engine backend for %S provider"
|
||||
backend provider))
|
||||
@@ -69,3 +68,32 @@ for the provider."
|
||||
(interactive)
|
||||
(let ((current-prefix-arg t))
|
||||
(call-interactively #'+lookup/online)))
|
||||
|
||||
|
||||
;;
|
||||
;;; Special provider frontends
|
||||
|
||||
(defvar ivy-initial-inputs-alist)
|
||||
(defvar counsel-search-engine)
|
||||
;;;###autoload
|
||||
(defun +lookup--online-backend-google (query)
|
||||
"Search google, starting with QUERY, with live autocompletion."
|
||||
(cond ((fboundp 'counsel-search)
|
||||
(let ((ivy-initial-inputs-alist `((t . ,query)))
|
||||
(counsel-search-engine 'google))
|
||||
(call-interactively #'counsel-search)
|
||||
t))
|
||||
((require 'helm-net nil t)
|
||||
(helm :sources 'helm-source-google-suggest
|
||||
:buffer "*helm google*"
|
||||
:input query)
|
||||
t)))
|
||||
|
||||
;;;###autoload
|
||||
(defun +lookup--online-backend-duckduckgo (query)
|
||||
"Search duckduckgo, starting with QUERY, with live autocompletion."
|
||||
(cond ((fboundp 'counsel-search)
|
||||
(let ((ivy-initial-inputs-alist `((t . ,query)))
|
||||
(counsel-search-engine 'ddg))
|
||||
(call-interactively #'counsel-search)
|
||||
t))))
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
;; "What am I looking at?" This module helps you answer this question.
|
||||
;;
|
||||
;; + `+lookup/definition': a jump-to-definition that should 'just work'
|
||||
;; + `+lookup/implementations': find a symbol's implementations in the current
|
||||
;; project
|
||||
;; + `+lookup/references': find a symbol's references in the current project
|
||||
;; + `+lookup/file': open the file referenced at point
|
||||
;; + `+lookup/online'; look up a symbol on online resources
|
||||
@@ -13,11 +15,12 @@
|
||||
;; `dumb-jump' to find what you want.
|
||||
|
||||
(defvar +lookup-provider-url-alist
|
||||
(append '(("Google" counsel-search helm-google-suggest "https://google.com/search?q=%s")
|
||||
(append '(("Doom Emacs issues" "https://github.com/hlissner/doom-emacs/issues?q=is%%3Aissue+%s")
|
||||
("Google" +lookup--online-backend-google "https://google.com/search?q=%s")
|
||||
("Google images" "https://www.google.com/images?q=%s")
|
||||
("Google maps" "https://maps.google.com/maps?q=%s")
|
||||
("Project Gutenberg" "http://www.gutenberg.org/ebooks/search/?query=%s")
|
||||
("DuckDuckGo" counsel-search "https://duckduckgo.com/?q=%s")
|
||||
("DuckDuckGo" +lookup--online-backend-duckduckgo "https://duckduckgo.com/?q=%s")
|
||||
("DevDocs.io" "https://devdocs.io/#q=%s")
|
||||
("StackOverflow" "https://stackoverflow.com/search?q=%s")
|
||||
("Github" "https://github.com/search?ref=simplesearch&q=%s")
|
||||
@@ -51,6 +54,24 @@ 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-implementations-functions ()
|
||||
"Function for `+lookup/implementations' to try. Stops at the first function to
|
||||
return non-nil or change the current window/point.
|
||||
|
||||
If the argument is interactive (satisfies `commandp'), it is called with
|
||||
`call-interactively' (with no arguments). Otherwise, it is called with one
|
||||
argument: the identifier at point. See `set-lookup-handlers!' about adding to
|
||||
this list.")
|
||||
|
||||
(defvar +lookup-type-definition-functions ()
|
||||
"Functions for `+lookup/type-definition' to try. Stops at the first function to
|
||||
return non-nil or change the current window/point.
|
||||
|
||||
If the argument is interactive (satisfies `commandp'), it is called with
|
||||
`call-interactively' (with no arguments). Otherwise, it is called with one
|
||||
argument: the identifier at point. See `set-lookup-handlers!' about adding to
|
||||
this list.")
|
||||
|
||||
(defvar +lookup-references-functions
|
||||
'(+lookup-xref-references-backend-fn
|
||||
+lookup-project-search-backend-fn)
|
||||
@@ -84,6 +105,19 @@ 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-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/dictionary-definition' and `+lookup/synonyms'.
|
||||
|
||||
For `+lookup/dictionary-definition', this is ignored on Mac, where Emacs users
|
||||
Dictionary.app behind the scenes to get definitions.")
|
||||
|
||||
(defvar +lookup--dash-docs-xwidget-webkit-last-session-buffer nil)
|
||||
|
||||
|
||||
;;
|
||||
;;; dumb-jump
|
||||
@@ -92,6 +126,7 @@ this list.")
|
||||
:commands dumb-jump-result-follow
|
||||
:config
|
||||
(setq dumb-jump-default-project doom-emacs-dir
|
||||
dumb-jump-prefer-searcher 'rg
|
||||
dumb-jump-aggressive nil
|
||||
dumb-jump-selector
|
||||
(cond ((featurep! :completion ivy) 'ivy)
|
||||
@@ -124,12 +159,17 @@ this list.")
|
||||
(use-package! ivy-xref
|
||||
:when (featurep! :completion ivy)
|
||||
:config
|
||||
(setq xref-show-xrefs-function #'ivy-xref-show-xrefs)
|
||||
(set-popup-rule! "^\\*xref\\*$" :ignore t))
|
||||
(set-popup-rule! "^\\*xref\\*$" :ignore t)
|
||||
;; xref initialization is different in Emacs 27 - there are two different
|
||||
;; variables which can be set rather than just one
|
||||
(when EMACS27+
|
||||
(setq xref-show-definitions-function #'ivy-xref-show-defs))
|
||||
;; Necessary in Emacs <27. In Emacs 27 it will affect all xref-based
|
||||
;; commands other than xref-find-definitions too (eg project-find-regexp)
|
||||
(setq xref-show-xrefs-function #'ivy-xref-show-xrefs))
|
||||
|
||||
(use-package! helm-xref
|
||||
:when (featurep! :completion helm)
|
||||
:config (setq xref-show-xrefs-function #'helm-xref-show-xrefs)))
|
||||
:when (featurep! :completion helm)))
|
||||
|
||||
|
||||
;;
|
||||
@@ -141,7 +181,7 @@ this list.")
|
||||
:init
|
||||
(add-hook '+lookup-documentation-functions #'+lookup-dash-docsets-backend-fn)
|
||||
:config
|
||||
(setq dash-docs-enable-debugging doom-debug-mode
|
||||
(setq dash-docs-enable-debugging doom-debug-p
|
||||
dash-docs-docsets-path (concat doom-etc-dir "docsets/")
|
||||
dash-docs-min-length 2
|
||||
dash-docs-browser-func #'eww)
|
||||
@@ -160,8 +200,44 @@ See https://github.com/magit/ghub/issues/81"
|
||||
(let ((gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3"))
|
||||
(funcall orig-fn url)))
|
||||
|
||||
(use-package! helm-dash
|
||||
:when (featurep! :completion helm))
|
||||
;; Dash docset + Xwidget integration
|
||||
(when (featurep! +xwidget)
|
||||
(defun +lookup-dash-docs-xwidget-webkit-browse-url-fn (url &optional new-session)
|
||||
(if (not (display-graphic-p))
|
||||
(eww url new-session)
|
||||
(setq xwidget-webkit-last-session-buffer +lookup--dash-docs-xwidget-webkit-last-session-buffer)
|
||||
(save-window-excursion
|
||||
(xwidget-webkit-browse-url url new-session))
|
||||
(with-popup-rules! '(("^\\*xwidget" :vslot -11 :size 0.35 :select nil))
|
||||
(pop-to-buffer xwidget-webkit-last-session-buffer))
|
||||
(setq +lookup--dash-docs-xwidget-webkit-last-session-buffer xwidget-webkit-last-session-buffer
|
||||
xwidget-webkit-last-session-buffer nil)))
|
||||
(setq dash-docs-browser-func #'+lookup-dash-docs-xwidget-webkit-browse-url-fn))
|
||||
|
||||
(use-package! counsel-dash
|
||||
:when (featurep! :completion ivy)))
|
||||
(cond ((featurep! :completion helm)
|
||||
(require 'helm-dash nil t))
|
||||
((featurep! :completion ivy)
|
||||
(require 'counsel-dash nil t))))
|
||||
|
||||
|
||||
;;
|
||||
;;; Dictionary integration
|
||||
|
||||
(use-package! define-word
|
||||
:when (featurep! +dictionary)
|
||||
:unless IS-MAC
|
||||
:defer t
|
||||
:config
|
||||
(setq define-word-displayfn-alist
|
||||
(cl-loop for (service . _) in define-word-services
|
||||
collect (cons service #'+eval-display-results-in-popup))))
|
||||
|
||||
|
||||
(when (featurep! +dictionary)
|
||||
(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
|
||||
|
||||
@@ -8,18 +8,31 @@
|
||||
(package! helm))
|
||||
|
||||
;;
|
||||
(package! dumb-jump)
|
||||
(package! dumb-jump :pin "d86f59c4c0eb9371dd84bc2aaff5d7445f04ba27")
|
||||
(when (featurep! :completion ivy)
|
||||
(package! ivy-xref)
|
||||
;; Need for Google/DuckDuckGo auto-completion on `+lookup/online'
|
||||
(package! request))
|
||||
(package! ivy-xref :pin "3d4c35fe2b243d948d8fe02a1f0d76a249d63de9"))
|
||||
(when (featurep! :completion helm)
|
||||
(package! helm-google)
|
||||
(package! helm-xref))
|
||||
(package! helm-xref :pin "6b4a8bd91f5eaf82f51bd31b03f6587387fe6983"))
|
||||
|
||||
;; For dictionary and online lookup
|
||||
(package! request :pin "912525c772984c6af0fd84acd6699ee43d91037a")
|
||||
|
||||
(when (featurep! +docsets)
|
||||
(package! dash-docs)
|
||||
(package! dash-docs :pin "dafc8fc9f1ddb2e4e39e0b8d066c42d5d7ce8d06")
|
||||
(when (featurep! :completion helm)
|
||||
(package! helm-dash))
|
||||
(package! helm-dash :pin "7f853bd34da666f0e9a883011c80f451b06f6c59"))
|
||||
(when (featurep! :completion ivy)
|
||||
(package! counsel-dash)))
|
||||
(package! counsel-dash :pin "370d5f6f14b5294d0eb717f7b2a6a8e93df1ed24")))
|
||||
|
||||
(when (featurep! +dictionary)
|
||||
(if IS-MAC
|
||||
(package! osx-dictionary :pin "1b79ff64c72485cb078db9ab7ee3256b11a99f4b")
|
||||
(package! define-word :pin "08c71b1ff4fd07bf0c78d1fcf77efeaafc8f7443")
|
||||
;; HACK Fix #2945: the main package is broken due to
|
||||
;; SavchenkoValeriy/emacs-powerthesaurus#11
|
||||
(package! powerthesaurus
|
||||
:recipe (:host github :repo "maxchaos/emacs-powerthesaurus" :branch "pt-api-change")
|
||||
:pin "4a834782a394f2dc70fc02d68b6962b44d87f0cf")
|
||||
(when (featurep! +offline)
|
||||
(package! wordnut :pin "feac531404041855312c1a046bde7ea18c674915")
|
||||
(package! synosaurus :pin "14d34fc92a77c3a916b4d58400424c44ae99cd81"))))
|
||||
|
||||
Reference in New Issue
Block a user