emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master 20fe015 18/31: Merge pull request #874 from amosbird/maste


From: Dmitry Gutov
Subject: [elpa] master 20fe015 18/31: Merge pull request #874 from amosbird/master
Date: Sun, 14 Apr 2019 22:06:18 -0400 (EDT)

branch: master
commit 20fe01542bf7665ba90f9fe1a86cbe0eea4d9f8a
Merge: edbb3c5 ebc4fce
Author: Dmitry Gutov <address@hidden>
Commit: GitHub <address@hidden>

    Merge pull request #874 from amosbird/master
    
    Make company-idle-delay support predicate function
---
 NEWS.md    |  2 ++
 company.el | 30 +++++++++++++++++-------------
 2 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/NEWS.md b/NEWS.md
index aedac18..5391bb5 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -2,6 +2,8 @@
 
 ## Next
 
+* `company-idle-delay` now accepts a function which generates the idle time or
+  nil indicating no idle completion.
 * Add custom variable `company-show-numbers-function` to make numbers of
   candidates customizable. 
 * When a symbol is already typed in full, calling `M-x company-complete` will
diff --git a/company.el b/company.el
index 728c42d..71f3756 100644
--- a/company.el
+++ b/company.el
@@ -584,6 +584,7 @@ The prefix still has to satisfy 
`company-minimum-prefix-length' before that
 happens.  The value of nil means no idle completion."
   :type '(choice (const :tag "never (nil)" nil)
                  (const :tag "immediate (0)" 0)
+                 (function :tag "Predicate function")
                  (number :tag "seconds")))
 
 (defcustom company-tooltip-idle-delay .5
@@ -1702,25 +1703,28 @@ prefix match (same case) will be prioritized."
               (company--perform)))
           (if company-candidates
               (company-call-frontends 'post-command)
-            (and (or (numberp company-idle-delay)
-                     ;; Deprecated.
-                     (eq company-idle-delay t))
-                 (not defining-kbd-macro)
-                 (company--should-begin)
-                 (setq company-timer
-                       (run-with-timer (company--idle-delay) nil
-                                       'company-idle-begin
-                                       (current-buffer) (selected-window)
-                                       (buffer-chars-modified-tick) 
(point))))))
+            (let ((delay (company--idle-delay)))
+             (and (numberp delay)
+                  (not defining-kbd-macro)
+                  (company--should-begin)
+                  (setq company-timer
+                        (run-with-timer 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))))
   (company-install-map))
 
 (defun company--idle-delay ()
-  (if (memql company-idle-delay '(t 0 0.0))
-      0.01
-    company-idle-delay))
+  (let ((delay
+          (if (functionp company-idle-delay)
+              (funcall company-idle-delay)
+            company-idle-delay)))
+    (if (memql delay '(t 0 0.0))
+        0.01
+      delay)))
 
 (defvar company--begin-inhibit-commands '(company-abort
                                           company-complete-mouse



reply via email to

[Prev in Thread] Current Thread [Next in Thread]