(completion-at-point-function-with-frecency-sorting
#'elisp-completion-at-point))
+(defun elisp-save-capf-frecency-cache ()
+ (interactive)
+ (with-temp-buffer
+ (let ((print-length nil)
+ (print-level nil)
+ (print-quoted t)
+ (print-circle t))
+ (prin1 (capfrecency--cache (symbol-function 'elisp-capf)) (current-buffer)))
+ (let* ((file-precious-flag t)
+ (file (locate-user-emacs-file "elisp-capf-frecency-cache.eld"))
+ (dir (file-name-directory file)))
+ (unless (file-exists-p dir) (make-directory dir t))
+ (write-region (point-min) (point-max) file nil
+ (unless (called-interactively-p 'interactive) 'quiet))
+ (set-file-modes file #o600))))
+
+(define-minor-mode elisp-persistent-capf-frecency-cache-mode
+ "Persist ELisp completion frecency cache."
+ :global t
+ :group 'lisp
+ (if elisp-persistent-capf-frecency-cache-mode
+ (progn
+ (add-hook 'kill-emacs-hook #'elisp-save-capf-frecency-cache)
+ (when-let ((file (locate-user-emacs-file "elisp-capf-frecency-cache.eld"))
+ ((file-exists-p file)))
+ (setf (capfrecency--cache (symbol-function 'elisp-capf))
+ (with-temp-buffer
+ (insert-file-contents file)
+ (goto-char (point-min))
+ (read (current-buffer))))))
+ (remove-hook 'kill-emacs-hook #'elisp-save-capf-frecency-cache)
+ (elisp-save-capf-frecency-cache)))
+
(defun elisp--company-kind (str)
(let ((sym (intern-soft str)))
(cond