dotfiles/emacs/.emacs.d/config/init-devdocs.el

41 lines
1.6 KiB
EmacsLisp

;; -*- lexical-binding: t; -*-
(use-package devdocs
:commands (devdocs-peruse
devdocs-lookup
devdocs-install
devdocs-delete
devdocs-update-all
devdocs-as-string)
:config
(defvar devdocs-entry-aliases nil
"Alist mapping expected DevDocs entry names to their actual names.")
(defun devdocs-as-string (entry doc &optional type-rx)
"Returns the devdocs for ENTRY in DOC as a string."
(let* ((entry (if (symbolp entry) (symbol-name entry) entry))
(entry (or (alist-get entry devdocs-entry-aliases nil nil #'equal) entry))
(docs (devdocs--doc-metadata doc))
(entries (devdocs--entries (list docs))))
(when-let ((entry-data (seq-find (lambda (e)
(let ((case-fold-search t)
(type (alist-get 'type (devdocs--get-data e))))
(if type-rx
(and (string-match type-rx type)
(string-match entry e))
(string-match entry e))))
entries)))
(with-current-buffer (devdocs--render (devdocs--get-data entry-data))
(buffer-string)))))
:general
(help-map "D" #'devdocs-lookup)
('normal devdocs-mode-map
"<" #'devdocs-first-page
">" #'devdocs-last-page
"gd" #'devdocs-peruse
"gg" #'devdocs-goto-page
"n" #'devdocs-next-entry
"p" #'devdocs-previous-entry))
(provide 'init-devdocs)