1 ;;; planner-erc.el --- ERC support for Planner, an organizer for Emacs
3 ;; Copyright (C) 2004, 2006 Free Software Foundation, Inc.
5 ;; Emacs Lisp Archive Entry
6 ;; Filename: planner-erc.el
7 ;; Keywords: hypermedia erc chat
8 ;; Author: Sacha Chua <sacha@free.net.ph>
9 ;; Description: Create tasks and notes based on IRC
10 ;; URL: http://www.plannerlove.com/
11 ;; Compatibility: Emacs20, Emacs21, XEmacs21
13 ;; This file is part of Planner. It is not part of GNU Emacs.
15 ;; Planner is free software; you can redistribute it and/or modify it
16 ;; under the terms of the GNU General Public License as published by
17 ;; the Free Software Foundation; either version 2, or (at your option)
20 ;; Planner is distributed in the hope that it will be useful, but
21 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 ;; General Public License for more details.
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with Planner; see the file COPYING. If not, write to the
27 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
28 ;; Boston, MA 02110-1301, USA.
32 ;; Place planner-erc.el in your load path and add this to your .emacs:
34 ;; (require 'planner-erc)
36 ;; IRC URLs may be of the following forms.
38 ;; irc://server/nick,isnick or
39 ;; irc://server/#channel or
42 ;; Annotations will be in the following forms.
44 ;; [[irc://server/nick,isnick][Chat with nick on server#channel]]
45 ;; [[irc://server/nick,isnick][Chat with nick on server]]
46 ;; [[irc://server/#channel][Chat on server#channel]]
47 ;; [[irc://server][Chat on server]]
56 (unless (boundp 'erc-server-announced-name
)
57 (message "ERC 5.1 or higher is required; please upgrade ERC"))
59 (defvar planner-irc-regexp
60 "\\`[ei]rc://\\([^:/\n]+\\)\\([^/\n]+\\)?\\(?:/\\([^,/\n]+\\)\\(.*\\)\\)?"
61 "Regexp used to match IRC URLs.")
64 (defun planner-erc-annotation-from-erc ()
65 "Return an annotation for the current line.
66 This function can be added to `planner-annotation-functions'."
67 (when (eq major-mode
'erc-mode
)
68 (if (erc-default-target)
69 (if (erc-channel-p (erc-default-target))
70 (if (and (get-text-property (point) 'erc-parsed
)
71 (elt (get-text-property (point) 'erc-parsed
) 1))
75 (elt (get-text-property (point) 'erc-parsed
) 1)))))
78 erc-server-announced-name
"/"
79 (substring nick
1) ",isnick")
80 (concat "Chat with " nick
" on "
81 erc-server-announced-name
(erc-default-target))
85 erc-server-announced-name
"/"
87 (concat "Chat on " erc-server-announced-name
91 (concat "irc://" erc-server-announced-name
"/"
93 (concat "Chat with " (erc-default-target) " on "
94 erc-server-announced-name
)
97 (concat "irc://" erc-server-announced-name
)
98 (concat "Chat on " erc-server-announced-name
)
102 (defun planner-erc-browse-url (url)
103 "If this is an IRC URL, jump to it."
104 (when (string-match planner-irc-regexp url
)
105 (let ((server (match-string 1 url
))
106 (port (match-string 2 url
))
107 (target (match-string 3 url
))
108 (flags (match-string 4 url
))
110 ;; find existing buffer
114 (let ((server-buffer (erc-server-buffer)))
117 (with-current-buffer server-buffer
118 erc-server-announced-name
)))))))
119 ;; switch to buffer or create new connection
121 (if (not (stringp target
))
122 ;; assume that the car is always the server buffer
123 (switch-to-buffer (car buffer-list
))
126 (dolist (buffer buffer-list
)
127 (when (string= target
(buffer-name buffer
))
128 (throw 'found buffer
))))
130 (erc-select :server server
:port port
)))
134 (planner-add-protocol "[ei]rc://" 'planner-erc-browse-url
'identity
)
136 (add-hook 'planner-annotation-functions
'planner-erc-annotation-from-erc
)
137 (custom-add-option 'planner-annotation-functions
138 'planner-erc-annotation-from-erc
)
140 (provide 'planner-erc
)
142 ;;; planner-erc.el ends here