Shorten text and change Sepia::flow() to shorten ",help" output.
[sepia.git] / sepia-w3m.el
blob25bd6a3c7bb0443df2de7c9a778bac822bb84081
1 ;;; sepia-w3m.el --- The add-on program to view Perl documents.
3 ;; Copyright (C) 2001 TSUCHIYA Masatoshi <tsuchiya@namazu.org>
4 ;; Modified 2004-2008 by Sean O'Rourke to work with Sepia and operate
5 ;; on 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 (if (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 '("--index" "--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")
68 ;; something went wrong
69 (message "POD errors in %s" buf)
70 (display-buffer (current-buffer))))))
72 ;;;###autoload
73 (defun sepia-w3m-view-pod (&optional buffer)
74 (require 'w3m)
75 (w3m-goto-url (concat "about://perldoc-buffer/"
76 (w3m-url-encode-string (buffer-name buffer)))))
78 ;;;###autoload
79 (defun sepia-module-list ()
80 "List installed modules with links to their documentation.
82 This lists not just top-level packages appearing in packlist
83 files, but all documented modules on the system, organized by
84 package."
85 (interactive)
86 (let ((file "/tmp/modlist.html"))
87 (unless (file-exists-p file)
88 (sepia-eval (format "Sepia::html_module_list(\"%s\")" file)))
89 (w3m-find-file file)))
91 ;;;###autoload
92 (defun sepia-package-list ()
93 "List installed packages with links to their documentation.
95 This lists only top-level packages appearing in packlist files.
96 For modules within packages, see `sepia-module-list'."
97 (interactive)
98 (let ((file "/tmp/packlist.html"))
99 (unless (file-exists-p file)
100 (sepia-eval (format "Sepia::html_package_list(\"%s\")" file)))
101 (w3m-find-file file)))
103 (defun sepia-w3m-create-imenu ()
104 "Create imenu index from pod2html output."
105 (save-excursion
106 (goto-char (point-min))
107 (when (looking-at "Location: \\(about://perldoc/[^#]+\\)")
108 (let ((base (match-string 1))
109 beg end
110 list)
111 (w3m-view-source)
112 (search-forward "<!-- INDEX BEGIN -->")
113 (setq beg (point))
114 (search-forward "<!-- INDEX END -->")
115 (setq end (point))
116 (goto-char beg)
117 (while (re-search-forward "<a href=\"\\(#[^\"]+\\)\">\\([^<]+\\)" end t)
118 (push (cons (match-string 2) (match-string 1)) list))
119 (w3m-view-source)
120 (nreverse list)))))
122 (defun sepia-w3m-goto-function (name anchor)
123 (if (string-match "^about://perldoc/" w3m-current-url)
124 (w3m-goto-url (concat w3m-current-url anchor))
125 (imenu-default-goto-function name anchor)))
127 (defun sepia-w3m-install-imenu ()
128 (setq imenu-create-index-function 'sepia-w3m-create-imenu
129 imenu-default-goto-function 'sepia-w3m-goto-function))
131 (provide 'sepia-w3m)
133 ;;; sepia-w3m.el ends here.