public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Maciej Barć" <xgqt@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/company-ebuild:master commit in: /
Date: Tue, 30 Aug 2022 18:22:45 +0000 (UTC)	[thread overview]
Message-ID: <1661883691.bfb0fac0258f2fb2e561e7066378ecf88e84d413.xgqt@gentoo> (raw)

commit:     bfb0fac0258f2fb2e561e7066378ecf88e84d413
Author:     Maciej Barć <xgqt <AT> gentoo <DOT> org>
AuthorDate: Tue Aug 30 18:21:31 2022 +0000
Commit:     Maciej Barć <xgqt <AT> gentoo <DOT> org>
CommitDate: Tue Aug 30 18:21:31 2022 +0000
URL:        https://gitweb.gentoo.org/proj/company-ebuild.git/commit/?id=bfb0fac0

company-ebuild.el: cache eclasses

Signed-off-by: Maciej Barć <xgqt <AT> gentoo.org>

 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."


             reply	other threads:[~2022-08-30 18:22 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-30 18:22 Maciej Barć [this message]
  -- strict thread matches above, loose matches on Subject: below --
2023-06-18 20:22 [gentoo-commits] proj/company-ebuild:master commit in: / Maciej Barć
2023-06-18 20:19 Maciej Barć
2023-06-18 20:15 Maciej Barć
2023-04-25 19:48 Maciej Barć
2023-04-25 19:38 Maciej Barć
2023-03-11  8:17 Maciej Barć
2023-02-03 13:50 Maciej Barć
2023-01-29 20:26 Maciej Barć
2022-12-13 10:44 Maciej Barć
2022-12-02  0:40 Maciej Barć
2022-12-02  0:38 Maciej Barć
2022-08-30 22:22 Maciej Barć
2022-08-30 18:22 Maciej Barć
2022-08-30 18:22 Maciej Barć
2022-08-25 23:17 Maciej Barć
2022-08-25 23:00 Maciej Barć
2022-08-25 23:00 Maciej Barć
2022-08-20 13:06 Maciej Barć
2022-08-17 15:23 Maciej Barć
2022-08-17 15:21 Maciej Barć
2022-08-17 15:19 Maciej Barć
2022-08-17 15:19 Maciej Barć
2022-08-17 15:19 Maciej Barć
2022-08-17  1:54 Maciej Barć
2022-08-17  1:54 Maciej Barć
2022-08-17  0:37 Maciej Barć
2022-08-17  0:31 Maciej Barć
2022-08-16 23:50 Maciej Barć
2022-08-16 23:50 Maciej Barć
2022-08-16 23:50 Maciej Barć
2022-08-16 23:50 Maciej Barć
2022-08-16 23:50 Maciej Barć
2022-08-16 23:50 Maciej Barć
2022-08-16 20:31 Maciej Barć
2022-08-16 20:28 Maciej Barć
2022-08-16 20:28 Maciej Barć

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1661883691.bfb0fac0258f2fb2e561e7066378ecf88e84d413.xgqt@gentoo \
    --to=xgqt@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox