Syntax highlighting would be correct if file parsing is enabled. First check whether the options suggested at the beginning of the AUCTeX manual are enabled:
(setq TeX-auto-save t)
(setq TeX-parse-self t)
(setq-default TeX-master nil)
In general AUCTeX should not highlight verbatim-like environments. How does it know these envs? Section 3.1.4 of AUCTex documentation says:
3.1.4 Verbatim macros and environments
Usually it is not desirable to have content to be typeset verbatim
highlighted according to LaTeX syntax. Therefore this content will be
fontified uniformly with the face `font-latex-verbatim-face'.
font-latex differentiates three different types of verbatim
constructs for fontification. Macros with special characters like | as
delimiters, macros with braces, and environments. Which macros and
environments are recognized is controlled by the variables
LaTeX-verbatim-macros-with-delims
,
LaTeX-verbatim-macros-with-braces
, and LaTeX-verbatim-environments
respectively.
So you can tell AUCTeX about a new verb-like env by adding to your
init file something like:
(eval-after-load 'latex '(add-to-list 'LaTeX-verbatim-environments "myverb"))
However, verb-like envs of common latex packages (including
lstlistings
from the listings
package) can be automatically
detected and 'styles' applied. By parsing your file, AUCTeX sees the
\usepackage{listings}
and so adds lstlistings
to its list of
verb-like envs.
AUCTeX parses the file only if TeX-parse-self
is set. If
TeX-auto-save
is set, it saves the found information in the auto
local directory. Once the file exists, it gets the information from
it and does not re-parse the file.
To make it parse again (eg because your file changed), run C-c C-n
(TeX-normal-mode
) (I found that I sometimes need to run it twice).
Actually, you can dispend setting any variable and just type C-c C-n
when you want your file to be parsed and styles applied.
(setq TeX-auto-save t) (setq TeX-parse-self t) (setq-default TeX-master nil)
(and read at least the "Quick Start" section of the manual, while you're at it)TeX-active-styles
variable (C-h v TeX-active-styles
) in your.tex
file buffer? The line suggested by JeanPierre is already in the style file associated to listings package, you shouldn't need to add it manually. Which version of AUCTeX and Emacs are you using?\usepackage{listings}
with the correct spelling?