After doing a long research in the web and careful examination of
ac documentation with a lot of trials on my machine to examine code line by line, I came up with this solution that can have
yasnippet working as well (optioinal) without any confict.
put this in your
.emacs taking care of sequence:
;; yasnippet code 'optional', before auto-complete
;; auto-complete setup, sequence is important
(add-to-list 'ac-modes 'latex-mode) ; beware of using 'LaTeX-mode instead
(require 'ac-math) ; package should be installed first
(defun my-ac-latex-mode () ; add ac-sources for latex
(add-hook 'LaTeX-mode-hook 'my-ac-latex-mode)
(setq ac-math-unicode-in-math-p t)
(ac-flyspell-workaround) ; fixes a known bug of delay due to flyspell (if it is there)
(add-to-list 'ac-modes 'org-mode) ; auto-complete for org-mode (optional)
(require 'auto-complete-config) ; should be after add-to-list 'ac-modes and hooks
(setq ac-auto-start nil) ; if t starts ac at startup automatically
(setq ac-auto-show-menu t)
as mentioned in the documentation of
ac, the adding to
ac-modes and hooks should be done before loading
Some suggested to put some code to play with
TAB key which I didn't need and do not recommend as it will somehow destroy something else later. However, I saw people put something like this at the end just before
Until I added
(ac-flyspell-workaround) auto-completion was too slow to think of using it in Auctex since I use flyspell. This bug was also mentioned in the documentation. Thanks!
I was glad to know from the documentation, though not very clear how, that one can add a user-defined dictionary(ies)! I tried this and worked well.
add these two lines just after
require-auto-complete line above:
(add-to-list 'ac-dictionary-directories "~/.emacs.d/.dict") ; make sure this folder exists
(add-to-list 'ac-user-dictionary-files "~/.emacs.d/.dict/custom-dict.txt") ; put any name to your `.txt` file
Now in your
.txt file add your favorite candidates for completion. Save yourself from candidates fewer than 4-letter long, they don't worth it! Simply put words of your like separated by a line feed or
Example of the contents in the
Enjoy auto-completion in LaTeX/AUCTeX with Emacs!