[Tex/LaTex] Adding custom macros to completion list with AUCTeX

auctexauto-completionemacs

I would like AUCTeX (that is, Emacs with auctex loaded) to suggest more LaTeX macros when using completion (M-Tab or C-Ret) than it does by default.
I would like to have macros from packages I have downloaded on CTAN and macros I have written.
I would also like it if it would complete \section or other macros that can be accessed via C-c C-s, C-c C-e etc.

Solution:
I could not make the code quoted by AUCTeX wiki
work. i get an error on loading emacs but did not looked much further in because I ca bear the nuisance of appending a few lines to my files.

The link given by Ben (Automatic add of private macros contains a working solution, thus I accept his answer. I had come across this page in my researchs but somehow messed up things. What eventually worked for me was using TeX-auto-generate TEX AUTO to create a bunch of .el files in the ~/.emacs.d/auctex/auto direcoty. Note that this directory must be created beforhand.
For some reasons TeX-macro-private did not achieve the wanted result.

Best Answer

AUCTeX has to be configured to parse files so that it can extract the macros you want. Make sure you have the variable TeX-parse-self set to t, so that it scans the current file for macros defined there, set TeX-auto-regexp-list to TeX-auto-full-regexp-list so it looks for as many macros as it can, and TeX-auto-parse-length to 999999 so it handles long files. These can be set in your .emacs file, and overridden as needed as file-local variables in your individual projects if they give you trouble. You should also try adding

%%% Local Variables:
%%% TeX-master: "your-main-filename"
%%% End:

to the bottom of all files belonging to your project, so that AUCTeX knows how to get back from one included file to the main one, and then to the other included files.

With all that done, it should be finding pretty much all the macros in your project.

EDIT

According to the AUCTeX wiki, you can avoid the TeX-master local variable by asking AUCTeX to guess the master file; they post the necessary elisp code to do this.

To check additional directories worth of style files, add the directories to the TeX-macro-private lists (see here).