1 ;; erc-page.el - CTCP PAGE support for ERC
3 ;; Copyright (C) 2002, 2004, 2006, 2007, 2008, 2009, 2010 Free Software Foundation
5 ;; This file is part of GNU Emacs.
7 ;; GNU Emacs is free software: you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation, either version 3 of the License, or
10 ;; (at your option) any later version.
12 ;; GNU Emacs is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22 ;; Requiring this file will make ERC react to CTCP PAGE messages
23 ;; received, and it will provide a new /PAGE command to send such
24 ;; messages yourself. To enable it, customize the variable
31 ;;;###autoload (autoload 'erc-page-mode "erc-page")
32 (define-erc-module page ctcp-page
33 "Process CTCP PAGE requests from IRC."
36 (erc-define-catalog-entry 'english
'CTCP-PAGE
"Page from %n (%u@%h): %m")
38 (defgroup erc-page nil
39 "React to CTCP PAGE messages."
42 (defcustom erc-page-function nil
43 "A function to process a \"page\" request.
44 If nil, this prints the page message in the minibuffer and calls
45 `beep'. If non-nil, it must be a function that takes two arguments:
46 SENDER and MSG, both strings.
48 Example for your ~/.emacs file:
50 \(setq erc-page-function
52 (play-sound-file \"/home/alex/elisp/erc/sounds/ni.wav\")
53 (message \"IRC Page from %s: %s\" sender msg)))"
55 :type
'(choice (const nil
)
58 (defcustom erc-ctcp-query-PAGE-hook
'(erc-ctcp-query-PAGE)
59 "List of functions to be called when a CTCP PAGE is received.
60 This is called from `erc-process-ctcp-query'. The functions are called
61 with six arguments: PROC NICK LOGIN HOST TO MSG. Note that you can
62 also set `erc-page-function' to a function, which only gets two arguments,
63 SENDER and MSG, so that might be easier to use."
65 :type
'(repeat function
))
67 (defun erc-ctcp-query-PAGE (proc nick login host to msg
)
68 "Deal with an CTCP PAGE query, if `erc-page-mode' is non-nil.
69 This will call `erc-page-function', if defined, or it will just print
70 a message and `beep'. In addition to that, the page message is also
71 inserted into the server buffer."
72 (when (and erc-page-mode
73 (string-match "PAGE\\(\\s-+.*\\)?$" msg
))
74 (let* ((m (match-string 1 msg
))
75 (page-msg (if m
(erc-controls-interpret (substring m
1))
78 (if m
(setq m
(substring m
1)))
79 (setq text
(erc-format-message 'CTCP-PAGE
83 (funcall erc-page-function nick page-msg
)
84 ;; if no function is defined
87 ;; insert text into buffer
89 nil
'notice nil text
)))
92 (defun erc-cmd-PAGE (line &optional force
)
93 "Send a CTCP page to the user given as the first word in LINE.
94 The rest of LINE is the message to send. Note that you will only
95 receive pages if `erc-page-mode' is on."
96 (when (string-match "^\\s-*\\(\\S-+\\) ?\\(.*\\)" line
)
97 (let ((nick (match-string 1 line
))
98 (msg (match-string 2 line
)))
99 (erc-cmd-CTCP nick
"PAGE" msg
))))
101 (put 'erc-cmd-PAGE
'do-not-parse-args t
)
105 ;;; erc-page.el ends here
108 ;; indent-tabs-mode: t
112 ;; arch-tag: 82fd2e0e-6060-4dd2-9788-8c1411e844de