From 575db3f1a8c6978df9d69f49dedd1bff15c73a9d Mon Sep 17 00:00:00 2001 From: Glenn Morris Date: Fri, 22 Jun 2012 00:38:26 -0700 Subject: [PATCH] Further speed up rpm completion, by caching the installed packages * lisp/pcmpl-rpm.el (pcmpl-rpm-cache): New option. (pcmpl-rpm-cache-stamp-file): New constant. (pcmpl-rpm-cache-time, pcmpl-rpm-packages): New variables. (pcmpl-rpm-packages): Optionally cache list of packages. --- lisp/ChangeLog | 5 +++++ lisp/pcmpl-rpm.el | 29 +++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 1119a52c451..50950a25b5d 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -14,6 +14,11 @@ 2012-06-22 Glenn Morris + * pcmpl-rpm.el (pcmpl-rpm-cache): New option. + (pcmpl-rpm-cache-stamp-file): New constant. + (pcmpl-rpm-cache-time, pcmpl-rpm-packages): New variables. + (pcmpl-rpm-packages): Optionally cache list of packages. + * pcmpl-rpm.el (pcmpl-rpm): New group. (pcmpl-rpm-query-options): New option. (pcmpl-rpm-packages): No need to inline it. diff --git a/lisp/pcmpl-rpm.el b/lisp/pcmpl-rpm.el index 6347666507b..12fce363804 100644 --- a/lisp/pcmpl-rpm.el +++ b/lisp/pcmpl-rpm.el @@ -48,16 +48,37 @@ :type '(repeat string) :group 'pcmpl-rpm) +(defcustom pcmpl-rpm-cache t + "Whether to cache the list of installed packages." + :version "24.2" + :type 'boolean + :group 'pcmpl-rpm) + +(defconst pcmpl-rpm-cache-stamp-file "/var/lib/rpm/Packages" + "File used to check that the list of installed packages is up-to-date.") + +(defvar pcmpl-rpm-cache-time nil + "Time at which the list of installed packages was updated.") + +(defvar pcmpl-rpm-packages nil + "List of installed packages.") + ;; Functions: -;; TODO ;; This can be slow, so: -;; Consider caching the result (cf woman). ;; Consider printing an explanatory message before running -qa. (defun pcmpl-rpm-packages () "Return a list of all installed rpm packages." - (split-string (apply 'pcomplete-process-result "rpm" - (append '("-q" "-a") pcmpl-rpm-query-options)))) + (if (and pcmpl-rpm-cache + pcmpl-rpm-cache-time + (let ((mtime (nth 5 (file-attributes pcmpl-rpm-cache-stamp-file)))) + (and mtime (not (time-less-p pcmpl-rpm-cache-time mtime))))) + pcmpl-rpm-packages + (setq pcmpl-rpm-cache-time (current-time) + pcmpl-rpm-packages + (split-string (apply 'pcomplete-process-result "rpm" + (append '("-q" "-a") + pcmpl-rpm-query-options)))))) ;; Should this use pcmpl-rpm-query-options? ;; I don't think it would speed it up at all (?). -- 2.39.2