Setting up autocomplete to work with semantic

十年热恋 提交于 2019-12-11 02:23:13

问题


I have a problem with auto-complete package in Emacs. Currently I have up and running cedet with proper autocompletion, but auto-complete package has some weird behaviour. It doesn't use semantic's (senator's?) database until I explicitly visit include file and make "C-u M-x bovinate". Then I can return to the source file and auto-complete's completion list will look exactly as the semantic's one.

Another point is if I edit my source file, for example, in c++-mode and try to "bovinate" header in c-mode, auto-complete won't get any additional points in it's completion list.

Any ideas how to get auto-complete work automatically?

My .emacs file is (Major parts of it were taken from Alex Ott's article)

(load "~/.emacs.d/cedet/cedet-devel-load.el")
(add-to-list 'semantic-default-submodes 'global-semanticdb-minor-mode)
(add-to-list 'semantic-default-submodes 'global-cedet-m3-minor-mode)
(add-to-list 'semantic-default-submodes 'global-semantic-mru-bookmark-mode)
(add-to-list 'semantic-default-submodes 'global-semantic-idle-local-symbol-highlight-mode)
(add-to-list 'semantic-default-submodes 'global-semantic-idle-scheduler-mode)
(add-to-list 'semantic-default-submodes 'global-semantic-idle-completions-mode)
(add-to-list 'semantic-default-submodes 'global-semantic-idle-summary-mode)
(add-to-list 'semantic-default-submodes 'global-semantic-decoration-mode)

(require 'semantic/ia)
(semantic-mode 1)

(require 'semantic/bovine/gcc)

(semantic-add-system-include "/usr/include/mpi/" 'c++-mode)

;; ;; Imenu integration
(defun my-semantic-hook ()
  (imenu-add-to-menubar "TAGS"))
(add-hook 'semantic-init-hooks 'my-semantic-hook)

;; Class suggest improvement
(defun my-c-mode-cedet-hook ()
 (local-set-key "." 'semantic-complete-self-insert)
 (local-set-key ">" 'semantic-complete-self-insert))
(add-hook 'c-mode-common-hook 'my-c-mode-cedet-hook)

;;;; Semantic and auto-config integration
(require 'auto-complete-config)
(ac-config-default)
(add-to-list 'ac-dictionary-directories "/home/zvord/.emacs.d/ac-dict")
(define-key ac-mode-map [(meta return)] 'auto-complete)

(defun my-cedet-hook ()
  (add-to-list 'ac-sources 'ac-source-semantic))
(add-hook 'c-mode-common-hook 'my-cedet-hook)

From all I've read this should be enough to get auto-complete work, but it isn't.


回答1:


Try to change:

(defun my-cedet-hook () (add-to-list 'ac-sources 'ac-source-semantic))

into:

(defun my-cedet-hook () (add-to-list 'ac-sources 'ac-source-semantic-raw))

It should work.




回答2:


Does your auto-complete config allows auto-start of completion? You need to check value of following variables: ac-auto-show-menu - how long to wait until show menu with possible completions (0.5sec by default), and ac-auto-start - when to start completion (how much symbols you need to type - original value is 2).

Full config for auto-complete could look like (in addition to your setup in my-cedet-hook):

(require 'auto-complete-config)
(ac-config-default)
;; start after 3 characters were typed
(setq ac-auto-start 3)
;; show menu immediately...
(setq ac-auto-show-menu t)
;; explicit call to auto-complete
(define-key ac-mode-map [(meta return)] 'auto-complete)

I use similar config, and it works fine for me, showing completions for Semantic data. For which language do you try to use name completion? For example, for C++ it would be necessary to add entries to spp-table, etc.



来源:https://stackoverflow.com/questions/13218664/setting-up-autocomplete-to-work-with-semantic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!