• Emacs中使用company + irony实现C++代码补全


    尝试过好多代码补全插件,目前找到一款用着比较满意的,前端用company,后端主要用irony,基本上对于C/C++项目来说使用体验非常好,其他语言的未体验过。

    下面是主要配置,一些插件可能需要emacs版本 >= 25.1

     1 ;; 代码补全的配置
     2 ;; ===================================================
     3 (require 'company)
     4 (require 'irony)
     5 (require 'company-irony)
     6 (add-hook 'c++-mode-hook 'company-mode)
     7 (add-hook 'c-mode-hook 'company-mode)
     8 (add-hook 'c++-mode-hook 'irony-mode)
     9 (add-hook 'c-mode-hook 'irony-mode)
    10 (add-hook 'irony-mode-hook 'irony-cdb-autosetup-compile-options)
    11 (setq company-idle-delay 0)
    12 (setq company-minimum-prefix-length 2)
    13 (setq company-dabbrev-downcase nil)
    14 (add-to-list 'company-backends 'company-dabbrev)
    15 (add-to-list 'company-backends 'company-dabbrev-code)
    16 (add-to-list 'company-backends 'company-files)
    17 (add-to-list 'company-backends 'company-semantic)
    18 (add-to-list 'company-backends 'company-keywords)
    19 (add-to-list 'company-backends 'company-irony)
    20 ;;(add-to-list 'company-backends 'company-gtags)
    21 (add-to-list 'company-backends 'company-capf)
    22 (require 'company-c-headers)
    23 (add-to-list 'company-c-headers-path-system "/usr/include/c++/4.9.2/")
    24 (add-to-list 'company-backends 'company-c-headers)
    25 (global-set-key (kbd "C-;") 'company-complete-common)
    26 ;;使用M-n 和 M-p 选择候选项
    27 ;;company 颜色设置
    28 (defun theme-dark ()
    29   (interactive)
    30    (set-face-foreground 'company-tooltip "#000")
    31     (set-face-background 'company-tooltip "#fff")
    32      (set-face-foreground 'company-scrollbar-bg "#fff")
    33       (set-face-background 'company-scrollbar-fg "#999")
    34 )
    35 (theme-dark)

    对于Irony的话,需要在emacs中手动执行 M-x irony-install-server 来安装好irony的后端server。

    另外有了irony和company-c-headers之后,如果你用的是一个大型项目,那么company-gtags就不需要了,因为company-gtags会使得大型项目下company的提升项居多,貌似是将当前项目所有的符号都作为备选了(也可能是我没配置对)。

    参考:

    http://cachestocaches.com/2015/8/c-completion-emacs/

  • 相关阅读:
    继承
    包、logging模块、hashlib模块、openpyxl模块、深浅拷贝
    Java中的Lambda表达式
    Java中udp/tcp的发送和接收
    Java中的IO流总结
    Java中的多线程
    Java中使用try-catch-finally处理IO流中的异常
    Java中的杂流(闸总)
    Java中的Properties
    Java中IO流之字符流
  • 原文地址:https://www.cnblogs.com/cobbliu/p/13337763.html
Copyright © 2020-2023  润新知