iquiw / company-ghc

Company-mode completion back-end for haskell-mode via ghc-mod
125 stars 6 forks source link

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

Closed yoeluk closed 9 years ago

yoeluk commented 9 years ago

Hi there, I am trying to set up company-ghc in Aquamacs and I get this error/warning when starting up aquamacs. Does anyone know what am I missing? Thanks.

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

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

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.

I have this configuration on `~/.emacs

;; Melpa
(require 'package)
(add-to-list 'package-archives 
         '("melpa" . "http://melpa-stable.milkbox.net/packages/"))
(package-initialize)

(autoload 'ghc-init "ghc" nil t)
(autoload 'ghc-debug "ghc" nil t)
(autoload 'company-mode "company" nil t)

(add-hook 'haskell-mode-hook (lambda () (ghc-init)))

(add-hook 'after-init-hook 'global-company-mode)
(add-to-list 'company-backends 'company-ghc)

The company-ghc-diagnostic-info cmd shows this

* company-ghc backend not found
* automatic scan module is disabled.
  You need to run either 'M-x company-ghc-turn-on-autoscan' once
  or 'M-x company-ghc-scan-modules' when it is necessary.
* ghc-boot process has been done

Module                  Alias           Candidates
-------------------------------------------------------------------------------

The ghc-debug cmd shows this

...
Version: all versions must be the same.
      ghc.el version 0
     ghc-mod version 4.1.6 compiled by GHC 7.8.3
    ghc-modi version 4.1.6 compiled by GHC 7.8.3
    The Glorious Glasgow Haskell Compilation System, version 7.8.3
...
iquiw commented 9 years ago

The easiest way I think is to use with-eval-after-load if you are using Emacs 24.4 or later. (Otherwise use eval-after-load instead)

(with-eval-after-load 'company
  (add-to-list 'company-backends 'company-ghc))

Alternatively, haskell-mode-hook can be used.

(add-hook 'haskell-mode-hook
          (lambda ()
            (ghc-init)
            (add-to-list (make-local-variable 'company-backends) 'company-ghc)))
yoeluk commented 9 years ago

Thanks a lot with-eval-after-load worked perfectly!

geraldus commented 9 years ago
(with-eval-after-load 'company
  (add-to-list 'company-backends 'company-ghc))

Thanks! Helped for me too!