Mercurial > emacs
comparison lisp/erc/erc-page.el @ 68451:fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Creator: Michael Olson <mwolson@gnu.org>
Install ERC.
author | Miles Bader <miles@gnu.org> |
---|---|
date | Sun, 29 Jan 2006 13:08:58 +0000 |
parents | |
children | 7010bb070445 |
comparison
equal
deleted
inserted
replaced
68450:a3ba4ef5d590 | 68451:fc745b05e928 |
---|---|
1 ;; erc-page.el - CTCP PAGE support for ERC | |
2 | |
3 ;; Copyright (C) 2002, 2004 Free Software Foundation | |
4 | |
5 ;; This file is part of GNU Emacs. | |
6 | |
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 2, or (at your option) | |
10 ;; any later version. | |
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 | |
18 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
19 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
20 ;; Boston, MA 02110-1301, USA. | |
21 | |
22 ;;; Commentary: | |
23 | |
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'. | |
28 | |
29 ;;; Code: | |
30 | |
31 (require 'erc) | |
32 | |
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) | |
37 | |
38 (erc-define-catalog-entry 'english 'CTCP-PAGE "Page from %n (%u@%h): %m") | |
39 | |
40 (defgroup erc-page nil | |
41 "React to CTCP PAGE messages." | |
42 :group 'erc) | |
43 | |
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. | |
49 | |
50 Example for your ~/.emacs file: | |
51 | |
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))) | |
59 | |
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)) | |
68 | |
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) | |
93 | |
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)))) | |
102 | |
103 (put 'erc-cmd-PAGE 'do-not-parse-args t) | |
104 | |
105 (provide 'erc-page) | |
106 | |
107 ;; arch-tag: 82fd2e0e-6060-4dd2-9788-8c1411e844de | |
108 ;;; erc-page.el ends here |