From bfb0fac0258f2fb2e561e7066378ecf88e84d413 Mon Sep 17 00:00:00 2001 From: Maciej Barć Date: Tue, 30 Aug 2022 20:21:31 +0200 Subject: company-ebuild.el: cache eclasses MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maciej Barć --- company-ebuild.el | 54 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/company-ebuild.el b/company-ebuild.el index 5c2272a..bcee8f5 100644 --- a/company-ebuild.el +++ b/company-ebuild.el @@ -24,7 +24,7 @@ ;; Version: 0.1.1 ;; Keywords: languages ;; Homepage: https://gitweb.gentoo.org/proj/company-ebuild.git -;; Package-Requires: ((emacs "25.1")) +;; Package-Requires: ((emacs "26.2")) ;; SPDX-License-Identifier: GPL-2.0-or-later @@ -150,26 +150,48 @@ REPO-ROOT is the location from which we start searching for Eclass files." (when (file-exists-p repo-eclass) (directory-files repo-eclass t ".*\\.eclass" t))))) +(defvar company-ebuild--eclass-mtimes '() + "Cache to prevent accessing eclasses multiple times. + +This is a global value holding a list of pairs. +The key is an eclass path and the value is it's last modification time. +This variable primarily is used in +`company-ebuild--regenerate-dynamic-keywords-eclass'.") + +(defun company-ebuild--mtime (file-path) + "Return the modification time of a file at FILE-PATH." + (file-attribute-modification-time (file-attributes file-path))) + (defun company-ebuild--regenerate-dynamic-keywords-eclass () "Set new content of the ‘company-ebuild--dynamic-keywords’ Eclass variables." (let ((repo-root (company-ebuild--find-repo-root buffer-file-name))) (when repo-root - (let ((eclass-files - (company-ebuild--find-eclass-files repo-root))) - (mapc - (lambda (eclass-file) - (mapc (lambda (str) - (add-to-list 'company-ebuild--dynamic-keywords-eclasses - (replace-regexp-in-string "\\.eclass" "" str))) - (company-ebuild--get-tags eclass-file "ECLASS")) - (mapc (lambda (str) - (add-to-list 'company-ebuild--dynamic-keywords-variables str)) - (company-ebuild--get-tags eclass-file "ECLASS_VARIABLE")) - (mapc (lambda (str) - (add-to-list 'company-ebuild--dynamic-keywords-functions str)) - (company-ebuild--get-tags eclass-file "FUNCTION"))) - eclass-files))))) + (mapc + (lambda (eclass-file) + (let ((eclass-file-mtime + (company-ebuild--mtime eclass-file))) + (unless (equal (cdr (assoc eclass-file + company-ebuild--eclass-mtimes)) + eclass-file-mtime) + (assoc-delete-all eclass-file company-ebuild--eclass-mtimes) + (push `(,eclass-file . ,eclass-file-mtime) + company-ebuild--eclass-mtimes) + (mapc (lambda (str) + (add-to-list 'company-ebuild--dynamic-keywords-eclasses + (replace-regexp-in-string "\\.eclass" + "" + str))) + (company-ebuild--get-tags eclass-file "ECLASS")) + (mapc (lambda (str) + (add-to-list 'company-ebuild--dynamic-keywords-variables + str)) + (company-ebuild--get-tags eclass-file "ECLASS_VARIABLE")) + (mapc (lambda (str) + (add-to-list 'company-ebuild--dynamic-keywords-functions + str)) + (company-ebuild--get-tags eclass-file "FUNCTION"))))) + (company-ebuild--find-eclass-files repo-root))))) (defun company-ebuild--regenerate-dynamic-keywords-use-flags () "Set new content of the ‘company-ebuild--dynamic-keywords-use-flags’ variable." -- cgit v1.2.3-65-gdbad