1 ;;; liece-url.el --- URL browsing.
2 ;; Copyright (C) 1998-2000 Daiki Ueno
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
7 ;; Keywords: IRC, liece
9 ;; This file is part of Liece.
11 ;; This program is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; This program is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
33 (require 'liece-inlines)
36 (require 'liece-menu))
38 (defvar-maybe browse-url-browser-function nil)
40 (defgroup liece-url nil
41 "URL Browsing in IRC buffer."
44 (defcustom liece-url-regexp "\\b\\(s?https?\\|ftp\\|file\\|gopher\\|news\\|telnet\\|wais\\|mailto\\):\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?[-a-zA-Z0-9_=?#$@~`%&*+|\\/.,]*[-a-zA-Z0-9_=#$@~`%&*+|\\/]"
45 "Regular expression that matches URLs."
49 (defcustom liece-url-mail-regexp "\\bmailto:\\([-a-zA-Z0-9_=?#$@~`%&*+|\\/.,]*[-a-zA-Z0-9_=#$@~`%&*+|\\/]\\)"
50 "Regular expression that matches mailto:."
54 (defcustom liece-url-browser-name
55 (let (url-func url-prog len)
56 (if (featurep 'browse-url)
57 (and (setq url-func browse-url-browser-function)
58 (setq url-prog (symbol-name url-func))
60 (setq len (length url-prog))
61 (setq url-prog (substring url-prog 11 len)))
63 "Default URL Browser Name.
64 netscape Netscape 1.1b1
68 iximosaic IXI Mosaic ?
74 (defvar liece-url-add-hook nil)
76 (defmacro liece-url-prepare-browser-function ()
77 (if (featurep 'browse-url)
78 '(intern (concat "browse-url-" liece-url-browser-name))
79 '(intern (concat "liece-url-browser-" liece-url-browser-name))))
81 (defcustom liece-url-browser-function
82 (liece-url-prepare-browser-function)
83 "Default URL Browser."
87 (defcustom liece-url-alist nil
88 "Alist for URL completion."
92 (define-widget 'liece-url-link 'link
93 "A link to an www page."
94 :help-echo 'widget-url-link-help-echo
95 :action 'liece-url-link-action)
97 (defun liece-url-link-action (widget &optional event)
98 (let ((func (liece-url-prepare-browser-function)))
100 (setq liece-url-browser-function func)
101 (setq func liece-url-browser-function))
102 (funcall func (widget-value widget))))
104 (defun liece-url-add-buttons (start end)
107 (while (re-search-forward liece-url-regexp end t)
108 (let* ((url-start (match-beginning 0))
109 (url-end (match-end 0))
110 (url (buffer-substring url-start url-end)))
111 (if liece-highlight-mode
112 (liece-widget-convert-button 'url-link url-start url-end url))
113 (unless (assoc url liece-url-alist)
114 (push (list url) liece-url-alist)
115 (run-hook-with-args 'liece-url-add-hook url))))))
117 (defun liece-command-browse-url (&optional url)
120 (if (and current-prefix-arg (eq current-prefix-arg '-))
121 (setq url (caar liece-url-alist))
122 (setq url (liece-minibuffer-completing-default-read
123 (_ "Open URL:") liece-url-alist)))
125 (let ((func (liece-url-prepare-browser-function)))
127 (setq liece-url-browser-function func)
128 (setq func liece-url-browser-function))
131 (defun url-irc-liece (host port channel user password)
133 `(:host ,host :service ,port :password ,password))
134 (liece-startup-channel channel))
139 ;;; liece-url.el ends here