2019-04-21 19:59:44 -04:00
|
|
|
;;; tools/lookup/autoload/lookup.el -*- lexical-binding: t; -*-
|
2018-01-04 17:05:37 -05:00
|
|
|
|
2018-06-15 17:27:48 +02:00
|
|
|
;;;###autodef
|
2019-10-15 22:23:35 -04:00
|
|
|
(defun set-lookup-handlers! (modes &rest plist)
|
2019-05-01 19:12:52 -04:00
|
|
|
"Define jump handlers for major or minor MODES.
|
2018-06-20 15:37:49 +02:00
|
|
|
|
2019-05-02 17:53:59 -04:00
|
|
|
A handler is either an interactive command that changes the current buffer
|
|
|
|
and/or location of the cursor, or a function that takes one argument: the
|
|
|
|
identifier being looked up, and returns either nil (failed to find it), t
|
|
|
|
(succeeded at changing the buffer/moving the cursor), or 'deferred (assume this
|
|
|
|
handler has succeeded, but expect changes not to be visible yet).
|
2019-01-05 17:04:40 -05:00
|
|
|
|
2019-05-02 17:53:59 -04:00
|
|
|
There are several kinds of handlers, which can be defined with the following
|
|
|
|
properties:
|
2018-06-02 17:02:08 +02:00
|
|
|
|
2018-06-20 15:37:49 +02:00
|
|
|
:definition FN
|
2019-05-02 17:53:59 -04:00
|
|
|
Run when jumping to a symbol's definition. Used by `+lookup/definition'.
|
2020-05-12 00:43:16 +09:00
|
|
|
:implementations FN
|
|
|
|
Run when looking for implementations of a symbol in the current project. Used
|
|
|
|
by `+lookup/implementations'.
|
2020-05-12 01:06:23 +09:00
|
|
|
:type-definition FN
|
|
|
|
Run when jumping to a symbol's type definition. Used by
|
|
|
|
`+lookup/type-definition'.
|
2018-06-20 15:37:49 +02:00
|
|
|
:references FN
|
2019-05-02 17:53:59 -04:00
|
|
|
Run when looking for usage references of a symbol in the current project. Used
|
|
|
|
by `+lookup/references'.
|
2018-06-20 15:37:49 +02:00
|
|
|
:documentation FN
|
2019-05-02 17:53:59 -04:00
|
|
|
Run when looking up documentation for a symbol. Used by
|
|
|
|
`+lookup/documentation'.
|
2018-06-20 15:37:49 +02:00
|
|
|
:file FN
|
2019-05-02 17:53:59 -04:00
|
|
|
Run when looking up the file for a symbol/string. Typically a file path. Used
|
|
|
|
by `+lookup/file'.
|
2018-06-20 15:37:49 +02:00
|
|
|
:xref-backend FN
|
2019-05-02 17:53:59 -04:00
|
|
|
Defines an xref backend for a major-mode. A :definition and :references
|
|
|
|
handler isn't necessary with a :xref-backend, but will have higher precedence
|
|
|
|
if they exist.
|
2019-01-08 00:33:38 -05:00
|
|
|
:async BOOL
|
2019-05-02 17:53:59 -04:00
|
|
|
Indicates that *all* supplied FNs are asynchronous. Note: lookups will not try
|
|
|
|
any handlers after async ones, due to their nature. To get around this, you
|
|
|
|
must write a specialized wrapper to await the async response, or use a
|
|
|
|
different heuristic to determine, ahead of time, whether the async call will
|
|
|
|
succeed or not.
|
2019-05-01 19:12:52 -04:00
|
|
|
|
2019-05-02 17:53:59 -04:00
|
|
|
If you only want to specify one FN is async, declare it inline instead:
|
2019-05-01 19:12:52 -04:00
|
|
|
|
|
|
|
(set-lookup-handlers! 'rust-mode
|
|
|
|
:definition '(racer-find-definition :async t))
|
|
|
|
|
|
|
|
Handlers can either be interactive or non-interactive. Non-interactive handlers
|
|
|
|
must take one argument: the identifier being looked up. This function must
|
|
|
|
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',
|
2020-05-12 01:06:23 +09:00
|
|
|
`+lookup-implementations-functions', `+lookup-type-definition-functions',
|
|
|
|
`+lookup-references-functions', `+lookup-file-functions' or
|
|
|
|
`+lookup-documentation-functions'.
|
2019-05-02 17:53:59 -04:00
|
|
|
|
|
|
|
Consecutive `set-lookup-handlers!' calls will overwrite previously defined
|
|
|
|
handlers for MODES. If used on minor modes, they are stacked onto handlers
|
|
|
|
defined for other minor modes or the major mode it's activated in.
|
|
|
|
|
|
|
|
This can be passed nil as its second argument to unset handlers for MODES. e.g.
|
|
|
|
|
2019-10-15 22:23:35 -04:00
|
|
|
(set-lookup-handlers! 'python-mode nil)
|
|
|
|
|
2020-05-12 01:06:23 +09:00
|
|
|
\(fn MODES &key DEFINITION IMPLEMENTATIONS TYPE-DEFINITION REFERENCES DOCUMENTATION FILE XREF-BACKEND ASYNC)"
|
2018-06-22 01:30:27 +02:00
|
|
|
(declare (indent defun))
|
2018-06-15 17:27:48 +02:00
|
|
|
(dolist (mode (doom-enlist modes))
|
2018-06-21 23:11:05 +02:00
|
|
|
(let ((hook (intern (format "%s-hook" mode)))
|
2019-07-22 23:45:31 +02:00
|
|
|
(fn (intern (format "+lookup--init-%s-handlers-h" mode))))
|
2020-04-08 15:29:29 -04:00
|
|
|
(if (null (car plist))
|
|
|
|
(progn
|
|
|
|
(remove-hook hook fn)
|
|
|
|
(unintern fn nil))
|
|
|
|
(fset
|
|
|
|
fn
|
|
|
|
(lambda ()
|
2020-05-12 01:06:23 +09:00
|
|
|
(cl-destructuring-bind (&key definition implementations type-definition references documentation file xref-backend async)
|
2020-04-08 15:29:29 -04:00
|
|
|
plist
|
|
|
|
(cl-mapc #'+lookup--set-handler
|
|
|
|
(list definition
|
2020-05-12 00:43:16 +09:00
|
|
|
implementations
|
2020-05-12 01:06:23 +09:00
|
|
|
type-definition
|
2020-04-08 15:29:29 -04:00
|
|
|
references
|
|
|
|
documentation
|
|
|
|
file
|
|
|
|
xref-backend)
|
|
|
|
(list '+lookup-definition-functions
|
2020-05-12 00:43:16 +09:00
|
|
|
'+lookup-implementations-functions
|
2020-05-12 01:06:23 +09:00
|
|
|
'+lookup-type-definition-functions
|
2020-04-08 15:29:29 -04:00
|
|
|
'+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)))))
|
2018-06-15 17:27:48 +02:00
|
|
|
|
2018-06-02 17:02:08 +02:00
|
|
|
|
feature/lookup: rewrite dash docset integration
+ Uses alist variable to store config, rather than hooks
+ Added check for installed docsets in +lookup/documentation
+ Set docsets for various language modules (c-mode, c++-mode, css-mode,
scss-mode, sass-mode, web-mode, go-mode, racket-mode, emacs-lisp-mode,
js2-mode, rjsx-mode, typescript-mode, rust-mode, and php-mode)
+ Made *eww* popups for dash docsets larger
+ Renamed set-docset! => set-docsets! (set-docset! is aliased to
set-docsets!)
+ New +lookup/install-docset alias
2018-08-31 02:44:49 +02:00
|
|
|
;;
|
2019-04-16 20:22:17 -04:00
|
|
|
;;; Helpers
|
|
|
|
|
2019-06-29 00:23:13 +02:00
|
|
|
(defun +lookup--set-handler (spec functions-var &optional async enable)
|
2019-04-16 20:22:17 -04:00
|
|
|
(when spec
|
|
|
|
(cl-destructuring-bind (fn . plist)
|
|
|
|
(doom-enlist spec)
|
2019-06-29 00:23:13 +02:00
|
|
|
(if (not enable)
|
|
|
|
(remove-hook functions-var fn 'local)
|
|
|
|
(put fn '+lookup-async (or (plist-get plist :async) async))
|
|
|
|
(add-hook functions-var fn nil 'local)))))
|
2018-01-04 17:05:37 -05:00
|
|
|
|
2019-04-16 20:22:17 -04:00
|
|
|
(defun +lookup--run-handler (handler identifier)
|
|
|
|
(if (commandp handler)
|
|
|
|
(call-interactively handler)
|
|
|
|
(funcall handler identifier)))
|
|
|
|
|
2019-05-02 17:53:59 -04:00
|
|
|
(defun +lookup--run-handlers (handler identifier origin)
|
2019-04-16 20:22:17 -04:00
|
|
|
(doom-log "Looking up '%s' with '%s'" identifier handler)
|
2019-05-14 22:26:21 -04:00
|
|
|
(condition-case-unless-debug e
|
2019-05-02 17:53:59 -04:00
|
|
|
(let ((wconf (current-window-configuration))
|
2019-05-14 22:26:21 -04:00
|
|
|
(result (condition-case-unless-debug e
|
2019-05-02 17:53:59 -04:00
|
|
|
(+lookup--run-handler handler identifier)
|
|
|
|
(error
|
2019-05-03 20:45:11 -04:00
|
|
|
(doom-log "Lookup handler %S threw an error: %s" handler e)
|
2019-05-02 17:53:59 -04:00
|
|
|
'fail))))
|
|
|
|
(cond ((eq result 'fail)
|
|
|
|
(set-window-configuration wconf)
|
|
|
|
nil)
|
|
|
|
((or (get handler '+lookup-async)
|
|
|
|
(eq result 'deferred)))
|
|
|
|
((or result
|
|
|
|
(null origin)
|
|
|
|
(/= (point-marker) origin))
|
|
|
|
(prog1 (point-marker)
|
|
|
|
(set-window-configuration wconf)))))
|
2019-05-14 22:26:21 -04:00
|
|
|
((error user-error)
|
2019-04-16 20:22:17 -04:00
|
|
|
(message "Lookup handler %S: %s" handler e)
|
2019-02-26 16:57:14 -05:00
|
|
|
nil)))
|
|
|
|
|
2019-05-16 00:37:27 -04:00
|
|
|
(defun +lookup--jump-to (prop identifier &optional display-fn arg)
|
2019-05-02 17:53:59 -04:00
|
|
|
(let* ((origin (point-marker))
|
2019-12-21 14:58:40 -05:00
|
|
|
(handlers
|
|
|
|
(plist-get (list :definition '+lookup-definition-functions
|
2020-05-12 00:43:16 +09:00
|
|
|
:implementations '+lookup-implementations-functions
|
2020-05-12 01:06:23 +09:00
|
|
|
:type-definition '+lookup-type-definition-functions
|
2019-12-21 14:58:40 -05:00
|
|
|
:references '+lookup-references-functions
|
|
|
|
:documentation '+lookup-documentation-functions
|
|
|
|
:file '+lookup-file-functions)
|
|
|
|
prop))
|
2019-05-02 17:53:59 -04:00
|
|
|
(result
|
2019-05-16 00:37:27 -04:00
|
|
|
(if arg
|
2019-12-21 14:58:40 -05:00
|
|
|
(if-let
|
|
|
|
(handler
|
|
|
|
(intern-soft
|
|
|
|
(completing-read "Select lookup handler: "
|
|
|
|
(delete-dups
|
|
|
|
(remq t (append (symbol-value handlers)
|
|
|
|
(default-value handlers))))
|
|
|
|
nil t)))
|
2019-05-16 00:37:27 -04:00
|
|
|
(+lookup--run-handlers handler identifier origin)
|
|
|
|
(user-error "No lookup handler selected"))
|
|
|
|
(run-hook-wrapped handlers #'+lookup--run-handlers identifier origin))))
|
2019-05-02 17:53:59 -04:00
|
|
|
(when (cond ((null result)
|
|
|
|
(message "No lookup handler could find %S" identifier)
|
|
|
|
nil)
|
|
|
|
((markerp result)
|
|
|
|
(funcall (or display-fn #'switch-to-buffer)
|
|
|
|
(marker-buffer result))
|
|
|
|
(goto-char result)
|
|
|
|
result)
|
|
|
|
(result))
|
|
|
|
(with-current-buffer (marker-buffer origin)
|
|
|
|
(better-jumper-set-jump (marker-position origin)))
|
2019-04-16 20:22:17 -04:00
|
|
|
result)))
|
2018-06-20 15:38:14 +02:00
|
|
|
|
2018-09-12 23:11:22 -04:00
|
|
|
|
|
|
|
;;
|
2019-04-16 20:22:17 -04:00
|
|
|
;;; Lookup backends
|
2018-09-12 23:11:22 -04:00
|
|
|
|
2020-04-08 15:16:50 -04:00
|
|
|
(defun +lookup--xref-show (fn identifier &optional show-fn)
|
2019-05-02 17:53:59 -04:00
|
|
|
(let ((xrefs (funcall fn
|
|
|
|
(xref-find-backend)
|
|
|
|
identifier)))
|
|
|
|
(when xrefs
|
2020-04-08 15:16:50 -04:00
|
|
|
(funcall (or show-fn #'xref--show-defs)
|
|
|
|
(lambda () xrefs)
|
|
|
|
nil)
|
2019-05-02 17:53:59 -04:00
|
|
|
(if (cdr xrefs)
|
|
|
|
'deferred
|
|
|
|
t))))
|
|
|
|
|
2020-08-06 00:19:56 -04:00
|
|
|
(defun +lookup-dictionary-definition-backend-fn (identifier)
|
|
|
|
"Look up dictionary definition for IDENTIFIER."
|
|
|
|
(when (derived-mode-p 'text-mode)
|
|
|
|
(+lookup/dictionary-definition identifier)
|
|
|
|
'deferred))
|
|
|
|
|
|
|
|
(defun +lookup-thesaurus-definition-backend-fn (identifier)
|
|
|
|
"Look up synonyms for IDENTIFIER."
|
|
|
|
(when (derived-mode-p 'text-mode)
|
|
|
|
(+lookup/synonyms identifier)
|
|
|
|
'deferred))
|
|
|
|
|
2019-07-22 23:45:31 +02:00
|
|
|
(defun +lookup-xref-definitions-backend-fn (identifier)
|
2018-04-23 01:19:26 -04:00
|
|
|
"Non-interactive wrapper for `xref-find-definitions'"
|
2020-04-08 15:16:50 -04:00
|
|
|
(+lookup--xref-show 'xref-backend-definitions identifier #'xref--show-defs))
|
2018-04-23 01:19:26 -04:00
|
|
|
|
2019-07-22 23:45:31 +02:00
|
|
|
(defun +lookup-xref-references-backend-fn (identifier)
|
2018-04-23 01:19:26 -04:00
|
|
|
"Non-interactive wrapper for `xref-find-references'"
|
2020-04-08 15:16:50 -04:00
|
|
|
(+lookup--xref-show 'xref-backend-references identifier #'xref--show-xrefs))
|
2018-04-23 01:19:26 -04:00
|
|
|
|
2019-07-22 23:45:31 +02:00
|
|
|
(defun +lookup-dumb-jump-backend-fn (_identifier)
|
2018-09-12 23:11:22 -04:00
|
|
|
"Look up the symbol at point (or selection) with `dumb-jump', which conducts a
|
|
|
|
project search with ag, rg, pt, or git-grep, combined with extra heuristics to
|
|
|
|
reduce false positives.
|
|
|
|
|
|
|
|
This backend prefers \"just working\" over accuracy."
|
2019-04-30 15:10:43 -04:00
|
|
|
(and (require 'dumb-jump nil t)
|
|
|
|
(dumb-jump-go)))
|
2018-09-12 23:11:22 -04:00
|
|
|
|
2019-07-22 23:45:31 +02:00
|
|
|
(defun +lookup-project-search-backend-fn (identifier)
|
2018-09-12 23:11:22 -04:00
|
|
|
"Conducts a simple project text search for IDENTIFIER.
|
|
|
|
|
|
|
|
Uses and requires `+ivy-file-search' or `+helm-file-search'. Will return nil if
|
2019-11-17 01:19:59 -05:00
|
|
|
neither is available. These require ripgrep to be installed."
|
2018-09-12 23:11:22 -04:00
|
|
|
(unless identifier
|
|
|
|
(let ((query (rxt-quote-pcre identifier)))
|
|
|
|
(ignore-errors
|
|
|
|
(cond ((featurep! :completion ivy)
|
2019-11-17 01:19:59 -05:00
|
|
|
(+ivy-file-search :query query)
|
2018-09-12 23:11:22 -04:00
|
|
|
t)
|
|
|
|
((featurep! :completion helm)
|
2019-11-17 01:19:59 -05:00
|
|
|
(+helm-file-search :query query)
|
2018-09-12 23:11:22 -04:00
|
|
|
t))))))
|
|
|
|
|
2019-07-22 23:45:31 +02:00
|
|
|
(defun +lookup-evil-goto-definition-backend-fn (_identifier)
|
2018-09-12 23:11:22 -04:00
|
|
|
"Uses `evil-goto-definition' to conduct a text search for IDENTIFIER in the
|
|
|
|
current buffer."
|
2019-02-26 16:57:14 -05:00
|
|
|
(and (fboundp 'evil-goto-definition)
|
2018-09-12 23:11:22 -04:00
|
|
|
(ignore-errors
|
|
|
|
(cl-destructuring-bind (beg . end)
|
|
|
|
(bounds-of-thing-at-point 'symbol)
|
|
|
|
(evil-goto-definition)
|
|
|
|
(let ((pt (point)))
|
|
|
|
(not (and (>= pt beg)
|
|
|
|
(< pt end))))))))
|
|
|
|
|
2018-01-04 17:05:37 -05:00
|
|
|
|
|
|
|
;;
|
2019-04-16 20:22:17 -04:00
|
|
|
;;; Main commands
|
2018-01-04 17:05:37 -05:00
|
|
|
|
|
|
|
;;;###autoload
|
2019-05-16 00:37:27 -04:00
|
|
|
(defun +lookup/definition (identifier &optional arg)
|
2018-06-20 15:39:14 +02:00
|
|
|
"Jump to the definition of IDENTIFIER (defaults to the symbol at point).
|
2018-01-04 17:05:37 -05:00
|
|
|
|
2018-06-20 15:39:14 +02:00
|
|
|
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."
|
2020-01-03 02:39:47 -05:00
|
|
|
(interactive (list (doom-thing-at-point-or-region)
|
2019-05-16 00:37:27 -04:00
|
|
|
current-prefix-arg))
|
2018-08-31 02:50:47 +02:00
|
|
|
(cond ((null identifier) (user-error "Nothing under point"))
|
2019-05-16 00:37:27 -04:00
|
|
|
((+lookup--jump-to :definition identifier nil arg))
|
2019-05-02 17:53:59 -04:00
|
|
|
((error "Couldn't find the definition of %S" identifier))))
|
2018-01-04 17:05:37 -05:00
|
|
|
|
2020-05-12 00:43:16 +09:00
|
|
|
;;;###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))))
|
|
|
|
|
2020-05-12 01:06:23 +09:00
|
|
|
;;;###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))))
|
|
|
|
|
2018-01-04 17:05:37 -05:00
|
|
|
;;;###autoload
|
2019-05-16 00:37:27 -04:00
|
|
|
(defun +lookup/references (identifier &optional arg)
|
2018-06-20 15:39:14 +02:00
|
|
|
"Show a list of usages of IDENTIFIER (defaults to the symbol at point)
|
2018-01-04 17:05:37 -05:00
|
|
|
|
2018-05-11 20:22:05 +02:00
|
|
|
Tries each function in `+lookup-references-functions' until one changes the
|
2018-06-20 15:39:14 +02:00
|
|
|
point and/or current buffer. Falls back to a naive ripgrep/the_silver_searcher
|
|
|
|
search otherwise."
|
2020-01-03 02:39:47 -05:00
|
|
|
(interactive (list (doom-thing-at-point-or-region)
|
2019-05-16 00:37:27 -04:00
|
|
|
current-prefix-arg))
|
2018-08-31 02:50:47 +02:00
|
|
|
(cond ((null identifier) (user-error "Nothing under point"))
|
2019-05-16 00:37:27 -04:00
|
|
|
((+lookup--jump-to :references identifier nil arg))
|
2019-05-02 17:53:59 -04:00
|
|
|
((error "Couldn't find references of %S" identifier))))
|
2018-01-04 17:05:37 -05:00
|
|
|
|
|
|
|
;;;###autoload
|
2019-05-16 00:37:27 -04:00
|
|
|
(defun +lookup/documentation (identifier &optional arg)
|
2018-01-04 17:05:37 -05:00
|
|
|
"Show documentation for IDENTIFIER (defaults to symbol at point or selection.
|
|
|
|
|
2019-01-08 00:33:38 -05:00
|
|
|
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'."
|
2020-01-03 02:39:47 -05:00
|
|
|
(interactive (list (doom-thing-at-point-or-region)
|
2019-05-16 00:37:27 -04:00
|
|
|
current-prefix-arg))
|
|
|
|
(cond ((+lookup--jump-to :documentation identifier #'pop-to-buffer arg))
|
2019-05-02 17:53:59 -04:00
|
|
|
((user-error "Couldn't find documentation for %S" identifier))))
|
2018-01-04 17:05:37 -05:00
|
|
|
|
2018-05-25 11:55:57 +02:00
|
|
|
(defvar ffap-file-finder)
|
2018-05-11 20:22:37 +02:00
|
|
|
;;;###autoload
|
|
|
|
(defun +lookup/file (path)
|
|
|
|
"Figure out PATH from whatever is at point and open it.
|
|
|
|
|
|
|
|
Each function in `+lookup-file-functions' is tried until one changes the point
|
|
|
|
or the current buffer.
|
|
|
|
|
|
|
|
Otherwise, falls back on `find-file-at-point'."
|
|
|
|
(interactive
|
|
|
|
(progn
|
|
|
|
(require 'ffap)
|
|
|
|
(list
|
|
|
|
(or (ffap-guesser)
|
|
|
|
(ffap-read-file-or-url
|
|
|
|
(if ffap-url-regexp "Find file or URL: " "Find file: ")
|
2020-01-03 02:39:47 -05:00
|
|
|
(doom-thing-at-point-or-region))))))
|
2018-05-11 20:22:37 +02:00
|
|
|
(require 'ffap)
|
2020-02-06 16:44:58 -05:00
|
|
|
(cond ((and path
|
|
|
|
buffer-file-name
|
|
|
|
(file-equal-p path buffer-file-name)
|
|
|
|
(user-error "Already here")))
|
|
|
|
|
|
|
|
((+lookup--jump-to :file path))
|
|
|
|
|
|
|
|
((stringp path) (find-file-at-point path))
|
|
|
|
|
|
|
|
((call-interactively #'find-file-at-point))))
|
2019-12-20 00:43:36 -05:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;;; Dictionary
|
|
|
|
|
|
|
|
;;;###autoload
|
2020-01-02 19:53:49 -05:00
|
|
|
(defun +lookup/dictionary-definition (identifier &optional arg)
|
2019-12-20 00:43:36 -05:00
|
|
|
"Look up the definition of the word at point (or selection)."
|
|
|
|
(interactive
|
2020-01-03 02:39:47 -05:00
|
|
|
(list (or (doom-thing-at-point-or-region 'word)
|
2020-01-02 21:08:04 -05:00
|
|
|
(read-string "Look up in dictionary: "))
|
2019-12-20 00:43:36 -05:00
|
|
|
current-prefix-arg))
|
2020-08-06 00:19:56 -04:00
|
|
|
(message "Looking up dictionary definition for %S" identifier)
|
2019-12-24 21:24:06 -05:00
|
|
|
(cond ((and IS-MAC (require 'osx-dictionary nil t))
|
2019-12-24 20:48:15 -05:00
|
|
|
(osx-dictionary--view-result identifier))
|
2020-01-25 16:55:04 -05:00
|
|
|
((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)
|
2019-12-20 00:43:36 -05:00
|
|
|
(define-word identifier nil arg))
|
2020-01-02 21:08:04 -05:00
|
|
|
((user-error "No dictionary backend is available"))))
|
2019-12-20 00:43:36 -05:00
|
|
|
|
|
|
|
;;;###autoload
|
2020-02-06 15:30:50 -05:00
|
|
|
(defun +lookup/synonyms (identifier &optional _arg)
|
2019-12-20 00:43:36 -05:00
|
|
|
"Look up and insert a synonym for the word at point (or selection)."
|
|
|
|
(interactive
|
2020-01-03 02:39:47 -05:00
|
|
|
(list (doom-thing-at-point-or-region 'word) ; TODO actually use this
|
2019-12-20 00:43:36 -05:00
|
|
|
current-prefix-arg))
|
2020-01-02 21:08:04 -05:00
|
|
|
(message "Looking up synonyms for %S" identifier)
|
2020-01-25 16:55:04 -05:00
|
|
|
(cond ((and +lookup-dictionary-prefer-offline
|
2020-04-08 05:00:29 -04:00
|
|
|
(require 'synosaurus-wordnet nil t))
|
2020-01-25 16:55:04 -05:00
|
|
|
(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"))))
|