2012-11-13 38 views
5

Tôi muốn làm cho yasnippet làm phụ trợ của auto-complete. Tuy nhiên, nó không hoạt động. những gì tôi làm sau khi đã tìm kiếm internet là như sau: được auto-complete-yasnippet.el, thêm một số elisp trong .emacs như thế này:Làm cách nào để đặt yasnippet thành phần phụ trợ tự động hoàn thành?

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

tôi nhìn vào nội dung trong ac-sources trong * cào * với Ch v, và nó có ac-source-yasnippet. ai đó said rằng có thể có sự cố với phiên bản và nâng cấp auto-complete cũng như yasnippet. Làm thế nào nó có thể được cố định? Phiên bản emacs của tôi là 23.3.1 phiên bản auto-complete của tôi là 1.3.1 và phiên bản yasnippet của tôi là 0.8.0 (beta) vừa được tải xuống từ github. bất kỳ giúp đỡ?

+0

Tôi đang sử dụng emacs dưới Windows 7, và 'M/'là keybinding mà tôi định nghĩa để làm cho' yasnippet' không xung đột với 'tự động hoàn thành' khi sử dụng phím TAB toolchainX

Trả lời

1

bạn có thể dễ dàng làm điều đó bằng cách (require 'auto-complete-yasnippet)

và sau đó bạn có thể thay đổi tự động hoàn tất của bạn như sau:

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

Nó hoạt động tốt trên máy tính của tôi.

+0

Tôi nghĩ rằng đó có thể là vấn đề của phiên bản' yasnippet', hãy xem phần trả lời của tôi. – toolchainX

2

có lẽ cái gì sai với auto-complete-config.el khi mua lại ac-yasnippet-candidates trong phiên bản auto-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)))))) 

đoạn mã trên phần nào phải được thay đổi để tương thích với các phiên bản yasnippet-0.8.0. Tôi tải xuống phiên bản mới nhất của auto-complete-1.4.0 từ github và giải quyết sự cố đánh giá phiên bản yasnippet và thực hiện các biện pháp phù hợp. như thế này:

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

tôi đã sao chép auto-complete-config.el từ phiên bản auto-complete-1.4.0, byte biên soạn nó, và thay thế các tập tin tương tự (cả auto-complete-config.elauto-complete-config.elc) trong phiên bản auto-complete-1.3.1. nó chỉ hoạt động! Tôi nghĩ rằng các tập tin cấu hình của auto-complete không nên bao gồm trong distro và có lẽ nó nên duy trì một cách riêng biệt để làm cho nó dễ dàng để tương thích với backends của nó.

tôi cấu hình lại các yasnippetauto-complete như thế này:

;; 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) 
Các vấn đề liên quan