(defun emchat-auto-away-timeout-set (&optional symbol value)
"Set timer for auto-away. See `emchat-auto-away-timeout'."
+ ;; delete the previous itimers
(when (itimerp (get-itimer "emchat auto-away"))
- (delete-itimer (get-itimer "emchat auto-away"))) ; delete previous
- (start-itimer
- "emchat auto-away"
- (lambda ()
- ;; auto away for first idle
- (when (member emchat-user-status '("online" "ffc"))
- (emchat-log-system "Auto away.")
- (emchat-change-status "away")
- (setq emchat-user-auto-away-p t)))
- value value
- 'is-idle)
+ (delete-itimer (get-itimer "emchat auto-away")))
(when (itimerp (get-itimer "emchat auto-na"))
(delete-itimer (get-itimer "emchat auto-na")))
- (start-itimer
- "emchat auto-na"
- (lambda ()
- ;; auto na for second idle
- (when (and emchat-user-auto-away-p
- (equal emchat-user-status "away"))
- (emchat-log-system "Auto na.")
- (emchat-change-status "na")
- ;; emchat-change-status resets this flag
- (setq emchat-user-auto-away-p t)))
- (* 2 value) (* 2 value)
- nil))
+ (unless (zerop value)
+ (start-itimer
+ "emchat auto-away"
+ (lambda ()
+ ;; auto away for first idle
+ (when (member emchat-user-status '("online" "ffc"))
+ (emchat-log-system "Auto away.")
+ (emchat-change-status "away")
+ (setq emchat-user-auto-away-p t)))
+ value value
+ 'is-idle)
+ (start-itimer
+ "emchat auto-na"
+ (lambda ()
+ ;; auto na for second idle
+ (when (and emchat-user-auto-away-p
+ (equal emchat-user-status "away"))
+ (emchat-log-system "Auto na.")
+ (emchat-change-status "na")
+ ;; emchat-change-status resets this flag
+ (setq emchat-user-auto-away-p t)))
+ (* 2 value) (* 2 value)
+ nil)))
(defcustom emchat-auto-away-timeout 300
"*Seconds of inactivity in Emacs before auto-away.
After two times the seconds of auto-away, it goes auto-na.
See `emchat-auto-away'.
+Setting this to zero disables the timeout.
+
If you set this outside of the custom buffer you _MUST_ use
`customize-set-variable' and _NOT_ `setq'."
:type 'number
:initialize 'custom-initialize-default
:group 'emchat-option)
-(defun emchat-change-idle-timeout (&optional seconds)
+(defun emchat-change-idle-timeout (seconds)
"Change the number of SECONDS before EMchat will idle to \"away\".
+If SECONDS is 0 \(zero\) the timeout will be disabled and EMchat will
+not automatically idle to \"away\" or \"na\".
+
Setting the timeout here does not save the value across emacs sessions.
To do that, customise the variable, `emchat-auto-away-timeout'."
- (interactive)
- (let ((timeout (or seconds
- (read-number
- "New idle timeout in seconds [RET for no change]: "
- nil "0"))))
- (unless (zerop timeout)
- (emchat-auto-away-timeout-set nil timeout))))
+ (interactive
+ (list (read-number "Idle timeout in seconds (0 to disable): "
+ nil (number-to-string emchat-auto-away-timeout))))
+ (emchat-auto-away-timeout-set nil seconds)
+ (if (zerop seconds)
+ (emchat-log-system "Auto-away disabled.")
+ (emchat-log-system "Auto-away timeout set to: %d seconds." seconds)))
(defun emchat-send-message-helper (message aliases type log-message)
"Send message, url, authorization or others.