Mercurial > emacs
annotate lisp/erc/erc-autoaway.el @ 95212:a6a4ada91449
* dispextern.h, xfaces.c (xstrcasecmp): Renamed from xstricmp.
* dosfns.c, fileio.c, font.c, fontset.c, image.c, macfns.c:
* macterm.c, process.c, w32.c, w32fns.c, w32proc.c, xfaces.c:
* xfns.c, xfont.c: Callers changed.
author | Jason Rumney <jasonr@gnu.org> |
---|---|
date | Thu, 22 May 2008 14:52:37 +0000 |
parents | 2a734255bcc7 |
children | b52fd6b0e051 |
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 |
79706 | 3 ;; Copyright (C) 2002, 2003, 2004, 2006, 2007, 2008 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 |
94660
2a734255bcc7
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
10 ;; GNU Emacs is free software: you can redistribute it and/or modify |
68451
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 |
94660
2a734255bcc7
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
12 ;; the Free Software Foundation, either version 3 of the License, or |
2a734255bcc7
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
13 ;; (at your option) any later version. |
68451
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 |
94660
2a734255bcc7
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
68451
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
22 |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
23 ;;; Commentary: |
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 ;; TODO: |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
26 ;; - 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
|
27 |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
28 ;;; Code: |
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 (require 'erc) |
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 (defgroup erc-autoaway nil |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
33 "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
|
34 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
|
35 :group 'erc) |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
36 |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
37 (defvar erc-autoaway-idletimer nil |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
38 "The Emacs idletimer. |
74093 | 39 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
|
40 |
76856 | 41 (defvar erc-autoaway-last-sent-time (erc-current-time) |
42 "The last time the user sent something.") | |
43 | |
44 (defvar erc-autoaway-caused-away nil | |
45 "Indicates whether this module was responsible for setting the | |
46 user's away status.") | |
47 | |
48 (eval-when-compile (defvar erc-autoaway-idle-seconds)) | |
49 | |
50 (defun erc-autoaway-reestablish-idletimer () | |
51 "Reestablish the Emacs idletimer. | |
52 If `erc-autoaway-idle-method' is 'emacs, you must call this | |
53 function each time you change `erc-autoaway-idle-seconds'." | |
54 (interactive) | |
55 (when erc-autoaway-idletimer | |
56 (erc-cancel-timer erc-autoaway-idletimer)) | |
57 (setq erc-autoaway-idletimer | |
58 (run-with-idle-timer erc-autoaway-idle-seconds | |
59 t | |
60 'erc-autoaway-set-away | |
61 erc-autoaway-idle-seconds))) | |
62 | |
63 (defun erc-autoaway-some-server-buffer () | |
64 "Return some ERC server buffer if its connection is alive. | |
65 If none is found, return nil." | |
66 (car (erc-buffer-list #'erc-open-server-buffer-p))) | |
67 | |
68 (defun erc-autoaway-insinuate-maybe (&optional server &rest ignored) | |
69 "Add autoaway reset function to `post-command-hook' if at least one | |
70 ERC process is alive. | |
71 | |
72 This is used when `erc-autoaway-idle-method' is 'user." | |
73 (when (or server (erc-autoaway-some-server-buffer)) | |
74 (add-hook 'post-command-hook 'erc-autoaway-reset-idle-user))) | |
75 | |
76 (defun erc-autoaway-remove-maybe (&rest ignored) | |
77 "Remove the autoaway reset function from `post-command-hook' if | |
78 no ERC process is alive. | |
79 | |
80 This is used when `erc-autoaway-idle-method' is 'user." | |
81 (unless (erc-autoaway-some-server-buffer) | |
82 (remove-hook 'post-command-hook 'erc-autoaway-reset-idle-user))) | |
83 | |
68451
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
84 ;;;###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
|
85 (define-erc-module autoaway nil |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
86 "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
|
87 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
|
88 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
|
89 |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
90 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
|
91 |
71883 | 92 User idle time measures how long you have not been sending any |
93 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
|
94 |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
95 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
|
96 currently not useful, since Emacs is non-idle when it handles |
71883 | 97 ping-pong with IRC servers. See `erc-autoaway-idle-method' |
98 for more information. | |
68451
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
99 |
71883 | 100 IRC idle time measures how long since you last sent something (see |
101 `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
|
102 |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
103 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
|
104 set you no longer away. |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
105 |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
106 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
|
107 ;; Enable: |
71883 | 108 ((when (boundp 'erc-autoaway-idle-method) |
76856 | 109 (add-hook 'erc-connect-pre-hook 'erc-autoaway-reset-indicators) |
110 (setq erc-autoaway-last-sent-time (erc-current-time)) | |
71883 | 111 (cond |
112 ((eq erc-autoaway-idle-method 'irc) | |
113 (add-hook 'erc-send-completed-hook 'erc-autoaway-reset-idle-irc) | |
114 (add-hook 'erc-server-001-functions 'erc-autoaway-reset-idle-irc)) | |
115 ((eq erc-autoaway-idle-method 'user) | |
76856 | 116 (add-hook 'erc-after-connect 'erc-autoaway-insinuate-maybe) |
117 (add-hook 'erc-disconnected-hook 'erc-autoaway-remove-maybe) | |
118 (erc-autoaway-insinuate-maybe)) | |
71883 | 119 ((eq erc-autoaway-idle-method 'emacs) |
120 (erc-autoaway-reestablish-idletimer))) | |
121 (add-hook 'erc-timer-hook 'erc-autoaway-possibly-set-away) | |
122 (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
|
123 ;; Disable: |
71883 | 124 ((when (boundp 'erc-autoaway-idle-method) |
76856 | 125 (remove-hook 'erc-connect-pre-hook 'erc-autoaway-reset-indicators) |
71883 | 126 (cond |
127 ((eq erc-autoaway-idle-method 'irc) | |
128 (remove-hook 'erc-send-completed-hook 'erc-autoaway-reset-idle-irc) | |
129 (remove-hook 'erc-server-001-functions 'erc-autoaway-reset-idle-irc)) | |
130 ((eq erc-autoaway-idle-method 'user) | |
76856 | 131 (remove-hook 'post-command-hook 'erc-autoaway-reset-idle-user) |
132 (remove-hook 'erc-after-connect 'erc-autoaway-insinuate-maybe) | |
133 (remove-hook 'erc-disconnected-hook 'erc-autoaway-remove-maybe)) | |
71883 | 134 ((eq erc-autoaway-idle-method 'emacs) |
135 (erc-cancel-timer erc-autoaway-idletimer) | |
136 (setq erc-autoaway-idletimer nil))) | |
137 (remove-hook 'erc-timer-hook 'erc-autoaway-possibly-set-away) | |
138 (remove-hook 'erc-server-305-functions 'erc-autoaway-reset-indicators)))) | |
139 | |
140 (defcustom erc-autoaway-idle-method 'user | |
141 "*The method used to determine how long you have been idle. | |
142 If 'user, the time of the last command sent to Emacs is used. | |
143 If 'emacs, the idle time in Emacs is used. | |
144 If 'irc, the time of the last IRC command is used. | |
145 | |
146 The time itself is specified by `erc-autoaway-idle-seconds'. | |
147 | |
148 See `erc-autoaway-mode' for more information on the various | |
149 definitions of being idle." | |
150 :group 'erc-autoaway | |
151 :type '(choice (const :tag "User idle time" user) | |
152 (const :tag "Emacs idle time" emacs) | |
153 (const :tag "Last IRC action" irc)) | |
154 :set (lambda (sym val) | |
76856 | 155 (if erc-autoaway-mode |
156 (progn | |
157 (erc-autoaway-disable) | |
158 (set sym val) | |
159 (erc-autoaway-enable)) | |
160 (set sym val)))) | |
68451
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-auto-set-away t |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
163 "*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
|
164 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
|
165 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
|
166 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
|
167 the other half." |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
168 :group 'erc-autoaway |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
169 :type 'boolean) |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
170 |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
171 (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
|
172 "*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
|
173 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
|
174 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
|
175 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
|
176 `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
|
177 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
|
178 :group 'erc-autoaway |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
179 :type 'boolean) |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
180 |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
181 (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
|
182 "*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
|
183 See `erc-auto-discard-away'." |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
184 :group 'erc-autoaway |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
185 :type 'regexp) |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
186 |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
187 (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
|
188 "*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
|
189 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
|
190 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
|
191 :group 'erc-autoaway |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
192 :set (lambda (sym val) |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
193 (set-default sym val) |
71883 | 194 (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
|
195 (erc-autoaway-reestablish-idletimer))) |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
196 :type 'number) |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
197 |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
198 (defcustom erc-autoaway-message |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
199 "I'm gone (autoaway after %i seconds of idletime)" |
71883 | 200 "*Message ERC will use when setting you automatically away. |
201 It is used as a `format' string with the argument of the idletime | |
202 in seconds." | |
68451
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
203 :group 'erc-autoaway |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
204 :type 'string) |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
205 |
71883 | 206 (defun erc-autoaway-reset-idle-user (&rest stuff) |
207 "Reset the stored user idle time. | |
208 This is one global variable since a user talking on one net can | |
209 talk on another net too." | |
210 (when erc-auto-discard-away | |
76856 | 211 (erc-autoaway-set-back #'erc-autoaway-remove-maybe)) |
71883 | 212 (setq erc-autoaway-last-sent-time (erc-current-time))) |
213 | |
214 (defun erc-autoaway-reset-idle-irc (line &rest stuff) | |
215 "Reset the stored IRC idle time. | |
216 This is one global variable since a user talking on one net can | |
217 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
|
218 (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
|
219 (stringp line) |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
220 (not (string-match erc-autoaway-no-auto-discard-regexp line))) |
71883 | 221 (erc-autoaway-set-back)) |
68451
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
222 (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
|
223 |
76856 | 224 (defun erc-autoaway-set-back (&optional none-alive-func) |
225 "Discard the away state globally. | |
226 | |
227 NONE-ALIVE-FUNC is the function to call if no ERC processes are alive." | |
228 (let ((server-buffer (erc-autoaway-some-server-buffer))) | |
229 (if (and erc-autoaway-caused-away | |
230 (buffer-live-p server-buffer) | |
231 (with-current-buffer server-buffer erc-away)) | |
232 (erc-cmd-GAWAY "") | |
233 (when none-alive-func (funcall none-alive-func))))) | |
234 | |
235 (defun erc-autoaway-some-open-server-buffer () | |
236 "Return some ERC server buffer if its connection is alive and the | |
237 user is not away. | |
238 If none is found, return nil." | |
239 (car (erc-buffer-list (lambda () | |
240 (and (erc-open-server-buffer-p) | |
241 (not erc-away)))))) | |
68451
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
242 |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
243 (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
|
244 "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
|
245 exceeds `erc-autoaway-idle-seconds'." |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
246 ;; 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
|
247 ;; 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
|
248 ;; whenever the server sends something to the client. |
86836 | 249 (when (and erc-server-connected |
250 erc-auto-set-away | |
74093 | 251 (not erc-autoaway-caused-away) |
76856 | 252 (erc-autoaway-some-open-server-buffer)) |
68451
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
253 (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
|
254 current-time))) |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
255 (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
|
256 (erc-display-message |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
257 nil 'notice nil |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
258 (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
|
259 idle-time)) |
76856 | 260 (erc-autoaway-set-away idle-time t))))) |
68451
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
261 |
76856 | 262 (defun erc-autoaway-set-away (idle-time &optional notest) |
263 "Set the away state globally. | |
264 | |
265 If NOTEST is specified, do not check to see whether there is an | |
266 activer server buffer available." | |
68451
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
267 ;; 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
|
268 ;; 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
|
269 ;; existing process. |
76856 | 270 (when (or notest (erc-autoaway-some-open-server-buffer)) |
71883 | 271 (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
|
272 (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
|
273 |
71883 | 274 (defun erc-autoaway-reset-indicators (&rest stuff) |
275 "Reset indicators used by the erc-autoaway module." | |
276 (setq erc-autoaway-last-sent-time (erc-current-time)) | |
277 (setq erc-autoaway-caused-away nil)) | |
278 | |
68451
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
279 (provide 'erc-autoaway) |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
280 |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
281 ;;; erc-autoaway.el ends here |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
282 ;; |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
283 ;; Local Variables: |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
284 ;; indent-tabs-mode: t |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
285 ;; tab-width: 8 |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
286 ;; End: |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
287 |
fc745b05e928
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
288 ;; arch-tag: 16fc241e-8358-4b56-9fe2-116bdd0ba3bc |