summaryrefslogtreecommitdiff
path: root/modules/help-utils.el
blob: 91ac894749add3e65d740b4b10d1764b13ee8e1c (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
;;; 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
  :commands (devdocs-search devdocs-peruse devdocs-lookup devdocs-install devdocs-delete devdocs-update-all)
  :init
  (keymap-global-set "C-h D s" #'devdocs-search)
  (keymap-global-set "C-h D b" #'devdocs-peruse)
  (keymap-global-set "C-h D l" #'devdocs-lookup)
  (keymap-global-set "C-h D i" #'devdocs-install)
  (keymap-global-set "C-h D d" #'devdocs-delete)
  (keymap-global-set "C-h D u" #'devdocs-update-all)
  :config
  (define-key devdocs-mode-map "b" #'devdocs-go-back)
  (define-key devdocs-mode-map "f" #'devdocs-go-forward))

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

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

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

(use-package wiki-summary
  :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?"))))
(keymap-global-set "C-h A" #'cj/local-arch-wiki-search)

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