Subject: bug#9798: 24.0.50; M-x package-install fails on fresh install without package-refresh-contents.

From: Phil Hagelberg <[email-masked]>
Date: Wed, 19 Oct 2011 11:21:38 -0700

If you start a fresh Emacs config with an empty ~/.emacs.d/elpa
directory, calling M-x package-install ANY-PACKAGE will fail since the
archive sources haven't been fetched yet. M-x package-list-packages will
work, but sometimes the simpler form is preferred.

The attached patch fixes this problem.

In GNU Emacs 24.0.50.1 (x86_64-unknown-linux-gnu, GTK+ Version 2.24.4)
 of 2011-09-26 on enigma
Windowing system distributor `The X.Org Foundation', version 11.0.11001000
Important settings:
  value of $LC_ALL: nil
  value of $LC_COLLATE: nil
  value of $LC_CTYPE: nil
  value of $LC_MESSAGES: en_US.utf8
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: nil
  value of $LANG: en_US.utf8
  value of $XMODIFIERS: nil
  locale-coding-system: utf-8-unix
  default enable-multibyte-characters: t

Major mode: EShell

Minor modes in effect:
  recentf-mode: t
  diff-auto-refine-mode: t
  ido-ubiquitous: t
  show-paren-mode: t
  mouse-wheel-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent input:
<return> y M-< C-s e n i g m a C-s C-s C-s M-b C-SPC 
C-e C-b C-g C-n C-n C-n C-n C-n C-n C-n C-n C-n C-l 
M-< C-v C-v M-< C-s p a c k a g e C-s C-s C-a C-p C-p 
C-n C-SPC C-n C-n C-n C-n C-n C-n M-w C-x k <return> 
y M-> C-x o M-< C-c v C-v M-< C-x o M-x r e p <ret
urn>

Recent messages:
Mark saved where search started
Mark set
Quit
Mark set [2 times]
Mark saved where search started
Mark set
Buffer *unsent mail to [email-masked]* modified; kill anyway? (y or n)  y
Mark set [2 times]
eval-buffer: Symbol's value as variable is void: gnus-secondary-select-methods
Mark set

Load-path shadows:
/home/phil/.emacs.d/elpa/htmlfontify-0.21/htmlfontify hides /usr/local/share/emacs/24.0.50/lisp/htmlfontify

Features:
(multi-isearch rfc2104 rot13 gnutls network-stream starttls tls
mailalias smtpmail auth-source eieio byte-opt bytecomp byte-compile
cconv macroexp password-cache vc-git cus-edit cus-start cus-load
sendmail mailcap recentf tree-widget wid-edit pcmpl-unix newcomment
help-mode view shadow sort regexp-opt flyspell ispell gnus-util
mail-extr message format-spec rfc822 mml mml-sec mm-decode mm-bodies
mm-encode mail-parse rfc2231 rfc2047 rfc2045 ietf-drums mm-util
mail-prsvr mailabbrev mail-utils gmm-utils mailheader emacsbug magit
diff-mode log-edit easymenu easy-mmode pcvs-util add-log magit-key-mode
assoc ffap paredit hl-line saveplace idle-highlight-mode thingatpt
ansi-color em-unix em-script em-ls em-hist em-pred em-glob em-dirs
em-basic em-cmpl em-term term disp-table ehelp electric em-prompt
esh-opt em-banner em-alias clojure-test-mode-autoloads
clojurescript-mode-autoloads color-theme-twilight-autoloads
color-theme-zenburn-autoloads color-theme-autoloads durendal-autoloads
clojure-mode-autoloads elisp-slime-nav-autoloads erc-hl-nicks-autoloads
highlight-parentheses-autoloads htmlize-autoloads
idle-highlight-autoloads ido-yes-or-no-autoloads finder-inf
markdown-mode-autoloads marmalade-autoloads furl-autoloads
oddmuse-autoloads pp-c-l-autoloads scpaste-autoloads
htmlfontify-autoloads slime-repl-autoloads slime-autoloads
starter-kit-bindings-autoloads windmove starter-kit-eshell-autoloads
starter-kit-lisp-autoloads starter-kit-autoloads ring esh-var esh-io
esh-cmd esh-ext esh-proc esh-arg eldoc esh-groups eshell esh-module
esh-mode smex starter-kit-misc ido-ubiquitous ido paren
starter-kit-defuns uniquify advice help-fns advice-preload
magit-autoloads ido-ubiquitous-autoloads smex-autoloads
find-file-in-project-autoloads idle-highlight-mode-autoloads
paredit-autoloads tuareg-autoloads windresize-autoloads
yaml-mode-autoloads package tabulated-list pcmpl-lein esh-util pcomplete
edmacro kmacro cl time-date tooltip ediff-hook vc-hooks lisp-float-type
mwheel x-win x-dnd tool-bar dnd fontset image fringe lisp-mode register
page menu-bar rfn-eshadow timer select scroll-bar mouse jit-lock
font-lock syntax facemenu font-core frame cham georgian utf-8-lang
misc-lang vietnamese tibetan thai tai-viet lao korean japanese hebrew
greek romanian slovak czech european ethiopic indian cyrillic chinese
case-table epa-hook jka-cmpr-hook help simple abbrev minibuffer loaddefs
button faces cus-face files text-properties overlay sha1 md5 base64
format env code-pages mule custom widget hashtable-print-readable
backquote make-network-process dbusbind dynamic-setting
system-font-setting font-render-setting move-toolbar gtk x-toolkit x
multi-tty emacs)
>From f8297c8d43fd8bb4a04fe4fac7d086648cb38f78 Mon Sep 17 00:00:00 2001
From: Phil Hagelberg <[email-masked]>
Date: Tue, 11 Oct 2011 20:31:03 -0700
Subject: [PATCH] Call package-refresh-contents in package-install if contents is nil.

Currently on the first run M-x package-install will fail.
---
 lisp/emacs-lisp/package.el |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index 2e340a4..a084d24 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -871,6 +871,8 @@ archive in `package-archives'.  Interactively, prompt for NAME."
      ;; symbols for completion.
      (unless package--initialized
        (package-initialize t))
+     (unless package-archive-contents
+       (package-refresh-contents))
      (list (intern (completing-read
 		    "Install package: "
 		    (mapcar (lambda (elt)
-- 
1.7.4.1