Allow disabling auto-away/auto-na timeouts.
authorSteve Youngs <steve@emchat.org>
Thu, 22 Aug 2013 11:28:03 +0000 (21:28 +1000)
committerSteve Youngs <steve@emchat.org>
Thu, 22 Aug 2013 11:28:03 +0000 (21:28 +1000)
* emchat.el (emchat-auto-away-timeout-set): Only set itimers if
value is not zero

* emchat.el (emchat-auto-away-timeout): Amend docstring.

* emchat.el (emchat-change-idle-timeout): Let setting to zero mean
disable the timeout.

Signed-off-by: Steve Youngs <steve@emchat.org>
emchat.el

index 4c31d13..56e9136 100644 (file)
--- a/emchat.el
+++ b/emchat.el
@@ -1809,32 +1809,34 @@ Need to relogin afterwards."
 
 (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.
@@ -1842,6 +1844,8 @@ Need to relogin afterwards."
 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
@@ -1849,18 +1853,21 @@ If you set this outside of the custom buffer you _MUST_ use
   :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.