Show
Ignore:
Timestamp:
07/16/06 08:36:52 (2 years ago)
Author:
miyoshi
Message:

Sync up with Emacs CVS HEAD.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lisp/erc/erc-autoaway.el

    r4035 r4111  
    4040  "The Emacs idletimer. 
    4141This is only used when `erc-autoaway-use-emacs-idle' is non-nil.") 
    42  
    43 (defcustom erc-autoaway-use-emacs-idle nil 
    44   "*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 various 
    48 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 Emacs 
    52 non-idle.  Emacs idle-time and user idle-time are just not the same." 
    53   :group 'erc-autoaway 
    54   :type 'boolean) 
    5542 
    5643;;;###autoload (autoload 'erc-autoaway-mode "erc-autoaway") 
     
    6249There are several kinds of being idle: 
    6350 
    64 IRC idle time measures how long since you last sent something (see 
    65 `erc-autoaway-last-sent-time').  This is the default. 
     51User idle time measures how long you have not been sending any 
     52commands to Emacs.  This is the default. 
    6653 
    6754Emacs idle time measures how long Emacs has been idle.  This is 
    6855currently 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. 
     56ping-pong with IRC servers.  See `erc-autoaway-idle-method' 
     57for more information. 
     58 
     59IRC idle time measures how long since you last sent something (see 
     60`erc-autoaway-last-sent-time'). 
    7561 
    7662If `erc-auto-discard-away' is set, then typing anything, will 
     
    7965Related variables: `erc-public-away-p' and `erc-away-nickname'." 
    8066  ;; 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))) 
    8678  ;; 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. 
     94If 'user, the time of the last command sent to Emacs is used. 
     95If 'emacs, the idle time in Emacs is used. 
     96If 'irc, the time of the last IRC command is used. 
     97 
     98The time itself is specified by `erc-autoaway-idle-seconds'. 
     99 
     100See `erc-autoaway-mode' for more information on the various 
     101definitions 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))) 
    93110 
    94111(defcustom erc-auto-set-away t 
     
    121138(defun erc-autoaway-reestablish-idletimer () 
    122139  "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." 
     140If `erc-autoaway-idle-method' is 'emacs, you must call this 
     141function each time you change `erc-autoaway-idle-seconds'." 
    125142  (interactive) 
    126143  (when erc-autoaway-idletimer 
     
    139156  :set (lambda (sym val) 
    140157         (set-default sym val) 
    141          (when erc-autoaway-use-emacs-idle 
     158         (when (eq erc-autoaway-idle-method 'emacs) 
    142159           (erc-autoaway-reestablish-idletimer))) 
    143160  :type 'number) 
     
    145162(defcustom erc-autoaway-message 
    146163  "I'm gone (autoaway after %i seconds of idletime)" 
    147   "*Message ERC will use when he sets you automatically away. 
    148 It is used as a `format' string with the argument of the idletime in 
    149 seconds." 
     164  "*Message ERC will use when setting you automatically away. 
     165It is used as a `format' string with the argument of the idletime 
     166in seconds." 
    150167  :group 'erc-autoaway 
    151168  :type 'string) 
     
    154171  "The last time the user sent something.") 
    155172 
    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 
     175user's away status.") 
     176 
     177(defun erc-autoaway-reset-idle-user (&rest stuff) 
     178  "Reset the stored user idle time. 
     179This is one global variable since a user talking on one net can 
     180talk 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. 
     187This is one global variable since a user talking on one net can 
     188talk on another net too." 
    160189  (when (and erc-auto-discard-away 
    161190             (stringp line) 
    162191             (not (string-match erc-autoaway-no-auto-discard-regexp line))) 
    163     (erc-autoaway-set-back line)) 
     192    (erc-autoaway-set-back)) 
    164193  (setq erc-autoaway-last-sent-time (erc-current-time))) 
    165194 
    166 (defun erc-autoaway-set-back (line
     195(defun erc-autoaway-set-back (
    167196  "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 "")))) 
    171201 
    172202(defun erc-autoaway-possibly-set-away (current-time) 
     
    194224  (when (and (erc-server-process-alive) 
    195225             (not (erc-away-p))) 
     226    (setq erc-autoaway-caused-away t) 
    196227    (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)) 
    197233 
    198234(provide 'erc-autoaway)