Commit | Line | Data |
---|---|---|
8c8b8430 | 1 | ;;; url-irc.el --- IRC URL interface |
00eef4de | 2 | |
71ddfde5 | 3 | ;; Copyright (C) 1996, 1997, 1998, 1999, 2004, |
12dc447f | 4 | ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
00eef4de | 5 | |
8c8b8430 SM |
6 | ;; Keywords: comm, data, processes |
7 | ||
00eef4de LH |
8 | ;; This file is part of GNU Emacs. |
9 | ||
10 | ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 | ;; it under the terms of the GNU General Public License as published by | |
8c0ee52a | 12 | ;; the Free Software Foundation; either version 3, or (at your option) |
00eef4de LH |
13 | ;; any later version. |
14 | ||
15 | ;; GNU Emacs 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 | |
4fc5845f LK |
22 | ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
23 | ;; Boston, MA 02110-1301, USA. | |
00eef4de LH |
24 | |
25 | ;;; Commentary: | |
26 | ||
27 | ;; IRC URLs are defined in http://www.w3.org/Addressing/draft-mirashi-url-irc-01.txt | |
8c8b8430 | 28 | |
00eef4de | 29 | ;;; Code: |
8c8b8430 SM |
30 | |
31 | (require 'url-vars) | |
32 | (require 'url-parse) | |
33 | ||
34 | (defconst url-irc-default-port 6667 "Default port for IRC connections") | |
35 | ||
7608c40c | 36 | (defcustom url-irc-function 'url-irc-rcirc |
8c8b8430 | 37 | "*Function to actually open an IRC connection. |
7608c40c | 38 | Should be a function that takes several arguments: |
8c8b8430 SM |
39 | HOST - the hostname of the IRC server to contact |
40 | PORT - the port number of the IRC server to contact | |
41 | CHANNEL - What channel on the server to visit right away (can be nil) | |
42 | USER - What username to use | |
43 | PASSWORD - What password to use" | |
7608c40c RF |
44 | :type '(choice (const :tag "rcirc" :value url-irc-rcirc) |
45 | (const :tag "ERC" :value url-irc-erc) | |
46 | (const :tag "ZEN IRC" :value url-irc-zenirc) | |
8c8b8430 SM |
47 | (function :tag "Other")) |
48 | :group 'url) | |
49 | ||
0bd90741 GM |
50 | ;; External. |
51 | (declare-function zenirc "ext:zenirc" (&optional prefix)) | |
52 | (declare-function zenirc-send-line "ext:zenirc" ()) | |
53 | ||
8c8b8430 SM |
54 | (defun url-irc-zenirc (host port channel user password) |
55 | (let ((zenirc-buffer-name (if (and user host port) | |
56 | (format "%s@%s:%d" user host port) | |
57 | (format "%s:%d" host port))) | |
58 | (zenirc-server-alist | |
59 | (list | |
60 | (list host port password nil user)))) | |
61 | (zenirc) | |
62 | (goto-char (point-max)) | |
63 | (if (not channel) | |
64 | nil | |
65 | (insert "/join " channel) | |
66 | (zenirc-send-line)))) | |
67 | ||
7608c40c RF |
68 | (defun url-irc-rcirc (host port channel user password) |
69 | (let ((chan (when channel (concat "#" channel)))) | |
70 | (rcirc-connect host port user nil nil (when chan (list chan))) | |
71 | (when chan | |
72 | (switch-to-buffer (concat chan "@" host))))) | |
73 | ||
74 | (defun url-irc-erc (host port channel user password) | |
0b6bb130 | 75 | (erc-handle-irc-url host port channel user password)) |
7608c40c | 76 | |
8c8b8430 SM |
77 | ;;;###autoload |
78 | (defun url-irc (url) | |
79 | (let* ((host (url-host url)) | |
60b5eb78 | 80 | (port (url-port url)) |
8c8b8430 SM |
81 | (pass (url-password url)) |
82 | (user (url-user url)) | |
83 | (chan (url-filename url))) | |
84 | (if (url-target url) | |
85 | (setq chan (concat chan "#" (url-target url)))) | |
86 | (if (string-match "^/" chan) | |
87 | (setq chan (substring chan 1 nil))) | |
88 | (if (= (length chan) 0) | |
89 | (setq chan nil)) | |
90 | (funcall url-irc-function host port chan user pass) | |
91 | nil)) | |
7608c40c | 92 | |
8c8b8430 | 93 | (provide 'url-irc) |
e5566bd5 | 94 | |
cbee283d | 95 | ;; arch-tag: 2e5eecf8-9eb3-436b-9fbd-c26f2fb2bf3e |
00eef4de | 96 | ;;; url-irc.el ends here |