summaryrefslogtreecommitdiff
path: root/modules/help-utils.el
blob: dcb7a748a9be14203c86505011e665f7136a2f84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
;;; help-utils --- Help Integrations and Searches -*- lexical-binding: t; coding: utf-8; -*-
;; author Craig Jennings <c@cjennings.net>
;;
;;; Commentary:
;;
;; This module provides various utilities for accessing documentation and help resources
;; directly within Emacs.
;; DevDocs for programming documentation
;; TLDR command line cheat sheets
;; Wikipedia pages through the `wiki-summary` package.
;; ArchWiki pages are also browsable via EWW.
;;
;;; Keybindings:
;; - C-h D s: Search DevDocs for documentation.
;; - C-h D b: Peruse DevDocs browsing through documentation.
;; - C-h D l: Lookup specific documentation in DevDocs.
;; - C-h D i: Install documentation for a chosen library in DevDocs.
;; - C-h D d: Delete documentation from DevDocs.
;; - C-h D u: Update all installed DevDocs documentation.
;; - C-h T: Access TLDR (cheat sheets for command-line tools).
;; - C-h W: Summarize wiki pages with the wiki-summary package.
;; - C-h A: Search and browse local Arch Wiki topics in EWW.
;;
;;; Code:

;; ---------------------------------- Devdocs ----------------------------------

(use-package devdocs
  :defer 1
  :config
  (global-set-key (kbd "C-h D s") 'devdocs-search)
  (global-set-key (kbd "C-h D b") 'devdocs-peruse)
  (global-set-key (kbd "C-h D l") 'devdocs-lookup)
  (global-set-key (kbd "C-h D i") 'devdocs-install)
  (global-set-key (kbd "C-h D d") 'devdocs-delete)
  (global-set-key (kbd "C-h D u") 'devdocs-update-all)
  (define-key devdocs-mode-map "b" 'devdocs-go-back)
  (define-key devdocs-mode-map "f" 'devdocs-go-forward))

;; ------------------------------------ TLDR -----------------------------------

(use-package tldr
  :defer 1
  :bind ("C-h T" . tldr))

;; -------------------------------- Wiki Summary -------------------------------

(use-package wiki-summary
  :defer 1
  :bind ("C-h W" . wiki-summary))

;; --------------------------- Browse Local Arch Wiki --------------------------
;; on Arch: yay (or whatever your AUR package manager is) -S  arch-wiki-docs
;; browse the arch wiki topics offline

(defun cj/local-arch-wiki-search ()
  "Prompt for an ArchWiki topic and open its local HTML copy in EWW.

Looks for “*.html” files under \"/usr/share/doc/arch-wiki/html/en\",
lets you complete on their basenames, and displays the chosen file
with `eww-browse-url'. If no file is found, reminds you to install
arch-wiki-docs."
  (interactive)
  (let* ((dir "/usr/share/doc/arch-wiki/html/en")
		 (full-filenames (directory-files dir t "\\.html\\'"))
		 (basenames (mapcar 'file-name-base full-filenames))
		 (chosen (completing-read "Choose an ArchWiki Topic: " basenames)))
	(if (member chosen basenames)
		(let* ((idx (cl-position chosen basenames :test 'equal))
			   (fullname (nth idx full-filenames))
			   (url (concat "file://" fullname)))
		  (eww-browse-url url))
	  (message "File not found! Is arch-wiki-docs installed?"))))
(global-set-key (kbd "C-h A") 'cj/local-arch-wiki-search)

(provide 'help-utils)
;;; help-utils.el ends here