summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaciej Barć <xgqt@gentoo.org>2022-08-30 20:21:31 +0200
committerMaciej Barć <xgqt@gentoo.org>2022-08-30 20:21:31 +0200
commitbfb0fac0258f2fb2e561e7066378ecf88e84d413 (patch)
tree8b3450aa41e50d40320626c9dc74fe45441d7a78
parentcompany-ebuild-keywords.el: revert to global (diff)
downloadcompany-ebuild-bfb0fac0258f2fb2e561e7066378ecf88e84d413.tar.gz
company-ebuild-bfb0fac0258f2fb2e561e7066378ecf88e84d413.tar.bz2
company-ebuild-bfb0fac0258f2fb2e561e7066378ecf88e84d413.zip
company-ebuild.el: cache eclasses
Signed-off-by: Maciej Barć <xgqt@gentoo.org>
-rw-r--r--company-ebuild.el54
1 files 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."