Commit | Line | Data |
---|---|---|
597993cf MB |
1 | ;; erc-page.el - CTCP PAGE support for ERC |
2 | ||
114f9c96 | 3 | ;; Copyright (C) 2002, 2004, 2006, 2007, 2008, 2009, 2010 Free Software Foundation |
597993cf MB |
4 | |
5 | ;; This file is part of GNU Emacs. | |
6 | ||
4ee57b2a | 7 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
597993cf | 8 | ;; it under the terms of the GNU General Public License as published by |
4ee57b2a GM |
9 | ;; the Free Software Foundation, either version 3 of the License, or |
10 | ;; (at your option) any later version. | |
597993cf MB |
11 | |
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. | |
16 | ||
17 | ;; You should have received a copy of the GNU General Public License | |
4ee57b2a | 18 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
597993cf MB |
19 | |
20 | ;;; Commentary: | |
21 | ||
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 | |
25 | ;; `erc-page-mode'. | |
26 | ||
27 | ;;; Code: | |
28 | ||
29 | (require 'erc) | |
30 | ||
31 | ;;;###autoload (autoload 'erc-page-mode "erc-page") | |
32 | (define-erc-module page ctcp-page | |
33 | "Process CTCP PAGE requests from IRC." | |
34 | nil nil) | |
35 | ||
36 | (erc-define-catalog-entry 'english 'CTCP-PAGE "Page from %n (%u@%h): %m") | |
37 | ||
38 | (defgroup erc-page nil | |
39 | "React to CTCP PAGE messages." | |
40 | :group 'erc) | |
41 | ||
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. | |
47 | ||
48 | Example for your ~/.emacs file: | |
49 | ||
50 | \(setq erc-page-function | |
51 | (lambda (sender msg) | |
52 | (play-sound-file \"/home/alex/elisp/erc/sounds/ni.wav\") | |
53 | (message \"IRC Page from %s: %s\" sender msg)))" | |
54 | :group 'erc-page | |
55 | :type '(choice (const nil) | |
56 | (function))) | |
57 | ||
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." | |
64 | :group 'erc-page | |
65 | :type '(repeat function)) | |
66 | ||
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)) | |
76 | "[no message]")) | |
77 | text) | |
78 | (if m (setq m (substring m 1))) | |
79 | (setq text (erc-format-message 'CTCP-PAGE | |
80 | ?n nick ?u login | |
81 | ?h host ?m page-msg)) | |
82 | (if erc-page-function | |
83 | (funcall erc-page-function nick page-msg) | |
84 | ;; if no function is defined | |
85 | (message "%s" text) | |
86 | (beep)) | |
87 | ;; insert text into buffer | |
88 | (erc-display-message | |
89 | nil 'notice nil text))) | |
90 | nil) | |
91 | ||
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)))) | |
100 | ||
101 | (put 'erc-cmd-PAGE 'do-not-parse-args t) | |
102 | ||
103 | (provide 'erc-page) | |
104 | ||
597993cf | 105 | ;;; erc-page.el ends here |
5e56b3fb MO |
106 | ;; |
107 | ;; Local Variables: | |
108 | ;; indent-tabs-mode: t | |
109 | ;; tab-width: 8 | |
110 | ;; End: | |
111 | ||
112 | ;; arch-tag: 82fd2e0e-6060-4dd2-9788-8c1411e844de |