* Makefile.am (EXTRA_DIST): Add liece.xbm and liece.xpm.
[elisp/liece.git] / lisp / liece-url.el
1 ;;; liece-url.el --- URL browsing.
2 ;; Copyright (C) 1998-2000 Daiki Ueno
3
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
5 ;; Created: 1998-09-28
6 ;; Revised: 1998-11-25
7 ;; Keywords: IRC, liece
8
9 ;; This file is part of Liece.
10
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)
14 ;; any later version.
15
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.
20
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.
25
26
27 ;;; Commentary:
28 ;; 
29
30 ;;; Code:
31
32 (eval-when-compile
33   (require 'liece-inlines)
34   (require 'liece-intl)
35   (require 'liece-menu))
36
37 (defvar browse-url-browser-function)
38
39 (defgroup liece-url nil
40   "URL Browsing in IRC buffer."
41   :group 'liece-vars)
42
43 (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_=#$@~`%&*+|\\/]"
44   "Regular expression that matches URLs."
45   :group 'liece-url
46   :type 'regexp)
47
48 (defcustom liece-url-browser-function browse-url-browser-function
49   "Default URL Browser."
50   :group 'liece-url)
51
52 (defcustom liece-url-alist nil
53   "Alist for URL completion."
54   :type 'alist
55   :group 'liece-url)
56
57 (define-widget 'liece-url-link 'link
58   "A link to an www page."
59   :help-echo 'widget-url-link-help-echo
60   :action 'liece-url-link-action)
61
62 (defun liece-url-link-action (widget &optional event)
63   (let ((browse-url-browser-function liece-url-browser-function))
64     (browse-url (widget-value widget))))
65
66 (defvar liece-add-url-functions nil)
67
68 (defun liece-url-add-buttons (start end)
69   (save-excursion
70     (goto-char start)
71     (while (re-search-forward liece-url-regexp end t)
72       (let ((url (match-string 0)))
73         (if liece-highlight-mode
74             (liece-widget-convert-button
75              'url-link (match-beginning 0)(match-end 0) url))
76         (unless (assoc url liece-url-alist)
77           (push (list url) liece-url-alist)
78           (run-hook-with-args 'liece-add-url-functions url))))))
79
80 (defun liece-command-browse-url (&optional url)
81   (interactive
82    (let (url)
83      (if (and current-prefix-arg (eq current-prefix-arg '-))
84          (setq url (caar liece-url-alist))
85        (setq url (completing-read (_ "Open URL:") liece-url-alist)))
86      (list url)))
87   (let ((browse-url-browser-function liece-url-browser-function))
88     (browse-url url)))
89
90 (defun url-irc-liece (host port channel user password)
91   (let ((liece-server
92          `(:host ,host :service ,port :password ,password))
93         (liece-startup-channel channel))
94     (liece)))
95
96 (provide 'liece-url)
97
98 ;;; liece-url.el ends here