0

My .emacs still uses old-style (pre MELPA, pre package.el) initializations.

Current (this works)

I'll use web-mode as a concrete example.

If I manually download web-mode.el and put it in ~/elisp, then start Emacs (25) with the .emacs file

(package-initialize)  ; Irrelevant here. Added by Emacs.
(setq load-path
      (cons "~/elisp" load-path))

(require 'web-mode)

(set-face-attribute 'web-mode-css-at-rule-face nil :foreground "magenta red")

all is well.

I'd like to change this .emacs to be able to use any machine+account without having to install manually an ~/elisp on each machine/account.

MELPA + package.el attempt (this doesn't work)

My attempt is:

(require 'package)

(add-to-list 'package-archives
             '("MELPA Stable" . "https://stable.melpa.org/packages/") t)

(package-initialize)

(custom-set-variables
 '(package-selected-packages
   (quote
    (web-mode))))

(set-face-attribute 'web-mode-css-at-rule-face nil :foreground "magenta red")

but this fails with

error: Invalid face, web-mode-css-at-rule-face

What am I doing wrong?

Update

When I run package-list-packages I see

web-mode: installed[1]

and so it appears that web-mode is installed.

I now have the impression from phil's comment that using package.el + MELPA may not actually spare me from having to download and install elisp packages manually. Please confirm one way or the other.

Post answer

It turns out that this change cannot be completely made. Too many packages are not on MELPA.

7
  • MELPA is a package archive and package.el a package manager, package-selected-packages can therefore not be a MELPA-specific thing.
    – wasamasa
    Commented Sep 3, 2017 at 12:13
  • Package web-mode was not loaded. Did you do (package-initialize)? It sounds like you have "installed" it but not loaded it.
    – Drew
    Commented Sep 3, 2017 at 14:56
  • @Drew Rewrote the question. Could you look again?
    – Calaf
    Commented Sep 3, 2017 at 17:19
  • Try putting package-initalize after your setting of package-selected-packages. The former activates autoloads provided by packages. If you don't tell it to choose package web-mode until after you tell it to activate the autoloads of installed packages, then perhaps that is your problem. Dunno.
    – Drew
    Commented Sep 3, 2017 at 18:25
  • @Drew Thanks, but that didn't help. Still the same error message.
    – Calaf
    Commented Sep 3, 2017 at 18:41

1 Answer 1

0

Untested, but I strongly suspect that what you need to do is:

(eval-after-load "web-mode"
  '(set-face-attribute 'web-mode-css-at-rule-face nil :foreground "magenta red"))

The web-mode package is evidentially installed, but it is not yet loaded, and so you were trying to use a face that is yet to be defined.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.