开发者

About the fix for the interference between Company mode and Yasnippet

Emacs wiki says:

Company does interfere with Yasnippet’s native behaviour. Here’s a quick fix: http://gist.github.com/265010

The code is the following:

(define-key company-active-map "\t" 'company-yasnippet-or-completion)

(defun company-yasnippet-or-completion ()
  (interactive)
  (if (yas/expansion-at-point)
      (progn (company-abort)
             (yas/expand))
    (company-complete-common)))

(defun yas/expansion-at-point ()
  "Tested with v0.6.1. Extracted from `yas/expand-1'"
    (first (yas/current-key)))

I placed that code in my .emacs and the following message appeared:

Warning (initialization): An error occurred while loading `c:/Documents and Settings/Alex.AUTOINSTALL.001/Application Data/.emacs.elc':

Symbol's value as variable is void: company-active-map

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开发者_JAVA技巧 error backtrace.

Do I have to place the fix code inside a YASnippet's .el file? or in my .emacs (which throws me an error)?


The snippet you mentioned doesn't work any more anyway.

Here's a snippet that you can use instead:

(defun company-yasnippet-or-completion ()
  (interactive)
  (let ((yas-fallback-behavior nil))
    (unless (yas-expand)
      (call-interactively #'company-complete-common))))

To make sure that this is called instead of company-complete-common, use

(add-hook 'company-mode-hook (lambda ()
  (substitute-key-definition 'company-complete-common
                             'company-yasnippet-or-completion
                             company-active-map)))

Background: This locally changes the value of yas-fallback-behaviour, which causes yas to call company-complete-common if no completion is found.


That sounds like a problem with the load-path. The symbol value being void means that emacs can't find a definition for it - most likely because the file containing its definition has not been loaded yet.

You may try adding something like this in your .emacs (before the error-causing code):

;; where ~/.emacs.d/ is the path to a directory containing
;; additional library code you want emacs to load
(add-to-list 'load-path "~/.emacs.d/")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜