6

I am using Emacs24, and my auto-complete plugin was working when I opened my .emacs file. However, it doesn't work when I open some file like :

whatever.c

To add to this, the auto-complete-c-headers do not work. I believe that auto-complete doesn't work on c/c++ mode.

Here is my .emacs file:

(add-to-list 'load-path "~/.emacs.d/elpa/neotree")
(require 'neotree)
(global-set-key [f8] 'neotree-toggle)

(defun my:ac-c-header-init()
    (require 'auto-complete-c-headers)
    (add-to-list 'ac-sources 'ac-source-c-header))
(add-hook 'c++-mode-hook 'my:a-c-header-init)
(add-hook 'c-mode-hook 'my:ac-c-header-init)

(require 'cc-mode)
(add-to-list 'auto-mode-alist '("\\.h\\'" . c++-mode))

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

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

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

(add-to-list 'load-path "~/.emacs.d/elpa/auto-complete-1.3.1")
(require 'auto-complete)
(require 'auto-complete-config)
(define-globalized-minor-mode real-global-auto-complete-mode
  auto-complete-mode (lambda ()
                       (if (not (minibufferp (current-buffer)))
                         (auto-complete-mode 1))
                       ))
(real-global-auto-complete-mode t)
(ac-config-default)
(ac-set-trigger-key "TAB")
(ac-set-trigger-key "<tab>")
Malabarba
  • 22,878
  • 6
  • 78
  • 163
Vivian Maya
  • 787
  • 1
  • 6
  • 17

1 Answers1

7

I added the following code to solve most of my problem:

(setq ac-source-yasnippet nil)

But, it caused complexity between yasnippet and auto-complete so I added this:

(define-key yas-minor-mode-map (kbd "<tab>") nil)
(define-key yas-minor-mode-map (kbd "TAB") nil)
(define-key yas-minor-mode-map (kbd "<backtab>") 'yas-expand)

Modified some keys:

(ac-set-trigger-key "TAB")
(ac-set-trigger-key "<tab>")

And solved all of my problems.

programking
  • 7,064
  • 9
  • 41
  • 62
Vivian Maya
  • 787
  • 1
  • 6
  • 17