tools/lookup: update to reflect changes upstream

counsel-dash no longer depends on helm
This commit is contained in:
Henrik Lissner 2019-05-12 01:45:48 -04:00
parent 4755258865
commit 8ec44959c5
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
5 changed files with 73 additions and 100 deletions

View file

@ -1,11 +1,7 @@
;;; tools/lookup/autoload/docsets.el -*- lexical-binding: t; -*-
;;;###if (featurep! +docsets)
(defvar +lookup-docset-alist 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.")
(defvar dash-docs-docsets nil)
;;;###autodef
(defun set-docsets! (modes &rest docsets)
@ -30,57 +26,54 @@ Example:
Used by `+lookup/in-docsets' and `+lookup/documentation'."
(declare (indent defun))
(let ((action (if (keywordp (car docsets)) (pop docsets))))
(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)
(setq +lookup-docset-alist
(delq (assq mode +lookup-docset-alist)
+lookup-docset-alist))
(let ((action (if (keywordp (car docsets)) (pop docsets)))
(docsets (mapcan #'doom-enlist docsets))) ; flatten list
(setf (alist-get mode +lookup-docset-alist)
(pcase action
(:add (append docsets (alist-get mode +lookup-docset-alist)))
(:remove (cl-set-difference (alist-get mode +lookup-docset-alist) docsets))
(_ docsets)))))))
(remove-hook hook fn)
(fset fn
(lambda ()
(make-local-variable 'dash-docs-docsets)
(unless (memq action '(:add :remove))
(setq dash-docs-docset nil))
(dolist (spec docsets)
(cl-destructuring-bind (docset . pred)
(cl-typecase spec
(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
(defun +lookup/in-docsets (&optional query 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
docset. Requires either helm or ivy.
Use `+lookup/install-docset' to install docsets."
Use `dash-docs-install-docset' to install docsets."
(interactive)
(let* ((counsel-dash-docsets (or docsets (+lookup-docsets-for-buffer)))
(helm-dash-docsets counsel-dash-docsets)
(require 'dash-docs)
(let ((dash-docs-docsets (or docsets (dash-docs-buffer-local-docsets)))
(query (or query (+lookup--symbol-or-region) "")))
(cond ((featurep! :completion helm)
(helm-dash query))

View file

@ -17,6 +17,6 @@ install it if necessary)."
(let (selected)
(when bang
(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/in-docsets query (or selected (+lookup-docsets-for-buffer)))))
(+lookup/in-docsets query selected)))

View file

@ -219,19 +219,6 @@ current buffer."
(not (and (>= pt beg)
(< 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

View file

@ -57,8 +57,7 @@ argument: the identifier at point. See `set-lookup-handlers!' about adding to
this list.")
(defvar +lookup-documentation-functions
'(+lookup-dash-docsets-backend
+lookup-online-backend)
'(+lookup-online-backend)
"Functions for `+lookup/documentation' to try, before resorting to
`dumb-jump'. Stops at the first function to return non-nil or change the current
window/point.
@ -113,39 +112,32 @@ this list.")
(global-set-key [remap xref-find-references] #'+lookup/references)
;; 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
:when (featurep! :completion ivy)
:after xref
:config (setq xref-show-xrefs-function #'ivy-xref-show-xrefs))
(def-package! helm-xref
: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
;; Both packages depend on helm-dash, for now
(def-package! helm-dash
(def-package! dash-docs
:when (featurep! +docsets)
:defer t
:init
(setq helm-dash-enable-debugging doom-debug-mode
helm-dash-browser-func #'eww)
(add-hook '+lookup-documentation-functions #'+lookup-dash-docsets-backend)
:config
(unless (file-directory-p helm-dash-docsets-path)
(setq helm-dash-docsets-path (concat doom-etc-dir "docsets/")))
(unless (file-directory-p helm-dash-docsets-path)
(make-directory helm-dash-docsets-path t)))
(setq dash-docs-enable-debugging doom-debug-mode
dash-docs-docsets-path (concat doom-etc-dir "docsets/")
dash-docs-min-length 2
dash-docs-browser-func #'eww)
(def-package! helm-dash
:when (featurep! :completion helm))
(def-package! counsel-dash
:when (and (featurep! +docsets)
(featurep! :completion ivy))
:commands counsel-dash-install-docset
:config (setq counsel-dash-min-length 2))
:when (featurep! :completion ivy)))

View file

@ -2,8 +2,8 @@
;;; tools/lookup/packages.el
;; `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
;; declare helm before dumb-jump.
;; be loaded before `dumb-jump' is byte-compiled during installation. To ensure
;; this, we declare helm before dumb-jump.
(when (featurep! :completion helm)
(package! helm))
@ -15,6 +15,7 @@
(package! helm-xref))
(when (featurep! +docsets)
(package! dash-docs)
(when (featurep! :completion helm)
(package! helm-dash))
(when (featurep! :completion ivy)