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

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

[elpa] master 526aa5b 5/8: Discard company-capf--current-completion-data


From: Dmitry Gutov
Subject: [elpa] master 526aa5b 5/8: Discard company-capf--current-completion-data when we can
Date: Sat, 8 Dec 2018 19:13:05 -0500 (EST)

branch: master
commit 526aa5b3cffb93e07313ace7a3902be19f46eddf
Author: Dmitry Gutov <address@hidden>
Commit: Dmitry Gutov <address@hidden>

    Discard company-capf--current-completion-data when we can
    
    #845
---
 company-capf.el | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/company-capf.el b/company-capf.el
index 4cc8a90..11e3382 100644
--- a/company-capf.el
+++ b/company-capf.el
@@ -36,7 +36,6 @@
 
 ;; FIXME: Provide a way to save this info once in Company itself
 ;; (https://github.com/company-mode/company-mode/pull/845).
-;; FIXME: What about memory usage?
 (defvar-local company-capf--current-completion-data nil
   "Value last returned by `company-capf' when called with `candidates'.
 For most properties/actions, this is just what we need: the exact values
@@ -76,6 +75,20 @@ that accompanied the completion table that's currently is 
use.")
       completion-at-point-functions
     (remq 'python-completion-complete-at-point completion-at-point-functions)))
 
+(defun company-capf--save-current-data (data)
+  (setq company-capf--current-completion-data data)
+  (add-hook 'company-completion-cancelled-hook
+            #'company-capf--clear-current-data nil t)
+  (add-hook 'company-completion-finished-hook
+            #'company-capf--clear-current-data nil t))
+
+(defun company-capf--clear-current-data (_ignored)
+  (setq company-capf--current-completion-data nil)
+  (remove-hook 'company-completion-cancelled-hook
+               #'company-capf--clear-current-data t)
+  (remove-hook 'company-completion-finished-hook
+               #'company-capf--clear-current-data t))
+
 (defun company-capf (command &optional arg &rest _args)
   "`company-mode' backend using `completion-at-point-functions'."
   (interactive (list 'interactive))
@@ -92,7 +105,7 @@ that accompanied the completion table that's currently is 
use.")
             (t prefix))))))
     (`candidates
      (let ((res (company--capf-data)))
-       (setq company-capf--current-completion-data res)
+       (company-capf--save-current-data res)
        (when res
          (let* ((table (nth 3 res))
                 (pred (plist-get (nthcdr 4 res) :predicate))



reply via email to

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