author | Oleksandr Gavenko <gavenkoa@gmail.com> |
Sun, 28 Jul 2019 13:49:08 +0300 | |
changeset 1595 | 0f4f0205ef3e |
parent 1242 | 3ac891ab0ad6 |
permissions | -rw-r--r-- |
1057
899bedcbfa57
Add docs to fix "M-x checkdoc" errors.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1056
diff
changeset
|
1 |
;;; debian-doc.el --- Debian doc-base integration with Emacs. |
1056
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
2 |
|
1057
899bedcbfa57
Add docs to fix "M-x checkdoc" errors.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1056
diff
changeset
|
3 |
;;; Commentary: |
899bedcbfa57
Add docs to fix "M-x checkdoc" errors.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1056
diff
changeset
|
4 |
;; |
899bedcbfa57
Add docs to fix "M-x checkdoc" errors.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1056
diff
changeset
|
5 |
|
899bedcbfa57
Add docs to fix "M-x checkdoc" errors.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1056
diff
changeset
|
6 |
;;; Code: |
1056
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
7 |
|
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
8 |
(defvar debian-doc-dir "/usr/share/doc-base") |
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
9 |
(defvar debian-doc-buffer-name "*debian-doc*") |
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
10 |
(defvar debian-doc-buffer nil) |
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
11 |
|
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
12 |
(defvar debian-doc-mode-map (make-sparse-keymap)) |
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
13 |
|
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
14 |
(defconst debian-doc-font-lock-keywords |
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
15 |
'(("^[^ ][^:\n]*: " . font-lock-function-name-face) |
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
16 |
("^\\(Index\\|Files\\): \\(/.*\\)" 2 font-lock-doc-face) |
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
17 |
("^Format: \\(.*\\)" 1 font-lock-type-face) |
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
18 |
("^Document: \\(.*\\)" 1 font-lock-keyword-face))) |
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
19 |
|
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
20 |
(defun debian-doc-mode () |
1057
899bedcbfa57
Add docs to fix "M-x checkdoc" errors.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1056
diff
changeset
|
21 |
"Debian-Doc mode for viewing doc-base information." |
1056
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
22 |
(kill-all-local-variables) |
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
23 |
(setq major-mode 'debian-doc-mode |
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
24 |
mode-name "Debian-Doc") |
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
25 |
(use-local-map debian-doc-mode-map) |
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
26 |
(setq font-lock-defaults '((debian-doc-font-lock-keywords) t nil nil nil))) |
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
27 |
|
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
28 |
(defvar debian-doc-completion-list nil) |
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
29 |
|
1060
53526ea61f74
Add autoloads to debian-doc.el.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1057
diff
changeset
|
30 |
;;;###autoload |
1056
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
31 |
(defun debian-doc (&optional prefix) |
1057
899bedcbfa57
Add docs to fix "M-x checkdoc" errors.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1056
diff
changeset
|
32 |
"Build Debian-Doc buffer. |
899bedcbfa57
Add docs to fix "M-x checkdoc" errors.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1056
diff
changeset
|
33 |
|
899bedcbfa57
Add docs to fix "M-x checkdoc" errors.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1056
diff
changeset
|
34 |
With PREFIX force to rebuild buffer from doc-base files." |
1056
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
35 |
(interactive "P") |
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
36 |
(when prefix |
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
37 |
(kill-buffer debian-doc-buffer)) |
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
38 |
(if (buffer-live-p debian-doc-buffer) |
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
39 |
(switch-to-buffer debian-doc-buffer) |
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
40 |
(setq debian-doc-completion-list nil) |
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
41 |
(setq debian-doc-buffer (get-buffer-create debian-doc-buffer-name)) |
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
42 |
(switch-to-buffer debian-doc-buffer) |
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
43 |
(let ( (coding-system-for-read 'utf-8) ) |
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
44 |
(mapc (lambda (file) |
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
45 |
(when (file-regular-p file) |
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
46 |
;; (with-temp-buffer |
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
47 |
;; (insert-file-contents file)) |
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
48 |
(insert "\n-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-\n\n") |
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
49 |
(insert-file-contents file) |
1242
3ac891ab0ad6
Fix: Warning: `end-of-buffer' is for interactive use only; use `(goto-char (point-max))' instead.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1060
diff
changeset
|
50 |
(goto-char (point-max)))) |
1056
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
51 |
(directory-files debian-doc-dir t))) |
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
52 |
(read-only-mode 1) |
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
53 |
(debian-doc-mode) |
1242
3ac891ab0ad6
Fix: Warning: `end-of-buffer' is for interactive use only; use `(goto-char (point-max))' instead.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1060
diff
changeset
|
54 |
(goto-char (point-min)))) |
1056
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
55 |
|
1060
53526ea61f74
Add autoloads to debian-doc.el.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1057
diff
changeset
|
56 |
;;;###autoload |
1056
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
57 |
(defun debian-doc-visit () |
1057
899bedcbfa57
Add docs to fix "M-x checkdoc" errors.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1056
diff
changeset
|
58 |
"Prompt for Debian package which represent docs and visit its entry in Debian-oc buffer." |
1056
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
59 |
(interactive) |
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
60 |
(let (word start) |
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
61 |
(debian-doc) |
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
62 |
(unless debian-doc-completion-list |
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
63 |
(save-excursion |
1242
3ac891ab0ad6
Fix: Warning: `end-of-buffer' is for interactive use only; use `(goto-char (point-max))' instead.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1060
diff
changeset
|
64 |
(goto-char (point-min)) |
1056
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
65 |
(while (setq start (search-forward "Document: " nil t)) |
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
66 |
(end-of-line) |
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
67 |
(push (buffer-substring-no-properties start (point)) debian-doc-completion-list)))) |
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
68 |
(when (setq word (completing-read "Package: " debian-doc-completion-list nil t)) |
1242
3ac891ab0ad6
Fix: Warning: `end-of-buffer' is for interactive use only; use `(goto-char (point-max))' instead.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1060
diff
changeset
|
69 |
(goto-char (point-min)) |
1056
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
70 |
(search-forward (concat "Document: " word) nil t) |
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
71 |
(recenter-top-bottom)))) |
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
72 |
(define-key debian-doc-mode-map (kbd "RET") 'debian-doc-visit-at-point) |
0ec83e102baa
Base implementation of Debian doc-base and Emacs integration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
73 |
|
1057
899bedcbfa57
Add docs to fix "M-x checkdoc" errors.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1056
diff
changeset
|
74 |
|
899bedcbfa57
Add docs to fix "M-x checkdoc" errors.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1056
diff
changeset
|
75 |
(provide 'debian-doc) |
899bedcbfa57
Add docs to fix "M-x checkdoc" errors.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1056
diff
changeset
|
76 |
|
899bedcbfa57
Add docs to fix "M-x checkdoc" errors.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1056
diff
changeset
|
77 |
;;; debian-doc.el ends here |