- ;; Ignore tags-completion-at-point-function because it subverts company-etags
- ;; in the default value of company-backends, where the latter comes later.
- (letf* (((default-value 'completion-at-point-functions) nil)
- (data (run-hook-wrapped 'completion-at-point-functions
- ;; Ignore misbehaving functions.
- #'completion--capf-wrapper 'optimist)))
- (when (and (consp data) (numberp (nth 1 data))) data)))
+ (let ((cache company--capf-cache))
+ (if (and (equal (current-buffer) (car cache))
+ (equal (point) (car (setq cache (cdr cache))))
+ (equal (buffer-chars-modified-tick) (car (setq cache (cdr cache)))))
+ (cadr cache)
+ (let ((data (company--capf-data-real)))
+ (setq company--capf-cache
+ (list (current-buffer) (point) (buffer-chars-modified-tick) data))
+ data))))
+
+(defun company--capf-data-real ()
+ (cl-letf* (((default-value 'completion-at-point-functions)
+ ;; Ignore tags-completion-at-point-function because it subverts
+ ;; company-etags in the default value of company-backends, where
+ ;; the latter comes later.
+ (remove 'tags-completion-at-point-function
+ (default-value 'completion-at-point-functions)))
+ (data (run-hook-wrapped 'completion-at-point-functions
+ ;; Ignore misbehaving functions.
+ #'completion--capf-wrapper 'optimist)))
+ (when (and (consp (cdr data)) (numberp (nth 1 data))) data)))