如何在emacs中使用公司模式,具有讽刺意味的后端和具有讽刺意味的标题

时间:2015-12-06 12:00:11

标签: c++ emacs autocomplete

我希望当我输入#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) 

1 个答案:

答案 0 :(得分:1)

我最初也努力让它开始工作。我自己对Lisp不太满意。

首先,我认为您需要额外的模式才能使#include文件正常工作。我认为你有company-irony-c-header文件。

Company-c-headers

Company-irony-c-headers

我认为公司反讽c-header应该更好地与公司一起讽刺。但我无法让它发挥作用。我改为下载了company-c-header而且工作正常。

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

我将在此处共享我自己的配置文件,该文件适用于我的Mac OS 10.9。

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

对于公司,反讽,公司反讽和公司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)

让我知道它是否有效。