]> code.delx.au - gnu-emacs-elpa/commitdiff
Switched to regular timer, because idle time fluctuates too much.
authorNikolaj Schumacher <git@nschum.de>
Tue, 17 Mar 2009 12:51:01 +0000 (13:51 +0100)
committerNikolaj Schumacher <git@nschum.de>
Fri, 20 Mar 2009 11:58:29 +0000 (12:58 +0100)
company.el

index 91cdfc1e97f2af91342a50cf4005daa684f2295c..5ea09254d95827c3001470b6ca5b65ae5d76eb40 100644 (file)
   :group 'company
   :type '(integer :tag "prefix length"))
 
-(defvar company-timer nil)
-
-(defun company-timer-set (variable value)
-  (set variable value)
-  (when company-timer (cancel-timer company-timer))
-  (when (numberp value)
-    (setq company-timer (run-with-idle-timer value t 'company-idle-begin))))
-
 (defcustom company-idle-delay .7
   "*"
-  :set 'company-timer-set
   :group 'company
   :type '(choice (const :tag "never (nil)" nil)
                  (const :tag "immediate (t)" t)
   (if company-mode
       (progn
         (add-hook 'pre-command-hook 'company-pre-command nil t)
-        (add-hook 'post-command-hook 'company-post-command nil t)
-        (company-timer-set 'company-idle-delay
-                           company-idle-delay))
+        (add-hook 'post-command-hook 'company-post-command nil t))
     (remove-hook 'pre-command-hook 'company-pre-command t)
     (remove-hook 'post-command-hook 'company-post-command t)
     (company-cancel)
 (defvar company-point nil)
 (make-variable-buffer-local 'company-point)
 
+(defvar company-timer nil)
+
 (defvar company-disabled-backends nil)
 
 (defsubst company-strip-prefix (str)
     (push (cons prefix company-candidates) company-candidates-cache))
   company-candidates)
 
-(defun company-idle-begin ()
+(defun company-idle-begin (buf win tick pos)
   (and company-mode
+       (eq buf (current-buffer))
+       (eq win (selected-window))
+       (eq tick (buffer-chars-modified-tick))
+       (eq pos (point))
        (not company-candidates)
        (not (equal (point) company-point))
        (let ((company-idle-delay t))
         company-selection 0
         company-selection-changed nil
         company-point nil)
+  (when company-timer
+    (cancel-timer company-timer))
   (company-search-mode 0)
   (company-call-frontends 'hide)
   (company-enable-overriding-keymap nil))
       (error (message "Company: An error occurred in pre-command")
              (message "%s" (error-message-string err))
              (company-cancel))))
+  (when company-timer
+    (cancel-timer company-timer))
   (company-uninstall-map))
 
 (defun company-post-command ()
           (unless (equal (point) company-point)
             (company-begin))
           (when company-candidates
-            (company-call-frontends 'post-command)))
+            (company-call-frontends 'post-command))
+          (when (numberp company-idle-delay)
+            (setq company-timer
+                  (run-with-timer company-idle-delay nil 'company-idle-begin
+                                  (current-buffer) (selected-window)
+                                  (buffer-chars-modified-tick) (point)))))
       (error (message "Company: An error occurred in post-command")
              (message "%s" (error-message-string err))
              (company-cancel))))