]> code.delx.au - gnu-emacs/blobdiff - lisp/emacs-lisp/package.el
emacs-lisp/package.el (package-dir-info): Fix `while' logic.
[gnu-emacs] / lisp / emacs-lisp / package.el
index 78138e9ebcdb0ee3a299b141be14330ec818383b..88fc950ee219c2a88b1d992e7f28f570ee185025 100644 (file)
@@ -239,7 +239,8 @@ selected. When higher versions are available from archives with
 lower priorities, the user has to select those manually.
 
 Archives not in this list have the priority 0."
-  :type 'integer
+  :type '(alist :key-type (string :tag "Archive name")
+                :value-type (integer :tag "Priority (default is 0)"))
   :risky t
   :group 'package
   :version "25.1")
@@ -413,6 +414,7 @@ Slots:
   (pcase (package-desc-kind pkg-desc)
     (`single ".el")
     (`tar ".tar")
+    (`dir "")
     (kind (error "Unknown package kind: %s" kind))))
 
 (defun package-desc--keywords (pkg-desc)
@@ -939,6 +941,9 @@ GnuPG keyring is located under \"gnupg\" in `package-user-dir'."
 
 (defun package-install-from-archive (pkg-desc)
   "Download and install a tar package."
+  ;; This won't happen, unless the archive is doing something wrong.
+  (when (eq (package-desc-kind pkg-desc) 'dir)
+    (error "Can't install directory package from archive"))
   (let* ((location (package-archive-base pkg-desc))
         (file (concat (package-desc-full-name pkg-desc)
                       (package-desc-suffix pkg-desc)))
@@ -1149,13 +1154,15 @@ Also, add the originating archive to the `package-desc' structure."
     (when (not (and pinned-to-archive
                     (not (equal (cdr pinned-to-archive) archive))))
       (setq package-archive-contents
-            (package--add-to-alist pkg-desc package-archive-contents)))))
+            (package--append-to-alist pkg-desc package-archive-contents)))))
 
-(defun package--add-to-alist (pkg-desc alist)
-  "Add PKG-DESC to ALIST.
+(defun package--append-to-alist (pkg-desc alist)
+  "Append an entry for PKG-DESC to the start of ALIST and return it.
+This entry takes the form (`package-desc-name' PKG-DESC).
 
-Packages are grouped by name. The package descriptions are sorted
-by version number."
+If ALIST already has an entry with this name, destructively add
+PKG-DESC to the cdr of this entry instead, sorted by version
+number."
   (let* ((name (package-desc-name pkg-desc))
          (priority-version (package-desc-priority-version pkg-desc))
          (existing-packages (assq name alist)))
@@ -1309,9 +1316,14 @@ The return result is a `package-desc'."
         (while files
           (with-temp-buffer
             (insert-file-contents (pop files))
-            (if (setq info (ignore-errors (package-buffer-info)))
-                (setq files nil)
-              (setf (package-desc-kind info) 'dir))))))))
+            ;; When we find the file with the data,
+            (when (setq info (ignore-errors (package-buffer-info)))
+              ;; stop looping,
+              (setq files nil)
+              ;; set the 'dir kind,
+              (setf (package-desc-kind info) 'dir))))
+        ;; and return the info.
+        info))))
 
 (defun package--read-pkg-desc (kind)
   "Read a `define-package' form in current buffer.
@@ -1368,8 +1380,12 @@ Downloads and installs required packages as needed."
 The file can either be a tar file or an Emacs Lisp file."
   (interactive "fPackage file name: ")
   (with-temp-buffer
-    (insert-file-contents-literally file)
-    (when (string-match "\\.tar\\'" file) (tar-mode))
+    (if (file-directory-p file)
+        (progn
+          (setq default-directory file)
+          (dired-mode))
+      (insert-file-contents-literally file)
+      (when (string-match "\\.tar\\'" file) (tar-mode)))
     (package-install-from-buffer)))
 
 (defun package-delete (pkg-desc)
@@ -2091,7 +2107,7 @@ If optional arg BUTTON is non-nil, describe its associated package."
         (cond ((member status '("installed" "unsigned"))
                (push pkg-desc installed))
               ((member status '("available" "new"))
-               (setq available (package--add-to-alist pkg-desc available))))))
+               (setq available (package--append-to-alist pkg-desc available))))))
     ;; Loop through list of installed packages, finding upgrades.
     (dolist (pkg-desc installed)
       (let* ((name (package-desc-name pkg-desc))