Gentoo Archives: gentoo-commits

From: "Maciej Barć" <xgqt@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/company-ebuild:master commit in: /
Date: Tue, 30 Aug 2022 18:22:49
Message-Id: 1661883691.bfb0fac0258f2fb2e561e7066378ecf88e84d413.xgqt@gentoo
1 commit: bfb0fac0258f2fb2e561e7066378ecf88e84d413
2 Author: Maciej Barć <xgqt <AT> gentoo <DOT> org>
3 AuthorDate: Tue Aug 30 18:21:31 2022 +0000
4 Commit: Maciej Barć <xgqt <AT> gentoo <DOT> org>
5 CommitDate: Tue Aug 30 18:21:31 2022 +0000
6 URL: https://gitweb.gentoo.org/proj/company-ebuild.git/commit/?id=bfb0fac0
7
8 company-ebuild.el: cache eclasses
9
10 Signed-off-by: Maciej Barć <xgqt <AT> gentoo.org>
11
12 company-ebuild.el | 54 ++++++++++++++++++++++++++++++++++++++----------------
13 1 file changed, 38 insertions(+), 16 deletions(-)
14
15 diff --git a/company-ebuild.el b/company-ebuild.el
16 index 5c2272a..bcee8f5 100644
17 --- a/company-ebuild.el
18 +++ b/company-ebuild.el
19 @@ -24,7 +24,7 @@
20 ;; Version: 0.1.1
21 ;; Keywords: languages
22 ;; Homepage: https://gitweb.gentoo.org/proj/company-ebuild.git
23 -;; Package-Requires: ((emacs "25.1"))
24 +;; Package-Requires: ((emacs "26.2"))
25 ;; SPDX-License-Identifier: GPL-2.0-or-later
26
27
28 @@ -150,26 +150,48 @@ REPO-ROOT is the location from which we start searching for Eclass files."
29 (when (file-exists-p repo-eclass)
30 (directory-files repo-eclass t ".*\\.eclass" t)))))
31
32 +(defvar company-ebuild--eclass-mtimes '()
33 + "Cache to prevent accessing eclasses multiple times.
34 +
35 +This is a global value holding a list of pairs.
36 +The key is an eclass path and the value is it's last modification time.
37 +This variable primarily is used in
38 +`company-ebuild--regenerate-dynamic-keywords-eclass'.")
39 +
40 +(defun company-ebuild--mtime (file-path)
41 + "Return the modification time of a file at FILE-PATH."
42 + (file-attribute-modification-time (file-attributes file-path)))
43 +
44 (defun company-ebuild--regenerate-dynamic-keywords-eclass ()
45 "Set new content of the ‘company-ebuild--dynamic-keywords’ Eclass variables."
46 (let ((repo-root
47 (company-ebuild--find-repo-root buffer-file-name)))
48 (when repo-root
49 - (let ((eclass-files
50 - (company-ebuild--find-eclass-files repo-root)))
51 - (mapc
52 - (lambda (eclass-file)
53 - (mapc (lambda (str)
54 - (add-to-list 'company-ebuild--dynamic-keywords-eclasses
55 - (replace-regexp-in-string "\\.eclass" "" str)))
56 - (company-ebuild--get-tags eclass-file "ECLASS"))
57 - (mapc (lambda (str)
58 - (add-to-list 'company-ebuild--dynamic-keywords-variables str))
59 - (company-ebuild--get-tags eclass-file "ECLASS_VARIABLE"))
60 - (mapc (lambda (str)
61 - (add-to-list 'company-ebuild--dynamic-keywords-functions str))
62 - (company-ebuild--get-tags eclass-file "FUNCTION")))
63 - eclass-files)))))
64 + (mapc
65 + (lambda (eclass-file)
66 + (let ((eclass-file-mtime
67 + (company-ebuild--mtime eclass-file)))
68 + (unless (equal (cdr (assoc eclass-file
69 + company-ebuild--eclass-mtimes))
70 + eclass-file-mtime)
71 + (assoc-delete-all eclass-file company-ebuild--eclass-mtimes)
72 + (push `(,eclass-file . ,eclass-file-mtime)
73 + company-ebuild--eclass-mtimes)
74 + (mapc (lambda (str)
75 + (add-to-list 'company-ebuild--dynamic-keywords-eclasses
76 + (replace-regexp-in-string "\\.eclass"
77 + ""
78 + str)))
79 + (company-ebuild--get-tags eclass-file "ECLASS"))
80 + (mapc (lambda (str)
81 + (add-to-list 'company-ebuild--dynamic-keywords-variables
82 + str))
83 + (company-ebuild--get-tags eclass-file "ECLASS_VARIABLE"))
84 + (mapc (lambda (str)
85 + (add-to-list 'company-ebuild--dynamic-keywords-functions
86 + str))
87 + (company-ebuild--get-tags eclass-file "FUNCTION")))))
88 + (company-ebuild--find-eclass-files repo-root)))))
89
90 (defun company-ebuild--regenerate-dynamic-keywords-use-flags ()
91 "Set new content of the ‘company-ebuild--dynamic-keywords-use-flags’ variable."