5

I'm trying to setup robe for Rails development. It needs company mode and I have some issues with it: Have following in init.el:

;; robe, documentation lookup and completion for Ruby
(require 'robe)
(add-hook 'ruby-mode-hook 'robe-mode)
(add-to-list 'load-path "./elpa/company-20150306.1548/")
(autoload 'company-mode "company" nil t)
(add-hook 'after-init-hook 'global-company-mode)
(push 'company-robe company-backends)
;; end robe setup

It raises:

Symbol's value as variable is void: company-backends

Full error trace is:

Debugger entered--Lisp error: (void-variable company-backends)
  (cons (quote company-robe) company-backends)
  (setq company-backends (cons (quote company-robe) company-backends))
  eval-buffer(#<buffer  *load*> nil "/home/me/.emacs.d/init.el" nil t)  ; Reading at buffer position 3073
  load-with-code-conversion("/home/me/.emacs.d/init.el" "/home/me/.emacs.d/init.el" t t)
  load("/home/me/.emacs.d/init" t t)
  #[0 "\205\262 \306=\203\307\310Q\202; \311=\204\307\312Q\202;\313\307\314\315#\203*\316\202;\313\307\314\317#\203:\320\nB\321\202;\316\322\323\322\211#\210\322=\203a\324\325\326\307\327Q!\"\323\322\211#\210\322=\203`\210\203\243\330!\331\232\203\243\332!\211\333P\334!\203}\211\202\210\334!\203\207\202\210\314\262\203\241\335\"\203\237\336\337#\210\340\341!\210\266\f?\205\260\314\323\342\322\211#)\262\207" [init-file-user system-type delayed-warnings-list user-init-file inhibit-default-init inhibit-startup-screen ms-dos "~" "/_emacs" windows-nt "/.emacs" directory-files nil "^\\.emacs\\(\\.elc?\\)?$" "~/.emacs" "^_emacs\\(\\.elc?\\)?$" (initialization "`_emacs' init file is deprecated, please use `.emacs'") "~/_emacs" t load expand-file-name "init" file-name-as-directory "/.emacs.d" file-name-extension "elc" file-name-sans-extension ".el" file-exists-p file-newer-than-file-p message "Warning: %s is newer than %s" sit-for 1 "default"] 7 "\n\n(fn)"]()
  command-line()
  normal-top-level()

I'm newbie in Emacs world and I can't figure out why company-backends is void? I doubt that somewhere it is not set and I should set it to myself but I can't find the way to do this.

Edit

  • Emacs version is GNU Emacs 24.3.1 (x86_64-pc-linux-gnu, GTK+ Version 3.10.7) of 2014-03-07 on lamiak, modified by Debian on Ubuntu 14.04.1
foki
  • 886
  • 8
  • 22
  • 1
    If you `(require 'company)` does the error go away? – erikstokes Mar 08 '15 at 14:54
  • 1
    Possible duplicate of [Defining key-bindings within \`helm-map\`: getting a \`void-variable helm-map\` error](https://emacs.stackexchange.com/questions/2539/defining-key-bindings-within-helm-map-getting-a-void-variable-helm-map-erro) – Drew Sep 23 '18 at 18:05

1 Answers1

16

You've configured company-mode to load after your init file is evaluated using the after-init-hook, but are then trying to modify company-backends right away.

That variable isn't defined until company-mode is loaded. You either need to just require company, or defer setting that variable using eval-after-load:

(eval-after-load 'company
    '(push 'company-robe company-backends)))

Another option would be to modify the company backends in a mode hook for robe or ruby. That approach would allow you to set different company backends for different modes. For example, this will use only the robe backend in ruby mode:

(add-hook 'ruby-mode-hook
        (lambda ()
          (setq-local company-backends '((company-robe)))))
glucas
  • 20,175
  • 1
  • 51
  • 83