4

我从这里下载了一个 emacs 配置文件:https
://github.com/redguardtoo/emacs.d 我安装它并学习使用 emacs。
使用 YASnippet 时,我发现自动完成的键绑定不起作用。
在编写C代码时,输​​入“inc”然后按TAB,emacs会弹出一个菜单来选择一个片段。
如果我想选择一个片段,它只有在按向上箭头和向下箭头时才有效,Cn 和 Cp 不起作用。
我发现emacs配置文件有绑定Cn和Cp。这是 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-completing-map (kbd "Cn") 'ac-next)
(define-key ac-completing-map (kbd "Cp") 'ac-previous)

如何绑定 Cn 和 Cp 以在弹出菜单中选择片段?

4

2 回答 2

3

我在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)

这对我有用。

于 2015-07-13T14:55:56.480 回答
0
(define-key ac-menu-map (kbd "C-n") 'ac-next)
(define-key ac-menu-map (kbd "C-p") 'ac-previous)

上面的代码怎么样

于 2012-05-28T17:50:26.683 回答