;;; java-help.el --- support for browsing java documentations
;; Copyright (C) Koji Nakamaru
;;
;; Author: Koji Nakamaru (nakamaru at gmail.com)
;; Modified: Apr 30 2005
;; * changed the contact information.
;; Modified: Jul 22 2001
;; Modified: Apr 30 2005
;; Created: Sep 10 1999
;; Keywords: hypertext, java
;; This file is part of java-help.
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;
;;; Commentary:
;; This package provides functions that read a java class name from
;; the Emacs minibuffer, defaulting to the name around point, and ask
;; a World-Wide Web browser to load its document. The package is
;; similar to jde-help-symbol of JDEE
;; (http://jdee.sunsite.dk/rootpage.html), but it was written when
;; JDEE had little support for browsing documents and has been
;; developed separately since then. Although jde-help-symbol is more
;; powerful, the package still has several good points:
;;
;; * Better symbol extraction - a package name is also extracted if
;; there is, for example.
;;
;; * A class name can be edited in the minibuffer before searching
;; from documents. It can be specified as a regular expression.
;;
;; * Yet another browsing function java-help-browse-url-w3m is
;; contained. It uses w3m
;; (http://w3m.sourceforge.net/index.en.html), a text-based
;; nifty browser written by Akinori Ito, for formatting java
;; documents. w3m is fast and can render tables. You can browse java
;; documents in Emacs very quickly.
;;
;; You can use this package with JDE, with java-mode defined in
;; cc-mode, or independently.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Usage
;;
;; Simply type the following and enter class name. The default class
;; name is the name around the current point.
;;
;; M-x java-help-open
;;
;; Note there might be the same class names in different packages. For
;; example, there are two Locale classes in JDK and Java3D
;; documents. You can designate the target class more specifically by
;; using (partial) package names that can also include regular
;; expressions:
;;
;; util.Locale -> JDK's Locale
;; javax.*Locale -> Java3D's Locale
;;
;; java-help-browse-url-w3m specific: if you set browser-function to
;; java-help-browse-url-w3m, you can show its last page by specifying
;; an empty class name.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Customization (.emacs)
;;
;; Add the following to invoke java-help-open by M-?, and change
;; java-help-open-dir-list appropriately.
;;
;; (global-set-key "\M-?" 'java-help-open)
;; (autoload 'java-help-open "java-help")
;; (setq java-help-open-dir-list '("/home/maru/doc/jdk/docs/api" "/home/maru/doc/j3d"))
;;
;; Add the following and set the exec-path to include paths for both
;; w3m, if you want to use java-help-browse-url-w3m for browsing
;; documents in emacs. The default is browse-url-browser-function.
;;
;; (setq java-help-browser-function 'java-help-browse-url-w3m)
;;
;; You can also use `M-x customize-group java-help' for customizing
;; these variables.
;;
;;; Code:
(require 'cl)
(require 'browse-url)
(require 'image-file)
;; java-help-open
(defgroup java-help nil
"Use a web browser to look at a URL."
:prefix "java-help-"
:group 'hypermedia)
(defcustom java-help-browser-function
browse-url-browser-function
"*browse-url-browser-function for browsing java documents."
:type '(choice
(function-item :tag "W3M" :value w3m)
(function-item :tag "W3M (java-help version)" :value java-help-browse-url-w3m)
(function-item :tag "Emacs W3" :value browse-url-w3)
(function-item :tag "W3 in another Emacs via `gnudoit'"
:value browse-url-w3-gnudoit)
(function-item :tag "Netscape" :value browse-url-netscape)
(function-item :tag "Mosaic" :value browse-url-mosaic)
(function-item :tag "Mosaic using CCI" :value browse-url-cci)
(function-item :tag "IXI Mosaic" :value browse-url-iximosaic)
(function-item :tag "Lynx in an xterm window"
:value browse-url-lynx-xterm)
(function-item :tag "Lynx in an Emacs window"
:value browse-url-lynx-emacs)
(function-item :tag "Grail" :value browse-url-grail)
(function-item :tag "MMM" :value browse-url-mmm)
(function-item :tag "Specified by `Browse Url Generic Program'"
:value browse-url-generic)
(function-item :tag "Default Windows browser"
:value browse-url-default-windows-browser)
(function :tag "Your own function"))
:group 'java-help)
(defcustom java-help-open-dir-list
nil
"*a list of root directories of java documents, containing allclasses-frame.html"
:type '(repeat (string :tag "Directory"))
:group 'java-help)
(defcustom java-help-browse-url-w3m-separator-regexp
"^\\( \\+[+-]+\\+\n *\n\\|-+\n\\)"
"*Regular expression of separators in w3m mode.
You can jump to a next/previous entry by
\\[java-help-browse-url-w3m-move-to-next-entry]/\\[java-help-browse-url-w3m-move-to-previous-entry] ."
:type 'string
:group 'java-help)
(defcustom java-help-browse-url-w3m-search-method-table-separators
"|"
"*Characters as vertical separators for tables, used by
\\[java-help-browse-url-w3m-search-method]"
:type 'string
:group 'java-help)
(defun java-help-open (name)
"Ask a WWW browser to load a java class document.
Prompts for a class name, defaulting to the name around point. Variable
`java-help-browser-function' says which browser to use."
(interactive (list (java-help-open-read-default)))
(let ((is-java-help t)
(browse-url-browser-function java-help-browser-function)
fname)
(if (equal name "")
(if (equal browse-url-browser-function 'java-help-browse-url-w3m)
(java-help-browse-url-w3m ""))
(progn
(save-window-excursion
(set-buffer
(or (get-buffer " *java-help-open-buffer*")
(get-buffer-create " *java-help-open-buffer*")))
(let ((tmp-list java-help-open-dir-list)
afname)
(while (not (null tmp-list))
(setq afname (car tmp-list))
(while (string-match "\\\\" afname)
(setq afname (replace-match "/" t nil afname)))
(if (not (string-match "/$" afname))
(setq afname (concat afname "/")))
(setq afname (file-truename (concat afname "allclasses-frame.html")))
; (save-window-excursion
; (set-buffer (get-buffer "*scratch*"))
; (insert afname))
(if (file-readable-p afname)
(progn
(insert-file-contents (concat (car tmp-list) "/allclasses-frame.html") nil nil nil t)
(if (or
(progn
(goto-char (point-min))
(re-search-forward (concat "/" name "\\.html") (point-max) t))
(progn
(goto-char (point-min))
(re-search-forward (concat "\"" name "\\.html") (point-max) t)))
(let ((dirpart
(if (string-match "^[A-Za-z]:" (car tmp-list)) "///" "")))
(beginning-of-line)
(re-search-forward "HREF=\"\\([^\"]*\\)\"")
(setq fname (concat "file:"
dirpart
(car tmp-list)
"/"
(buffer-substring (match-beginning 1) (match-end 1))))
(setq tmp-list nil)))))
(setq tmp-list (cdr tmp-list)))))
(if fname
(progn
;; (let ((buf (current-buffer)))
;; (set-buffer (get-buffer "*scratch*"))
;; (insert fname "\n")
;; (set-buffer buf))
(browse-url fname)
(message (concat "`" name "' is found")))
(message (concat "No `" name "' is found")))))))
(defun java-help-open-read-default ()
(interactive)
(let* ((java-help-util-re-search-non-word-regexp-backward
"[^A-Za-z0-9.]")
(java-help-util-re-search-word-regexp-forward
"[a-z0-9.]*[A-Z][A-Za-z0-9]*[a-z0-9][A-Z]*\\(\\.[A-Z][A-Za-z0-9]*[a-z0-9][A-Z]*\\)*")
(default
(java-help-util-re-search-get-word-at-point))
ret)
(if (null default) (setq default ""))
(set-text-properties 0 (length default) nil default)
(read-string "class name: " default)))
(defun java-help-browse-url-w3m-search-method ()
"Search the corresponding entry of the current method entry.
The corresponding entry depends on the current cursor position: the
entry is the one describing details if the position is in the table,
and vise versa."
(interactive)
(let* ((hsep java-help-browse-url-w3m-separator-regexp)
(vsep java-help-browse-url-w3m-search-method-table-separators)
(limit (or (save-excursion (re-search-forward hsep nil t)) (point-max))))
(cond ((save-excursion
(beginning-of-line)
(and (save-excursion (re-search-forward (concat "[" vsep "] *\\([A-Za-z0-9.]+\\)(\\([^()]*\\))") nil t))
(< (match-beginning 1) (line-end-position))))
(let ((name (buffer-substring-no-properties (match-beginning 1) (match-end 1)))
(end (match-end 2))
(regexp "")
(skip 0))
(save-excursion
(goto-char (match-beginning 2))
(while (< (point) end)
(let ((c (buffer-substring-no-properties (point) (1+ (point))))
(r nil))
(cond ((string-match (concat "[" vsep "]") c)
(setq skip (1+ skip))
(forward-char))
((not (= (% skip 3) 0))
(forward-char))
((string-match "[ \t\n]" c)
(setq regexp (concat regexp "[ \t\n]*"))
(skip-chars-forward "[ \t\n]"))
((string-match "[][]" c)
(setq regexp (concat regexp "\\" c))
(forward-char))
(t
(setq regexp (concat regexp c))
(forward-char))))))
(cond ((re-search-forward (concat "^ * *\n" name " *\n *\n" " *[^" vsep "].*" name "(" regexp ")") nil t)
(goto-char (match-beginning 0))
(recenter 1))
((re-search-forward (concat "^" name "(" regexp ")") nil t)
(goto-char (match-beginning 0))
(forward-line -1)
(recenter 1)))))
((save-excursion
(beginning-of-line)
(and (save-excursion (re-search-forward (concat "\\([A-Za-z0-9.]+\\)(\\([^()]*\\))") nil t))
(< (match-beginning 1) limit)))
(let ((name (buffer-substring-no-properties (match-beginning 1) (match-end 1)))
(end (match-end 2))
(regexp ""))
(save-excursion
(goto-char (match-beginning 2))
(while (< (point) end)
(let ((c (buffer-substring-no-properties (point) (1+ (point))))
(r nil))
(cond ((string-match "[ \t\n]" c)
(setq regexp (concat regexp "[][ \t\n" vsep "]*"))
(skip-chars-forward "[ \t\n]"))
((string-match "[][]" c)
(setq regexp (concat regexp "\\" c))
(forward-char))
(t
(setq regexp (concat regexp c))
(forward-char))))))
(cond ((re-search-backward (concat "[" vsep "] *" name "(" regexp ")") nil t)
(goto-char (match-beginning 0))
(beginning-of-line)
(recenter 1))))))))
(defun java-help-browse-url-w3m-move-to-next-entry ()
"Go to the next entry"
(interactive)
(cond ((re-search-forward java-help-browse-url-w3m-separator-regexp nil t)
(goto-char (match-end 0))
(beginning-of-line)
(recenter 1))))
(defun java-help-browse-url-w3m-move-to-previous-entry ()
"Go to the previous entry"
(interactive)
(let ((p (point)))
(cond ((re-search-backward java-help-browse-url-w3m-separator-regexp nil t)
(goto-char (match-end 0))
(beginning-of-line)
(cond ((and (= p (point)) (re-search-backward java-help-browse-url-w3m-separator-regexp nil t 2))
(goto-char (match-end 0))
(beginning-of-line)))
(recenter 1)))))
;; java-help-browse-url-w3m
(defcustom java-help-browse-url-w3m-history-max-length 10
"*History length of w3m mode."
:type 'number
:group 'java-help)
(defcustom java-help-browse-url-w3m-mode-hook nil
"*w3m mode hook, where you can change keymap by calling such as local-set-key/local-unset-key."
:type 'hook
:group 'java-help)
(defcustom java-help-browse-url-w3m-charset "Shift_JIS"
"*Character set for w3m output."
:type '(choice
(function-item :tag "Shift_JIS" :value "Shift_JIS")
(function-item :tag "EUC-JP" :value "EUC-JP")
(function-item :tag "JIS" :value "JIS"))
:group 'java-help)
(defvar java-help-browse-url-w3m-mode-map nil
"*Keymap for w3m mode.")
(if java-help-browse-url-w3m-mode-map
nil
(setq java-help-browse-url-w3m-mode-map (make-sparse-keymap))
(define-key java-help-browse-url-w3m-mode-map "q" 'java-help-browse-url-w3m-quit)
(define-key java-help-browse-url-w3m-mode-map "Q" 'java-help-browse-url-w3m-quit-and-kill)
(define-key java-help-browse-url-w3m-mode-map "u" 'java-help-browse-url-w3m-next-anchor)
(define-key java-help-browse-url-w3m-mode-map "\C-i" 'java-help-browse-url-w3m-next-anchor)
(define-key java-help-browse-url-w3m-mode-map "\C-m" 'java-help-browse-url-w3m-follow-anchor)
(define-key java-help-browse-url-w3m-mode-map " " 'java-help-browse-url-w3m-history-next)
(define-key java-help-browse-url-w3m-mode-map [delete] 'java-help-browse-url-w3m-history-previous)
(define-key java-help-browse-url-w3m-mode-map [backspace] 'java-help-browse-url-w3m-history-previous)
(define-key java-help-browse-url-w3m-mode-map "\177" 'java-help-browse-url-w3m-history-previous)
(define-key java-help-browse-url-w3m-mode-map "i" 'java-help-browse-url-w3m-scroll-up1)
(define-key java-help-browse-url-w3m-mode-map "o" 'java-help-browse-url-w3m-scroll-down1)
(define-key java-help-browse-url-w3m-mode-map "j" 'backward-char)
(define-key java-help-browse-url-w3m-mode-map "k" 'java-help-browse-url-w3m-next-line1)
(define-key java-help-browse-url-w3m-mode-map "l" 'java-help-browse-url-w3m-previous-line1)
(define-key java-help-browse-url-w3m-mode-map ";" 'forward-char)
(define-key java-help-browse-url-w3m-mode-map "m" 'recenter)
(define-key java-help-browse-url-w3m-mode-map "," 'scroll-up)
(define-key java-help-browse-url-w3m-mode-map "." 'scroll-down))
(defvar java-help-browse-url-w3m-history nil)
(defvar java-help-browse-url-w3m-history-position -1)
(defvar java-help-browse-url-w3m-line-correction-regexp
"^\\( *\\)\\(-+\\)")
(defface java-help-browse-url-w3m-anchor-face
'((((class color) (background light)) (:foreground "blue" :underline t))
(((class color) (background dark)) (:foreground "cyan" :underline t))
(t (:underline t)))
"*Face to fontify anchors."
:group 'w3m-face)
(defface java-help-browse-url-w3m-xanchor-face
'((((class color) (background light)) (:foreground "blue"))
(((class color) (background dark)) (:foreground "cyan"))
(t ()))
"*Face to fontify anchors."
:group 'w3m-face)
(defface java-help-browse-url-w3m-image-face
'((((class color) (background light)) (:foreground "ForestGreen"))
(((class color) (background dark)) (:foreground "PaleGreen"))
(t (:underline t)))
"*Face to fontify image alternate strings."
:group 'java-help-browse-url-w3m-face)
(defface java-help-browse-url-w3m-bold-face
'((((class color) (background light)) (:bold t))
(((class color) (background dark)) (:bold t))
(t (:bold t)))
"*Face to fontify bold strings."
:group 'w3m-face)
(make-variable-buffer-local 'buw-line)
(make-variable-buffer-local 'buw-line-last)
(make-variable-buffer-local 'buw-line-offset)
(make-variable-buffer-local 'buw-proc)
(make-variable-buffer-local 'buw-is-displayed)
(make-variable-buffer-local 'buw-is-java-help)
(make-variable-buffer-local 'buw-name)
(set-default 'buw-line nil)
(set-default 'buw-line-last nil)
(set-default 'buw-line-offset 0)
(set-default 'buw-proc nil)
(set-default 'buw-is-java-help nil)
(set-default 'buw-is-displayed nil)
(set-default 'buw-name nil)
(defun java-help-browse-url-w3m-mode ()
"\
Mode for browsing the output of w3m, mainly for java documents.
Keybindings:
\\{java-help-browse-url-w3m-mode-map}"
(interactive)
(kill-all-local-variables)
(setq buw-line "")
(setq buw-line-offset 0)
(setq buw-proc nil)
(set (make-local-hook 'kill-buffer-hook)
'(lambda ()
(java-help-browse-url-w3m-history-remove (current-buffer))
(if (and buw-proc (processp buw-proc))
(progn
(set-process-filter buw-proc nil)
(set-process-sentinel buw-proc nil)))))
(setq buw-is-displayed nil)
(setq buffer-read-only nil)
(setq truncate-lines t)
(erase-buffer)
(set-buffer-modified-p nil)
(buffer-disable-undo (current-buffer))
(setq major-mode 'java-help-browse-url-w3m-mode
mode-name "w3m"
buffer-read-only t
mode-line-buffer-identification '("%12b"))
(use-local-map java-help-browse-url-w3m-mode-map)
(run-hooks 'java-help-browse-url-w3m-mode-hook)
(java-help-browse-url-w3m-history-add (current-buffer)))
(defun java-help-browse-url-w3m (url &optional new-window)
;; new-window ignored
"Ask the w3m WWW browser to load URL.
Default to the URL around or before point. Run a new w3m process in
an Emacs buffer. Popup the current page if the URL is empty."
(interactive (browse-url-interactive-arg "w3m URL: "))
(let* ((buffname (buffer-name (current-buffer)))
(is-w3m-buf (string-match " \\*w3m " buffname))
(name nil)
buf)
(if (string-match "^[ \t]+" url) (setq url (replace-match "" t nil url)))
(if (string-match "[ \t]+$" url) (setq url (replace-match "" t nil url)))
(setq url (java-help-browse-url-w3m-resolve-url url buffname))
(if (string-match "\\(.*\\)#\\(.*\\)$" url)
(progn
(setq name (match-string 2 url))
(setq url (match-string 1 url))))
(setq buf
(if (equal url "")
(java-help-browse-url-w3m-history-current)
(get-buffer (format " *w3m %s*" url))))
(cond (buf
(if (not (equal url ""))
(java-help-browse-url-w3m-history-raise buf))
(if is-w3m-buf
(switch-to-buffer buf)
(display-buffer buf)))
((let ((case-fold-search t)) (string-match ".*\\.\\(gif\\|jpg\\|png\\)$" url))
(browse-url url))
((not (equal url ""))
(let ((buf (get-buffer-create (format " *w3m %s*" url)))
width)
(set-buffer buf)
(setq buw-line-last "")
(setq width (- (window-width) 4))
(if (< width 1)
(setq width 1))
(setq width (format "%d" width))
(java-help-browse-url-w3m-mode)
(setq buw-proc
(let ((process-connection-type nil))
(if (and (boundp 'is-java-help) is-java-help)
(progn
(setq buw-is-java-help t)
(setq buw-name name)
(local-set-key "/" 'java-help-browse-url-w3m-search-method)
(local-set-key "n" 'java-help-browse-url-w3m-move-to-next-entry)
(local-set-key "p" 'java-help-browse-url-w3m-move-to-previous-entry)
(java-help-browse-url-w3m-start-process buf width url))
(progn
(setq buw-is-java-help nil)
(setq buw-name name)
(java-help-browse-url-w3m-start-process buf width url)))))
(set-process-filter
buw-proc
'(lambda (proc str)
(let ((buf (process-buffer proc))
(buffname nil)
(is-w3m-buf (string-match " *w3m " (buffer-name (current-buffer)))))
(if buf
(save-excursion
(set-buffer buf)
(setq buffname (buffer-name buf))
(setq buffer-read-only nil)
(goto-char (point-max))
;; the following accumulate inputs into
;; buw-line and insert buw-line once the
;; accumulation is finished. buw-line is
;; embedded anchors' information before the
;; insertion.
(while (string-match "\n" str)
(setq buw-line (concat buw-line (substring str 0 (match-beginning 0))))
(setq str (substring str (match-end 0)))
(setq buw-line (java-help-browse-url-w3m-modify-line buw-line))
;; very adhoc solution to correct strange
;; rendering for an incorrect html file
(if (string-match
java-help-browse-url-w3m-line-correction-regexp
buw-line)
(setq buw-line-offset (length (match-string 1 buw-line))))
(if (= buw-line-offset 0)
(progn
(setq
buw-line
(concat buw-line "\n")))
(let ((offset buw-line-offset))
(if (or (get-text-property 0 'URL buw-line) (get-text-property 0 'NAME buw-line))
(setq offset 0))
(if (> offset 0)
(setq offset (min offset (or (next-property-change 0 buw-line) offset))))
(if (and (> offset 0) (string-match "[^ ]" buw-line) (< (match-beginning 0) offset))
(setq offset (min offset (match-beginning 0))))
(setq
buw-line
(concat (substring buw-line (min offset (length buw-line))) "\n"))))
;;
(if (not (and (equal buw-line-last "\n") (equal buw-line "\n")))
(insert buw-line))
(setq buw-line-last buw-line)
(setq buw-line ""))
(setq buw-line (concat buw-line str))
(goto-char (point-min))
(set-buffer-modified-p nil)
(setq buffer-read-only t)
(if (not buw-is-displayed)
(progn
(setq buw-is-displayed t)
(if is-w3m-buf
(switch-to-buffer buf))
(display-buffer buf))))))))
(set-process-sentinel
buw-proc
'(lambda (proc str)
(if (eq (process-status proc) 'exit)
(let ((buf (process-buffer proc)))
(if buf
(let ((buf0 (current-buffer)))
(if (not (string-match "^ \\*w3m" (buffer-name buf0)))
(progn
(pop-to-buffer buf t t)
(set-buffer-modified-p nil)
(setq buw-proc nil)
(if (and buw-is-java-help (equal (point) (point-min)))
(java-help-browse-url-w3m-move-to-next-entry))
(pop-to-buffer buf0 t t)))))))))
)))))
(defun java-help-browse-url-w3m-start-process (buf width url)
(start-process
"w3m" buf
"w3m"
"-halfdump"
"-O" java-help-browse-url-w3m-charset
"-o" "ext_halfdump=1"
"-o" "pre_conv=1"
"-o" "strict_iso2022=0"
"-S"
"-no-graph"
"-cols" width
url))
(defun java-help-browse-url-w3m-modify-line (buw-line)
(let ((case-fold-search t))
(while (string-match " *" buw-line)
(setq buw-line (replace-match "" t nil buw-line)))
(if (string-match "[ \t]*$" buw-line)
(setq buw-line (replace-match "" t nil buw-line)))
(while (string-match "[ \t]*hseq=\"[^\"]+\"[ \t]*" buw-line)
(setq buw-line (replace-match "" t nil buw-line)))
(while (string-match "\\([^<]*\\)" buw-line)
(let ((label (match-string 1 buw-line)))
(add-text-properties
0
(length label)
(list
'face 'java-help-browse-url-w3m-bold-face)
label)
(setq buw-line (replace-match label t nil buw-line))))
(while (string-match
"\\([^<]*\\)"
buw-line)
(let* ((url (match-string 1 buw-line))
(label (match-string 2 buw-line))
(props (list
'face 'java-help-browse-url-w3m-image-face
'URL url)))
(let ((image (java-help-browse-url-w3m-resolve-url url buffname)))
(if (or (string-match "^file:///\\(.*\\)" image)
(string-match "^file:\\(.*\\)" image))
(setq props (append props (list 'display (create-image (match-string 1 image)))))))
(add-text-properties 0 (length label) props label)
(string-match
"\\([^<]*\\)"
buw-line)
(setq buw-line (replace-match label t nil buw-line))))
(while (string-match
"\\([^<]*\\)"
buw-line)
(let* ((url (match-string 1 buw-line))
(label (match-string 2 buw-line))
(props (list
'face 'java-help-browse-url-w3m-image-face
'URL url)))
(add-text-properties 0 (length label) props label)
; (setq label (concat (java-help-browse-url-w3m-resolve-url url buffname) label))
(string-match
"\\([^<]*\\)"
buw-line)
(setq buw-line (replace-match label t nil buw-line))))
(while (string-match
"]*href=\"\\(http:\\|\\)\\([^\"]*\\)\"[^>]*>\\([^<]*\\)"
buw-line)
(let ((prefix (match-string 1 buw-line))
(url (match-string 2 buw-line))
(label (match-string 3 buw-line)))
(add-text-properties
0
(length label)
(list
'face (cond ((equal prefix "")
'java-help-browse-url-w3m-anchor-face)
(t
'java-help-browse-url-w3m-xanchor-face))
'URL (concat prefix url))
label)
(setq buw-line (replace-match label t nil buw-line))))
(while (string-match
"]*name=\"\\([^\"]*\\)\">"
buw-line)
(let ((b (match-beginning 0))
(name (match-string 1 buw-line)))
(setq buw-line (replace-match "" t nil buw-line))
(if (< (length buw-line) (+ b 1))
(setq buw-line (concat buw-line " ")))
(add-text-properties
b
(+ b 1)
(list
'NAME name)
buw-line)))
(while (string-match "<[^>]*>" buw-line)
(setq buw-line (replace-match "" t nil buw-line)))
(while (string-match "[\200-\377]" buw-line)
(setq buw-line (replace-match " " t nil buw-line)))
(while (string-match " " buw-line)
(setq buw-line (replace-match " " t nil buw-line)))
(while (string-match ">" buw-line)
(setq buw-line (replace-match ">" t nil buw-line)))
(while (string-match "<" buw-line)
(setq buw-line (replace-match "<" t nil buw-line)))
(while (string-match "&" buw-line)
(setq buw-line (replace-match "&" t nil buw-line)))
(while (string-match """ buw-line)
(setq buw-line (replace-match "\"" t nil buw-line)))
(while (string-match "'" buw-line)
(setq buw-line (replace-match "'" t nil buw-line)))
buw-line))
(defun java-help-browse-url-w3m-resolve-url (url buffname)
(if (not (or (equal url "") (string-match "^http:" url)))
(progn
(setq url
(cond ((string-match "^\\([^:]+\\):\\(.*\\)$" url)
(concat (match-string 1 url) ":" (file-truename (match-string 2 url))))
((string-match "^[^/]" url)
(cond ((and
buffname
(string-match " \\*w3m \\([^:]+\\):\\(.*\\)/[^/]*$" buffname))
(concat
(match-string 1 buffname)
":"
(file-truename (concat (match-string 2 buffname) "/" url))))
(t
(concat "file:" url))))
(t
(concat "file:" url))))
(if (string-match "^file:/*\\([^:]+:\\)" url)
(setq url (concat "file:///" (replace-match (match-string 1 url) t nil url))))))
url)
(defun java-help-browse-url-w3m-next-anchor ()
(interactive)
(let ((p0 (point)) (p (point)))
(cond ((catch 'found
(while (setq p (next-single-property-change p 'URL))
(if (get-text-property p 'URL)
(throw 'found t))))
(goto-char p))
((and
(setq p (point-min))
(catch 'found
(while (setq p (next-single-property-change p 'URL (current-buffer) p0))
(if (get-text-property p 'URL)
(throw 'found t)))))
(goto-char p)))))
(defun java-help-browse-url-w3m-follow-anchor ()
(interactive)
(let ((url (get-text-property (point) 'URL))
(is-java-help buw-is-java-help))
(cond (url
(cond ((string-match "^http:" url) (browse-url url))
(t (java-help-browse-url-w3m url))))
(is-java-help
(java-help-open (java-help-open-read-default))))))
(defun java-help-browse-url-w3m-quit ()
(interactive)
(let ((buf (current-buffer)))
(delete-windows-on buf)))
(defun java-help-browse-url-w3m-quit-and-kill ()
(interactive)
(let ((buf (current-buffer)))
(delete-windows-on buf)
(kill-buffer buf)))
(defun java-help-browse-url-w3m-scroll-up1 ()
(interactive)
(scroll-up 1)
(forward-line 1))
(defun java-help-browse-url-w3m-scroll-down1 ()
(interactive)
(scroll-down 1)
(forward-line -1))
(defun java-help-browse-url-w3m-next-line1 ()
(interactive)
(next-line 1))
(defun java-help-browse-url-w3m-previous-line1 ()
(interactive)
(previous-line 1))
(defun java-help-browse-url-w3m-history-next ()
(interactive)
(let ((p (1+ (position (current-buffer) java-help-browse-url-w3m-history))))
(if (>= p (length java-help-browse-url-w3m-history))
(setq p (1- p)))
(setq java-help-browse-url-w3m-history-position p)
(if (not (eq (nth p java-help-browse-url-w3m-history) (current-buffer)))
(switch-to-buffer (nth p java-help-browse-url-w3m-history)))))
(defun java-help-browse-url-w3m-history-previous ()
(interactive)
(let ((p (1- (position (current-buffer) java-help-browse-url-w3m-history))))
(if (< p 0)
(setq p 0))
(setq java-help-browse-url-w3m-history-position p)
(if (not (eq (nth p java-help-browse-url-w3m-history) (current-buffer)))
(switch-to-buffer (nth p java-help-browse-url-w3m-history)))))
(defun java-help-browse-url-w3m-history-current ()
(if (< java-help-browse-url-w3m-history-position 0)
nil
(nth java-help-browse-url-w3m-history-position java-help-browse-url-w3m-history)))
(defun java-help-browse-url-w3m-history-add (buf)
(mapcar
'kill-buffer
(last java-help-browse-url-w3m-history (- (length java-help-browse-url-w3m-history) (1+ java-help-browse-url-w3m-history-position))))
(setq java-help-browse-url-w3m-history (append java-help-browse-url-w3m-history (list buf)))
(if (> (length java-help-browse-url-w3m-history) java-help-browse-url-w3m-history-max-length)
(kill-buffer (car java-help-browse-url-w3m-history)))
(setq java-help-browse-url-w3m-history-position (or (position buf java-help-browse-url-w3m-history) -1)))
(defun java-help-browse-url-w3m-history-remove (buf)
(setq java-help-browse-url-w3m-history (remove buf java-help-browse-url-w3m-history))
(if (>= java-help-browse-url-w3m-history-position (length java-help-browse-url-w3m-history))
(setq java-help-browse-url-w3m-history-position (1- (length java-help-browse-url-w3m-history)))))
(defun java-help-browse-url-w3m-history-raise (buf)
(setq java-help-browse-url-w3m-history (append (remove buf java-help-browse-url-w3m-history) (list buf)))
(setq java-help-browse-url-w3m-history-position (or (position buf java-help-browse-url-w3m-history) -1)))
;; java-help-util-re-search
(defvar java-help-util-re-search-regexp nil)
(defvar java-help-util-re-search-non-word-regexp-backward "[^A-z0-9]")
(defvar java-help-util-re-search-word-regexp-forward "[A-z0-9]+")
(defvar java-help-util-re-search-force-wrap nil)
(defun java-help-util-re-search-forward ()
(interactive)
(re-search-forward (setq java-help-util-re-search-regexp (read-string "regexp: " (java-help-util-re-search-get-word-at-point)))))
(defun java-help-util-re-search-next ()
(interactive)
(if (and (not (null java-help-util-re-search-regexp))
(not (re-search-forward java-help-util-re-search-regexp nil t))
java-help-util-re-search-force-wrap)
(progn
(goto-char (point-min))
(re-search-forward java-help-util-re-search-regexp))))
(defun java-help-util-re-search-previous ()
(interactive)
(if (and (not (null java-help-util-re-search-regexp))
(not (re-search-backward java-help-util-re-search-regexp nil t))
java-help-util-re-search-force-wrap)
(progn
(goto-char (point-max))
(re-search-backward java-help-util-re-search-regexp))))
(defun java-help-util-re-search-get-word-at-point ()
(save-excursion
(if (and (= (point) (line-end-position)) (< (line-beginning-position) (line-end-position)))
(backward-char))
(cond ((or (= (point) (point-max)) (string-match "[ \n\t]" (buffer-substring-no-properties (point) (1+ (point)))))
nil)
(t
(let* ((case-fold-search nil)
(blimit
(save-excursion
(if (re-search-backward "[^A-Za-z0-9.]" (line-beginning-position) t)
(match-end 0) (line-beginning-position))))
(elimit
(save-excursion
(if (re-search-forward "[^A-Za-z0-9.]" (line-end-position) t)
(match-beginning 0) (line-end-position)))))
(if (and (goto-char elimit) (re-search-backward java-help-util-re-search-non-word-regexp-backward (1- blimit) t))
(if (and (goto-char blimit) (re-search-forward java-help-util-re-search-word-regexp-forward elimit t))
(buffer-substring-no-properties (match-beginning 0) (match-end 0)))))))))
;;; java-help.el ends here