Changeset 4111 for trunk/lisp/erc/erc-autoaway.el
- Timestamp:
- 07/16/06 08:36:52 (2 years ago)
- Files:
-
- trunk/lisp/erc/erc-autoaway.el (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lisp/erc/erc-autoaway.el
r4035 r4111 40 40 "The Emacs idletimer. 41 41 This is only used when `erc-autoaway-use-emacs-idle' is non-nil.") 42 43 (defcustom erc-autoaway-use-emacs-idle nil44 "*If non-nil, the idle time refers to idletime in Emacs.45 If nil, the idle time refers to idletime on IRC only.46 The time itself is specified by `erc-autoaway-idle-seconds'.47 See `erc-autoaway-mode' for more information on the various48 definitions of being idle.49 50 Note that using Emacs idletime is currently broken for most versions,51 since process activity (as happens all the time on IRC) makes Emacs52 non-idle. Emacs idle-time and user idle-time are just not the same."53 :group 'erc-autoaway54 :type 'boolean)55 42 56 43 ;;;###autoload (autoload 'erc-autoaway-mode "erc-autoaway") … … 62 49 There are several kinds of being idle: 63 50 64 IRC idle time measures how long since you last sent something (see 65 `erc-autoaway-last-sent-time'). This is the default.51 User idle time measures how long you have not been sending any 52 commands to Emacs. This is the default. 66 53 67 54 Emacs idle time measures how long Emacs has been idle. This is 68 55 currently not useful, since Emacs is non-idle when it handles 69 ping-pong with IRC servers. See `erc-autoaway-use-emacs-idle' for 70 more information. 71 72 User idle time measures how long you have not been sending any 73 commands to Emacs, or to your system. Emacs currently provides no way 74 to measure user idle time. 56 ping-pong with IRC servers. See `erc-autoaway-idle-method' 57 for more information. 58 59 IRC idle time measures how long since you last sent something (see 60 `erc-autoaway-last-sent-time'). 75 61 76 62 If `erc-auto-discard-away' is set, then typing anything, will … … 79 65 Related variables: `erc-public-away-p' and `erc-away-nickname'." 80 66 ;; Enable: 81 ((add-hook 'erc-send-completed-hook 'erc-autoaway-reset-idletime) 82 (add-hook 'erc-server-001-functions 'erc-autoaway-reset-idletime) 83 (add-hook 'erc-timer-hook 'erc-autoaway-possibly-set-away) 84 (when erc-autoaway-use-emacs-idle 85 (erc-autoaway-reestablish-idletimer))) 67 ((when (boundp 'erc-autoaway-idle-method) 68 (cond 69 ((eq erc-autoaway-idle-method 'irc) 70 (add-hook 'erc-send-completed-hook 'erc-autoaway-reset-idle-irc) 71 (add-hook 'erc-server-001-functions 'erc-autoaway-reset-idle-irc)) 72 ((eq erc-autoaway-idle-method 'user) 73 (add-hook 'post-command-hook 'erc-autoaway-reset-idle-user)) 74 ((eq erc-autoaway-idle-method 'emacs) 75 (erc-autoaway-reestablish-idletimer))) 76 (add-hook 'erc-timer-hook 'erc-autoaway-possibly-set-away) 77 (add-hook 'erc-server-305-functions 'erc-autoaway-reset-indicators))) 86 78 ;; Disable: 87 ((remove-hook 'erc-send-completed-hook 'erc-autoaway-reset-idletime) 88 (remove-hook 'erc-server-001-functions 'erc-autoaway-reset-idletime) 89 (remove-hook 'erc-timer-hook 'erc-autoaway-possibly-set-away) 90 (when erc-autoaway-idletimer 91 (erc-cancel-timer erc-autoaway-idletimer) 92 (setq erc-autoaway-idletimer nil)))) 79 ((when (boundp 'erc-autoaway-idle-method) 80 (cond 81 ((eq erc-autoaway-idle-method 'irc) 82 (remove-hook 'erc-send-completed-hook 'erc-autoaway-reset-idle-irc) 83 (remove-hook 'erc-server-001-functions 'erc-autoaway-reset-idle-irc)) 84 ((eq erc-autoaway-idle-method 'user) 85 (remove-hook 'post-command-hook 'erc-autoaway-reset-idle-user)) 86 ((eq erc-autoaway-idle-method 'emacs) 87 (erc-cancel-timer erc-autoaway-idletimer) 88 (setq erc-autoaway-idletimer nil))) 89 (remove-hook 'erc-timer-hook 'erc-autoaway-possibly-set-away) 90 (remove-hook 'erc-server-305-functions 'erc-autoaway-reset-indicators)))) 91 92 (defcustom erc-autoaway-idle-method 'user 93 "*The method used to determine how long you have been idle. 94 If 'user, the time of the last command sent to Emacs is used. 95 If 'emacs, the idle time in Emacs is used. 96 If 'irc, the time of the last IRC command is used. 97 98 The time itself is specified by `erc-autoaway-idle-seconds'. 99 100 See `erc-autoaway-mode' for more information on the various 101 definitions of being idle." 102 :group 'erc-autoaway 103 :type '(choice (const :tag "User idle time" user) 104 (const :tag "Emacs idle time" emacs) 105 (const :tag "Last IRC action" irc)) 106 :set (lambda (sym val) 107 (erc-autoaway-disable) 108 (set-default sym val) 109 (erc-autoaway-enable))) 93 110 94 111 (defcustom erc-auto-set-away t … … 121 138 (defun erc-autoaway-reestablish-idletimer () 122 139 "Reestablish the emacs idletimer. 123 You have to call this function each time you change 124 `erc-autoaway-idle-seconds', if `erc-autoaway-use-emacs-idle' is set."140 If `erc-autoaway-idle-method' is 'emacs, you must call this 141 function each time you change `erc-autoaway-idle-seconds'." 125 142 (interactive) 126 143 (when erc-autoaway-idletimer … … 139 156 :set (lambda (sym val) 140 157 (set-default sym val) 141 (when erc-autoaway-use-emacs-idle158 (when (eq erc-autoaway-idle-method 'emacs) 142 159 (erc-autoaway-reestablish-idletimer))) 143 160 :type 'number) … … 145 162 (defcustom erc-autoaway-message 146 163 "I'm gone (autoaway after %i seconds of idletime)" 147 "*Message ERC will use when he setsyou automatically away.148 It is used as a `format' string with the argument of the idletime in149 seconds."164 "*Message ERC will use when setting you automatically away. 165 It is used as a `format' string with the argument of the idletime 166 in seconds." 150 167 :group 'erc-autoaway 151 168 :type 'string) … … 154 171 "The last time the user sent something.") 155 172 156 (defun erc-autoaway-reset-idletime (line &rest stuff) 157 "Reset the stored idletime for the user. 158 This is one global variable since a user talking on one net can talk 159 on another net too." 173 (defvar erc-autoaway-caused-away nil 174 "Indicates whether this module was responsible for setting the 175 user's away status.") 176 177 (defun erc-autoaway-reset-idle-user (&rest stuff) 178 "Reset the stored user idle time. 179 This is one global variable since a user talking on one net can 180 talk on another net too." 181 (when erc-auto-discard-away 182 (erc-autoaway-set-back)) 183 (setq erc-autoaway-last-sent-time (erc-current-time))) 184 185 (defun erc-autoaway-reset-idle-irc (line &rest stuff) 186 "Reset the stored IRC idle time. 187 This is one global variable since a user talking on one net can 188 talk on another net too." 160 189 (when (and erc-auto-discard-away 161 190 (stringp line) 162 191 (not (string-match erc-autoaway-no-auto-discard-regexp line))) 163 (erc-autoaway-set-back line))192 (erc-autoaway-set-back)) 164 193 (setq erc-autoaway-last-sent-time (erc-current-time))) 165 194 166 (defun erc-autoaway-set-back ( line)195 (defun erc-autoaway-set-back () 167 196 "Discard the away state globally." 168 (when (erc-away-p) 169 (setq erc-autoaway-last-sent-time (erc-current-time)) 170 (erc-cmd-GAWAY ""))) 197 (let ((server-buffer (car (erc-buffer-list #'erc-server-buffer-p)))) 198 (when (and erc-autoaway-caused-away 199 (with-current-buffer server-buffer (erc-away-p))) 200 (erc-cmd-GAWAY "")))) 171 201 172 202 (defun erc-autoaway-possibly-set-away (current-time) … … 194 224 (when (and (erc-server-process-alive) 195 225 (not (erc-away-p))) 226 (setq erc-autoaway-caused-away t) 196 227 (erc-cmd-GAWAY (format erc-autoaway-message idle-time)))) 228 229 (defun erc-autoaway-reset-indicators (&rest stuff) 230 "Reset indicators used by the erc-autoaway module." 231 (setq erc-autoaway-last-sent-time (erc-current-time)) 232 (setq erc-autoaway-caused-away nil)) 197 233 198 234 (provide 'erc-autoaway)
