diff options
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/ChangeLog | 5 | ||||
-rw-r--r-- | 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 <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. 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 (?). |