annotate lisp/erc/erc-autoaway.el @ 76446:622e7c78002b

* faces.el (face-set-after-frame-default): Recalculate face customizations after applying X resources.
author Chong Yidong <cyd@stupidchicken.com>
date Sat, 10 Mar 2007 22:28:41 +0000
parents 7a3f13e2dd57
children 2fae574a2382
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
1 ;;; erc-autoaway.el --- Provides autoaway for ERC
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
2
75346
7a3f13e2dd57 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 74093
diff changeset
3 ;; Copyright (C) 2002, 2003, 2004, 2006, 2007 Free Software Foundation, Inc.
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
4
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
5 ;; Author: Jorgen Schaefer <forcer@forcix.cx>
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
6 ;; URL: http://www.emacswiki.org/cgi-bin/wiki.pl?ErcAutoAway
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
7
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
9
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
13 ;; any later version.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
14
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
18 ;; GNU General Public License for more details.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
19
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
23 ;; Boston, MA 02110-1301, USA.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
24
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
25 ;;; Commentary:
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
26
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
27 ;; TODO:
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
28 ;; - Legacy names: erc-auto-discard-away, erc-auto-set-away
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
29
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
30 ;;; Code:
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
31
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
32 (require 'erc)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
33
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
34 (defgroup erc-autoaway nil
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
35 "Set yourself automatically away after some idletime and set
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
36 yourself back when you type something."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
37 :group 'erc)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
38
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
39 (defvar erc-autoaway-idletimer nil
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
40 "The Emacs idletimer.
74093
bc5d69739d5e Merge from erc--emacs--22
Miles Bader <miles@gnu.org>
parents: 73725
diff changeset
41 This is only used when `erc-autoaway-idle-method' is set to 'emacs.")
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
42
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
43 ;;;###autoload (autoload 'erc-autoaway-mode "erc-autoaway")
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
44 (define-erc-module autoaway nil
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
45 "In ERC autoaway mode, you can be set away automatically.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
46 If `erc-auto-set-away' is set, then you will be set away after
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
47 the number of seconds specified in `erc-autoaway-idle-seconds'.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
48
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
49 There are several kinds of being idle:
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
50
71883
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
51 User idle time measures how long you have not been sending any
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
52 commands to Emacs. This is the default.
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
53
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
54 Emacs idle time measures how long Emacs has been idle. This is
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
55 currently not useful, since Emacs is non-idle when it handles
71883
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
56 ping-pong with IRC servers. See `erc-autoaway-idle-method'
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
57 for more information.
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
58
71883
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
59 IRC idle time measures how long since you last sent something (see
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
60 `erc-autoaway-last-sent-time').
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
61
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
62 If `erc-auto-discard-away' is set, then typing anything, will
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
63 set you no longer away.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
64
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
65 Related variables: `erc-public-away-p' and `erc-away-nickname'."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
66 ;; Enable:
71883
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
67 ((when (boundp 'erc-autoaway-idle-method)
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
68 (cond
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
69 ((eq erc-autoaway-idle-method 'irc)
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
70 (add-hook 'erc-send-completed-hook 'erc-autoaway-reset-idle-irc)
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
71 (add-hook 'erc-server-001-functions 'erc-autoaway-reset-idle-irc))
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
72 ((eq erc-autoaway-idle-method 'user)
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
73 (add-hook 'post-command-hook 'erc-autoaway-reset-idle-user))
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
74 ((eq erc-autoaway-idle-method 'emacs)
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
75 (erc-autoaway-reestablish-idletimer)))
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
76 (add-hook 'erc-timer-hook 'erc-autoaway-possibly-set-away)
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
77 (add-hook 'erc-server-305-functions 'erc-autoaway-reset-indicators)))
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
78 ;; Disable:
71883
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
79 ((when (boundp 'erc-autoaway-idle-method)
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
80 (cond
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
81 ((eq erc-autoaway-idle-method 'irc)
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
82 (remove-hook 'erc-send-completed-hook 'erc-autoaway-reset-idle-irc)
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
83 (remove-hook 'erc-server-001-functions 'erc-autoaway-reset-idle-irc))
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
84 ((eq erc-autoaway-idle-method 'user)
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
85 (remove-hook 'post-command-hook 'erc-autoaway-reset-idle-user))
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
86 ((eq erc-autoaway-idle-method 'emacs)
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
87 (erc-cancel-timer erc-autoaway-idletimer)
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
88 (setq erc-autoaway-idletimer nil)))
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
89 (remove-hook 'erc-timer-hook 'erc-autoaway-possibly-set-away)
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
90 (remove-hook 'erc-server-305-functions 'erc-autoaway-reset-indicators))))
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
91
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
92 (defcustom erc-autoaway-idle-method 'user
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
93 "*The method used to determine how long you have been idle.
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
94 If 'user, the time of the last command sent to Emacs is used.
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
95 If 'emacs, the idle time in Emacs is used.
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
96 If 'irc, the time of the last IRC command is used.
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
97
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
98 The time itself is specified by `erc-autoaway-idle-seconds'.
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
99
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
100 See `erc-autoaway-mode' for more information on the various
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
101 definitions of being idle."
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
102 :group 'erc-autoaway
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
103 :type '(choice (const :tag "User idle time" user)
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
104 (const :tag "Emacs idle time" emacs)
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
105 (const :tag "Last IRC action" irc))
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
106 :set (lambda (sym val)
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
107 (erc-autoaway-disable)
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
108 (set-default sym val)
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
109 (erc-autoaway-enable)))
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
110
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
111 (defcustom erc-auto-set-away t
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
112 "*If non-nil, set away after `erc-autoaway-idle-seconds' seconds of idling.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
113 ERC autoaway mode can set you away when you idle, and set you no
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
114 longer away when you type something. This variable controls whether
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
115 you will be set away when you idle. See `erc-auto-discard-away' for
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
116 the other half."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
117 :group 'erc-autoaway
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
118 :type 'boolean)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
119
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
120 (defcustom erc-auto-discard-away t
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
121 "*If non-nil, sending anything when away automatically discards away state.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
122 ERC autoaway mode can set you away when you idle, and set you no
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
123 longer away when you type something. This variable controls whether
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
124 you will be set no longer away when you type something. See
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
125 `erc-auto-set-away' for the other half.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
126 See also `erc-autoaway-no-auto-discard-regexp'."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
127 :group 'erc-autoaway
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
128 :type 'boolean)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
129
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
130 (defcustom erc-autoaway-no-auto-discard-regexp "^/g?away.*$"
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
131 "*Input that matches this will not automatically discard away status.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
132 See `erc-auto-discard-away'."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
133 :group 'erc-autoaway
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
134 :type 'regexp)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
135
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
136 (eval-when-compile (defvar erc-autoaway-idle-seconds))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
137
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
138 (defun erc-autoaway-reestablish-idletimer ()
73725
ee3d80fd6bb9 (erc-autoaway-reestablish-idletimer): Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 71883
diff changeset
139 "Reestablish the Emacs idletimer.
71883
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
140 If `erc-autoaway-idle-method' is 'emacs, you must call this
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
141 function each time you change `erc-autoaway-idle-seconds'."
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
142 (interactive)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
143 (when erc-autoaway-idletimer
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
144 (erc-cancel-timer erc-autoaway-idletimer))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
145 (setq erc-autoaway-idletimer
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
146 (run-with-idle-timer erc-autoaway-idle-seconds
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
147 t
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
148 'erc-autoaway-set-away
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
149 erc-autoaway-idle-seconds)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
150
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
151 (defcustom erc-autoaway-idle-seconds 1800
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
152 "*Number of seconds after which ERC will set you automatically away.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
153 If you are changing this variable using lisp instead of customizing it,
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
154 you have to run `erc-autoaway-reestablish-idletimer' afterwards."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
155 :group 'erc-autoaway
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
156 :set (lambda (sym val)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
157 (set-default sym val)
71883
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
158 (when (eq erc-autoaway-idle-method 'emacs)
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
159 (erc-autoaway-reestablish-idletimer)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
160 :type 'number)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
161
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
162 (defcustom erc-autoaway-message
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
163 "I'm gone (autoaway after %i seconds of idletime)"
71883
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
164 "*Message ERC will use when setting you automatically away.
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
165 It is used as a `format' string with the argument of the idletime
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
166 in seconds."
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
167 :group 'erc-autoaway
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
168 :type 'string)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
169
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
170 (defvar erc-autoaway-last-sent-time (erc-current-time)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
171 "The last time the user sent something.")
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
172
71883
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
173 (defvar erc-autoaway-caused-away nil
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
174 "Indicates whether this module was responsible for setting the
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
175 user's away status.")
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
176
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
177 (defun erc-autoaway-reset-idle-user (&rest stuff)
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
178 "Reset the stored user idle time.
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
179 This is one global variable since a user talking on one net can
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
180 talk on another net too."
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
181 (when erc-auto-discard-away
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
182 (erc-autoaway-set-back))
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
183 (setq erc-autoaway-last-sent-time (erc-current-time)))
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
184
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
185 (defun erc-autoaway-reset-idle-irc (line &rest stuff)
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
186 "Reset the stored IRC idle time.
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
187 This is one global variable since a user talking on one net can
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
188 talk on another net too."
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
189 (when (and erc-auto-discard-away
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
190 (stringp line)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
191 (not (string-match erc-autoaway-no-auto-discard-regexp line)))
71883
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
192 (erc-autoaway-set-back))
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
193 (setq erc-autoaway-last-sent-time (erc-current-time)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
194
71883
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
195 (defun erc-autoaway-set-back ()
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
196 "Discard the away state globally."
71883
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
197 (let ((server-buffer (car (erc-buffer-list #'erc-server-buffer-p))))
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
198 (when (and erc-autoaway-caused-away
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
199 (with-current-buffer server-buffer (erc-away-p)))
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
200 (erc-cmd-GAWAY ""))))
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
201
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
202 (defun erc-autoaway-possibly-set-away (current-time)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
203 "Set autoaway when `erc-auto-set-away' is true and the idletime is
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
204 exceeds `erc-autoaway-idle-seconds'."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
205 ;; A test for (erc-server-process-alive) is not necessary, because
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
206 ;; this function is called from `erc-timer-hook', which is called
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
207 ;; whenever the server sends something to the client.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
208 (when (and erc-auto-set-away
74093
bc5d69739d5e Merge from erc--emacs--22
Miles Bader <miles@gnu.org>
parents: 73725
diff changeset
209 (not erc-autoaway-caused-away)
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
210 (not (erc-away-p)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
211 (let ((idle-time (erc-time-diff erc-autoaway-last-sent-time
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
212 current-time)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
213 (when (>= idle-time erc-autoaway-idle-seconds)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
214 (erc-display-message
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
215 nil 'notice nil
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
216 (format "Setting automatically away after %i seconds of idle-time"
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
217 idle-time))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
218 (erc-autoaway-set-away idle-time)))))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
219
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
220 (defun erc-autoaway-set-away (idle-time)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
221 "Set the away state globally."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
222 ;; Note that the idle timer runs, even when Emacs is inactive. In
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
223 ;; order to prevent flooding when we connect, we test for an
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
224 ;; existing process.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
225 (when (and (erc-server-process-alive)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
226 (not (erc-away-p)))
71883
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
227 (setq erc-autoaway-caused-away t)
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
228 (erc-cmd-GAWAY (format erc-autoaway-message idle-time))))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
229
71883
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
230 (defun erc-autoaway-reset-indicators (&rest stuff)
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
231 "Reset indicators used by the erc-autoaway module."
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
232 (setq erc-autoaway-last-sent-time (erc-current-time))
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
233 (setq erc-autoaway-caused-away nil))
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
234
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
235 (provide 'erc-autoaway)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
236
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
237 ;;; erc-autoaway.el ends here
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
238 ;;
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
239 ;; Local Variables:
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
240 ;; indent-tabs-mode: t
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
241 ;; tab-width: 8
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
242 ;; End:
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
243
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
244 ;; arch-tag: 16fc241e-8358-4b56-9fe2-116bdd0ba3bc