jcollard / elm-mode

Elm mode for emacs
GNU General Public License v3.0
375 stars 67 forks source link

company-elm backend is active in all buffers; whether elm-based or not #57

Closed JJJollyjim closed 8 years ago

JJJollyjim commented 8 years ago

The company-elm backend does not perform checks to see if the current buffer is in elm-mode.

This means that, if users follow the wiki-recommended technique of having all of their backends in the list at all times, they get an error on every keypress:

Completion only works inside Elm projects. Create one with M-x elm-create-package RET

Other backends, like company-ghc, check the buffer mode and only returns a non-nil value if the buffer is in an appropriate mode:

(defun company-ghc (command &optional arg &rest ignored)
  "`company-mode' completion back-end for `haskell-mode' via ghc-mod.
Provide completion info according to COMMAND and ARG.  IGNORED, not used."
  (interactive (list 'interactive))
  (cl-case command
    (init (when (and (derived-mode-p 'haskell-mode) company-ghc-autoscan)
            (company-ghc-scan-modules)
            (add-hook 'after-save-hook #'company-ghc-scan-modules nil t)))
    (interactive (company-begin-backend 'company-ghc))
    (prefix (and (derived-mode-p 'haskell-mode)
                 (company-ghc-prefix)))
    (candidates (company-ghc-candidates arg))
    (meta (company-ghc-meta arg))
    (doc-buffer (company-ghc-doc-buffer arg))
    (location (company-ghc-location arg))
    (annotation (company-ghc-annotation arg))
    (sorted t)))