tools/lookup: update to reflect changes upstream
counsel-dash no longer depends on helm
This commit is contained in:
parent
4755258865
commit
8ec44959c5
5 changed files with 73 additions and 100 deletions
|
@ -1,11 +1,7 @@
|
||||||
;;; tools/lookup/autoload/docsets.el -*- lexical-binding: t; -*-
|
;;; tools/lookup/autoload/docsets.el -*- lexical-binding: t; -*-
|
||||||
;;;###if (featurep! +docsets)
|
;;;###if (featurep! +docsets)
|
||||||
|
|
||||||
(defvar +lookup-docset-alist nil
|
(defvar dash-docs-docsets nil)
|
||||||
"An alist mapping major and minor modes to lists of Dash docsets.
|
|
||||||
|
|
||||||
Entries are added by `set-docsets!' and used by `+lookup-docsets-for-buffer' to
|
|
||||||
assemble a list of installed & active docsets.")
|
|
||||||
|
|
||||||
;;;###autodef
|
;;;###autodef
|
||||||
(defun set-docsets! (modes &rest docsets)
|
(defun set-docsets! (modes &rest docsets)
|
||||||
|
@ -30,57 +26,54 @@ Example:
|
||||||
|
|
||||||
Used by `+lookup/in-docsets' and `+lookup/documentation'."
|
Used by `+lookup/in-docsets' and `+lookup/documentation'."
|
||||||
(declare (indent defun))
|
(declare (indent defun))
|
||||||
|
(let ((action (if (keywordp (car docsets)) (pop docsets))))
|
||||||
(dolist (mode (doom-enlist modes))
|
(dolist (mode (doom-enlist modes))
|
||||||
|
(let ((hook (intern (format "%s-hook" mode)))
|
||||||
|
(fn (make-symbol (format "+lookup|init--%s-%s" (or action "set") mode))))
|
||||||
(if (null docsets)
|
(if (null docsets)
|
||||||
(setq +lookup-docset-alist
|
(remove-hook hook fn)
|
||||||
(delq (assq mode +lookup-docset-alist)
|
(fset fn
|
||||||
+lookup-docset-alist))
|
(lambda ()
|
||||||
(let ((action (if (keywordp (car docsets)) (pop docsets)))
|
(make-local-variable 'dash-docs-docsets)
|
||||||
(docsets (mapcan #'doom-enlist docsets))) ; flatten list
|
(unless (memq action '(:add :remove))
|
||||||
(setf (alist-get mode +lookup-docset-alist)
|
(setq dash-docs-docset nil))
|
||||||
(pcase action
|
(dolist (spec docsets)
|
||||||
(:add (append docsets (alist-get mode +lookup-docset-alist)))
|
(cl-destructuring-bind (docset . pred)
|
||||||
(:remove (cl-set-difference (alist-get mode +lookup-docset-alist) docsets))
|
(cl-typecase spec
|
||||||
(_ docsets)))))))
|
(string (cons spec nil))
|
||||||
|
(vector (cons (aref spec 0) (aref spec 1)))
|
||||||
|
(otherwise (signal 'wrong-type-arguments (list spec '(vector string)))))
|
||||||
|
(when (or (null pred)
|
||||||
|
(eval pred t))
|
||||||
|
(if (eq action :remove)
|
||||||
|
(setq dash-docs-docsets (delete docset dash-docs-docsets))
|
||||||
|
(cl-pushnew docset dash-docs-docsets)))))))
|
||||||
|
(add-hook hook fn 'append))))))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun +lookup-dash-docsets-backend (identifier)
|
||||||
|
"Looks up IDENTIFIER in available Dash docsets, if any are installed.
|
||||||
|
|
||||||
|
This backend is meant for `+lookup-documentation-functions'.
|
||||||
|
|
||||||
|
Docsets must be installed with one of the following commands:
|
||||||
|
|
||||||
|
+ `dash-docs-install-docset'
|
||||||
|
+ `dash-docs-install-docset-from-file'
|
||||||
|
+ `dash-docs-install-user-docset'
|
||||||
|
+ `dash-docs-async-install-docset'
|
||||||
|
+ `dash-docs-async-install-docset-from-file'
|
||||||
|
|
||||||
|
Docsets can be searched directly via `+lookup/in-docsets'."
|
||||||
|
(let ((docsets (dash-docs-buffer-local-docsets)))
|
||||||
|
(when (cl-some #'dash-docs-docset-path docsets)
|
||||||
|
(+lookup/in-docsets identifier docsets)
|
||||||
|
'deferred)))
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
;; Library
|
;;; Commands
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun +lookup-docsets-for-buffer ()
|
|
||||||
"Return list of installed & selected docsets for the current major mode.
|
|
||||||
|
|
||||||
This list is built from `+lookup-docset-alist'."
|
|
||||||
(cl-loop for docset in (cdr (assq major-mode +lookup-docset-alist))
|
|
||||||
when (or (stringp docset)
|
|
||||||
(and (vectorp docset)
|
|
||||||
(eval (aref docset 1) t)))
|
|
||||||
collect docset))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun +lookup-docset-installed-p (docset)
|
|
||||||
"Return t if DOCSET is installed."
|
|
||||||
(let ((path (helm-dash-docsets-path)))
|
|
||||||
(file-directory-p
|
|
||||||
(expand-file-name (format "%s.docset" docset)
|
|
||||||
path))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(autoload 'helm-dash-installed-docsets "helm-dash")
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(autoload 'helm-dash-docset-installed-p "helm-dash")
|
|
||||||
|
|
||||||
|
|
||||||
;;
|
|
||||||
;; Commands
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defalias '+lookup/install-docset #'helm-dash-install-docset)
|
|
||||||
|
|
||||||
(defvar counsel-dash-docsets)
|
|
||||||
(defvar helm-dash-docsets)
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +lookup/in-docsets (&optional query docsets)
|
(defun +lookup/in-docsets (&optional query docsets)
|
||||||
"Lookup QUERY in dash DOCSETS.
|
"Lookup QUERY in dash DOCSETS.
|
||||||
|
@ -88,10 +81,10 @@ This list is built from `+lookup-docset-alist'."
|
||||||
QUERY is a string and docsets in an array of strings, each a name of a Dash
|
QUERY is a string and docsets in an array of strings, each a name of a Dash
|
||||||
docset. Requires either helm or ivy.
|
docset. Requires either helm or ivy.
|
||||||
|
|
||||||
Use `+lookup/install-docset' to install docsets."
|
Use `dash-docs-install-docset' to install docsets."
|
||||||
(interactive)
|
(interactive)
|
||||||
(let* ((counsel-dash-docsets (or docsets (+lookup-docsets-for-buffer)))
|
(require 'dash-docs)
|
||||||
(helm-dash-docsets counsel-dash-docsets)
|
(let ((dash-docs-docsets (or docsets (dash-docs-buffer-local-docsets)))
|
||||||
(query (or query (+lookup--symbol-or-region) "")))
|
(query (or query (+lookup--symbol-or-region) "")))
|
||||||
(cond ((featurep! :completion helm)
|
(cond ((featurep! :completion helm)
|
||||||
(helm-dash query))
|
(helm-dash query))
|
||||||
|
|
|
@ -17,6 +17,6 @@ install it if necessary)."
|
||||||
(let (selected)
|
(let (selected)
|
||||||
(when bang
|
(when bang
|
||||||
(setq selected (helm-dash-read-docset "Select docset" (helm-dash-official-docsets)))
|
(setq selected (helm-dash-read-docset "Select docset" (helm-dash-official-docsets)))
|
||||||
(unless (+lookup-docset-installed-p selected)
|
(unless (dash-docs-docset-path selected)
|
||||||
(+lookup/install-docset selected)))
|
(+lookup/install-docset selected)))
|
||||||
(+lookup/in-docsets query (or selected (+lookup-docsets-for-buffer)))))
|
(+lookup/in-docsets query selected)))
|
||||||
|
|
|
@ -219,19 +219,6 @@ current buffer."
|
||||||
(not (and (>= pt beg)
|
(not (and (>= pt beg)
|
||||||
(< pt end))))))))
|
(< pt end))))))))
|
||||||
|
|
||||||
(defun +lookup-dash-docsets-backend (identifier)
|
|
||||||
"Looks up IDENTIFIER in available Dash docsets, if any are installed.
|
|
||||||
|
|
||||||
Docsets must be installed with `+lookup/install-docset'. These can also be
|
|
||||||
accessed via `+lookup/in-docsets'."
|
|
||||||
(and (featurep! +docsets)
|
|
||||||
(or (require 'counsel-dash nil t)
|
|
||||||
(require 'helm-dash nil t))
|
|
||||||
(let ((docsets (+lookup-docsets-for-buffer)))
|
|
||||||
(when (cl-some #'+lookup-docset-installed-p docsets)
|
|
||||||
(+lookup/in-docsets identifier docsets)
|
|
||||||
'deferred))))
|
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
;;; Main commands
|
;;; Main commands
|
||||||
|
|
|
@ -57,8 +57,7 @@ argument: the identifier at point. See `set-lookup-handlers!' about adding to
|
||||||
this list.")
|
this list.")
|
||||||
|
|
||||||
(defvar +lookup-documentation-functions
|
(defvar +lookup-documentation-functions
|
||||||
'(+lookup-dash-docsets-backend
|
'(+lookup-online-backend)
|
||||||
+lookup-online-backend)
|
|
||||||
"Functions for `+lookup/documentation' to try, before resorting to
|
"Functions for `+lookup/documentation' to try, before resorting to
|
||||||
`dumb-jump'. Stops at the first function to return non-nil or change the current
|
`dumb-jump'. Stops at the first function to return non-nil or change the current
|
||||||
window/point.
|
window/point.
|
||||||
|
@ -113,39 +112,32 @@ this list.")
|
||||||
(global-set-key [remap xref-find-references] #'+lookup/references)
|
(global-set-key [remap xref-find-references] #'+lookup/references)
|
||||||
|
|
||||||
;; Use `better-jumper' instead of xref's marker stack
|
;; Use `better-jumper' instead of xref's marker stack
|
||||||
(advice-add #'xref-push-marker-stack :around #'doom*set-jump))
|
(advice-add #'xref-push-marker-stack :around #'doom*set-jump)
|
||||||
|
|
||||||
|
|
||||||
(def-package! ivy-xref
|
(def-package! ivy-xref
|
||||||
:when (featurep! :completion ivy)
|
:when (featurep! :completion ivy)
|
||||||
:after xref
|
|
||||||
:config (setq xref-show-xrefs-function #'ivy-xref-show-xrefs))
|
:config (setq xref-show-xrefs-function #'ivy-xref-show-xrefs))
|
||||||
|
|
||||||
|
|
||||||
(def-package! helm-xref
|
(def-package! helm-xref
|
||||||
:when (featurep! :completion helm)
|
:when (featurep! :completion helm)
|
||||||
:after xref
|
:config (setq xref-show-xrefs-function #'helm-xref-show-xrefs)))
|
||||||
:config (setq xref-show-xrefs-function #'helm-xref-show-xrefs))
|
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
;;; Dash docset integration
|
;;; Dash docset integration
|
||||||
|
|
||||||
;; Both packages depend on helm-dash, for now
|
(def-package! dash-docs
|
||||||
(def-package! helm-dash
|
|
||||||
:when (featurep! +docsets)
|
:when (featurep! +docsets)
|
||||||
:defer t
|
|
||||||
:init
|
:init
|
||||||
(setq helm-dash-enable-debugging doom-debug-mode
|
(add-hook '+lookup-documentation-functions #'+lookup-dash-docsets-backend)
|
||||||
helm-dash-browser-func #'eww)
|
|
||||||
:config
|
:config
|
||||||
(unless (file-directory-p helm-dash-docsets-path)
|
(setq dash-docs-enable-debugging doom-debug-mode
|
||||||
(setq helm-dash-docsets-path (concat doom-etc-dir "docsets/")))
|
dash-docs-docsets-path (concat doom-etc-dir "docsets/")
|
||||||
(unless (file-directory-p helm-dash-docsets-path)
|
dash-docs-min-length 2
|
||||||
(make-directory helm-dash-docsets-path t)))
|
dash-docs-browser-func #'eww)
|
||||||
|
|
||||||
|
(def-package! helm-dash
|
||||||
|
:when (featurep! :completion helm))
|
||||||
|
|
||||||
(def-package! counsel-dash
|
(def-package! counsel-dash
|
||||||
:when (and (featurep! +docsets)
|
:when (featurep! :completion ivy)))
|
||||||
(featurep! :completion ivy))
|
|
||||||
:commands counsel-dash-install-docset
|
|
||||||
:config (setq counsel-dash-min-length 2))
|
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
;;; tools/lookup/packages.el
|
;;; tools/lookup/packages.el
|
||||||
|
|
||||||
;; `dumb-jump' uses the `helm-build-sync-source' macro, but this requires helm
|
;; `dumb-jump' uses the `helm-build-sync-source' macro, but this requires helm
|
||||||
;; be loaded before it is byte-compiled during installation. To ensure this, we
|
;; be loaded before `dumb-jump' is byte-compiled during installation. To ensure
|
||||||
;; declare helm before dumb-jump.
|
;; this, we declare helm before dumb-jump.
|
||||||
(when (featurep! :completion helm)
|
(when (featurep! :completion helm)
|
||||||
(package! helm))
|
(package! helm))
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@
|
||||||
(package! helm-xref))
|
(package! helm-xref))
|
||||||
|
|
||||||
(when (featurep! +docsets)
|
(when (featurep! +docsets)
|
||||||
|
(package! dash-docs)
|
||||||
(when (featurep! :completion helm)
|
(when (featurep! :completion helm)
|
||||||
(package! helm-dash))
|
(package! helm-dash))
|
||||||
(when (featurep! :completion ivy)
|
(when (featurep! :completion ivy)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue