1 ;;; package-get.el --- Retrieve XEmacs package
3 ;; Copyright (C) 1998 by Pete Ware
5 ;; Author: Pete Ware <ware@cis.ohio-state.edu>
8 ;; This file is part of XEmacs.
10 ;; XEmacs is free software; you can redistribute it and/or modify it
11 ;; under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; XEmacs is distributed in the hope that it will be useful, but
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ;; General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 ;;; Synched up with: Not in FSF
30 ;; Retrieve a package and any other required packages from an archive
33 ;; A new XEmacs lisp-only release is generated with the following steps:
34 ;; 1. The maintainer runs some yet to be written program that
35 ;; generates all the dependency information. This should
36 ;; determine all the require and provide statements and associate
37 ;; them with a package.
38 ;; 2. All the packages are then bundled into their own tar balls
39 ;; (or whatever format)
40 ;; 3. Maintainer automatically generates a new `package-get-base'
41 ;; data structure which contains information such as the
42 ;; package name, the file to be retrieved, an md5 checksum,
43 ;; etc (see `package-get-base').
44 ;; 4. The maintainer posts an announcement with the new version
45 ;; of `package-get-base'.
46 ;; 5. A user/system manager saves this posting and runs
47 ;; `package-get-update' which uses the previously saved list
48 ;; of packages, `package-get-here' that the user/site
49 ;; wants to determine what new versions to download and
52 ;; A user/site manager can generate a new `package-get-here' structure
53 ;; by using `package-get-setup' which generates a customize like
54 ;; interface to the list of packages. The buffer looks something
57 ;; gnus - a mail and news reader
60 ;; [] Required by other [packages]
66 ;; [] Required by other [packages]
68 ;; Where `[]' indicates a toggle box
70 ;; - Clicking on "Always install" puts this into
71 ;; `package-get-here' list. "Needs updating" indicates a new
72 ;; version is available. Anything already in
73 ;; `package-get-here' has this enabled.
74 ;; - "Required by other" means some other packages are going to force
75 ;; this to be installed. Clicking on [packages] gives a list
76 ;; of packages that require this.
78 ;; The `package-get-base' should be installed in a file in
79 ;; `data-directory'. The `package-get-here' should be installed in
80 ;; site-lisp. Both are then read at run time.
83 ;; - Implement `package-get-setup'
84 ;; - Actually put `package-get-base' and `package-get-here' into
85 ;; files that are read.
86 ;; - Allow users to have their own packages that they want installed
88 ;; - SOMEONE needs to write the programs that generate the
89 ;; provides/requires database and makes it into a lisp data
90 ;; structure suitable for `package-get-base'
91 ;; - Handle errors such as no package providing a required symbol.
92 ;; - Tie this into the `require' function to download packages
99 (require 'package-admin)
100 ;; (require 'package-get-base)
102 (defgroup package-tools nil
103 "Tools to manipulate packages."
106 (defgroup package-get nil
107 "Automatic Package Fetcher and Installer."
108 :prefix "package-get"
109 :group 'package-tools)
111 (defvar package-get-base nil
112 "List of packages that are installed at this site.
113 For each element in the alist, car is the package name and the cdr is
114 a plist containing information about the package. Typical fields
115 kept in the plist are:
117 version - version of this package
118 provides - list of symbols provided
119 requires - list of symbols that are required.
120 These in turn are provided by other packages.
121 filename - name of the file.
122 size - size of the file (aka the bundled package)
123 md5sum - computed md5 checksum
124 description - What this package is for.
125 type - Whether this is a 'binary (default) or 'single file package
127 More fields may be added as needed. An example:
131 (version \"<version 2>\"
133 description \"what this package is about.\"
140 (version \"<version 1>\"
142 description \"what this package is about.\"
152 For version information, it is assumed things are listed in most
153 recent to least recent -- in other words, the version names don't have to
154 be lexically ordered. It is debatable if it makes sense to have more than
155 one version of a package available.")
157 (defcustom package-get-dir (temp-directory)
158 "*Where to store temporary files for staging."
159 :tag "Temporary directory"
163 ;; JV Any Custom expert know to get "Host" and "Dir" for the remote option
164 (defcustom package-get-remote
165 '(("ftp.xemacs.org" "/pub/xemacs/packages"))
166 "*List of remote sites to contact for downloading packages.
167 List format is '(site-name directory-on-site). Each site is tried in
168 order until the package is found. As a special case, `site-name' can be
169 `nil', in which case `directory-on-site' is treated as a local directory."
170 :tag "Package repository"
171 :type '(repeat (choice (list :tag "Local" (const :tag "Local" nil) directory )
172 (list :tag "Remote" string string) ))
175 (defcustom package-get-remove-copy nil
176 "*After copying and installing a package, if this is T, then remove the
177 copy. Otherwise, keep it around."
181 (defcustom package-get-base-filename
182 "/ftp.xemacs.org:/pub/xemacs/packages/package-index.LATEST"
183 "*Name of the default package database file, usually on ftp.xemacs.org."
188 (defun package-get-require-base ()
189 "Require that a package-get database has been loaded."
190 (when (or (not (boundp 'package-get-base))
191 (not package-get-base))
192 (package-get-update-base))
193 (when (or (not (boundp 'package-get-base))
194 (not package-get-base))
195 (error "Package-get database not loaded")))
197 (defconst package-get-pgp-signed-begin-line "^-----BEGIN PGP SIGNED MESSAGE-----"
198 "Text for start of PGP signed messages.")
199 (defconst package-get-pgp-signature-begin-line "^-----BEGIN PGP SIGNATURE-----"
200 "Text for beginning of PGP signature.")
201 (defconst package-get-pgp-signature-end-line "^-----END PGP SIGNATURE-----"
202 "Text for end of PGP signature.")
205 (defun package-get-update-base-entry (entry)
206 "Update an entry in `package-get-base'."
207 (let ((existing (assoc (car entry) package-get-base)))
209 (setcdr existing (cdr entry))
210 (setq package-get-base (cons entry package-get-base)))))
213 (defun package-get-update-base (&optional db-file)
214 "Update the package-get database file with entries from DB-FILE."
216 (read-file-name "Load package-get database: "
217 (file-name-directory package-get-base-filename)
218 package-get-base-filename
220 (file-name-nondirectory package-get-base-filename))))
221 (setq db-file (expand-file-name (or db-file package-get-base-filename)))
222 (if (not (file-exists-p db-file))
223 (error "Package-get database file `%s' does not exist" db-file))
224 (if (not (file-readable-p db-file))
225 (error "Package-get database file `%s' not readable" db-file))
226 (let ((buf (get-buffer-create "*package database*")))
231 (insert-file-contents-internal db-file)
232 (package-get-update-base-from-buffer buf))
236 (defun package-get-update-base-from-buffer (&optional buf)
237 "Update the package-get database with entries from BUFFER.
238 BUFFER defaults to the current buffer. This command can be
239 used interactively, for example from a mail or news buffer."
241 (setq buf (or buf (current-buffer)))
242 (let (content-beg content-end beg end)
245 (goto-char (point-min))
246 (setq content-beg (point))
247 (setq content-end (save-excursion (goto-char (point-max)) (point)))
248 (when (re-search-forward package-get-pgp-signed-begin-line nil t)
249 (setq beg (match-beginning 0))
250 (setq content-beg (match-end 0)))
251 (when (re-search-forward package-get-pgp-signature-begin-line nil t)
252 (setq content-end (match-beginning 0)))
253 (when (re-search-forward package-get-pgp-signature-end-line nil t)
255 (if (not (and content-beg content-end beg end))
256 (or (yes-or-no-p "Package-get entries not PGP signed, continue? ")
257 (error "Package-get database not updated")))
258 (if (and content-beg content-end beg end)
259 (if (not (condition-case nil
260 (or (fboundp 'mc-pgp-verify-region)
261 (load-library "mc-pgp")
262 (fboundp 'mc-pgp-verify-region))
265 "No mailcrypt; can't verify package-get DB signature, continue? ")
266 (error "Package-get database not updated"))))
268 (fboundp 'mc-pgp-verify-region)
271 (mc-pgp-verify-region beg end)
273 (and (string-match "No such file" (nth 2 err))
275 "Can't find PGP, continue without package-get DB verification? ")))
277 (error "Package-get PGP signature failed to verify"))
278 (package-get-update-base-entries content-beg content-end)
279 (message "Updated package-get database"))))
281 (defun package-get-update-base-entries (beg end)
282 "Update the package-get database with the entries found between
283 BEG and END in the current buffer."
286 (if (not (re-search-forward "^(package-get-update-base-entry" nil t))
287 (error "Buffer does not contain package-get database entries"))
290 (while (and (< (point) end)
291 (re-search-forward "^(package-get-update-base-entry" nil t))
293 (let ((entry (read (current-buffer))))
294 (if (or (not (consp entry))
295 (not (eq (car entry) 'package-get-update-base-entry)))
296 (error "Invalid package-get database entry found"))
297 (package-get-update-base-entry
298 (car (cdr (car (cdr entry)))))
299 (setq count (1+ count))))
300 (message "Got %d package-get database entries" count))))
302 (defun package-get-interactive-package-query (get-version package-symbol)
303 "Perform interactive querying for package and optional version.
304 Query for a version if GET-VERSION is non-nil. Return package name as
305 a symbol instead of a string if PACKAGE-SYMBOL is non-nil.
306 The return value is suitable for direct passing to `interactive'."
307 (package-get-require-base)
308 (let ( (table (mapcar '(lambda (item)
309 (let ( (name (symbol-name (car item))) )
313 package package-symbol default-version version)
314 (save-window-excursion
315 (setq package (completing-read "Package: " table nil t))
316 (setq package-symbol (intern package))
319 (setq default-version
320 (package-get-info-prop
321 (package-get-info-version
322 (package-get-info-find-package package-get-base
326 (setq version (read-string "Version: " default-version))
330 (list package-symbol version)
331 (list package version))
334 (list package-symbol)
339 (defun package-get-delete-package (package &optional pkg-topdir)
340 "Delete an installation of PACKAGE below directory PKG-TOPDIR.
341 PACKAGE is a symbol, not a string.
342 This is just an interactive wrapper for `package-admin-delete-binary-package'."
343 (interactive (package-get-interactive-package-query nil t))
344 (package-admin-delete-binary-package package pkg-topdir))
347 (defun package-get-update-all ()
348 "Fetch and install the latest versions of all currently installed packages."
350 (package-get-require-base)
353 (mapcar (lambda (pkg)
354 (if (not (package-get (car pkg) nil 'never))
355 (throw 'exit nil) ;; Bail out if error detected
357 packages-package-list)))
360 (defun package-get-all (package version &optional fetched-packages install-dir)
361 "Fetch PACKAGE with VERSION and all other required packages.
362 Uses `package-get-base' to determine just what is required and what
363 package provides that functionality. If VERSION is nil, retrieves
364 latest version. Optional argument FETCHED-PACKAGES is used to keep
365 track of packages already fetched. Optional argument INSTALL-DIR,
366 if non-nil, specifies the package directory where fetched packages
369 Returns nil upon error."
370 (interactive (package-get-interactive-package-query t nil))
371 (let* ((the-package (package-get-info-find-package package-get-base
373 (this-package (package-get-info-version
374 the-package version))
375 (this-requires (package-get-info-prop this-package 'requires))
378 (setq version (package-get-info-prop this-package 'version))
379 (unless (package-get-installedp package version)
380 (if (not (package-get package version nil install-dir))
382 (setq fetched-packages nil)
384 (setq fetched-packages
385 (append (list package)
386 (package-get-info-prop this-package 'provides)
388 ;; grab everything that this package requires plus recursively
389 ;; grab everything that the requires require. Keep track
390 ;; in `fetched-packages' the list of things provided -- this
391 ;; keeps us from going into a loop
393 (if (not (member (car this-requires) fetched-packages))
394 (let* ((reqd-package (package-get-package-provider
395 (car this-requires)))
396 (reqd-version (cadr reqd-package))
397 (reqd-name (car reqd-package)))
399 (error "Unable to find a provider for %s"
400 (car this-requires)))
401 (if (not (setq fetched-packages
402 (package-get-all reqd-name reqd-version
407 (setq this-requires (cdr this-requires)))
413 (defun package-get-dependencies (packages)
414 "Compute dependencies for PACKAGES.
415 Uses `package-get-base' to determine just what is required and what
416 package provides that functionality. Returns the list of packages
417 required by PACKAGES."
418 (package-get-require-base)
419 (let ((orig-packages packages)
420 dependencies provided)
422 (let* ((package (car packages))
423 (the-package (package-get-info-find-package
424 package-get-base package))
425 (this-package (package-get-info-version
427 (this-requires (package-get-info-prop this-package 'requires))
428 (new-depends (set-difference
431 (let* ((reqd-package (package-get-package-provider reqd))
432 (reqd-version (cadr reqd-package))
433 (reqd-name (car reqd-package)))
435 (error "Unable to find a provider for %s" reqd))
439 (this-provides (package-get-info-prop this-package 'provides)))
441 (union dependencies new-depends))
443 (union provided (union (list package) this-provides)))
445 (union new-depends (cdr packages)))))
446 (set-difference dependencies orig-packages)))
448 (defun package-get-load-package-file (lispdir file)
450 (setq pathname (expand-file-name file lispdir))
456 (message "Error loading package file \"%s\" %s!" pathname err)
460 (defun package-get-init-package (lispdir)
461 "Initialize the package.
462 This really assumes that the package has never been loaded. Updating
463 a newer package can cause problems, due to old, obsolete functions in
466 Return `t' upon complete success, `nil' if any errors occurred."
469 (file-accessible-directory-p lispdir))
471 ;; Add lispdir to load-path if it doesn't already exist.
472 ;; NOTE: this does not take symlinks, etc., into account.
473 (if (let ( (dirs load-path) )
476 (if (string-equal (car dirs) lispdir)
478 (setq dirs (cdr dirs))
481 (setq load-path (cons lispdir load-path)))
482 (if (not (package-get-load-package-file lispdir "auto-autoloads"))
483 (package-get-load-package-file lispdir "_pkg"))
489 (defun package-get (package &optional version conflict install-dir)
490 "Fetch PACKAGE from remote site.
491 Optional arguments VERSION indicates which version to retrieve, nil
492 means most recent version. CONFLICT indicates what happens if the
493 package is already installed. Valid values for CONFLICT are:
494 'always always retrieve the package even if it is already installed
495 'never do not retrieve the package if it is installed.
496 INSTALL-DIR, if non-nil, specifies the package directory where
497 fetched packages should be installed.
499 The value of `package-get-base' is used to determine what files should
500 be retrieved. The value of `package-get-remote' is used to determine
501 where a package should be retrieved from. The sites are tried in
502 order so one is better off listing easily reached sites first.
504 Once the package is retrieved, its md5 checksum is computed. If that
505 sum does not match that stored in `package-get-base' for this version
506 of the package, an error is signalled.
508 Returns `t' upon success, the symbol `error' if the package was
509 successfully installed but errors occurred during initialization, or
511 (interactive (package-get-interactive-package-query nil t))
513 (package-get-info-version
514 (package-get-info-find-package package-get-base
516 (this-requires (package-get-info-prop this-package 'requires))
518 (search-dirs package-get-remote)
519 (base-filename (package-get-info-prop this-package 'filename))
521 filenames full-package-filename)
522 (if (null this-package)
523 (error "Couldn't find package %s with version %s"
525 (if (null base-filename)
526 (error "No filename associated with package %s, version %s"
529 (package-admin-get-install-dir package install-dir
530 (or (eq package 'mule-base) (memq 'mule-base this-requires))))
532 ;; Contrive a list of possible package filenames.
533 ;; Ugly. Is there a better way to do this?
534 (setq filenames (cons base-filename nil))
535 (if (string-match "^\\(..*\\)\.tar\.gz$" base-filename)
536 (setq filenames (append filenames
537 (list (concat (match-string 1 base-filename)
540 (setq version (package-get-info-prop this-package 'version))
541 (unless (and (eq conflict 'never)
542 (package-get-installedp package version))
543 ;; Find the package from the search list in package-get-remote
544 ;; and copy it into the staging directory. Then validate
545 ;; the checksum. Finally, install the package.
547 (let (search-filenames current-dir-entry host dir current-filename
549 ;; In each search directory ...
551 (setq current-dir-entry (car search-dirs)
552 host (car current-dir-entry)
553 dir (car (cdr current-dir-entry))
554 search-filenames filenames
557 ;; Look for one of the possible package filenames ...
558 (while search-filenames
559 (setq current-filename (car search-filenames)
560 dest-filename (package-get-staging-dir current-filename))
562 ;; No host means look on the current system.
564 (setq full-package-filename
565 (substitute-in-file-name
566 (expand-file-name current-filename
567 (file-name-as-directory dir))))
570 ;; If it's already on the disk locally, and the size is
571 ;; greater than zero ...
572 ( (and (file-exists-p dest-filename)
574 ;; file-attributes could return -1 for LARGE files,
575 ;; but, hopefully, packages won't be that large.
576 (and (setq attrs (file-attributes dest-filename))
577 (> (nth 7 attrs) 0))))
578 (setq full-package-filename dest-filename)
581 ;; If the file exists on the remote system ...
582 ( (file-exists-p (package-get-remote-filename
583 current-dir-entry current-filename))
585 (setq full-package-filename dest-filename)
586 (message "Retrieving package `%s' ..."
589 (copy-file (package-get-remote-filename current-dir-entry
591 full-package-filename t)
595 ;; If we found it, we're done.
596 (if (and full-package-filename
597 (file-exists-p full-package-filename))
599 ;; Didn't find it. Try the next possible filename.
600 (setq search-filenames (cdr search-filenames))
602 ;; Try looking in the next possible directory ...
603 (setq search-dirs (cdr search-dirs))
607 (if (or (not full-package-filename)
608 (not (file-exists-p full-package-filename)))
609 (error "Unable to find file %s" base-filename))
610 ;; Validate the md5 checksum
611 ;; Doing it with XEmacs removes the need for an external md5 program
612 (message "Validating checksum for `%s'..." package) (sit-for 0)
614 ;; What ever happened to i-f-c-literally
615 (let (file-name-handler-alist)
616 (insert-file-contents-internal full-package-filename))
617 (if (not (string= (md5 (current-buffer))
618 (package-get-info-prop this-package
620 (error "Package %s does not match md5 checksum" base-filename)))
622 (package-admin-delete-binary-package package install-dir)
624 (message "Installing package `%s' ..." package) (sit-for 0)
626 (package-admin-add-binary-package full-package-filename
630 ;; clear messages so that only messages from
631 ;; package-get-init-package are seen, below.
633 (if (package-get-init-package (package-admin-get-lispdir
634 install-dir package))
636 (message "Added package `%s'" package)
640 ;; display message only if there isn't already one.
641 (if (not (current-message))
643 (message "Added package `%s' (errors occurred)"
648 (setq package-status 'errors))
651 (message "Installation of package %s failed." base-filename)
653 (switch-to-buffer package-admin-temp-buffer)
654 (setq package-status nil)
657 (if (and found package-get-remove-copy)
658 (delete-file full-package-filename))
662 (defun package-get-info-find-package (which name)
663 "Look in WHICH for the package called NAME and return all the info
664 associated with it. See `package-get-base' for info on the format
667 To access fields returned from this, use
668 `package-get-info-version' to return information about particular a
669 version. Use `package-get-info-find-prop' to find particular property
670 from a version returned by `package-get-info-version'."
671 (interactive "xPackage list: \nsPackage Name: ")
673 (if (eq (caar which) name)
676 (package-get-info-find-package (cdr which) name)))))
678 (defun package-get-info-version (package version)
679 "In PACKAGE, return the plist associated with a particular VERSION of the
680 package. PACKAGE is typically as returned by
681 `package-get-info-find-package'. If VERSION is nil, then return the
682 first (aka most recent) version. Use `package-get-info-find-prop'
683 to retrieve a particular property from the value returned by this."
684 (interactive (package-get-interactive-package-query t t))
685 (while (and version package (not (string= (plist-get (car package) 'version) version)))
686 (setq package (cdr package)))
687 (if package (car package)))
689 (defun package-get-info-prop (package-version property)
690 "In PACKAGE-VERSION, return the value associated with PROPERTY.
691 PACKAGE-VERSION is typically returned by `package-get-info-version'
692 and PROPERTY is typically (although not limited to) one of the
695 version - version of this package
696 provides - list of symbols provided
697 requires - list of symbols that are required.
698 These in turn are provided by other packages.
699 size - size of the bundled package
700 md5sum - computed md5 checksum"
701 (interactive "xPackage Version: \nSProperty")
702 (plist-get package-version property))
704 (defun package-get-info-version-prop (package-list package version property)
705 "In PACKAGE-LIST, search for PACKAGE with this VERSION and return
707 (package-get-info-prop
708 (package-get-info-version
709 (package-get-info-find-package package-list package) version) property))
711 (defun package-get-set-version-prop (package-list package version
713 "A utility to make it easier to add a VALUE for a specific PROPERTY
714 in this VERSION of a specific PACKAGE kept in the PACKAGE-LIST.
715 Returns the modified PACKAGE-LIST. Any missing fields are created."
718 (defun package-get-staging-dir (filename)
719 "Return a good place to stash FILENAME when it is retrieved.
720 Use `package-get-dir' for directory to store stuff.
721 Creates `package-get-dir' it it doesn't exist."
722 (interactive "FPackage filename: ")
723 (if (not (file-exists-p package-get-dir))
724 (make-directory package-get-dir))
726 (file-name-nondirectory (or (and (fboundp 'efs-ftp-path)
727 (nth 2 (efs-ftp-path filename)))
729 (file-name-as-directory package-get-dir)))
731 (defun package-get-remote-filename (search filename)
732 "Return FILENAME as a remote filename.
733 It first checks if FILENAME already is a remote filename. If it is
734 not, then it uses the (car search) as the remote site-name and the (cadr
735 search) as the remote-directory and concatenates filename. In other
737 site-name:remote-directory/filename
739 (if (efs-ftp-path filename)
741 (let ((dir (cadr search)))
744 (if (string-match "/$" dir)
750 (defun package-get-installedp (package version)
751 "Determine if PACKAGE with VERSION has already been installed.
752 I'm not sure if I want to do this by searching directories or checking
753 some built in variables. For now, use packages-package-list."
754 ;; Use packages-package-list which contains name and version
756 (package-get-info-find-package packages-package-list
758 (if (floatp version) version (string-to-number version))))
761 (defun package-get-package-provider (sym)
762 "Search for a package that provides SYM and return the name and
763 version. Searches in `package-get-base' for SYM. If SYM is a
764 consp, then it must match a corresponding (provide (SYM VERSION)) from
766 (interactive "SSymbol: ")
767 (package-get-require-base)
768 (let ((packages package-get-base)
771 (while (and (not done) packages)
772 (let* ((this-name (caar packages))
773 (this-package (cdr (car packages)))) ;strip off package name
774 (while (and (not done) this-package)
775 (if (or (eq this-name sym)
777 (package-get-info-prop (car this-package) 'version))
779 (member sym (package-get-info-prop (car this-package) 'provides)))
781 (setq found (list (caar packages)
782 (package-get-info-prop (car this-package) 'version))))
783 (setq this-package (cdr this-package)))))
784 (setq packages (cdr packages)))
788 ;; customize interfaces.
789 ;; The group is in this file so that custom loads includes this file.
791 (defgroup packages nil
792 "Configure XEmacs packages."
796 (defun package-get-custom ()
797 "Fetch and install the latest versions of all customized packages."
799 (package-get-require-base)
801 (load "package-get-custom.el")
802 (mapcar (lambda (pkg)
803 (if (eval (intern (concat (symbol-name (car pkg)) "-package")))
804 (package-get-all (car pkg) nil))
808 (defun package-get-ever-installed-p (pkg &optional notused)
809 (string-match "-package$" (symbol-name pkg))
810 (custom-initialize-set
812 (if (package-get-info-find-package
813 packages-package-list
814 (intern (substring (symbol-name pkg) 0 (match-beginning 0))))
817 (defun package-get-file-installed-p (file &optional paths)
818 "Return absolute-path of FILE if FILE exists in PATHS.
819 If PATHS is omitted, `load-path' is used."
821 (setq paths load-path)
826 (setq path (expand-file-name file (car paths)))
827 (if (file-exists-p path)
830 (setq paths (cdr paths))
833 (defun package-get-create-custom ()
834 "Creates a package customization file package-get-custom.el.
835 Entries in the customization file are retrieved from package-get-base.el."
838 (let ((custom-buffer (find-file-noselect
839 (or (package-get-file-installed-p
840 "package-get-custom.el")
842 "package-get-custom.el"
844 (package-get-file-installed-p
845 "package-get-base.el"))
849 ;; clear existing stuff
850 (delete-region (point-min custom-buffer)
851 (point-max custom-buffer) custom-buffer)
852 (insert-string "(require 'package-get)\n" custom-buffer)
854 (mapcar (lambda (pkg)
855 (let ((category (plist-get (car (cdr pkg)) 'category)))
856 (or (memq (intern category) pkg-groups)
858 (setq pkg-groups (cons (intern category) pkg-groups))
860 (concat "(defgroup " category "-packages nil\n"
861 " \"" category " package group\"\n"
862 " :group 'packages)\n\n") custom-buffer)))
865 (concat "(defcustom " (symbol-name (car pkg))
867 " \"" (plist-get (car (cdr pkg)) 'description) "\"\n"
868 " :group '" category "-packages\n"
869 " :initialize 'package-get-ever-installed-p\n"
870 " :type 'boolean)\n\n") custom-buffer)))
871 package-get-base) custom-buffer)
874 ;; need this first to avoid infinite dependency loops
875 (provide 'package-get)
877 ;; potentially update the custom dependencies every time we load this
878 (when nil ;; #### disable for now... -gk
879 (unless noninteractive
880 (let ((custom-file (package-get-file-installed-p "package-get-custom.el"))
881 (package-file (package-get-file-installed-p "package-get-base.el")))
882 ;; update custom file if it doesn't exist
883 (if (or (not custom-file)
884 (and (< (car (nth 5 (file-attributes custom-file)))
885 (car (nth 5 (file-attributes package-file))))
886 (< (car (nth 5 (file-attributes custom-file)))
887 (car (nth 5 (file-attributes package-file))))))
889 (message "generating package customizations...")
890 (set-buffer (package-get-create-custom))
892 (message "generating package customizations...done")))
893 (load "package-get-custom.el")))
896 ;;; package-get.el ends here