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
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)
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.
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/
37 (require 'w3m-perldoc
))
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
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))
62 (narrow-to-region (match-beginning 2) (match-end 2))
63 (while (search-backward "/" nil t
)
66 (goto-char (point-max))))
70 (defun sepia-w3m-view-pod (&optional buffer
)
72 (w3m-goto-url (concat "about://perldoc-buffer/"
73 (w3m-url-encode-string (buffer-name buffer
)))))
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
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
)))
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'."
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."
103 (goto-char (point-min))
104 (when (looking-at "Location: \\(about://perldoc/[^#]+\\)")
105 (let ((base (match-string 1))
109 (search-forward "<!-- INDEX BEGIN -->")
111 (search-forward "<!-- INDEX END -->")
114 (while (re-search-forward "<a href=\"\\(#[^\"]+\\)\">\\([^<]+\\)" end t
)
115 (push (cons (match-string 2) (match-string 1)) 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
))
130 ;;; sepia-w3m.el ends here.