瀏覽代碼

Check for the existence of the x11idle command only once.

* org-clock.el (org-x11idle-exists-p): New variable.
(org-user-idle-seconds): Use it.
Bastien Guerry 12 年之前
父節點
當前提交
42d2552a83
共有 1 個文件被更改,包括 7 次插入6 次删除
  1. 7 6
      lisp/org-clock.el

+ 7 - 6
lisp/org-clock.el

@@ -999,6 +999,12 @@ If `only-dangling-p' is non-nil, only ask to resolve dangling
   "Return the current Mac idle time in seconds."
   (string-to-number (shell-command-to-string "ioreg -c IOHIDSystem | perl -ane 'if (/Idle/) {$idle=(pop @F)/1000000000; print $idle; last}'")))
 
+(defvar org-x11idle-exists-p
+  ;; Check that x11idle exists
+  (and (eq (call-process-shell-command "command" nil nil nil "-v" "x11idle") 0)
+       ;; Check that x11idle can retrieve the idle time
+       (eq (call-process-shell-command "x11idle" nil nil nil) 0)))
+
 (defun org-x11-idle-seconds ()
   "Return the current X11 idle time in seconds."
   (/ (string-to-number (shell-command-to-string "x11idle")) 1000))
@@ -1009,12 +1015,7 @@ This routine returns a floating point number."
   (cond
    ((eq system-type 'darwin)
     (org-mac-idle-seconds))
-   ((and
-     (eq window-system 'x)
-     ;; Check that x11idle exists
-     (eq (call-process-shell-command "command" nil nil nil "-v" "x11idle") 0)
-     ;; Check that x11idle can retrieve the idle time
-     (eq (call-process-shell-command "x11idle" nil nil nil ) 0))
+   ((and (eq window-system 'x) org-x11idle-exists-p)
     (org-x11-idle-seconds))
    (t
     (org-emacs-idle-seconds))))