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.
This commit is contained in:
Glenn Morris 2012-06-22 00:38:26 -07:00
parent c5695d1d09
commit 575db3f1a8
2 changed files with 30 additions and 4 deletions

View file

@ -14,6 +14,11 @@
2012-06-22 Glenn Morris <rgm@gnu.org>
* 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.

View file

@ -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 (?).