关于公司模式和Yasnippet之间干扰的修复

时间:2010-01-18 15:49:16

标签: emacs plugins

Emacs wiki说:

  

公司干预了   Yasnippet的本土行为。这是一个   快速解决:   http://gist.github.com/265010

代码如下:

(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)))

我将该代码放在我的.emacs中,并显示以下消息:

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 error backtrace.

我是否必须将修复代码放在YASnippet的.el文件中? 或者在我的.emacs中(这会引发错误)?

2 个答案:

答案 0 :(得分:3)

你提到的片段无论如何都无法使用。

以下是您可以使用的代码段:

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

要确保调用此项而不是company-complete-common,请使用

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

背景:这会在本地更改yas-fallback-behaviour的值,如果找不到完成,则会导致yas调用company-complete-common

答案 1 :(得分:-2)

这听起来像是负载路径的问题。无效的符号值意味着emacs无法找到它的定义 - 很可能是因为尚未加载包含其定义的文件。

您可以尝试在.emacs中添加类似的内容(在导致错误的代码之前):

;; 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/")