diff options
Diffstat (limited to 'emacs/guix-main.scm')
-rw-r--r-- | emacs/guix-main.scm | 95 |
1 files changed, 46 insertions, 49 deletions
diff --git a/emacs/guix-main.scm b/emacs/guix-main.scm index 2be86f026b..e645a85e7d 100644 --- a/emacs/guix-main.scm +++ b/emacs/guix-main.scm @@ -32,14 +32,6 @@ ;; still "name-version" string. So ‘id’ package parameter in the code ;; below is either an object-address number or a full-name string. -;; To speed-up the process of getting information, the following -;; auxiliary variables are used: -;; -;; - `%packages' - VHash of "package address"/"package" pairs. -;; -;; - `%package-table' - Hash table of -;; "name+version key"/"list of packages" pairs. - ;;; Code: (use-modules @@ -101,38 +93,6 @@ return two values: name and version. For example, for SPEC (string-append full-name ":" output) full-name))) -(define name+version->key cons) -(define key->name+version car+cdr) - -(define %package-vhash - (delay - (fold-packages (lambda (pkg res) - (vhash-consq (object-address pkg) pkg res)) - vlist-null))) - -(define (package-vhash) - "Return vhash of 'package ID (address)'/'package' pairs." - (force %package-vhash)) - -(define %package-table - (delay - (let ((table (make-hash-table (vlist-length (package-vhash))))) - (vlist-for-each - (lambda (elem) - (match elem - ((address . pkg) - (let* ((key (name+version->key (package-name pkg) - (package-version pkg))) - (ref (hash-ref table key))) - (hash-set! table key - (if ref (cons pkg ref) (list pkg))))))) - (package-vhash)) - table))) - -(define (package-table) - "Return hash table of 'name+version key'/'list of packages' pairs." - (force %package-table)) - (define (manifest-entry->name+version+output entry) (values (manifest-entry-name entry) @@ -340,15 +300,39 @@ Example: ;;; Finding packages. -(define (package-by-address address) - (match (vhash-assq address (package-vhash)) - ((_ . package) package) - (_ #f))) - -(define (packages-by-name+version name version) - (or (hash-ref (package-table) - (name+version->key name version)) - '())) +(define-values (package-by-address + register-package) + (let ((table (delay (fold-packages + (lambda (package table) + (vhash-consq (object-address package) + package table)) + vlist-null)))) + (values + (lambda (address) + "Return package by its object ADDRESS." + (match (vhash-assq address (force table)) + ((_ . package) package) + (_ #f))) + (lambda (package) + "Register PACKAGE by its 'object-address', so that later +'package-by-address' can be used to access it." + (let ((table* (force table))) + (set! table + (delay (vhash-consq (object-address package) + package table*)))))))) + +(define packages-by-name+version + (let ((table (delay (fold-packages + (lambda (package table) + (let ((file (location-file + (package-location package)))) + (vhash-cons (cons (package-name package) + (package-version package)) + package table))) + vlist-null)))) + (lambda (name version) + "Return packages matching NAME and VERSION." + (vhash-fold* cons '() (cons name version) (force table))))) (define (packages-by-full-name full-name) (call-with-values @@ -435,6 +419,15 @@ MATCH-PARAMS is a list of parameters that REGEXP can match." '() (find-newest-available-packages))) +(define (packages-from-file file) + "Return a list of packages from FILE." + (let ((package (load (canonicalize-path file)))) + (if (package? package) + (begin + (register-package package) + (list package)) + '()))) + ;;; Making package/output patterns. @@ -687,6 +680,8 @@ ENTRIES is a list of installed manifest entries." (lookup-license license-name)))) (location-proc (lambda (_ location) (packages-by-location-file location))) + (file-proc (lambda (_ file) + (packages-from-file file))) (all-proc (lambda _ (all-available-packages))) (newest-proc (lambda _ (newest-available-packages)))) `((package @@ -697,6 +692,7 @@ ENTRIES is a list of installed manifest entries." (regexp . ,regexp-proc) (license . ,license-proc) (location . ,location-proc) + (from-file . ,file-proc) (all-available . ,all-proc) (newest-available . ,newest-proc)) (output @@ -707,6 +703,7 @@ ENTRIES is a list of installed manifest entries." (regexp . ,regexp-proc) (license . ,license-proc) (location . ,location-proc) + (from-file . ,file-proc) (all-available . ,all-proc) (newest-available . ,newest-proc))))) |