comparison
[sepia.git] / sepia-w3m.el
blob6f1e6edfa047760a0f1b66e878f7a18e724d1b39
1 ;;; sepia-w3m.el --- The add-on program to view Perl documents.
3 ;; Copyright (C) 2001 TSUCHIYA Masatoshi <tsuchiya@namazu.org>
4 ;; Modified 2004 by Sean O'Rourke to work with Sepia and operate on
5 ;; buffer.
7 ;; Author: TSUCHIYA Masatoshi <tsuchiya@namazu.org>
8 ;; Keywords: w3m, perldoc
10 ;; This file is a part of emacs-w3m.
12 ;; This program is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
17 ;; This program is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with this program; if not, you can either send email to this
24 ;; program's maintainer or write to: The Free Software Foundation,
25 ;; Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA.
28 ;;; Commentary:
30 ;; w3m-perldoc.el is the add-on program of emacs-w3m to view Perl
31 ;; documents. For more detail about emacs-w3m, see:
33 ;; http://emacs-w3m.namazu.org/
35 ;;; Code:
36 (eval-when-compile
37 (require 'w3m-perldoc))
39 ;;;###autoload
40 (defun w3m-about-perldoc-buffer (url &optional no-decode no-cache &rest args)
41 "Handle about://perldoc-buffer/ links."
42 (when (string-match "\\`about://perldoc-buffer/" url)
43 (let ((buf (get-buffer (w3m-url-decode-string
44 (substring url (match-end 0)))))
45 (default-directory w3m-profile-directory)
46 (process-environment (copy-sequence process-environment)))
47 ;; To specify the place in which pod2html generates its cache files.
48 (setenv "HOME" (expand-file-name w3m-profile-directory))
49 (insert-buffer-substring buf)
50 (when (zerop (apply #'call-process-region
51 (point-min) (point-max)
52 w3m-perldoc-pod2html-command
53 t '(t nil) nil
54 (append w3m-perldoc-pod2html-arguments
55 '("--htmlroot=about://perldoc-buffer"))))
56 (let ((case-fold-search t))
57 (goto-char (point-min))
58 (while (re-search-forward
59 "<a href=\"about://perldoc\\(-buffer\\)?/\\([^\"]*\\)\\(\\.html\\)\">" nil t)
60 (delete-region (match-beginning 3) (match-end 3))
61 (save-restriction
62 (narrow-to-region (match-beginning 2) (match-end 2))
63 (while (search-backward "/" nil t)
64 (delete-char 1)
65 (insert "::"))
66 (goto-char (point-max))))
67 "text/html")))))
69 ;;;###autoload
70 (defun sepia-w3m-view-pod (&optional buffer)
71 (require 'w3m)
72 (w3m-goto-url (concat "about://perldoc-buffer/"
73 (w3m-url-encode-string (buffer-name buffer)))))
75 ;;;###autoload
76 (defun sepia-module-list ()
77 "List installed modules with links to their documentation.
79 This lists not just top-level packages appearing in packlist
80 files, but all documented modules on the system, organized by
81 package."
82 (interactive)
83 (let ((file "/tmp/modlist.html"))
84 (unless (file-exists-p file)
85 (sepia-eval (format "Sepia::html_module_list(\"%s\")" file)))
86 (w3m-find-file file)))
88 ;;;###autoload
89 (defun sepia-package-list ()
90 "List installed packages with links to their documentation.
92 This lists only top-level packages appearing in packlist files.
93 For modules within packages, see `sepia-module-list'."
94 (interactive)
95 (let ((file "/tmp/packlist.html"))
96 (unless (file-exists-p file)
97 (sepia-eval (format "Sepia::html_package_list(\"%s\")" file)))
98 (w3m-find-file file)))
100 (defun sepia-w3m-create-imenu ()
101 "Create imenu index from pod2html output."
102 (save-excursion
103 (goto-char (point-min))
104 (when (looking-at "Location: \\(about://perldoc/[^#]+\\)")
105 (let ((base (match-string 1))
106 beg end
107 list)
108 (w3m-view-source)
109 (search-forward "<!-- INDEX BEGIN -->")
110 (setq beg (point))
111 (search-forward "<!-- INDEX END -->")
112 (setq end (point))
113 (goto-char beg)
114 (while (re-search-forward "<a href=\"\\(#[^\"]+\\)\">\\([^<]+\\)" end t)
115 (push (cons (match-string 2) (match-string 1)) list))
116 (w3m-view-source)
117 (nreverse list)))))
119 (defun sepia-w3m-goto-function (name anchor)
120 (if (string-match "^about://perldoc/" w3m-current-url)
121 (w3m-goto-url (concat w3m-current-url anchor))
122 (imenu-default-goto-function name anchor)))
124 (defun sepia-w3m-install-imenu ()
125 (setq imenu-create-index-function 'sepia-w3m-create-imenu
126 imenu-default-goto-function 'sepia-w3m-goto-function))
128 (provide 'sepia-w3m)
130 ;;; sepia-w3m.el ends here.