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
This commit is contained in:
parent
2df2622329
commit
fd8f8c5108
13 changed files with 119 additions and 35 deletions
|
@ -1,16 +1,16 @@
|
||||||
;;; feature/lookup/autoload/docsets.el -*- lexical-binding: t; -*-
|
;;; feature/lookup/autoload/docsets.el -*- lexical-binding: t; -*-
|
||||||
;;;###if (featurep! +docsets)
|
;;;###if (featurep! +docsets)
|
||||||
|
|
||||||
(defvar-local helm-dash-docsets nil
|
(defvar +lookup-docset-alist nil
|
||||||
"Docsets to use for this buffer.")
|
"An alist mapping major and minor modes to lists of Dash docsets.
|
||||||
|
|
||||||
(defvar-local counsel-dash-docsets nil
|
Entries are added by `set-docsets!' and used by `+lookup-docsets-for-buffer' to
|
||||||
"Docsets to use for this buffer.")
|
assemble a list of installed & active docsets.")
|
||||||
|
|
||||||
;;;###autodef
|
;;;###autodef
|
||||||
(defun set-docset! (modes &rest docsets)
|
(defun set-docsets! (modes &rest docsets)
|
||||||
"Registers a list of DOCSETS (strings) for MODES (either one major/minor mode
|
"Registers a list of DOCSETS (strings) for MODES (either one major/minor mode
|
||||||
symbol or a list of them).
|
symbol or a list of them). DOCSETS can also contain sublists.
|
||||||
|
|
||||||
If MODES is a minor mode, you can use :add or :remove as the first element of
|
If MODES is a minor mode, you can use :add or :remove as the first element of
|
||||||
DOCSETS, to instruct it to append (or remove) those from the docsets already set
|
DOCSETS, to instruct it to append (or remove) those from the docsets already set
|
||||||
|
@ -19,29 +19,82 @@ by a major-mode, if any.
|
||||||
Used by `+lookup/in-docsets' and `+lookup/documentation'."
|
Used by `+lookup/in-docsets' and `+lookup/documentation'."
|
||||||
(declare (indent defun))
|
(declare (indent defun))
|
||||||
(dolist (mode (doom-enlist modes))
|
(dolist (mode (doom-enlist modes))
|
||||||
(let ((fn (intern (format "+lookup|init-docsets--%s" mode)))
|
(if (null docsets)
|
||||||
(hook (intern (format "%s-hook" mode))))
|
(setq +lookup-docset-alist
|
||||||
(cond ((null (car-safe docsets))
|
(delq (assq mode +lookup-docset-alist)
|
||||||
(remove-hook hook fn)
|
+lookup-docset-alist)))
|
||||||
(unintern fn nil))
|
(setf (alist-get mode +lookup-docset-alist)
|
||||||
((fset fn
|
(mapcan #'doom-enlist docsets))))
|
||||||
(lambda ()
|
|
||||||
(let ((var-sym (if (featurep! :completion ivy)
|
;;;###autodef
|
||||||
'counsel-dash-docsets
|
(defalias 'set-docset! #'set-docsets!)
|
||||||
'helm-dash-docsets)))
|
|
||||||
(set var-sym
|
|
||||||
(append (symbol-value var-sym)
|
|
||||||
docsets)))))
|
|
||||||
(add-hook hook fn))))))
|
|
||||||
|
|
||||||
;; FIXME obsolete :docset
|
;; FIXME obsolete :docset
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(def-setting! :docset (modes &rest docsets)
|
(def-setting! :docset (modes &rest docsets)
|
||||||
:obsolete set-docset!
|
:obsolete set-docset!
|
||||||
`(set-docset! ,modes ,@docsets))
|
`(set-docsets! ,modes ,@docsets))
|
||||||
|
|
||||||
|
|
||||||
|
;;
|
||||||
|
;; Library
|
||||||
|
;;
|
||||||
|
|
||||||
|
;;;###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'."
|
||||||
|
(let ((base-docsets (cdr (assq major-mode +lookup-docset-alist))))
|
||||||
|
(dolist (spec +lookup-docset-alist)
|
||||||
|
(cl-destructuring-bind (mode . docsets) spec
|
||||||
|
(when (and (boundp mode) (symbol-value mode))
|
||||||
|
(pcase (car docsets)
|
||||||
|
(:add (nconc base-docsets (cdr docsets)))
|
||||||
|
(:remove
|
||||||
|
(dolist (docset (cdr docsets))
|
||||||
|
(setq base-docsets (delete docset base-docsets))))
|
||||||
|
(_ (setq base-docsets docsets))))))
|
||||||
|
base-docsets))
|
||||||
|
|
||||||
|
;;;###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
|
||||||
(autoload 'helm-dash-installed-docsets "helm-dash")
|
(autoload 'helm-dash-installed-docsets "helm-dash")
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(autoload 'helm-dash-docset-installed-p "helm-dash")
|
(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.
|
||||||
|
|
||||||
|
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."
|
||||||
|
(interactive)
|
||||||
|
(let* ((counsel-dash-docsets (or docsets (+lookup-docsets-for-buffer)))
|
||||||
|
(helm-dash-docsets counsel-dash-docsets)
|
||||||
|
(query (or query (+lookup--symbol-or-region) "")))
|
||||||
|
(cond ((featurep! :completion helm)
|
||||||
|
(helm-dash query))
|
||||||
|
((featurep! :completion ivy)
|
||||||
|
(counsel-dash query))
|
||||||
|
((user-error "No dash backend is installed, enable ivy or helm.")))))
|
||||||
|
|
|
@ -63,6 +63,10 @@ properties:
|
||||||
`(set-lookup-handlers! ,modes ,@plist))
|
`(set-lookup-handlers! ,modes ,@plist))
|
||||||
|
|
||||||
|
|
||||||
|
;;
|
||||||
|
;; Library
|
||||||
|
;;
|
||||||
|
|
||||||
;; Helpers
|
;; Helpers
|
||||||
(defun +lookup--online-provider (&optional force-p namespace)
|
(defun +lookup--online-provider (&optional force-p namespace)
|
||||||
(let ((key (or namespace major-mode)))
|
(let ((key (or namespace major-mode)))
|
||||||
|
@ -201,17 +205,18 @@ Goes down a list of possible backends:
|
||||||
3. Fall back to an online search, with `+lookup/online'"
|
3. Fall back to an online search, with `+lookup/online'"
|
||||||
(interactive
|
(interactive
|
||||||
(list (+lookup--symbol-or-region)))
|
(list (+lookup--symbol-or-region)))
|
||||||
(cond ((and +lookup-documentation-functions
|
(cond ((null identifier) (user-error "Nothing under point"))
|
||||||
|
|
||||||
|
((and +lookup-documentation-functions
|
||||||
(+lookup--jump-to :documentation identifier)))
|
(+lookup--jump-to :documentation identifier)))
|
||||||
|
|
||||||
((and (featurep! +docsets)
|
((and (featurep! +docsets)
|
||||||
(or (require 'counsel-dash nil t)
|
(or (require 'counsel-dash nil t)
|
||||||
(require 'helm-dash nil t))
|
(require 'helm-dash nil t))
|
||||||
(or (bound-and-true-p counsel-dash-docsets)
|
(let ((docsets (+lookup-docsets-for-buffer)))
|
||||||
(bound-and-true-p helm-dash-docsets))
|
(when (cl-some #'+lookup-docset-installed-p docsets)
|
||||||
;; counsel-dash uses helm-dash under the hood
|
(+lookup/in-docsets identifier docsets)
|
||||||
(helm-dash-installed-docsets))
|
t))))
|
||||||
(+lookup/in-docsets identifier))
|
|
||||||
|
|
||||||
((+lookup/online
|
((+lookup/online
|
||||||
identifier
|
identifier
|
||||||
|
|
|
@ -120,8 +120,8 @@ argument: the identifier at point.")
|
||||||
|
|
||||||
;; Both packages depend on helm-dash, for now
|
;; Both packages depend on helm-dash, for now
|
||||||
(def-package! helm-dash
|
(def-package! helm-dash
|
||||||
:defer t
|
|
||||||
:when (featurep! +docsets)
|
:when (featurep! +docsets)
|
||||||
|
:defer t
|
||||||
:init
|
:init
|
||||||
(setq helm-dash-enable-debugging doom-debug-mode
|
(setq helm-dash-enable-debugging doom-debug-mode
|
||||||
helm-dash-browser-func #'eww)
|
helm-dash-browser-func #'eww)
|
||||||
|
|
|
@ -41,6 +41,8 @@ compilation database is present in the project.")
|
||||||
|
|
||||||
:config
|
:config
|
||||||
(set-electric! '(c-mode c++-mode objc-mode java-mode) :chars '(?\n ?\}))
|
(set-electric! '(c-mode c++-mode objc-mode java-mode) :chars '(?\n ?\}))
|
||||||
|
(set-docsets! 'c-mode "C")
|
||||||
|
(set-docsets! 'c++-mode "C++" "Boost")
|
||||||
|
|
||||||
(set-pretty-symbols! '(c-mode c++-mode)
|
(set-pretty-symbols! '(c-mode c++-mode)
|
||||||
;; Functional
|
;; Functional
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
(set-lookup-handlers! 'emacs-lisp-mode
|
(set-lookup-handlers! 'emacs-lisp-mode
|
||||||
:definition #'elisp-def
|
:definition #'elisp-def
|
||||||
:documentation #'info-lookup-symbol)
|
:documentation #'info-lookup-symbol)
|
||||||
(set-docset! 'emacs-lisp-mode "Emacs Lisp")
|
(set-docsets! 'emacs-lisp-mode "Emacs Lisp")
|
||||||
(set-pretty-symbols! 'emacs-lisp-mode :lambda "lambda")
|
(set-pretty-symbols! 'emacs-lisp-mode :lambda "lambda")
|
||||||
(set-rotate-patterns! 'emacs-lisp-mode
|
(set-rotate-patterns! 'emacs-lisp-mode
|
||||||
:symbols '(("t" "nil")
|
:symbols '(("t" "nil")
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
(after! go-mode
|
(after! go-mode
|
||||||
(set-env! "GOPATH" "GOROOT")
|
(set-env! "GOPATH" "GOROOT")
|
||||||
|
(set-docsets! 'go-mode "Go")
|
||||||
(set-repl-handler! 'go-mode #'gorepl-run)
|
(set-repl-handler! 'go-mode #'gorepl-run)
|
||||||
(set-lookup-handlers! 'go-mode
|
(set-lookup-handlers! 'go-mode
|
||||||
:definition #'go-guru-definition
|
:definition #'go-guru-definition
|
||||||
|
|
|
@ -1,5 +1,14 @@
|
||||||
;;; lang/javascript/config.el -*- lexical-binding: t; -*-
|
;;; lang/javascript/config.el -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
|
(defvar +javascript-docsets
|
||||||
|
'("JavaScript"
|
||||||
|
"AngularJS" "Backbone" "BackboneJS" "Bootstrap" "D3JS" "EmberJS" "Express"
|
||||||
|
"ExtJS" "JQuery" "JQuery_Mobile" "JQuery_UI" "KnockoutJS" "Lo-Dash"
|
||||||
|
"MarionetteJS" "MomentJS" "NodeJS" "PrototypeJS" "React" "RequireJS"
|
||||||
|
"SailsJS" "UnderscoreJS" "VueJS" "ZeptoJS")
|
||||||
|
"A list of dash docsets to use for Javascript modes (`js2-mode' and
|
||||||
|
`rjsx-mode'). These are used by `+lookup/in-docsets'.")
|
||||||
|
|
||||||
(after! (:any js2-mode web-mode)
|
(after! (:any js2-mode web-mode)
|
||||||
(set-pretty-symbols! '(js2-mode web-mode)
|
(set-pretty-symbols! '(js2-mode web-mode)
|
||||||
;; Functional
|
;; Functional
|
||||||
|
@ -46,6 +55,7 @@
|
||||||
|
|
||||||
(set-electric! 'js2-mode :chars '(?\} ?\) ?. ?:))
|
(set-electric! 'js2-mode :chars '(?\} ?\) ?. ?:))
|
||||||
(set-repl-handler! 'js2-mode #'+javascript/repl)
|
(set-repl-handler! 'js2-mode #'+javascript/repl)
|
||||||
|
(set-docsets! 'js2-mode +javascript-docsets)
|
||||||
|
|
||||||
(map! :map js2-mode-map
|
(map! :map js2-mode-map
|
||||||
:localleader
|
:localleader
|
||||||
|
@ -66,6 +76,7 @@
|
||||||
(add-to-list 'magic-mode-alist '(+javascript-jsx-file-p . rjsx-mode))
|
(add-to-list 'magic-mode-alist '(+javascript-jsx-file-p . rjsx-mode))
|
||||||
:config
|
:config
|
||||||
(set-electric! 'rjsx-mode :chars '(?\} ?\) ?. ?>))
|
(set-electric! 'rjsx-mode :chars '(?\} ?\) ?. ?>))
|
||||||
|
(set-docsets! 'rjsx-mode +javascript-docsets)
|
||||||
(add-hook! 'rjsx-mode-hook
|
(add-hook! 'rjsx-mode-hook
|
||||||
;; jshint doesn't know how to deal with jsx
|
;; jshint doesn't know how to deal with jsx
|
||||||
(push 'javascript-jshint flycheck-disabled-checkers))
|
(push 'javascript-jshint flycheck-disabled-checkers))
|
||||||
|
@ -86,6 +97,7 @@
|
||||||
comment-line-break-function #'js2-line-break)
|
comment-line-break-function #'js2-line-break)
|
||||||
(set-electric! 'typescript-mode
|
(set-electric! 'typescript-mode
|
||||||
:chars '(?\} ?\)) :words '("||" "&&"))
|
:chars '(?\} ?\)) :words '("||" "&&"))
|
||||||
|
(set-docsets! 'typescript-mode "TypeScript" "AngularTS")
|
||||||
(set-pretty-symbols! 'typescript-mode
|
(set-pretty-symbols! 'typescript-mode
|
||||||
;; Functional
|
;; Functional
|
||||||
:def "function"
|
:def "function"
|
||||||
|
@ -106,6 +118,8 @@
|
||||||
|
|
||||||
;; `coffee-mode'
|
;; `coffee-mode'
|
||||||
(setq coffee-indent-like-python-mode t)
|
(setq coffee-indent-like-python-mode t)
|
||||||
|
(after! coffee-mode
|
||||||
|
(set-docsets! 'coffee-mode "CoffeeScript"))
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
;; php+html. Use the .phtml
|
;; php+html. Use the .phtml
|
||||||
(setq php-template-compatibility nil)
|
(setq php-template-compatibility nil)
|
||||||
|
|
||||||
|
(set-docsets! 'php-mode "PHP" "PHPUnit" "Laravel" "CakePHP" "CodeIgniter" "Doctrine_ORM")
|
||||||
(set-repl-handler! 'php-mode #'php-boris)
|
(set-repl-handler! 'php-mode #'php-boris)
|
||||||
(set-lookup-handlers! 'php-mode :documentation #'php-search-documentation)
|
(set-lookup-handlers! 'php-mode :documentation #'php-search-documentation)
|
||||||
(set-formatter! 'php-mode #'php-cs-fixer-fix)
|
(set-formatter! 'php-mode #'php-cs-fixer-fix)
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
(set-lookup-handlers! 'racket-mode
|
(set-lookup-handlers! 'racket-mode
|
||||||
:definition #'racket-visit-definition
|
:definition #'racket-visit-definition
|
||||||
:documentation #'racket-describe)
|
:documentation #'racket-describe)
|
||||||
(set-docset! 'racket-mode "Racket")
|
(set-docsets! 'racket-mode "Racket")
|
||||||
(set-pretty-symbols! 'racket-mode
|
(set-pretty-symbols! 'racket-mode
|
||||||
:lambda "lambda"
|
:lambda "lambda"
|
||||||
:map "map"
|
:map "map"
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
(after! rust-mode
|
(after! rust-mode
|
||||||
(set-env! "RUST_SRC_PATH")
|
(set-env! "RUST_SRC_PATH")
|
||||||
(set-docset! 'rust-mode "Rust")
|
(set-docsets! 'rust-mode "Rust")
|
||||||
(setq rust-indent-method-chain t)
|
(setq rust-indent-method-chain t)
|
||||||
|
|
||||||
(map! :map rust-mode-map
|
(map! :map rust-mode-map
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
;;; lang/web/+css.el -*- lexical-binding: t; -*-
|
;;; lang/web/+css.el -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
|
(defvar +web-css-docsets '("CSS" "HTML" "Bourbon" "Compass")
|
||||||
|
"TODO")
|
||||||
|
|
||||||
;; An improved newline+continue comment function
|
;; An improved newline+continue comment function
|
||||||
(setq-hook! css-mode comment-indent-function #'+css/comment-indent-new-line)
|
(setq-hook! css-mode comment-indent-function #'+css/comment-indent-new-line)
|
||||||
|
|
||||||
|
@ -33,10 +36,10 @@
|
||||||
:defer t
|
:defer t
|
||||||
:config
|
:config
|
||||||
;; contains both css-mode & scss-mode
|
;; contains both css-mode & scss-mode
|
||||||
(set-docset! 'css-mode "CSS")
|
(set-docsets! 'css-mode +web-css-docsets)
|
||||||
(set-docset! 'scss-mode "Sass")
|
(set-docsets! 'scss-mode "Sass" +web-css-docsets)
|
||||||
(unless EMACS26+
|
(unless EMACS26+
|
||||||
;; css-mode's built in completion is superior
|
;; css-mode's built in completion is superior in 26+
|
||||||
(set-company-backend! '(css-mode scss-mode) 'company-css))
|
(set-company-backend! '(css-mode scss-mode) 'company-css))
|
||||||
(map! :map scss-mode-map :localleader :n "b" #'+css/scss-build))
|
(map! :map scss-mode-map :localleader :n "b" #'+css/scss-build))
|
||||||
|
|
||||||
|
@ -44,7 +47,7 @@
|
||||||
(def-package! sass-mode
|
(def-package! sass-mode
|
||||||
:defer t
|
:defer t
|
||||||
:config
|
:config
|
||||||
(set-docset! 'sass-mode "Sass")
|
(set-docsets! 'sass-mode "Sass" +web-css-docsets)
|
||||||
(set-company-backend! 'sass-mode 'company-css)
|
(set-company-backend! 'sass-mode 'company-css)
|
||||||
(map! :map scss-mode-map :localleader :n "b" #'+css/sass-build))
|
(map! :map scss-mode-map :localleader :n "b" #'+css/sass-build))
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
:mode "wp-content/themes/.+/.+\\.php$"
|
:mode "wp-content/themes/.+/.+\\.php$"
|
||||||
:mode "templates/.+\\.php$"
|
:mode "templates/.+\\.php$"
|
||||||
:config
|
:config
|
||||||
|
(set-docsets! 'web-mode "HTML" "Twig" "WordPress")
|
||||||
|
|
||||||
(setq web-mode-enable-html-entities-fontification t
|
(setq web-mode-enable-html-entities-fontification t
|
||||||
web-mode-auto-close-style 2)
|
web-mode-auto-close-style 2)
|
||||||
|
|
||||||
|
|
|
@ -156,6 +156,9 @@ prevent the popup(s) from messing up the UI (or vice versa)."
|
||||||
;; `help-mode', `helpful-mode'
|
;; `help-mode', `helpful-mode'
|
||||||
("^\\*[Hh]elp"
|
("^\\*[Hh]elp"
|
||||||
:slot 2 :vslot 2 :size 0.35 :select t)
|
:slot 2 :vslot 2 :size 0.35 :select t)
|
||||||
|
;; `eww' (and used by dash docsets)
|
||||||
|
("^\\*eww\\*"
|
||||||
|
:vslot 50 :size 0.35 :select t)
|
||||||
;; `Info-mode'
|
;; `Info-mode'
|
||||||
("^\\*info\\*$"
|
("^\\*info\\*$"
|
||||||
:slot 2 :vslot 2 :size 0.45 :select t)))
|
:slot 2 :vslot 2 :size 0.45 :select t)))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue