1

I use a function, ensure-packages-installed to "bootstrap" packages in my .emacs file. This ensures that if the package isn't already install. The follow is at the top of my .emacs:

;
; Set up Emacs package system.
;
(require 'package)
;(add-to-list 'package-archives
;             '("elpa" . "http://elpa.gnu.org/packages"))
(add-to-list 'package-archives
             '("melpa" . "http://melpa.org/packages/"))
;(add-to-list 'package-archives
;             '("marmalade" . "https://marmalade-repo.org/packages/") t)
(package-initialize)

; fetch the list of packages available
(or (file-exists-p package-user-dir)
  (package-refresh-contents))

(defun ensure-packages-installed (&rest packages)
  (mapcar (lambda (package)
    (unless (package-installed-p package)
      (package-install package))) packages))

(ensure-packages-installed
  'company-mode
  'exec-path-from-shell
  'evil
  'haskell-mode
  'intero
  'idris-mode
  'org
  'projectile
  'solarized-theme
  )

However, when I add company-mode to the list it, I get the following error:

Warning (initialization): An error occurred while loading `/Users/steshaw/.emacs':

error: Package `company-mode-' is unavailable

To ensure normal operation, you should investigate and remove the
cause of the error in your initialization file.  Start Emacs with
the `--debug-init' option to view a complete error backtrace.
  • 2
    Is the package name company-mode or just company? – Melioratus Sep 9 '16 at 4:38
  • 1
    Yes, company seems to work. It's not mentioned on their website AFAICS. Is this a common emacs package naming convention? i.e. <package> for the package and <package>-mode for the function to enable the package? – Steven Shaw Sep 9 '16 at 6:21
  • Yes I think package is the standard based on examples I read on how to set buffer mode using local variables. – Melioratus Sep 9 '16 at 15:37
4

You need to use company instead of company-mode.

  • Thanks for the update @Dan. As far as I can work out, it's rather strange to name the package in this way. Quite unfortunate and not mentioned on their website :(. BTW, I used to love Scheme and Common Lisp (because it was fast) but I'd recommend taking a leap into Haskell and Idris. I think you'd enjoy the ride! – Steven Shaw Sep 9 '16 at 15:07
  • 1
    @StevenShaw: no worries. I don't use company, but I agree that it's a little odd that it wouldn't be company-mode in this setting. I updated this post because Community was flagging it as low quality due to length. – Dan Sep 9 '16 at 15:52
  • Ah, ok. I'm only just getting a taste of how Stackexchange works behind the scenes. It doesn't seem to be all good. – Steven Shaw Sep 9 '16 at 15:57
1

You should consider using use-package. It would look like:

(use-package company :ensure t :pin melpa)

  • Does use-package replace my "custom" (aka copied from the interwebs) ensure-packages-installed? I figure that's what :ensure t does. What's :pin melpa for? – Steven Shaw Sep 9 '16 at 14:44
  • 1
    It specifies the repository from which you want to download the package. But you can do far more with use-package. Take a look at github.com/jwiegley/use-package. – bertfred Sep 9 '16 at 14:50
  • Oh thanks, that does look nice. The missing packager (aka package management system) that I've been looking for! I felt kind of dirty having a half-baked packager in my ~/.emacs. Any more tips to modernise my Emacs usage? I'm considering a complete jump to Spacemacs. Just installed it today. Seems very well thought out so far. – Steven Shaw Sep 9 '16 at 15:03
  • 1
    I don't know anything about spacemacs. However in terms of organizing your .emacs you should try an org-mode based config. Watch this video youtube.com/watch?v=VIuOwIBL-ZU. – bertfred Sep 9 '16 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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