* riece-keyword.el (riece-notify-keyword-functions): Mark as obsolete.
[riece] / lisp / riece-url.el
1 ;;; riece-url.el --- URL collector add-on
2 ;; Copyright (C) 1998-2003 Daiki Ueno
3
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
5 ;; Created: 1998-09-28
6 ;; Keywords: IRC, riece
7
8 ;; This file is part of Riece.
9
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;; To use, add the following line to your ~/.riece/init.el:
28 ;; (add-to-list 'riece-addons 'riece-url)
29
30 ;;; Code:
31
32 (require 'riece-options)
33 (require 'riece-menu)                   ;riece-menu-items
34
35 (autoload 'browse-url "browse-url")
36 (defvar browse-url-browser-function)
37
38 (defgroup riece-url nil
39   "URL Browsing in IRC buffer."
40   :group 'riece-vars)
41
42 (defcustom riece-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_=#$@~`%&*+|\\/]"
43   "Regular expression that matches URLs."
44   :group 'riece-url
45   :type 'regexp)
46
47 (defvar riece-urls nil
48   "A list of URL which appears in Riece buffers.")
49
50 (autoload 'widget-convert-button "wid-edit")
51
52 (defun riece-url-scan-region (start end)
53   (save-excursion
54     (goto-char start)
55     (while (re-search-forward riece-url-regexp end t)
56       (let ((url (match-string 0)))
57         (if (memq 'riece-highlight riece-addons)
58             (widget-convert-button
59              'url-link (match-beginning 0) (match-end 0) url))
60         (unless (member url riece-urls)
61           (setq riece-urls (cons url riece-urls)))))))
62
63 (defun riece-command-browse-url (&optional url)
64   (interactive
65    (list (completing-read "Open URL: " (mapcar #'list riece-urls))))
66   (browse-url url))
67
68 (defun riece-url-create-menu (menu)
69   (mapcar (lambda (url)
70             (vector url (list 'browse-url url)))
71           riece-urls))
72             
73 (defvar riece-dialogue-mode-map)
74
75 (defun riece-url-requires ()
76   (append (if (memq 'riece-highlight riece-addons)
77               '(riece-highlight))
78           (if (memq 'riece-menu riece-addons)
79               '(riece-menu))))
80
81 (defun riece-url-insinuate ()
82   (add-hook 'riece-after-insert-functions 'riece-url-scan-region)
83   (define-key riece-dialogue-mode-map "U" 'riece-command-browse-url)
84   (if (memq 'riece-menu riece-addons)
85       (add-hook 'riece-command-mode-hook
86                 (lambda ()
87                   (easy-menu-add-item
88                    nil (list (car riece-menu-items))
89                    '("Open URL..." :filter riece-url-create-menu)))
90                 t)))
91
92 (provide 'riece-url)
93
94 ;;; riece-url.el ends here