Fix typos in ChangeLogs.
[emacs.git] / lisp / erc / erc-page.el
blobe667627cb019e076264f11e7864d74f8c5e15aca
1 ;; erc-page.el - CTCP PAGE support for ERC
3 ;; Copyright (C) 2002, 2004, 2006-2013 Free Software Foundation, Inc.
5 ;; Maintainer: FSF
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22 ;;; Commentary:
24 ;; Requiring this file will make ERC react to CTCP PAGE messages
25 ;; received, and it will provide a new /PAGE command to send such
26 ;; messages yourself. To enable it, customize the variable
27 ;; `erc-page-mode'.
29 ;;; Code:
31 (require 'erc)
33 ;;;###autoload (autoload 'erc-page-mode "erc-page")
34 (define-erc-module page ctcp-page
35 "Process CTCP PAGE requests from IRC."
36 nil nil)
38 (erc-define-catalog-entry 'english 'CTCP-PAGE "Page from %n (%u@%h): %m")
40 (defgroup erc-page nil
41 "React to CTCP PAGE messages."
42 :group 'erc)
44 (defcustom erc-page-function nil
45 "A function to process a \"page\" request.
46 If nil, this prints the page message in the minibuffer and calls
47 `beep'. If non-nil, it must be a function that takes two arguments:
48 SENDER and MSG, both strings.
50 Example for your init file:
52 \(setq erc-page-function
53 (lambda (sender msg)
54 (play-sound-file \"/home/alex/elisp/erc/sounds/ni.wav\")
55 (message \"IRC Page from %s: %s\" sender msg)))"
56 :group 'erc-page
57 :type '(choice (const nil)
58 (function)))
60 (defcustom erc-ctcp-query-PAGE-hook '(erc-ctcp-query-PAGE)
61 "List of functions to be called when a CTCP PAGE is received.
62 This is called from `erc-process-ctcp-query'. The functions are called
63 with six arguments: PROC NICK LOGIN HOST TO MSG. Note that you can
64 also set `erc-page-function' to a function, which only gets two arguments,
65 SENDER and MSG, so that might be easier to use."
66 :group 'erc-page
67 :type '(repeat function))
69 (defun erc-ctcp-query-PAGE (proc nick login host to msg)
70 "Deal with an CTCP PAGE query, if `erc-page-mode' is non-nil.
71 This will call `erc-page-function', if defined, or it will just print
72 a message and `beep'. In addition to that, the page message is also
73 inserted into the server buffer."
74 (when (and erc-page-mode
75 (string-match "PAGE\\(\\s-+.*\\)?$" msg))
76 (let* ((m (match-string 1 msg))
77 (page-msg (if m (erc-controls-interpret (substring m 1))
78 "[no message]"))
79 text)
80 (if m (setq m (substring m 1)))
81 (setq text (erc-format-message 'CTCP-PAGE
82 ?n nick ?u login
83 ?h host ?m page-msg))
84 (if erc-page-function
85 (funcall erc-page-function nick page-msg)
86 ;; if no function is defined
87 (message "%s" text)
88 (beep))
89 ;; insert text into buffer
90 (erc-display-message
91 nil 'notice nil text)))
92 nil)
94 (defun erc-cmd-PAGE (line &optional force)
95 "Send a CTCP page to the user given as the first word in LINE.
96 The rest of LINE is the message to send. Note that you will only
97 receive pages if `erc-page-mode' is on."
98 (when (string-match "^\\s-*\\(\\S-+\\) ?\\(.*\\)" line)
99 (let ((nick (match-string 1 line))
100 (msg (match-string 2 line)))
101 (erc-cmd-CTCP nick "PAGE" msg))))
103 (put 'erc-cmd-PAGE 'do-not-parse-args t)
105 (provide 'erc-page)
107 ;;; erc-page.el ends here
109 ;; Local Variables:
110 ;; indent-tabs-mode: t
111 ;; tab-width: 8
112 ;; End: