emacs自动完成密钥绑定不起作用

时间:2012-05-28 05:13:52

标签: emacs autocomplete

我从这里下载了一个emacs配置文件:https://github.com/redguardtoo/emacs.d
我安装它并学习使用emacs 当使用YASnippet时,我发现自动完成的键绑定不起作用 编写C代码时,键入“inc”然后按TAB键,emacs会弹出一个菜单来选择一个代码段。
如果我想选择一个片段,C-n和C-p不起作用,它只适用于按下向上箭头和向下箭头的情况。
我发现emacs配置文件具有绑定C-n和C-p。这是init-auto-complete.el

(require 'auto-complete)
(require 'auto-complete-config)
(global-auto-complete-mode t)
(setq ac-auto-start nil)
(setq ac-dwim nil) ; To get pop-ups with docs even if a word is uniquely completed
(define-key ac-completing-map (kbd "C-n") 'ac-next)
(define-key ac-completing-map (kbd "C-p") 'ac-previous)

;;----------------------------------------------------------------------------
;; Use Emacs' built-in TAB completion hooks to trigger AC (Emacs >= 23.2)
;;----------------------------------------------------------------------------
(setq tab-always-indent 'complete)  ;; use 'complete when auto-complete is disabled
(add-to-list 'completion-styles 'initials t)

;; hook AC into completion-at-point
(defun set-auto-complete-as-completion-at-point-function ()
  (setq completion-at-point-functions '(auto-complete)))
(add-hook 'auto-complete-mode-hook 'set-auto-complete-as-completion-at-point-function)


(set-default 'ac-sources
             '(ac-source-dictionary
               ac-source-words-in-buffer
               ac-source-words-in-same-mode-buffers
               ac-source-words-in-all-buffer))

(dolist (mode '(magit-log-edit-mode log-edit-mode org-mode text-mode haml-mode
                sass-mode yaml-mode csv-mode espresso-mode haskell-mode
                html-mode nxml-mode sh-mode smarty-mode clojure-mode
                lisp-mode textile-mode markdown-mode tuareg-mode
                js3-mode css-mode less-css-mode))
  (add-to-list 'ac-modes mode))


;; Exclude very large buffers from dabbrev
(defun sanityinc/dabbrev-friend-buffer (other-buffer)
  (< (buffer-size other-buffer) (* 1 1024 1024)))

(setq dabbrev-friend-buffer-function 'sanityinc/dabbrev-friend-buffer)


(provide 'init-auto-complete)

我认为这两行应该有效,但事实并非如此。这让我很生气     (define-key ac-completion-map(kbd“C-n”)'ac-next)
    (define-key ac-completion-map(kbd“C-p”)'ac-previous)

如何绑定C-n和C-p以在弹出菜单中选择片段?

2 个答案:

答案 0 :(得分:2)

我在http://www.emacswiki.org/emacs/auto-complete.el

中找到了
;; Use C-n/C-p to select candidates
;; --------------------------------
;;
;; Add following code to your .emacs.
;; 
;;     (define-key ac-complete-mode-map "\C-n" 'ac-next)
;;     (define-key ac-complete-mode-map "\C-p" 'ac-previous)

这适合我。

答案 1 :(得分:0)

(define-key ac-menu-map (kbd "C-n") 'ac-next)
(define-key ac-menu-map (kbd "C-p") 'ac-previous)

上面的代码怎么样