emacs autocomplete for C ++

时间:2014-11-15 23:43:51

标签: emacs

我正在尝试为c ++编程设置emacs。 大部分都遵循此处的说明.. http://truongtx.me/2013/03/10/emacs-setting-up-perfect-environment-for-cc-programming/ 一切都很好,除了我遵循指示的自动完成 http://truongtx.me/2013/03/06/emacs-ccpp-autocomplete-with-clang/

根据说明,[C-]应该绑定,但是当我按[ctrl +' - ']时,我看不到任何建议.. 这是我的.emacs文件

(require 'package)
(add-to-list 'package-archives
             '("marmalade" . "http://marmalade-repo.org/packages/"))
(package-refresh-contents)


(require 'cc-mode)
(setq-default c-basic-offset 4 c-default-style "linux")
(setq-default tab-width 4 indent-tabs-mode t)
(define-key c-mode-base-map (kbd "RET") 'newline-and-indent)

(add-to-list 'load-path "/home/mohit/Documents/scratch/autopair")
(require 'autopair)
(autopair-global-mode 1)
(setq autopair-autowrap t)

(add-to-list 'load-path "/home/mohit/Documents/scratch/ecb")
(require 'ecb)
(setq ecb-layout-name "left8")
(setq ecb-show-sources-in-directories-buffer 'always)
(setq ecb-compile-window-height 12)

;;; activate and deactivate ecb
(global-set-key (kbd "C-x C-;") 'ecb-activate)
(global-set-key (kbd "C-x C-'") 'ecb-deactivate)
;;; show/hide ecb window
(global-set-key (kbd "C-;") 'ecb-show-ecb-windows)
(global-set-key (kbd "C-'") 'ecb-hide-ecb-windows)
;;; quick navigation between ecb windows
(global-set-key (kbd "C-)") 'ecb-goto-window-edit1)
(global-set-key (kbd "C-!") 'ecb-goto-window-directories)
(global-set-key (kbd "C-@") 'ecb-goto-window-sources)
(global-set-key (kbd "C-#") 'ecb-goto-window-methods)
(global-set-key (kbd "C-$") 'ecb-goto-window-compilation)

;;; replacement for built-in ecb-deactive, ecb-hide-ecb-windows and
;;; ecb-show-ecb-windows functions
;;; since they hide/deactive ecb but not restore the old windows for me
(defun tmtxt/ecb-deactivate ()
  "deactive ecb and then split emacs into 2 windows that contain 2 most recent buffers"
  (interactive)
  (ecb-deactivate)
  (split-window-right)
  (switch-to-next-buffer)
  (other-window 1))
(defun tmtxt/ecb-hide-ecb-windows ()
  "hide ecb and then split emacs into 2 windows that contain 2 most recent buffers"
  (interactive)
  (ecb-hide-ecb-windows)
  (split-window-right)
  (switch-to-next-buffer)
  (other-window 1))
(defun tmtxt/ecb-show-ecb-windows ()
  "show ecb windows and then delete all other windows except the current one"
  (interactive)
  (ecb-show-ecb-windows)
  (delete-other-windows))

(global-set-key (kbd "C-x C-'") 'tmtxt/ecb-deactivate)
(global-set-key (kbd "C-;") 'tmtxt/ecb-show-ecb-windows)
(global-set-key (kbd "C-'") 'tmtxt/ecb-hide-ecb-windows)

(add-to-list 'load-path "~/.emacs.d/elpa/yasnippet-0.8.0/")
(require 'yasnippet)
(yas-global-mode 1)

(setq package-user-dir "~/.emacs.d/elpa/")
(package-initialize)

;;; (add-to-list 'load-path "~/.emacs.d/elpa/auto-complete-1.4/")
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories "~/.emacs.d/ac-dict")
(ac-config-default)
;;; set the trigger key so that it can work together with yasnippet on tab key,
;;; if the word exists in yasnippet, pressing tab will cause yasnippet to
;;; activate, otherwise, auto-complete will
(ac-set-trigger-key "TAB")
(ac-set-trigger-key "<tab>")
(add-to-list 'load-path "~/.emacs.d/elpa/auto-complete-clang/")
(require 'auto-complete-clang)
(global-set-key (kbd "C-`") 'ac-complete-clang)

1 个答案:

答案 0 :(得分:2)

ac-complete-clang已绑定到C-`,而不是C--;如果用正确的bindng触发它,它应该可以工作。

正如the troubleshooting section of auto-complete-clang's README中所述,您可能需要在系统库中手动指向auto-complete-clang

  
      
  • clang无法找到标准的inlcude文件?

         

    这是因为clang的包含文件搜索路径不正确。这是解决方案:

  •   
  • 找出g ++的包含文件搜索路径:

    echo "" | g++ -v -x c++ -E -
    
         你会得到这样的东西:

    #include "..." search starts here:
    #include <...> search starts here:
     /usr/include/c++/4.6
     /usr/include/c++/4.6/x86_64-linux-gnu/.
     /usr/include/c++/4.6/backward
     /usr/lib/gcc/x86_64-linux-gnu/4.6.1/include
     /usr/local/include
     /usr/lib/gcc/x86_64-linux-gnu/4.6.1/include-fixed
     /usr/include/x86_64-linux-gnu
     /usr/include
    End of search list.
    
  •   
  • 设置ac-clang-flags以包含这些默认包含的pathes。如,

    (setq ac-clang-flags
          (mapcar (lambda (item)(concat "-I" item))
                  (split-string
                   "
     /usr/include/c++/4.6
     /usr/include/c++/4.6/x86_64-linux-gnu/.
     /usr/include/c++/4.6/backward
     /usr/lib/gcc/x86_64-linux-gnu/4.6.1/include
     /usr/local/include
     /usr/lib/gcc/x86_64-linux-gnu/4.6.1/include-fixed
     /usr/include/x86_64-linux-gnu
     /usr/include
    "
                   )))
    
  •   
     

您可以将其放入.emacs文件中。

     

然后代码完成工作正常!