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