lang/org: add lookup handlers for src blocks
- Fixes: `set-lookup-handlers!` couldn't define :definition or :references handlers in text-mode derivatives. - Adds: support for evaluating code in jupyter blocks (#2477).
This commit is contained in:
parent
3b159dda0a
commit
5a80db875c
4 changed files with 60 additions and 9 deletions
|
@ -17,6 +17,45 @@
|
|||
(+eval/region beg end)))))
|
||||
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-lookup-definition-handler (identifier)
|
||||
"TODO"
|
||||
(when (org-in-src-block-p t)
|
||||
(let ((mode (org-src-get-lang-mode
|
||||
(or (org-eldoc-get-src-lang)
|
||||
(user-error "No lang specified for this src block")))))
|
||||
(cond ((and (eq mode 'emacs-lisp-mode)
|
||||
(fboundp '+emacs-lisp-lookup-definition))
|
||||
(+emacs-lisp-lookup-definition identifier)
|
||||
'deferred)
|
||||
((user-error "Definition lookup in SRC blocks isn't supported yet"))))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-lookup-references-handler (identifier)
|
||||
"TODO"
|
||||
(when (org-in-src-block-p t)
|
||||
(user-error "References lookup in SRC blocks isn't supported yet")))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-lookup-documentation-handler (identifier)
|
||||
"TODO"
|
||||
(when (org-in-src-block-p t)
|
||||
(let ((mode (org-src-get-lang-mode
|
||||
(or (org-eldoc-get-src-lang)
|
||||
(user-error "No lang specified for this src block"))))
|
||||
(info (org-babel-get-src-block-info t)))
|
||||
(cond ((string-prefix-p "jupyter-" (car info))
|
||||
(and (require 'jupyter nil t)
|
||||
(call-interactively #'jupyter-inspect-at-point)
|
||||
(display-buffer (help-buffer))
|
||||
'deferred))
|
||||
((and (eq mode 'emacs-lisp-mode)
|
||||
(fboundp '+emacs-lisp-lookup-documentation))
|
||||
(+emacs-lisp-lookup-documentation identifier)
|
||||
'deferred)
|
||||
((user-error "Documentation lookup in SRC blocks isn't supported yet"))))))
|
||||
|
||||
|
||||
;;
|
||||
;;; Hooks
|
||||
|
||||
|
|
|
@ -1107,6 +1107,10 @@ compelling reason, so..."
|
|||
:config
|
||||
(set-company-backend! 'org-mode 'company-capf 'company-dabbrev)
|
||||
(set-eval-handler! 'org-mode #'+org-eval-handler)
|
||||
(set-lookup-handlers! 'org-mode
|
||||
:definition #'+org-lookup-definition-handler
|
||||
:references #'+org-lookup-references-handler
|
||||
:documentation #'+org-lookup-documentation-handler)
|
||||
|
||||
;; Save target buffer after archiving a node.
|
||||
(setq org-archive-subtree-save-file-p t)
|
||||
|
|
|
@ -192,6 +192,18 @@ This can be passed nil as its second argument to unset handlers for MODES. e.g.
|
|||
'deferred
|
||||
t))))
|
||||
|
||||
(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))
|
||||
|
||||
(defun +lookup-xref-definitions-backend-fn (identifier)
|
||||
"Non-interactive wrapper for `xref-find-definitions'"
|
||||
(+lookup--xref-show 'xref-backend-definitions identifier #'xref--show-defs))
|
||||
|
@ -343,7 +355,7 @@ 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)
|
||||
(message "Looking up dictionary definition for %S" identifier)
|
||||
(cond ((and IS-MAC (require 'osx-dictionary nil t))
|
||||
(osx-dictionary--view-result identifier))
|
||||
((and +lookup-dictionary-prefer-offline
|
||||
|
|
|
@ -41,7 +41,8 @@ Used by `+lookup/online'.")
|
|||
"Function to use to open search urls.")
|
||||
|
||||
(defvar +lookup-definition-functions
|
||||
'(+lookup-xref-definitions-backend-fn
|
||||
'(+lookup-dictionary-definition-backend-fn
|
||||
+lookup-xref-definitions-backend-fn
|
||||
+lookup-dumb-jump-backend-fn
|
||||
+lookup-project-search-backend-fn
|
||||
+lookup-evil-goto-definition-backend-fn)
|
||||
|
@ -73,7 +74,8 @@ argument: the identifier at point. See `set-lookup-handlers!' about adding to
|
|||
this list.")
|
||||
|
||||
(defvar +lookup-references-functions
|
||||
'(+lookup-xref-references-backend-fn
|
||||
'(+lookup-thesaurus-definition-backend-fn
|
||||
+lookup-xref-references-backend-fn
|
||||
+lookup-project-search-backend-fn)
|
||||
"Functions for `+lookup/references' to try, before resorting to `dumb-jump'.
|
||||
Stops at the first function to return non-nil or change the current
|
||||
|
@ -203,11 +205,5 @@ Dictionary.app behind the scenes to get definitions.")
|
|||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue