emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/emacs-24 r108680: Further speed up rpm comp


From: Glenn Morris
Subject: [Emacs-diffs] /srv/bzr/emacs/emacs-24 r108680: Further speed up rpm completion, by caching the installed packages
Date: Fri, 02 Nov 2012 02:20:39 -0000
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 108680
committer: Glenn Morris <address@hidden>
branch nick: trunk
timestamp: Fri 2012-06-22 00:38:26 -0700
message:
  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.
modified:
  lisp/ChangeLog
  lisp/pcmpl-rpm.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2012-06-22 07:30:33 +0000
+++ b/lisp/ChangeLog    2012-06-22 07:38:26 +0000
@@ -14,6 +14,11 @@
 
 2012-06-22  Glenn Morris  <address@hidden>
 
+       * 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.

=== modified file 'lisp/pcmpl-rpm.el'
--- a/lisp/pcmpl-rpm.el 2012-06-22 07:01:32 +0000
+++ b/lisp/pcmpl-rpm.el 2012-06-22 07:38:26 +0000
@@ -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 (?).


reply via email to

[Prev in Thread] Current Thread [Next in Thread]