gpt4 book ai didi

c++ - 如何在 emacs 中使用公司模式、irony 后端和 irony header

转载 作者:行者123 更新时间:2023-11-30 05:34:44 24 4
gpt4 key购买 nike

我期望的是,当我键入 #incl 并按 Tab 键时,它会为我完成 #include

但是我现在需要做的是:我先按Tab键,它会弹出一个包含可能单词的列表。我继续打字,直到一个独特的选择,它为我完成。但是我觉得这种风格很不方便。

现在这是我的 elisp 设置。我不擅长口齿不清。请帮我看看有没有问题。

(eval-after-load 'company
'(add-to-list 'company-backends 'company-irony))
(eval-after-load 'company
'(add-to-list
'company-backends '(company-irony-c-headers company-irony)))
(require 'company)
(require 'cc-mode)
(add-hook 'after-init-hook 'global-company-mode)
(setq company-backends (delete 'company-semantic company-backends))
(define-key c-mode-map [(tab)] 'company-complete)
(define-key c++-mode-map [(tab)] 'company-complete)

最佳答案

我最初也努力让它工作。我自己对 Lisp 不是很好。

首先我认为你需要一个额外的模式来使#include 文件工作。我想你有 company-irony-c-headers 文件。

Company-c-headers

Company-irony-c-headers

我认为 company-irony-c-headers 应该与 company-irony 一起更好地工作。但我无法让它工作。我下载了 company-c-headers 并且有效。

关键部分是正确配置这些模式。

我将在这里分享我自己的配置文件,它适用于我的 Mac OS 10.9。

我将所有配置文件存储在 ~/.emacs.d/config/下

对于 company、irony、company-irony 和 company-c-header 模式,我将它们全部配置在一个大的 .el 文件中。您可以将它放在您的 .emacs 文件中,该文件应该可以正常工作。

这是我的文件:

;; Define the modes/packages you need
(require 'company)
(require 'irony)
(require 'company-c-headers)
;; Enable company mode globally
(add-hook 'after-init-hook 'global-company-mode)

;; Here I define a function so it can be called anytime I want to load it
(defun irony-comp-setup-basic()
;; A function to add path to company-c-headers
(defun company-c-headers-includes ()
;; You just need to modified the path inside the quote to your header files path
(add-to-list 'company-c-headers-path-system "$ROOTSYS/include")
)
;; Now call this function so it add your path to company-c-header-path-system
(company-c-headers-includes)
;; Irony-mode configuration
(add-hook 'c++-mode-hook 'irony-mode)
(add-hook 'c-mode-hook 'irony-mode)
(add-hook 'objc-mode-hook 'irony-mode)

;; replace the `completion-at-point' and `complete-symbol' bindings in
;; irony-mode's buffers by irony-mode's function
(defun my-irony-mode-hook ()
(define-key irony-mode-map [remap completion-at-point]
'irony-completion-at-point-async)
(define-key irony-mode-map [remap complete-symbol]
'irony-completion-at-point-async))
(add-hook 'irony-mode-hook 'my-irony-mode-hook)
;; This customize some backends to the company-backends I took it from my friend's code
(custom-set-variables
'(company-backends (quote (company-irony company-elisp company-bbdb company-nxml company-css company-eclim company-semantic company-\
clang company-xcode company-ropemacs company-cmake company-capf (company-dabbrev-code company-gtags company-etags company-keywords) com\
pany-oddmuse company-files company-dabbrev))))

(custom-set-faces
)

;; This add your company-c-headers to company-backends
(add-to-list 'company-backends 'company-c-headers)

;; Default config for company-irony mode
(eval-after-load 'company
'(add-to-list
'company-backends 'company-irony))

;; For irony mode I think
(add-hook 'irony-mode-hook 'company-irony-setup-begin-commands)
)
;; Now call this function to active it
(irony-comp-setup-basic)

让我知道它是否有效。

关于c++ - 如何在 emacs 中使用公司模式、irony 后端和 irony header,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34117163/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com