5

我想yasnippetauto-complete. 但是,它不起作用。我在网上搜索后的操作如下:获取auto-complete-yasnippet.el,添加一些 elisp.emacs如下:

(add-to-list 'load-path
     "~/.emacs.d/plugins/yasnippet")
(require 'yasnippet)
(yas-global-mode 1)
(yas-minor-mode nil)
(global-set-key (kbd "M-/") 'yas/expand)

;; Auto-complete settings
;; this is the code for the auto-complete
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories "~/.emacs.d//ac-dict")
(ac-config-default)

;;setup for auto-complete-yasnippet
(require 'auto-complete-yasnippet)
(setq-default ac-sources
      '(
        ;; ac-source-semantic
        ac-source-yasnippet
        ac-source-abbrev
        ac-source-words-in-buffer
        ac-source-words-in-all-buffer
        ;; ac-source-imenu
        ac-source-files-in-current-dir
        ac-source-filename
        )
      )

我用 . 查看ac-sources*scratch* 中的内容C-h v,它确实有ac-source-yasnippet. 有人可能是auto-completeas的版本和升级有问题yasnippet。如何修复?我的emacs版本是 23.3.1 我的auto-complete版本是 1.3.1 我的yasnippet版本是 0.8.0(beta) 是刚刚从github下载的。有什么帮助吗?

4

2 回答 2

2

版本中auto-complete-config.el获取时可能有问题:ac-yasnippet-candidatesauto-complete-1.3.1

(defun ac-yasnippet-candidates ()
  (with-no-warnings
    (if (fboundp 'yas/get-snippet-tables)
        ;; >0.6.0
        (apply 'append (mapcar 'ac-yasnippet-candidate-1 (yas/get-snippet-tables major-mode)))
      (let ((table
             (if (fboundp 'yas/snippet-table)
                 ;; <0.6.0
                 (yas/snippet-table major-mode)
               ;; 0.6.0
               (yas/current-snippet-table))))
        (if table
            (ac-yasnippet-candidate-1 table))))))

必须更改上面的代码片段以与yasnippet-0.8.0版本兼容。auto-complete-1.4.0我从github下载了最新版本的,它解决了判断版本yasnippet并采取相应措施的问题。像这样:

(defun ac-yasnippet-candidates ()
  (with-no-warnings
    (cond (;; 0.8 onwards
           (fboundp 'yas-active-keys)
           (all-completions ac-prefix (yas-active-keys)))
          (;; >0.6.0
           (fboundp 'yas/get-snippet-tables)
           (apply 'append (mapcar 'ac-yasnippet-candidate-1
                                  (condition-case nil
                                      (yas/get-snippet-tables major-mode)
                                    (wrong-number-of-arguments
                                     (yas/get-snippet-tables))))))
          (t
           (let ((table
                  (if (fboundp 'yas/snippet-table)
                      ;; <0.6.0
                      (yas/snippet-table major-mode)
                    ;; 0.6.0
                    (yas/current-snippet-table))))
             (if table
                 (ac-yasnippet-candidate-1 table)))))))

auto-complete-config.el我从版本中复制auto-complete-1.4.0,字节编译它,并在版本中替换了相同的文件(auto-complete-config.elauto-complete-config.elcauto-complete-1.3.1。它刚刚奏效!我认为配置文件可能auto-complete不应该包含在发行版中,并且可能应该单独维护以使其易于与其后端兼容。

我重新配置了yasnippet这样的auto-complete

;; setup for yasnippet
(add-to-list 'load-path
      "~/.emacs.d/plugins/yasnippet")
;; Extension and configuration of yasnippet.
(require 'yasnippet-config)
;; If you use yasnippet from 'auto-complete', add
(yas/set-ac-modes)
(yas/enable-emacs-lisp-paren-hack)
;; before 'auto-complete' settings.
;; Auto-complete settings
;; this is the code for the auto-complete
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories "~/.emacs.d//ac-dict")
(ac-config-default)
于 2012-11-14T08:22:16.827 回答
2

你可以很容易地做到这一点(require 'auto-complete-yasnippet)

然后你可以改变你的自动完成,如下所示:

(defun my-ac-config ()
  (setq-default ac-sources '(ac-source-abbrev ac-source-dictionary ac-source-words-in-same-mode-buffers))
  (add-hook 'emacs-lisp-mode-hook 'ac-emacs-lisp-mode-setup)
  ;; (add-hook 'c-mode-common-hook 'ac-cc-mode-setup)
  (add-hook 'ruby-mode-hook 'ac-ruby-mode-setup)
  (add-hook 'css-mode-hook 'ac-css-mode-setup)
  (add-hook 'auto-complete-mode-hook 'ac-common-setup)
  (add-hook 'octave-mode-hook 'ac-octave-mode-setup)
  (global-auto-complete-mode t))
(defun my-ac-cc-mode-setup ()
  (setq ac-sources (append '(ac-source-clang ac-source-yasnippet) ac-sources)))
(add-hook 'c-mode-common-hook 'my-ac-cc-mode-setup)
;; ac-source-gtags
(my-ac-config)

它在我的机器上运行良好。

于 2012-11-14T08:05:37.067 回答