summaryrefslogtreecommitdiff
path: root/lisp/pcmpl-rpm.el
diff options
context:
space:
mode:
authorGlenn Morris <rgm@gnu.org>2012-06-22 00:38:26 -0700
committerGlenn Morris <rgm@gnu.org>2012-06-22 00:38:26 -0700
commit575db3f1a8c6978df9d69f49dedd1bff15c73a9d (patch)
treec7656593664eb1dc1065065ccfee84e663deac4c /lisp/pcmpl-rpm.el
parentc5695d1d098bc4f275cfe4b4492a70779a06de02 (diff)
downloademacs-575db3f1a8c6978df9d69f49dedd1bff15c73a9d.tar.gz
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.
Diffstat (limited to 'lisp/pcmpl-rpm.el')
-rw-r--r--lisp/pcmpl-rpm.el29
1 files changed, 25 insertions, 4 deletions
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 (?).