emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/auctex 334da3d 95/95: Merge branch 'master' into extern


From: Tassilo Horn
Subject: [elpa] externals/auctex 334da3d 95/95: Merge branch 'master' into externals/auctex
Date: Sun, 16 Apr 2017 01:27:04 -0400 (EDT)

branch: externals/auctex
commit 334da3d9fa0a6c50bbded2df72b86c84b02ae906
Merge: f0cb472 2116248
Author: Tassilo Horn <address@hidden>
Commit: Tassilo Horn <address@hidden>

    Merge branch 'master' into externals/auctex
---
 .gitignore                                |   6 +-
 Makefile.in                               |  12 +-
 context.el                                |   6 +-
 doc/auctex.texi                           | 175 +++++++++--
 doc/changes.texi                          |  52 ++++
 etc/auctex-logo.tex                       |  27 ++
 font-latex.el                             | 173 +++++++----
 latex.el                                  | 238 +++++++++++----
 latex/preview.dtx                         |   4 +-
 plain-tex.el                              |  15 +-
 style/amsmath.el                          |   5 +-
 style/biblatex.el                         |   2 +
 style/breqn.el                            | 185 ++++++++++++
 style/caption.el                          |  38 +--
 style/color.el                            |  29 +-
 style/empheq.el                           |   4 +-
 style/fancyvrb.el                         | 485 +++++++++++++++++++++++++-----
 style/fvextra.el                          | 139 +++++++++
 style/j-book.el                           |   2 +-
 style/jarticle.el                         |  16 +-
 style/jbook.el                            |  15 +-
 style/jreport.el                          |  17 +-
 style/jsarticle.el                        |  20 +-
 style/jsbook.el                           |  26 +-
 style/jsreport.el                         |  28 ++
 style/listings.el                         |  72 ++++-
 style/minted.el                           | 118 ++++++--
 style/newfloat.el                         |   2 +-
 style/paracol.el                          |   7 +-
 style/preview.el                          | 104 +++++++
 style/sourcecodepro.el                    |  80 +++++
 style/subcaption.el                       |  12 +-
 style/subfiles.el                         |  15 +-
 style/tarticle.el                         |  15 +
 style/tbook.el                            |  15 +
 style/tcolorbox.el                        |  22 +-
 style/treport.el                          |  15 +
 style/xcolor.el                           |  20 +-
 tests/Makefile                            |  17 +-
 tests/latex/fontification-verb-macros.tex | 143 +++++++++
 tests/latex/latex-filling-in.tex          |  23 ++
 tests/latex/latex-filling-out.tex         |  17 ++
 tests/latex/latex-test.el                 |  36 ++-
 tests/latex/tabular-in.tex                |  41 +++
 tests/latex/tabular-out.tex               |  41 +++
 tests/tex/command-expansion.el            |   8 +
 tex-buf.el                                |   4 +-
 tex-info.el                               |   6 +-
 tex-ispell.el                             | 124 ++++++--
 tex-jp.el                                 | 208 +++++++------
 tex.el                                    |  87 +++++-
 texmathp.el                               |  13 +-
 52 files changed, 2477 insertions(+), 507 deletions(-)

diff --git a/.gitignore b/.gitignore
index 62fffdb..d185fdb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,8 @@
 #*
+*.aux
 *.elc
 *.log
+*.synctex.gz
 *~
 CHANGES
 ChangeLog
@@ -21,6 +23,8 @@ tex-site.el.out
 doc/preview-dtxdoc.texi
 doc/version.texi
 auto.el
+etc/auctex-logo.pdf
+etc/auto
 latex/prauctex.cfg
 latex/prauctex.def
 latex/prcounters.def
@@ -37,7 +41,7 @@ latex/prshowlabels.def
 latex/prtightpage.def
 latex/prtracingall.def
 preview-latex.el
-preview.el
+/preview.el
 PROBLEMS.preview
 # Files generated when installing/compiling the package in place.
 auctex-pkg.el
diff --git a/Makefile.in b/Makefile.in
index b54a808..a454950 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -60,7 +60,9 @@ AUTOLOAD=--eval '(let ((generated-autoload-file 
(expand-file-name "$@"))) \
 PREVIEW_AUTOLOAD=--eval '(let ((generated-autoload-file (expand-file-name 
"$@"))) \
                (update-file-autoloads "preview.el")(save-buffers-kill-emacs 
t))'
 
-EXCLUDEDFILES=autogen.sh .cvsignore .gitignore doc/.gitignore README.GIT tests 
build-aux
+# Files and directories excluded from distributed tar ball.
+EXCLUDEDFILES=autogen.sh .gitignore doc/.gitignore doc/tex-ref.log \
+       latex/.gitignore README.GIT tests build-aux
 
 .SUFFIXES: .el .elc .texi
 
@@ -95,6 +97,8 @@ STYLESRC = style/prosper.el \
           style/dutch.el     style/german.el    style/dk.el \
           style/j-article.el style/j-book.el    style/j-report.el \
           style/jarticle.el  style/jbook.el     style/jreport.el \
+          style/tarticle.el  style/tbook.el     style/treport.el \
+          style/jsarticle.el style/jsbook.el    style/jsreport.el \
           style/dinbrief.el  style/virtex.el    style/plfonts.el \
           style/plhb.el      style/harvard.el   style/swedish.el \
           style/danish.el    style/slovak.el    style/czech.el \
@@ -111,8 +115,6 @@ STYLESRC = style/prosper.el \
           style/alltt.el     style/italian.el   style/doc.el \
           style/ltxdoc.el    style/ltx-base.el  style/units.el \
           style/nicefrac.el  style/url.el       style/listings.el \
-          style/jurabib.el   style/csquotes.el  style/jsarticle.el \
-          style/jsbook.el    style/babel.el     style/dk-bib.el \
           style/inputenc.el  style/frenchb.el   style/francais.el \
           style/MinionPro.el style/pdfsync.el   style/polish.el \
           style/polski.el    style/icelandic.el style/comment.el \
@@ -161,7 +163,9 @@ STYLESRC = style/prosper.el \
           style/bicaption.el style/amsfonts.el  style/subfiles.el \
           style/dcolumn.el   style/mdframed.el  style/tcolorboxlib-raster.el \
           style/titleps.el   style/titlesec.el  style/titletoc.el \
-          style/exam.el
+          style/exam.el      style/breqn.el     style/sourcecodepro.el \
+          style/preview.el   style/fvextra.el   style/jurabib.el \
+          style/csquotes.el  style/babel.el     style/dk-bib.el
 
 STYLEELC = $(STYLESRC:.el=.elc)
 
diff --git a/context.el b/context.el
index 941057a..2f302b3 100644
--- a/context.el
+++ b/context.el
@@ -1,6 +1,6 @@
 ;;; context.el --- Support for ConTeXt documents.
 
-;; Copyright (C) 2003-2006, 2008, 2010, 2012, 2014-2016
+;; Copyright (C) 2003-2006, 2008, 2010, 2012, 2014-2017
 ;;   Free Software Foundation, Inc.
 
 ;; Maintainer: Berend de Boer <address@hidden>
@@ -1037,7 +1037,7 @@ header is at the start of a line."
    (regexp-quote TeX-esc)
    "\\("
    (mapconcat #'ConTeXt-environment-full-start-name ConTeXt-section-block-list 
"\\|") "\\|"
-   (mapconcat #'car ConTeXt-numbered-section-list "\\|")
+   (mapconcat #'car ConTeXt-numbered-section-list "\\|") "\\|"
    (mapconcat #'car ConTeXt-unnumbered-section-list "\\|")
    "\\)\\b"
    (if TeX-outline-extra
@@ -1623,7 +1623,7 @@ Use `ConTeXt-Mark-version' to choose the command."
    ;; In any other case fall back on Mark II.
    (t
     (concat
-     (let ((engine (eval (nth 4 (assq TeX-engine (TeX-engine-alist))))))
+     (let ((engine (eval (nth 4 (TeX-engine-in-engine-alist TeX-engine)))))
        (when engine
         (format "--engine=%s " engine)))
      (unless (eq ConTeXt-current-interface "en")
diff --git a/doc/auctex.texi b/doc/auctex.texi
index 13661c6..d8c02a6 100644
--- a/doc/auctex.texi
+++ b/doc/auctex.texi
@@ -12,7 +12,7 @@ This manual is for @AUCTeX{}
 (version @value{VERSION} from @value{UPDATED}),
 a sophisticated TeX environment for Emacs.
 
-Copyright @copyright{} 1992-1995, 2001, 2002, 2004-2016
+Copyright @copyright{} 1992-1995, 2001, 2002, 2004-2017
 Free Software Foundation, Inc.
 
 @quotation
@@ -2137,10 +2137,11 @@ Face: @code{font-latex-type-face}
 described above.  You can disable these defaults per class by
 customizing the variable @code{font-latex-deactivated-keyword-classes}.
 This is a list of strings for keyword classes to be deactivated.  Valid
-entries are "warning", "variable", "reference", "function" ,
-"sectioning-0", "sectioning-1", "sectioning-2", "sectioning-3",
-"sectioning-4", "sectioning-5", "textual", "bold-command",
-"italic-command", "math-command", "type-command", "bold-declaration",
+entries are "warning", "variable", "biblatexnoarg", "biblatex",
+"reference", "function" , "sectioning-0", "sectioning-1",
+"sectioning-2", "sectioning-3", "sectioning-4", "sectioning-5",
+"slide-title", "textual", "bold-command", "italic-command",
+"math-command", "type-command", "bold-declaration",
 "italic-declaration", "type-declaration".
 
 You can also get rid of certain keywords only.  For example if you want
@@ -2151,7 +2152,9 @@ following stanza into your init file:
 (eval-after-load "font-latex"
   '(setq-default
     font-latex-match-reference-keywords-local
-    (remove "footnote" font-latex-match-reference-keywords-local)))
+    (remove (TeX-assoc-string "footnote"
+            font-latex-match-reference-keywords-local)
+                font-latex-match-reference-keywords-local)))
 @end lisp
 
 But note that this means fiddling with @fontlatex{}'s internals and is
@@ -2177,7 +2180,7 @@ covered by the keyword class.  A keyword can either be a 
simple command
 name omitting the leading backslash or a list consisting of the command
 name and a string specifying the sequence of arguments for the command.
 
-The face argument can either be an existing face or font specifications
+The face argument can either be an existing face or face attributes
 made by you.  (The latter option is not available on XEmacs.)
 
 There are three alternatives for the type of keywords---``Command with
@@ -3106,6 +3109,21 @@ Finally, @AUCTeX{} provides a function called
 information.
 @end defopt
 
address@hidden also provides a facility to skip the argument of in-line
+verbatim macros like @samp{\Verb} from @file{fancyvrb.sty} or
address@hidden from @file{minted.sty}.  Characters delimiting the
+verbatim text are stored in @code{TeX-ispell-verb-delimiters}.
+
address@hidden TeX-ispell-verb-delimiters
+String with delimiters recognized for in-line verbatim macros.  This
+variable is initialized to @samp{!|#~\"*/+^-}.  Since this string is
+used to build a character alternative inside a regular expression,
+special characters @samp{^} and @samp{-} should come last.  Other
+characters like opening brace @address@hidden, asterisk @samp{*} or at sign
address@hidden@@} should be avoided as they are not recognized by
address@hidden
address@hidden defopt
+
 @node Processor Options
 @subsection Options for @TeX{} Processors
 
@@ -4544,29 +4562,94 @@ If nil do it the other way round.
 @cindex ASCII address@hidden
 @cindex address@hidden
 @cindex address@hidden
address@hidden address@hidden
address@hidden address@hidden
 @cindex @file{tex-jp.el}
 @vindex TeX-default-mode
address@hidden TeX-parse-self
address@hidden TeX-engine
address@hidden TeX-engine-alist
 @vindex japanese-TeX-engine-default
 @vindex japanese-LaTeX-default-style
-
-To write Japanese text with @AUCTeX{}, you need to have versions of
address@hidden and Emacs that support Japanese.  There exist at least two
-variants of @TeX{} for Japanese text (NTT address@hidden and ASCII 
address@hidden).
address@hidden can be used with @acronym{MULE, MULtilingual Enhancement to GNU
-Emacs} supported Emacsen.
-
-To use the Japanese @TeX{} variants, simply activate
address@hidden or @code{japanese-latex-mode} and
-everything should work.  If not, send mail to Masayuki Ataka
address@hidden<ataka@@milk.freemail.ne.jp>}, who kindly donated the code for
-supporting Japanese in @AUCTeX{}.  None of the primary @AUCTeX{}
address@hidden japanese-TeX-use-kanji-opt-flag
address@hidden TeX-japanese-process-input-coding-system
address@hidden TeX-japanese-process-output-coding-system
+
+To write Japanese text with @AUCTeX{}, you need the versions of
address@hidden and Emacs that support Japanese.  @AUCTeX{} supports three
+Japanese @TeX{} engines by default: NTT address@hidden, ASCII address@hidden 
and
address@hidden  On XEmacs, @AUCTeX{} needs @acronym{MULE, MULtilingual
+Enhancement to GNU Emacs} feature to deal with Japanese text.
+
+To use the Japanese @TeX{} engines, activate
address@hidden or @code{japanese-latex-mode}.  If it
+doesn't work, send mail to Masayuki Ataka
address@hidden<masayuki.ataka@@gmail.com>} or Ikumi Keita
address@hidden<ikumikeita@@jcom.home.ne.jp>}, who currently concern with
+stuff related to Japanese in @AUCTeX{}.  None of the primary @AUCTeX{}
 maintainers understand Japanese, so they cannot help you.
 
+It is recommended to enable @code{TeX-parse-self} for typical Japanese
address@hidden users.  When enabled, @code{japanese-latex-mode} selects the
+suitable Japanese @TeX{} engine automatically based on the class file
+name (such as @code{jbook}, @code{jsarticle} and @code{tjreport}) and
+its option.  @pxref{Parsing Files}.
+
+It is important to select the suitable Japanese @TeX{} engine because
+the selected engine determines the command name such as @samp{platex}
+and @samp{uptex} to typeset the document.  If you find that wrong
+command is used, check the value of @code{TeX-engine} on that buffer.
+If the value does not suit the current document, change the value by the
address@hidden Options} submenu below the @samp{Command} menu.
address@hidden Options}.
+
+To make the selected engine to persist across Emacs sessions, there are
+two ways from which you can choose one according to your needs:
+
address@hidden
address@hidden
+If you use a specific engine (almost) exclusively, customize the option
address@hidden
+
address@hidden japanese-TeX-engine-default
+The default TeX engine in Japanese @TeX{} mode.
+
+The default value is @samp{ptex}.
address@hidden defopt
address@hidden
+If you want to set the engine on a per file basis, use the file local
+variables to set @code{TeX-engine}.
+
+Here is a sample code to set @code{TeX-engine} to @samp{uptex}:
+
address@hidden
+%%% Local Variables:
+%%% mode: japanese-latex
+%%% TeX-engine: uptex
+%%% End:
address@hidden example
address@hidden enumerate
+
+In the both cases above, the valid value is one of @samp{ptex},
address@hidden and @samp{uptex}.
+
+You can override the command names associated with the above three
+engines or define your own engine by customizing
address@hidden  @xref{Processor Options}.
+
+It is sometimes necessary to use an engine which differs from the one
address@hidden selects automatically.  For example, even when you want to use
address@hidden document class deliberately with ASCII address@hidden,
address@hidden selects NTT address@hidden command if @code{TeX-parse-self} is
+enabled, because @code{j-article} originally belongs to NTT address@hidden
+In such cases, use the file local variable method above to select the
+engine you intend to use.
+
 If you usually use @AUCTeX{} in Japanese, setting the following
 variables is useful.
 
 @defopt TeX-default-mode
-Mode to enter for a new file when it cannott be determined whether the
+Mode to enter for a new file when it cannot be determined whether the
 file is plain @TeX{} or @LaTeX{} or what.
 
 If you want to enter Japanese @LaTeX{} mode whenever this may happen,
@@ -4576,18 +4659,37 @@ set the variable like this:
 @end lisp
 @end defopt
 
address@hidden japanese-TeX-engine-default
-The default TeX engine in Japanese @TeX{} mode.
-
-The default value is @samp{ptex}.
address@hidden defopt
-
 @defopt japanese-LaTeX-default-style
 The default style/class when creating a new Japanese @LaTeX{} document.
 
 The default value is @samp{"jarticle"}.
 @end defopt
 
+It is recommended also for Japanese users to customize the option
address@hidden to @code{"Dvipdfmx"}.  @xref{Processor Options}
+
+There are three customize options with regard to the encoding of
+Japanese text.
+
address@hidden japanese-TeX-use-kanji-opt-flag
+If non-nil, @AUCTeX{} adds @code{-kanji} option to the typesetting
+command when @code{TeX-engine} is @samp{ptex}.
address@hidden defopt
+
+Usually @AUCTeX{} guesses the right coding systems for input to and
+output from the Japanese @TeX{} process, but you can override them by
+the following two customize options.
+
address@hidden TeX-japanese-process-input-coding-system
+If non-nil, used for encoding input to Japanese @TeX{} process.
+When @code{nil}, @AUCTeX{} tries to choose suitable coding system.
address@hidden defopt
+
address@hidden TeX-japanese-process-output-coding-system
+If non-nil, used for decoding output from Japanese @TeX{} process.
+When @code{nil}, @AUCTeX{} tries to choose suitable coding system.
address@hidden defopt
+
 The former customize options @code{japanese-TeX-command-default} and
 @code{japanese-LaTeX-command-default} are obsolete.  Use
 @code{japanese-TeX-engine-default} instead.  If you need to customize
@@ -4598,6 +4700,27 @@ Also, the option @code{japanese-TeX-command-list} is 
considered as
 semi-obsolete.  It still functions as before, but in theory, it is not
 required anymore in normal use.
 
+The following two additional font commands are available in
address@hidden mode buffer.
+
address@hidden @kbd
address@hidden C-c C-f g
address@hidden C-c C-f g
address@hidden @code{\textgt}
+Insert @b{gothic face} font command @address@hidden@address@hidden or
address@hidden@address@hidden@}} depending on the context.
+
address@hidden C-c C-f m
address@hidden C-c C-f m
address@hidden @code{\textmc}
+Insert mincho font command @address@hidden@address@hidden or
address@hidden@address@hidden@}} depending on the context.
+
address@hidden table
+
+Although they are meaningful only with @samp{ptex} and @samp{uptex}
+engines, it won't matter in buffers with other engines.
+
 See @file{tex-jp.el} for more information.
 
 @node Automatic
diff --git a/doc/changes.texi b/doc/changes.texi
index 3cdc886..db02a37 100644
--- a/doc/changes.texi
+++ b/doc/changes.texi
@@ -8,6 +8,58 @@
 
 @end ifset
 
address@hidden News since 11.90
+
address@hidden @bullet
address@hidden
address@hidden has a new customize option @code{TeX-ispell-verb-delimiters}.
+This string contains usual characters used as delimiters for in-line
+verbatim macros like @samp{\verb}.  Text between delimiters after an
+in-line verbatim macro will be skipped during spell checking.
+
address@hidden
+Fontification of in-line verbatim macros has been improved.
address@hidden recognizes an optional or a mandatory argument for
+macros like @samp{\Verb} from @file{fancyvrb.sty}, @samp{\mint} and
address@hidden from @file{minted.sty} and fontifies verbatim content
+correctly.
+
address@hidden
address@hidden can put and parse labels in optional argument of environments.
+Inserting labels is done by new function
address@hidden  A new customize option
address@hidden is available as prefix to labels in code
+typesetting environments, e.g. @samp{lstlisting} environment provided by
address@hidden package.  @code{LaTeX-listing-label} defaults to
address@hidden:}.  Parsing of labels for later referencing relies on two
+requirements:
address@hidden
address@hidden
+Label should come as last key-value argument, and
address@hidden
+label must be enclosed in braces, e.g.
address@hidden
address@hidden@}[caption=Some Caption,address@hidden:address@hidden
+...
address@hidden@}
address@hidden example
address@hidden enumerate
+
address@hidden
+The function @code{LaTeX-label} now takes a second optional argument
address@hidden  When address@hidden, @code{LaTeX-label} reads a label
+and returns it as a string.  This argument is also passed to any
+function bound to @code{LaTeX-label-function} (see next item).
+
address@hidden
address@hidden change:} The signature for the function passed with
+the customize option @code{LaTeX-label-function} has changed.  The
+function bound to this variable is now expected to take an optional
+second argument @code{NO-INSERT}.  When this argument is address@hidden,
+the function should read and only return a label as a string; insertion
+is done by another function.
address@hidden itemize
+
 @heading News in 11.90
 
 @itemize @bullet
diff --git a/etc/auctex-logo.tex b/etc/auctex-logo.tex
new file mode 100644
index 0000000..f8b7fbf
--- /dev/null
+++ b/etc/auctex-logo.tex
@@ -0,0 +1,27 @@
+% Copyright (C) Free Software Foundation, Inc.
+% License: GNU GPLv3 or later
+
+\documentclass{article}
+\usepackage{crimson,listings,tikz,geometry}
+\geometry{paperwidth=7.5mm,paperheight=7.5mm}
+\definecolor{bg}{HTML}{8596B0}\pagecolor{bg}
+\definecolor{fg}{HTML}{F0F0EA}\color{fg}
+\lstset{basicstyle=\color{fg!65!bg}\ttfamily,
+  commentstyle=\itshape,language={[LaTeX]TeX}}
+\begin{document}
+\begin{tikzpicture}[overlay]
+  \coordinate (a) at (-7.26pt,1.89098pt) {};
+  \node[inner sep=0pt] at (-0.265,0.07)
+  {\resizebox{6.4mm}{!}
+    {\lstinputlisting{\jobname}}};
+  \node[inner sep=0pt,align=center] at (a)
+  {A\kern-0.05emU\kern-0.03emC\\[-0.7ex]%
+    T\kern-.15em\lower.46ex%
+    \hbox{\color[HTML]{CAE674}E}\kern-.06emX};
+\end{tikzpicture}
+\end{document}
+
+%%% Local Variables:
+%%% mode: latex
+%%% TeX-master: t
+%%% End:
diff --git a/font-latex.el b/font-latex.el
index 91cb0de..0f2c893 100644
--- a/font-latex.el
+++ b/font-latex.el
@@ -286,7 +286,7 @@ variable `font-latex-fontify-sectioning'." ',num)
      ("nopagebreak" "pagebreak" "newpage" "clearpage" "cleardoublepage"
       "enlargethispage" "nolinebreak" "linebreak" "newline" "-" "\\" "\\*"
       "appendix" "displaybreak" "allowdisplaybreaks" "include")
-     'font-latex-warning-face 1 noarg)
+     font-latex-warning-face 1 noarg)
     ("variable"
      (("setlength" "|{\\{") ("settowidth" "|{\\{") ("settoheight" "{{")
       ("settodepth" "{{") ("setcounter" "{|{\\")
@@ -294,10 +294,10 @@ variable `font-latex-fontify-sectioning'." ',num)
       ("stepcounter" "{") ("refstepcounter" "{")
       ("arabic" "{") ("roman" "{") ("Roman" "{") ("alph" "{") ("Alph" "{")
       ("fnsymbol" "{"))
-     'font-lock-variable-name-face 2 command)
+     font-lock-variable-name-face 2 command)
     ("biblatexnoarg"
      ("newrefsegment" "mancite" "pno" "ppno" "nopp" "psq" "psqq")
-     'font-lock-variable-name-face 2 noarg)
+     font-lock-variable-name-face 2 noarg)
     ("biblatex"
      (("newrefsection" "[") ("ExecuteBibliographyOptions" "[{")
       ("printbibliography" "[") ("printshorthands" "[") ("printbibheading" "[")
@@ -322,13 +322,13 @@ variable `font-latex-fontify-sectioning'." ',num)
       ("cites" "(([[{") ("Cites" "(([[{") ("parencites" "(([[{") ("Parencites" 
"(([[{")
       ("footcites" "(([[{") ("footcitetexts" "(([[{") ("smartcites" "(([[{")
       ("Smartcites" "(([[{") ("textcites" "(([[{") ("Textcites" "(([[{") 
("supercites" "(([[{"))
-     'font-lock-constant-face 2 command)
+     font-lock-constant-face 2 command)
     ("reference"
      (("nocite" "*{") ("cite" "*[[{") ("label" "{") ("pageref" "{")
       ("vref" "*{") ("eqref" "{") ("ref" "{") ("include" "{")
       ("input" "{") ("bibliography" "{") ("index" "{") ("glossary" "{")
       ("footnote" "[{") ("footnotemark" "[") ("footnotetext" "[{"))
-     'font-lock-constant-face 2 command)
+     font-lock-constant-face 2 command)
     ("function"
      (("begin" "{") ("end" "{") ("pagenumbering" "{")
       ("thispagestyle" "{") ("pagestyle" "{") ("nofiles" "")
@@ -345,7 +345,7 @@ variable `font-latex-fontify-sectioning'." ',num)
       ;; separate category with 'noarg instead of 'command handling?
       ("enspace" "") ("enskip" "") ("quad" "") ("qquad" "") ("nonumber" "")
       ("centering" "") ("TeX" "") ("LaTeX" ""))
-     'font-lock-function-name-face 2 command)
+     font-lock-function-name-face 2 command)
     ("sectioning-0"
      (("part" "*[{"))
      (if (eq font-latex-fontify-sectioning 'color)
@@ -383,36 +383,36 @@ variable `font-latex-fontify-sectioning'." ',num)
         'font-lock-type-face
        'font-latex-sectioning-5-face)
      2 command)
-    ("slide-title" () 'font-latex-slide-title-face 2 command)
+    ("slide-title" () font-latex-slide-title-face 2 command)
     ("textual"
      (("item" "[") ("title" "{") ("author" "{") ("date" "{")
       ("thanks" "{") ("address" "{") ("caption" "[{")
-      ("textsuperscript" "{") ("textsubscript" "{"))
-     'font-lock-type-face 2 command)
+      ("textsuperscript" "{") ("textsubscript" "{") ("verb" "*"))
+     font-lock-type-face 2 command)
     ("bold-command"
      (("textbf" "{") ("textsc" "{") ("textup" "{") ("boldsymbol" "{")
       ("pmb" "{"))
-     'font-latex-bold-face 1 command)
+     font-latex-bold-face 1 command)
     ("italic-command"
      (("emph" "{") ("textit" "{") ("textsl" "{"))
-     'font-latex-italic-face 1 command)
+     font-latex-italic-face 1 command)
     ("math-command"
      (("ensuremath" "|{\\"))
-     'font-latex-math-face 1 command)
+     font-latex-math-face 1 command)
     ("type-command"
      (("texttt" "{") ("textsf" "{") ("textrm" "{") ("textmd" "{"))
-     'font-lock-type-face 1 command)
+     font-lock-type-face 1 command)
     ("bold-declaration"
      ("bf" "bfseries" "sc" "scshape" "upshape")
-     'font-latex-bold-face 1 declaration)
+     font-latex-bold-face 1 declaration)
     ("italic-declaration"
      ("em" "it" "itshape" "sl" "slshape")
-     'font-latex-italic-face 1 declaration)
+     font-latex-italic-face 1 declaration)
     ("type-declaration"
      ("tt" "ttfamily" "sf" "sffamily" "rm" "rmfamily" "mdseries"
       "tiny" "scriptsize" "footnotesize" "small" "normalsize"
       "large" "Large" "LARGE" "huge" "Huge")
-     'font-lock-type-face 1 declaration))
+     font-lock-type-face 1 declaration))
   "Built-in keywords and specifications for font locking.
 
 The first element of each item is the name of the keyword class.
@@ -440,11 +440,13 @@ will match macros of the form \"\\foo[bar]{baz}\".")
 (defcustom font-latex-deactivated-keyword-classes nil
   "List of strings for built-in keyword classes to be deactivated.
 
-Valid entries are \"warning\", \"variable\", \"reference\",
-\"function\" , \"sectioning-0\", \"sectioning-1\", \"sectioning-2\",
-\"sectioning-3\", \"sectioning-4\", \"sectioning-5\", \"textual\",
-\"bold-command\", \"italic-command\", \"math-command\", \"type-command\",
-\"bold-declaration\", \"italic-declaration\", \"type-declaration\".
+Valid entries are \"warning\", \"variable\", \"biblatexnoarg\",
+\"biblatex\", \"reference\", \"function\" , \"sectioning-0\",
+\"sectioning-1\", \"sectioning-2\", \"sectioning-3\",
+\"sectioning-4\", \"sectioning-5\", \"slide-title\", \"textual\",
+\"bold-command\", \"italic-command\", \"math-command\",
+\"type-command\", \"bold-declaration\", \"italic-declaration\",
+\"type-declaration\".
 
 You have to restart Emacs for a change of this variable to take effect."
   :group 'font-latex-keywords
@@ -457,7 +459,10 @@ You have to restart Emacs for a change of this variable to 
take effect."
                                    (mapconcat 'identity name " "))
                                  " keywords in `"
                                  ;; Name of the face
-                                 (symbol-name (eval (nth 2 spec))) "'.\n"
+                                 (symbol-name
+                                  (let ((face (nth 2 spec)))
+                                    (if (symbolp face) face (eval face))))
+                                 "'.\n"
                                  ;; List of keywords
                                  (with-temp-buffer
                                    (insert "  Keywords: "
@@ -467,8 +472,7 @@ You have to restart Emacs for a change of this variable to 
take effect."
                                                           x))
                                                       (nth 1 spec) ", "))
                                    (fill-paragraph nil)
-                                   (buffer-substring-no-properties
-                                    (point-min) (point-max))))
+                                   (buffer-string)))
                           ,(car spec)))
                 font-latex-built-in-keyword-classes)))
 
@@ -502,9 +506,9 @@ Generated by `font-latex-make-match-defun'.")
                      ,(intern (concat prefix name "-keywords")))
                     ;; `face' can be a face symbol, a form returning
                     ;; a face symbol, or a list of face attributes.
-                    (if (and (listp ,face) (functionp (car ,face)))
-                        (eval ,face)
-                      ,face)
+                    ,(if (and (listp face) (fboundp (car face)))
+                        face
+                       `',face)
                     limit)))))
        ((eq type 'declaration)
         (eval `(defun ,(intern (concat prefix name)) (limit)
@@ -526,15 +530,21 @@ Generated by `font-latex-make-match-defun'.")
 (defun font-latex-keyword-matcher (prefix name face type)
   "Return a matcher and highlighter as required by `font-lock-keywords'.
 PREFIX and NAME are strings which are concatenated to form the
-respective match function.  FACE is a face name or a list of text
-properties that will be applied to the respective part of the
-match returned by the match function.  TYPE is the type of
-construct to be highlighted.  Currently the symbols 'command,
-'sectioning, 'declaration and 'noarg are valid.
+respective match function.  FACE is a face name or a list of face
+attributes that will be applied to the respective part of the
+match returned by the match function.  A lisp form returning a
+face name or a list of face attributes is also valid for FACE.
+TYPE is the type of construct to be highlighted.  Currently the
+symbols 'command, 'declaration and 'noarg are valid.
 
 This is a helper function for `font-latex-make-built-in-keywords'
 and `font-latex-make-user-keywords' and not intended for general
 use."
+  ;; Quote a list of face attributes and a face symbol
+  ;; but do not quote a form returning such value.
+  (unless (and (listp face) (fboundp (car face)))
+    (setq face `',face))
+
   ;; In an earlier version of font-latex the type could be a list like
   ;; (command 1).  This indicated a macro with one argument.  Provide
   ;; a matcher in this case but don't actually support it.
@@ -550,10 +560,7 @@ use."
           (7 (font-latex-matched-face 7) append t)))
        ((eq type 'noarg)
         `(,(intern (concat prefix name))
-          ;; Quote a list of face properties but do not to quote a face symbol.
-          (0 ,(if (and (listp face) (not (fboundp (car face))))
-                  `',face
-                face))))
+          (0 ,face)))
        ((eq type 'declaration)
         `(,(intern (concat prefix name))
           (0 'font-latex-warning-face t t)
@@ -574,14 +581,18 @@ use."
       (eval `(defvar ,(intern (concat prefix name "-keywords-local"))
               ',keywords
               ,(concat "Buffer-local keywords to add to `"
-                       prefix name "-keywords'.
-
+                       prefix name "-keywords'.\n\n"
+                       (if (eq type 'command)
+                           "\
 This must be a list where each element is a list consisting of a
 keyword string \(not a regular expression\) omitting the leading
-backslash and a format specifier as.  The options for the format
-specifier are described in the doc string of
-`font-latex-user-keyword-classes'.
+backslash and a format specifier as described in the doc string of
+`font-latex-user-keyword-classes'."
+                         "\
+This must be a list where each element is a keyword string \(not a
+regular expression\) omitting the leading backslash.")
 
+                       "\n\n\
 This is an internal variable which should not be set directly.
 Use `font-latex-add-keywords' instead.
 
@@ -638,7 +649,6 @@ Setting this variable directly does not take effect; restart
 Emacs.
 
 Generated by `font-latex-make-built-in-keywords'.")
-              :type '(repeat (string :tag "Keyword"))
               :type '(repeat ,(if (eq type 'command)
                                   '(list (string :tag "Keyword")
                                          (string :tag "Format"))
@@ -649,8 +659,11 @@ Generated by `font-latex-make-built-in-keywords'.")
               :group 'font-latex-keywords))
 
       ;; defvar font-latex-match-*
-      (eval `(defvar ,(intern (concat prefix name))
-              ,(intern (concat prefix name "-keywords"))))
+      (eval `(defvar ,(intern (concat prefix name)) nil
+              ,(concat "Regular expression to match " name
+                       " keywords.
+
+Generated by `font-latex-make-built-in-keywords'")))
       (make-variable-buffer-local (intern (concat prefix name)))
 
       ;; defun font-latex-match-*
@@ -663,7 +676,7 @@ Generated by `font-latex-make-built-in-keywords'.")
                                     (number-to-string level)))
                     keywords-entry t)
        (when (= level 1)
-         (add-to-list (intern (concat "font-latex-keywords-2"))
+         (add-to-list 'font-latex-keywords-2
                       keywords-entry t))))))
 (font-latex-make-built-in-keywords)
 
@@ -694,8 +707,8 @@ also specify two alternative arguments by prefixing them 
with
 \"|\".  As an example, the specifier for \\newcommand is
 \"*|{\\=\\[[{\".
 
-The face argument can either be an existing face or a font
-specification.  (The latter option is not available in XEmacs.)
+The face argument can either be an existing face or a face
+attribute.  (The latter option is not available in XEmacs.)
 
 There are three alternatives for the class type:
 
@@ -714,7 +727,7 @@ A value of `noarg' indicates commands without arguments
 specified.
 
 Setting this variable directly does not take effect;
-use \\[customize] or restart Emacs."
+restart Emacs."
   :group 'font-latex-keywords
   :type `(repeat (list (string :tag "Name")
                       (choice (repeat :tag "Keywords" (string :tag "Keyword"))
@@ -724,8 +737,8 @@ use \\[customize] or restart Emacs."
                                       (string :tag "Format specifier"))))
                       ,(if (featurep 'xemacs)
                            '(face :tag "Face name")
-                         '(choice (custom-face-edit :tag "Face attributes")
-                                  (face :tag "Face name")))
+                         '(choice (face :tag "Face name")
+                                  (custom-face-edit :tag "Face attributes")))
                       (choice :tag "Type"
                               ;; Maps to
                               ;;`font-latex-match-command-with-arguments'
@@ -755,7 +768,11 @@ use \\[customize] or restart Emacs."
           (dolist (elt value)
             (unless (boundp (intern (concat prefix (car elt))))
               ;; defvar font-latex-match-*
-              (eval `(defvar ,(intern (concat prefix (car elt))) nil)))
+              (eval `(defvar ,(intern (concat prefix (car elt))) nil
+                       ,(concat "Regular expression to match " (car elt)
+                                " keywords.
+
+Generated by `font-latex-user-keyword-classes'"))))
             (let ((keywords (nth 1 elt))
                   single-char-macro-flag)
               (setq keywords (if (listp (car keywords))
@@ -789,7 +806,7 @@ use \\[customize] or restart Emacs."
 Generated by `font-latex-make-user-keywords'.")))
 
        ;; defun font-latex-match-*
-       (eval `(font-latex-make-match-defun prefix name '',face type))
+       (font-latex-make-match-defun prefix name face type)
 
        ;; Add the matcher to `font-latex-keywords-2'.
        (add-to-list 'font-latex-keywords-2
@@ -810,7 +827,7 @@ Generated by `font-latex-make-user-keywords'.")))
     (add-to-list 'font-latex-keywords-1 item)
     (add-to-list 'font-latex-keywords-2 item))
   (dolist (item
-          `((font-latex-match-math-env
+          '((font-latex-match-math-env
              (0 'font-latex-warning-face t t)
              (1 'font-latex-math-face append t))
             (font-latex-match-math-envII
@@ -828,11 +845,12 @@ Generated by `font-latex-make-user-keywords'.")))
   "Add KEYWORDS to CLASS.
 KEYWORDS is a list of keywords or keywords with syntax specs.
 CLASS corresponds to a keyword class and can be one of the
-symbols 'warning, 'variable, 'reference, 'biblatex, 'function,
-'sectioning-0, 'sectioning-1, 'sectioning-2, 'sectioning-3,
-'sectioning-4, 'sectioning-5, 'slide-title, 'textual,
-'bold-command, 'italic-command, 'math-command, 'type-command,
-'bold-declaration, 'italic-declaration or 'type-declaration.
+symbols 'warning, 'variable, 'reference, 'biblatexnoarg,
+'biblatex, 'function, 'sectioning-0, 'sectioning-1,
+'sectioning-2, 'sectioning-3, 'sectioning-4, 'sectioning-5,
+'slide-title, 'textual, 'bold-command, 'italic-command,
+'math-command, 'type-command, 'bold-declaration,
+'italic-declaration or 'type-declaration.
 
 The keywords will be added to the buffer-local list of keywords
 of the respective keyword class and necessary updates of the font
@@ -987,6 +1005,10 @@ have changed."
     (unless (= (length verb-macros-with-delims) 0)
       (add-to-list 'font-latex-syntactic-keywords
                   `(,(concat "\\\\\\(?:" verb-macros-with-delims "\\)"
+                             ;; Some macros take an optional
+                             ;; argument.  This is the same line as
+                             ;; above for environments.
+                             "\\(?:\\[[^][]*\\(?:\\[[^][]*\\][^][]*\\)*\\]\\)?"
                              ;; An opening curly brace as delimiter
                              ;; is valid, but allowing it might screw
                              ;; up fontification of stuff like
@@ -1001,6 +1023,10 @@ have changed."
     (unless (= (length verb-macros-with-braces) 0)
       (add-to-list 'font-latex-syntactic-keywords
                   `(,(concat "\\\\\\(?:" verb-macros-with-braces "\\)"
+                             ;; Some macros take an optional
+                             ;; argument.  This is the same line as
+                             ;; above for environments.
+                             "\\(?:\\[[^][]*\\(?:\\[[^][]*\\][^][]*\\)*\\]\\)?"
                              "\\({\\).*?[^\\]\\(?:\\\\\\\\\\)*\\(}\\)")
                     (1 "|") (2 "|")))))
   (when font-latex-syntactic-keywords-extra
@@ -1416,14 +1442,29 @@ modified.  Such variables include
 `LaTeX-verbatim-environments-local',
 `LaTeX-verbatim-macros-with-braces-local',
 `LaTeX-verbatim-macros-with-delims-local'."
-  ;; Note to self: directory-local variables are also added to
-  ;; file-local-variables-alist.
-  (let ((hacked-local-vars (mapcar #'car file-local-variables-alist)))
-    (when (or (memq 'LaTeX-verbatim-environments-local hacked-local-vars)
-             (memq 'LaTeX-verbatim-macros-with-braces-local hacked-local-vars)
-             (memq 'LaTeX-verbatim-macros-with-delims-local hacked-local-vars))
-      ;; Ok, we need to refresh fontification.
-      (font-latex-update-font-lock t))))
+  (when (if (boundp 'file-local-variables-alist)
+           ;; In Emacs we know if the value came from file or directory
+           ;; locals.  Note to self: directory-local variables are also added
+           ;; to file-local-variables-alist.
+           (let ((hacked-local-vars (mapcar #'car file-local-variables-alist)))
+             (or (memq 'LaTeX-verbatim-environments-local hacked-local-vars)
+                 (memq 'LaTeX-verbatim-macros-with-braces-local 
hacked-local-vars)
+                 (memq 'LaTeX-verbatim-macros-with-delims-local 
hacked-local-vars)))
+         ;; In XEmacs and old Emacs versions we don't know if a buffer-local
+         ;; variable has been set by a file-local variables block or somehow
+         ;; else.  So we trigger a refresh if any of those variables has a
+         ;; non-nil local binding.
+         (or (and LaTeX-verbatim-environments-local
+                  (local-variable-p LaTeX-verbatim-environments-local
+                                    (current-buffer)))
+             (and LaTeX-verbatim-macros-with-braces-local
+                  (local-variable-p LaTeX-verbatim-macros-with-braces-local
+                                    (current-buffer)))
+             (and LaTeX-verbatim-macros-with-delims-local
+                  (local-variable-p LaTeX-verbatim-macros-with-delims-local
+                                    (current-buffer)))))
+    ;; Ok, we need to refresh fontification.
+    (font-latex-update-font-lock t)))
 
 ;;; Utility functions
 
diff --git a/latex.el b/latex.el
index 6960749..fa87c98 100644
--- a/latex.el
+++ b/latex.el
@@ -66,6 +66,7 @@ the lines are outcommented, like in dtx files."
 (defun LaTeX-newline ()
   "Start a new line potentially staying within comments.
 This depends on `LaTeX-insert-into-comments'."
+  (interactive)
   (if LaTeX-insert-into-comments
       (cond ((and (save-excursion (skip-chars-backward " \t") (bolp))
                  (save-excursion
@@ -213,8 +214,7 @@ section."
 (defun LaTeX-section-list-add-locally (sections &optional clean)
   "Add SECTIONS to `LaTeX-section-list'.
 SECTIONS can be a single list containing the section macro name
-as a string and the the level as an integer or a list of such
-lists.
+as a string and the level as an integer or a list of such lists.
 
 If optional argument CLEAN is non-nil, remove any existing
 entries from `LaTeX-section-list' before adding the new ones.
@@ -849,7 +849,7 @@ The compatibility argument IGNORE is ignored."
     (save-excursion
       (while (and (not found)
                  (re-search-backward
-                  
"\\\\documentclass\\(\\[[a-z0-9A-Z\-\_,]*\\]\\)?\\({[^}]+}\\)"
+                  "\\\\documentclass\\(\\[[^]\n\r]*\\]\\)?\\({[^}]+}\\)"
                   nil t))
        (and (not (TeX-in-commented-line))
             (setq found t))))
@@ -887,9 +887,12 @@ optional argument is omitted.)"
   :group 'LaTeX)
 
 (defcustom LaTeX-label-function nil
-  "*A function inserting a label at point.
-Sole argument of the function is the environment.  The function has to return
-the label inserted, or nil if no label was inserted."
+  "*A function inserting a label at point or returning a label string.
+Sole mandatory argument of the function is the environment.  The
+function has to return the label inserted, or nil if no label was
+inserted.  If the optional argument NO-INSERT is non-nil, then
+the function has to return the label as string without any
+insertion or nil if no label was read in."
   :group 'LaTeX-label
   :type 'function)
 
@@ -905,6 +908,14 @@ the label inserted, or nil if no label was inserted."
   :group 'LaTeX-environment
   :type 'string)
 
+(defcustom LaTeX-listing-label "lst:"
+  "Default prefix to listing labels.
+This prefix should apply to all environments which typeset
+code listings and take a caption and label."
+  :group 'LaTeX-label
+  :group 'LaTeX-environment
+  :type 'string)
+
 (defcustom LaTeX-default-format ""
   "Default format for array and tabular environments."
   :group 'LaTeX-environment
@@ -986,7 +997,7 @@ corresponding entry."
 
 (make-variable-buffer-local 'LaTeX-label-alist)
 
-(defun LaTeX-label (name &optional type)
+(defun LaTeX-label (name &optional type no-insert)
   "Insert a label for NAME at point.
 The optional TYPE argument can be either environment or section:
 in the former case this function looks up `LaTeX-label-alist' to
@@ -998,7 +1009,9 @@ prefix.
 If `LaTeX-label-function' is a valid function, LaTeX label will
 transfer the job to this function.
 
-The inserted label is returned, nil if it is empty."
+If the optional NO-INSERT is non-nil, only the label is returned
+and no insertion happens.  Otherwise the inserted label is
+returned, nil if it is empty."
   (let ((TeX-read-label-prefix
         (cond
          ((eq type 'environment)
@@ -1018,22 +1031,21 @@ The inserted label is returned, nil if it is empty."
     (when (symbolp TeX-read-label-prefix)
       (setq TeX-read-label-prefix (symbol-value TeX-read-label-prefix)))
     (when TeX-read-label-prefix
-      (if (and (boundp 'LaTeX-label-function)
-              LaTeX-label-function
-              (fboundp LaTeX-label-function))
-         (setq label (funcall LaTeX-label-function name))
+      (if (and (fboundp LaTeX-label-function))
+         (funcall LaTeX-label-function name no-insert)
        ;; Use completing-read as we do with `C-c C-m \label RET'
        (setq label (TeX-read-label t "What label" t))
        ;; No label or empty string entered?
        (if (or (string= TeX-read-label-prefix label)
                (string= "" label))
            (setq label nil)
-         (insert TeX-esc "label" TeX-grop label TeX-grcl))
-       (if label
-           (progn
-             (LaTeX-add-labels label)
-             label)
-         nil)))))
+         ;; We have a label; when NO-INSERT is nil, insert
+         ;; \label{label} in the buffer, add new label to list of
+         ;; known labels and return it
+         (unless no-insert
+           (insert TeX-esc "label" TeX-grop label TeX-grcl))
+         (LaTeX-add-labels label)
+         label)))))
 
 (defcustom LaTeX-short-caption-prompt-length 40
   "The length that the caption of a figure should be before
@@ -1236,6 +1248,78 @@ Just like array and tabular."
                       (make-marker))))
       (TeX-parse-arguments args))))
 
+(defun LaTeX-env-label-as-keyval (_optional &optional keyword keyvals 
environment)
+  "Query for a label and insert it in the optional argument of an environment.
+OPTIONAL is ignored.  Optional KEYWORD is a string to search for
+in the optional argument, label is only included if KEYWORD is
+found.  KEYVALS is a string with key=val's read in.  If nil, this
+function searchs for key=val's itself.  ENVIRONMENT is a string
+with the name of environment, if non-nil, don't bother to find
+out."
+  (let ((env-start (make-marker))
+       (body-start (make-marker))
+       (opt-start (make-marker))
+       (opt-end   (make-marker))
+       (currenv (or environment (LaTeX-current-environment))))
+    ;; Save the starting point as we will come back here
+    (set-marker body-start (point))
+    ;; Go to the start of the current environment and save the position
+    (LaTeX-find-matching-begin)
+    (set-marker env-start (point))
+    ;; Check if an opt. argument is there; assume that it starts in
+    ;; the same line and save the points in markers
+    (when (re-search-forward
+          (concat "\\\\begin{" currenv "}[ \t]*\\[") body-start t)
+      (set-marker opt-start (1- (point)))
+      (goto-char opt-start)
+      (forward-sexp)
+      (set-marker opt-end (1- (point))))
+    ;; If keyword argument is given and keyvals argument is not given,
+    ;; parse the optional argument and put it into keyvals; the regexp
+    ;; takes care of multi-line arguments
+    (when (and keyword
+              (marker-position opt-start)
+              (not keyvals))
+      (goto-char (1+ opt-start))
+      (re-search-forward "\\(.*\\([\n\r].*\\)*\\)" opt-end t)
+      (setq keyvals (match-string-no-properties 0)))
+    ;; If keyword is given, only insert a label when keyword is found
+    ;; inside the keyvals.  If keyword is nil, then insert a label
+    ;; anyways
+    (if (stringp keyword)
+       (when (and (stringp keyvals)
+                  (not (string= keyvals ""))
+                  (string-match (concat keyword "[ \t]*=") keyvals))
+         (goto-char opt-end)
+         (let ((opt-label (LaTeX-label currenv 'environment t)))
+           (when opt-label
+             (insert (if (equal (preceding-char) ?,)
+                         "label="
+                       ",label=")
+                     TeX-grop opt-label TeX-grcl))))
+      (let ((opt-label (LaTeX-label currenv 'environment t)))
+       (when opt-label
+         ;; Check if an opt. argument is found and go to the end if
+         (if (marker-position opt-end)
+             (progn
+               (goto-char opt-end)
+               (insert (if (equal (preceding-char) ?,)
+                           "label="
+                         ",label=")
+                       TeX-grop opt-label TeX-grcl))
+           ;; Otherwise start at the beginning of environment in
+           ;; order to not mess with any other mandatory arguments
+           ;; which can be there
+           (goto-char env-start)
+           (re-search-forward (concat "\\\\begin{" currenv "}"))
+           (insert LaTeX-optop "label=" TeX-grop opt-label TeX-grcl 
LaTeX-optcl)))))
+    ;; Go to where we started and clean up the markers
+    (goto-char body-start)
+    (set-marker env-start nil)
+    (set-marker body-start nil)
+    (set-marker opt-start nil)
+    (set-marker opt-end nil)))
+
 ;;; Item hooks
 
 (defvar LaTeX-item-list nil
@@ -1522,7 +1606,7 @@ This is necessary since index entries may contain 
commands and stuff.")
        (, (concat "\\\\bibitem\\[[^][\n\r]+\\]{\\(" token "[^, 
\n\r\t%\"#'()={}]*\\)}")
          1 LaTeX-auto-bibitem)
        ("\\\\bibliography{\\([^#}\\\\\n\r]+\\)}" 1 LaTeX-auto-bibliography)
-       ("\\\\addbibresource\\(?:\\[[^]]+\\]\\)?{\\([^#}\\\\\n\r\.]+\\)\\..+}"
+       ("\\\\addbibresource\\(?:\\[[^]]+\\]\\)?{\\([^#}\\\\\n\r]+\\)\\..+}"
        1 LaTeX-auto-bibliography)
        
("\\\\add\\(?:global\\|section\\)bib\\(?:\\[[^]]+\\]\\)?{\\([^#}\\\\\n\r\.]+\\)\\(?:\\..+\\)?}"
 1 LaTeX-auto-bibliography)
        ("\\\\newrefsection\\[\\([^]]+\\)\\]" 1 LaTeX-split-bibs)
@@ -1542,9 +1626,9 @@ This is necessary since index entries may contain 
commands and stuff.")
 Split the string at commas and remove Biber file extensions."
   (let ((bibs (TeX-split-string " *, *" (TeX-match-buffer match))))
     (dolist (bib bibs)
-      (LaTeX-add-bibliographies (replace-regexp-in-string
+      (LaTeX-add-bibliographies (TeX-replace-regexp-in-string
                                 (concat "\\(?:\\."
-                                        (mapconcat 'regexp-quote
+                                        (mapconcat #'regexp-quote
                                                    TeX-Biber-file-extensions
                                                    "\\|\\.")
                                         "\\)")
@@ -1618,6 +1702,12 @@ See also `LaTeX-provided-package-options'.")
 The value is actually the tail of the list of options given to CLASS."
   (member option (cdr (assoc class LaTeX-provided-class-options))))
 
+(defun LaTeX-match-class-option (regexp)
+  "Check if a documentclass option matching REGEXP is active."
+  (TeX-member regexp (apply #'append
+                           (mapcar #'cdr LaTeX-provided-class-options))
+             'string-match))
+
 (defvar LaTeX-provided-package-options nil
   "Alist of options provided to LaTeX packages.
 For each element, the CAR is the name of the package, the CDR is
@@ -1708,9 +1798,10 @@ The value is actually the tail of the list of options 
given to PACKAGE."
                              (list (cons style options)))))
 
        ;; The third argument if "class" indicates LaTeX2e features.
-       (cond ((equal class "class")
+       (cond ((or (string-equal class "class")
+                  (string-equal class "Class"))
               (add-to-list 'TeX-auto-file "latex2e"))
-             ((equal class "style")
+             ((string-equal class "style")
               (add-to-list 'TeX-auto-file "latex2"))))))
 
   ;; Cleanup optional arguments
@@ -1822,16 +1913,41 @@ argument, otherwise as a mandatory one."
 
 (defun TeX-read-label (optional &optional prompt definition)
   "Prompt for a label completing with known labels and return it.
-If OPTIONAL is non-nil, insert the resulting value as an optional
-argument, otherwise as a mandatory one.  Use PROMPT as the prompt
-string.  If DEFINITION is non-nil, add the chosen label to the
-list of defined labels.  `TeX-read-label-prefix' is used as
-initial input for the label."
-  (let ((label (completing-read
-               (TeX-argument-prompt optional prompt "Key")
-               (LaTeX-label-list) nil nil TeX-read-label-prefix)))
-    (if (and definition (not (string-equal "" label)))
-       (LaTeX-add-labels label))
+This function always returns a string depending on user input:
+the returned value can be an empty string \"\", the value of
+`TeX-read-label-prefix' if present (e.g. \"fig:\") or a complete
+label input (e.g. \"fig:foo\").  If OPTIONAL is non-nil, indicate
+optional as part of prompt in minibuffer.  Use PROMPT as the
+prompt string.  If DEFINITION is non-nil, add the chosen label to
+the list of defined labels.  `TeX-read-label-prefix' is used as
+initial input for the label.  Also check if label is already
+defined and ask user for confirmation before proceeding."
+  (let (label valid)
+    (while (not valid)
+      (setq label
+           (completing-read
+            (TeX-argument-prompt optional prompt "Key")
+            (LaTeX-label-list) nil nil TeX-read-label-prefix))
+      ;; If we're defining a label, check if it's already defined and
+      ;; ask user for confirmation, otherwise ask again
+      (cond ((and definition
+                 (assoc label (LaTeX-label-list)))
+            (ding)
+            (when (y-or-n-p
+                   (format-message "Label `%s' exists. Use anyway? " label))
+              (setq valid t)))
+           (t
+            (setq valid t))))
+    ;; Only add a newly defined label to list of known one if it is
+    ;; not empty and not equal to `TeX-read-label-prefix', if given
+    (when (and definition
+              (not (string-equal "" label))
+              (if TeX-read-label-prefix
+                  (not (string-equal TeX-read-label-prefix label))
+                t))
+      (LaTeX-add-labels label))
+    ;; Return label, can be empty string "", TeX-read-label-prefix
+    ;; only "fig:" or the real thing like "fig:foo"
     label))
 
 (defun TeX-arg-label (optional &optional prompt definition)
@@ -4430,10 +4546,21 @@ value of NO-SUBSECTIONS."
   "Internal list of LaTeX macros that should have their own line.")
 
 (defun LaTeX-paragraph-commands-regexp-make ()
-  "Return a regular expression matching defined paragraph commands."
-  (concat (regexp-quote TeX-esc) "\\("
-         (regexp-opt (append LaTeX-paragraph-commands
-                             LaTeX-paragraph-commands-internal)) "\\)"))
+  "Return a regular expression matching defined paragraph commands.
+Regexp part containing TeX control words is postfixed with `\\b'
+to avoid ambiguities (e.g. \\par vs. \\parencite)."
+  (let (cmds symbs)
+    (dolist (mac (append LaTeX-paragraph-commands
+                        LaTeX-paragraph-commands-internal))
+      (if (string-match "[^a-zA-Z]" mac)
+         (push mac symbs)
+       (push mac cmds)))
+    (concat (regexp-quote TeX-esc) "\\(?:"
+           (regexp-opt cmds "\\(?:")
+           "\\b"
+           "\\|"
+           (regexp-opt symbs)
+           "\\)")))
 
 (defcustom LaTeX-paragraph-commands nil
   "List of LaTeX macros that should have their own line.
@@ -5391,7 +5518,7 @@ char."
 (defun LaTeX-narrow-to-environment (&optional count)
   "Make text outside current environment invisible.
 With optional COUNT keep visible that number of enclosing
-environmens."
+environments."
   (interactive "p")
   (setq count (if count (abs count) 1))
   (save-excursion
@@ -5952,7 +6079,9 @@ i.e. you do _not_ have to cater for this yourself by 
adding \\\\' or $."
   "Default start of trailer marker for LaTeX documents.")
 
 (defcustom LaTeX-clean-intermediate-suffixes
-  TeX-clean-default-intermediate-suffixes
+  (append TeX-clean-default-intermediate-suffixes
+         ;; These are extensions of files created by makeglossaries.
+         '("\\.acn" "\\.acr" "\\.alg" "\\.glg" "\\.ist"))
   "List of regexps matching suffixes of files to be deleted.
 The regexps will be anchored at the end of the file name to be matched,
 i.e. you do _not_ have to cater for this yourself by adding \\\\' or $."
@@ -6508,16 +6637,21 @@ function would return non-nil and `(match-string 1)' 
would return
 
 (defun LaTeX-hanging-ampersand-position ()
   "Return indent column for a hanging ampersand (i.e. ^\\s-*&)."
-  (destructuring-bind (beg-pos . beg-col)
-      (LaTeX-env-beginning-pos-col)
-    (let* ((cur-pos (point)))
-      (save-excursion
-        (if (re-search-backward "\\\\\\\\" beg-pos t)
-            (let ((cur-idx (TeX-how-many "[^\\]&" (point) cur-pos)))
-              (goto-char beg-pos)
-              (re-search-forward "[^\\]&" cur-pos t (+ 1 cur-idx))
-              (- (current-column) 1))
-          (+ 2 beg-col))))))
+  (destructuring-bind
+   (beg-pos . beg-col)
+   (LaTeX-env-beginning-pos-col)
+   (let* ((cur-pos (point)))
+     (save-excursion
+       (if (re-search-backward "\\\\\\\\" beg-pos t)
+          (let ((cur-idx (TeX-how-many "[^\\]&" (point) cur-pos)))
+            (goto-char beg-pos)
+            (re-search-forward "[^\\]&" cur-pos t (+ 1 cur-idx))
+            ;; If the above searchs fails, i.e. no "&" found,
+            ;; (- (current-column) 1) returns -1, which is wrong.  So
+            ;; we use a fallback (+ 2 beg-col) whenever this happens:
+            (max (- (current-column) 1)
+                 (+ 2 beg-col)))
+        (+ 2 beg-col))))))
 
 (defun LaTeX-indent-tabular ()
   "Return indent column for the current tabular-like line."
@@ -6545,10 +6679,10 @@ function would return non-nil and `(match-string 1)' 
would return
           (t
            (+ 2
               (let ((any-col (save-excursion
-                               (when (re-search-backward "\\\\\\\\\\|&" 
beg-pos t)
+                               (when (re-search-backward "\\\\\\\\\\|[^\\]&" 
beg-pos t)
                                  (current-column)))))
-                (if (and any-col (string= "&" (match-string 0)))
-                    any-col
+                (if (and any-col (= ?& (char-before (match-end 0))))
+                    (1+ any-col)
                   beg-col))))))))
 
 (provide 'latex)
diff --git a/latex/preview.dtx b/latex/preview.dtx
index 5372032..c98a451 100644
--- a/latex/preview.dtx
+++ b/latex/preview.dtx
@@ -388,7 +388,7 @@
 % 
 % As an example for using this argument, you might want to specify
 % \begin{quote}
-%   |\PreviewMacro*\footnote[{[]}][#1{}]|
+%   |\PreviewMacro*[{[]}][#1{}]{\footnote}|
 % \end{quote}
 % This will replace a footnote by an empty footnote, but taking any
 % optional parameter into account, since an optional paramter changes
@@ -420,7 +420,7 @@
 % is essential for the operation of \cmd{\PreviewOpen} that the macro
 % treated with it will open an additional group even when the preview
 % falls inside of another preview or inside of a |nopreview|
-% environment.  Similarly, the macro treated with \cmd{PreviewClose}
+% environment.  Similarly, the macro treated with \cmd{\PreviewClose}
 % will close an environment even when inactive.
 % 
 % \DescribeMacro{\ifPreview} In case you need to know whether
diff --git a/plain-tex.el b/plain-tex.el
index dfdc423..4960196 100644
--- a/plain-tex.el
+++ b/plain-tex.el
@@ -152,30 +152,29 @@ of plain-TeX-mode-hook."
   (set (make-local-variable 'TeX-style-hook-dialect) plain-TeX-dialect)
   (setq paragraph-start
        (concat
-        "\\(^[ \t]*$"
+        "\\(?:[ \t]*$"
         "\\|" (regexp-quote TeX-esc) "par\\|"
-        "^[ \t]*"
+        "[ \t]*"
         (regexp-quote TeX-esc)
-        "\\("
+        "\\(?:"
         "begin\\|end\\|part\\|chapter\\|"
         "section\\|subsection\\|subsubsection\\|"
         "paragraph\\|include\\|includeonly\\|"
-        "tableofcontents\\|appendix\\|label\\|caption\\|"
-        "\\[\\|\\]"                    ; display math delimitors
+        "tableofcontents\\|appendix\\|label\\|caption\\|\\(?:item\\)?item"
         "\\)"
         "\\|"
-        "^[ \t]*\\$\\$"                ; display math delimitor
+        "[ \t]*\\$\\$"         ; display math delimitor
         "\\)" ))
   (setq paragraph-separate
        (concat
         "[ \t]*"
-        "\\("
+        "\\(?:"
         (regexp-quote TeX-esc) "par\\|"
         "%\\|"
         "$\\|"
         "\\$\\$\\|"
         (regexp-quote TeX-esc)
-        "\\("
+        "\\(?:"
         "begin\\|end\\|label\\|caption\\|part\\|chapter\\|"
         "section\\|subsection\\|subsubsection\\|"
         "paragraph\\|include\\|includeonly\\|"
diff --git a/style/amsmath.el b/style/amsmath.el
index 6daec4e..76f922f 100644
--- a/style/amsmath.el
+++ b/style/amsmath.el
@@ -220,7 +220,10 @@ START and END."
                                        "sumlimits" "nosumlimits"
                                        "namelimits" "nonamelimits"
                                        "leqno" "reqno" "centertags"
-                                       "tbtags" "cmex10" "fleqn" "?")
+                                       "tbtags" "cmex10" "fleqn" "?"
+                                       "alignedleftspaceyes"
+                                       "alignedleftspaceno"
+                                       "alignedleftspaceyesifneg")
     "Package options for the amsmath package.")
 
 ;;; amsmath.el ends here.
diff --git a/style/biblatex.el b/style/biblatex.el
index aa5fcc9..6662695 100644
--- a/style/biblatex.el
+++ b/style/biblatex.el
@@ -578,6 +578,8 @@ for citation keys."
            (?U    . "\\autocite*[][]{%l}")
            (?a    . "\\citeauthor{%l}")
            (?A    . "\\citeauthor*{%l}")
+           (?i    . "\\citetitle{%l}")
+           (?I    . "\\citetitle*{%l}")
            (?y    . "\\citeyear{%l}")
            (?Y    . "\\citeyear*{%l}")
            (?n    . "\\nocite{%l}")))))))
diff --git a/style/breqn.el b/style/breqn.el
new file mode 100644
index 0000000..8006082
--- /dev/null
+++ b/style/breqn.el
@@ -0,0 +1,185 @@
+;;; breqn.el --- AUCTeX style for `breqn.sty' (v0.98e)
+
+;; Copyright (C) 2017 Free Software Foundation, Inc.
+
+;; Author: Arash Esbati <address@hidden>
+;; Maintainer: address@hidden
+;; Created: 2017-01-06
+;; Keywords: tex
+
+;; This file is part of AUCTeX.
+
+;; AUCTeX is free software; you can redistribute it and/or modify it
+;; under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 3, or (at your option)
+;; any later version.
+
+;; AUCTeX is distributed in the hope that it will be useful, but
+;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;; General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with AUCTeX; see the file COPYING.  If not, write to the Free
+;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+;; 02110-1301, USA.
+
+;;; Commentary:
+
+;; This file adds support for `breqn.sty' (v0.98e) from 2017/01/27.
+;; `breqn.sty' is part of TeXLive.
+
+;; In breqn documentation, there is the following statement:
+;;
+;;   9 Various environment options
+;;
+;;   Use of the normal \label command instead of the label option
+;;   works, I think, most of the time (untested).
+;;
+;; To be on the safe side, a label should be written in the optional
+;; argument of an environment as value to the `label' key, e.g.:
+;;
+;;   \begin{dmath}[label={eq:42}]
+;;     ...
+;;   \end{dmath}
+;;
+;; This style achieves this requirement by using the function
+;; `LaTeX-env-label-as-keyval'.
+
+;;; Code:
+
+(defvar LaTeX-breqn-key-val-options
+  '(("style" ("\\tiny" "\\scriptsize" "\\footnotesize" "\\small"
+             "\\normalsize" "\\large" "\\Large" "\\LARGE"
+             "\\huge" "\\Huge"))
+    ("number")
+    ("indentstep")
+    ("compact")
+    ("spread")
+    ("frame")
+    ("framesep")
+    ("background")
+    ("color")
+    ("breakdepth"))
+  "Key=value options for breqn environments.
+The keys \"label\" and \"labelprefix\" are omitted.")
+
+(defvar LaTeX-breqn-key-val-options-local nil
+  "Buffer-local key=value options for breqn environments.")
+(make-variable-buffer-local 'LaTeX-breqn-key-val-options-local)
+
+(defvar LaTeX-breqn-key-val-label-regexp
+  `(,(concat
+      "\\\\begin{"
+      (regexp-opt '("dmath" "dseries" "dgroup" "darray"))
+      "}"
+      "\\(?:\\[[^][]*"
+       "\\(?:{[^}{]*"
+         "\\(?:{[^}{]*"
+           "\\(?:{[^}{]*}[^}{]*\\)*"
+         "}[^}{]*\\)*"
+       "}[^][]*\\)*"
+      "label[ \t]*=[ \t]*{\\([^}]+\\)}"
+      "\\(?:[^]]*\\)*"
+      "\\]\\)")
+    1 LaTeX-auto-label)
+  "Matches the label inside an optional argument after 
\\begin{<breqn-env's>}.")
+
+(defun LaTeX-breqn-env (env)
+  "Insert ENV from breqn package incl. optional key=val argument.
+Keys offered for key=val query depend on ENV.  \"label\" and
+\"labelprefix\" are omitted."
+  (let ((keyvals
+        (TeX-read-key-val t
+                          (cond ((or (string= env "dgroup")
+                                     (string= env "dgroup*"))
+                                 (append '(("noalign") ("brace"))
+                                         LaTeX-breqn-key-val-options-local))
+                                ((or (string= env "darray")
+                                     (string= env "darray*"))
+                                 (append '(("noalign") ("brace") ("cols" 
("{}")))
+                                         LaTeX-breqn-key-val-options-local))
+                                (t LaTeX-breqn-key-val-options-local)))))
+    (LaTeX-insert-environment env (when (and keyvals
+                                            (not (string= keyvals "")))
+                                   (concat LaTeX-optop keyvals LaTeX-optcl)))
+    (LaTeX-env-label-as-keyval nil nil keyvals env)))
+
+(defun LaTeX-breqn-update-color-keys ()
+  "Update color relevant keys from `LaTeX-breqn-key-val-options-local'."
+  (when (or (member "xcolor" (TeX-style-list))
+           (member "color" (TeX-style-list)))
+    (let* ((colorcmd (if (member "xcolor" (TeX-style-list))
+                        #'LaTeX-xcolor-definecolor-list
+                      #'LaTeX-color-definecolor-list))
+          (keys '("color" "background"))
+          (tmp (copy-alist LaTeX-breqn-key-val-options-local)))
+      (dolist (x keys)
+       (assq-delete-all (car (assoc x tmp)) tmp)
+       (push (list x (mapcar #'car (funcall colorcmd))) tmp))
+      (setq LaTeX-breqn-key-val-options-local
+           (copy-alist tmp)))))
+
+(add-hook 'TeX-auto-cleanup-hook #'LaTeX-breqn-update-color-keys t)
+(add-hook 'TeX-update-style-hook #'TeX-auto-parse t)
+
+(TeX-add-style-hook
+ "breqn"
+ (lambda ()
+
+   ;; Local version of key-val options
+   (setq LaTeX-breqn-key-val-options-local
+        (copy-alist LaTeX-breqn-key-val-options))
+
+   ;; Add breqn to parser:
+   (TeX-auto-add-regexp LaTeX-breqn-key-val-label-regexp)
+
+   ;; Tell AUCTeX that we want to prefix the labels with 
`LaTeX-equation-label':
+   (let ((envs '("dmath"  "dseries" "dgroup" "darray")))
+     (dolist (env envs)
+       (add-to-list 'LaTeX-label-alist `(,env . LaTeX-equation-label) t)))
+
+   ;; For RefTeX, we must distinguish between equation and eqnarray-like:
+   ;; breqn env == equivalent -- starred
+   ;; dmath     == equation   -- dmath*   == unnumbered
+   ;; dseries   == equation   -- dseries* == unnumbered
+   ;; dgroup    == align      -- dgroup*  == unnumbered
+   ;; darray    == eqnarray   -- darray*  == unnumbered
+   (when (fboundp 'reftex-add-label-environments)
+     (dolist (env '("dmath" "dseries" "dgroup"))
+       (reftex-add-label-environments `((,env ?e nil nil t))))
+     (reftex-add-label-environments '(("darray" ?e nil nil eqnarray-like))))
+
+   (LaTeX-add-environments
+    '("dmath" LaTeX-breqn-env)
+    '("dmath*" LaTeX-breqn-env)
+    '("dseries" LaTeX-breqn-env)
+    '("dseries*" LaTeX-breqn-env)
+    '("dgroup" LaTeX-breqn-env)
+    '("dgroup*" LaTeX-breqn-env)
+    '("darray" LaTeX-breqn-env)
+    '("darray*" LaTeX-breqn-env)
+    '("dsuspend"))
+
+   (TeX-add-symbols
+    '("condition"  [ "Punctuation mark (default ,)" ] t)
+    '("condition*" [ "Punctuation mark (default ,)" ] t)
+    '("hiderel" t))
+
+   ;; Fontification
+   (when (and (featurep 'font-latex)
+             (eq TeX-install-font-lock 'font-latex-setup)
+             (boundp 'font-latex-math-environments))
+     (make-local-variable 'font-latex-math-environments)
+     (let ((envs '(;; Do not insert the starred versions here;
+                  ;; function `font-latex-match-math-envII' takes
+                  ;; care of it
+                  "dmath" "dseries" "dgroup" "darray")))
+       (dolist (env envs)
+        (add-to-list 'font-latex-math-environments env t)))))
+ LaTeX-dialect)
+
+(defvar LaTeX-breqn-package-options nil
+  "Package options for the breqn package.")
+
+;;; breqn.el ends here
diff --git a/style/caption.el b/style/caption.el
index ec1d36d..84809b9 100644
--- a/style/caption.el
+++ b/style/caption.el
@@ -293,25 +293,25 @@ STAR is non-nil, do not query for a short-caption and a 
label."
       (insert LaTeX-optop short-caption LaTeX-optcl))
     (TeX-argument-insert caption optional)
     (LaTeX-fill-paragraph)
-    (unless star
-      ;; Check if `envtype' is a figure or a table, also consult
-      ;; `LaTeX-label-alist' for additions from user or newfloat.el,
-      ;; then run `LaTeX-label' w/ 'environment arg, otherwise w/o.
-      (save-excursion
-       (if (or (member envtype figtypes)
-               (member envtype tabtypes)
-               (assoc envtype LaTeX-label-alist))
-           (LaTeX-label (cond ((member envtype figtypes)
-                               "figure")
-                              ((member envtype tabtypes)
-                               "table")
-                              (t envtype))
-                        'environment)
-         (LaTeX-label envtype)))
-      (when (looking-at-p "\\\\label{")
-       (LaTeX-newline)
-       (indent-according-to-mode)
-       (end-of-line)))))
+    (when (and (not star)
+              ;; Check if `envtype' is a figure or a table, also
+              ;; consult `LaTeX-label-alist' for additions from user
+              ;; or newfloat.el, then run `LaTeX-label' w/
+              ;; 'environment arg, otherwise w/o.
+              (save-excursion
+                (if (or (member envtype figtypes)
+                        (member envtype tabtypes)
+                        (assoc envtype LaTeX-label-alist))
+                    (LaTeX-label (cond ((member envtype figtypes)
+                                        "figure")
+                                       ((member envtype tabtypes)
+                                        "table")
+                                       (t envtype))
+                                 'environment)
+                  (LaTeX-label envtype))))
+      (LaTeX-newline)
+      (indent-according-to-mode)
+      (end-of-line))))
 
 (TeX-add-style-hook
  "caption"
diff --git a/style/color.el b/style/color.el
index 1b878d3..0a9c74a 100644
--- a/style/color.el
+++ b/style/color.el
@@ -1,6 +1,6 @@
 ;;; color.el --- AUCTeX style for `color.sty' (v1.1a)
 
-;; Copyright (C) 2015, 2016 Free Software Foundation, Inc.
+;; Copyright (C) 2015--2017 Free Software Foundation, Inc.
 
 ;; Author: Arash Esbati <address@hidden>
 ;; Maintainer: address@hidden
@@ -61,37 +61,18 @@
 ;; Needed for auto-parsing.
 (require 'tex)
 
-;; Plug color into the parser -- after that we have the following:
-;; 1. LaTeX-auto-color-definecolor: Name of temporary variable used
-;; when parsing.
-;; 2. LaTeX-add-color-definecolors: Name of function to add
-;; information to add to #3.
-;; 3. LaTeX-color-definecolor-list: Name of variable holding buffer
-;; local information.
-;; 4. LaTeX-color-definecolors-changed: Name of variable indicating
-;; that #3 has changed.
+;; Plug \definecolor into the parser
 (TeX-auto-add-type "color-definecolor" "LaTeX")
 
 (defvar LaTeX-color-definecolor-regexp
-  '("\\\\definecolor{\\([^}]+\\)}{\\([^}]+\\)}{\\([^}]+\\)}"
-    1 LaTeX-auto-color-definecolor)
-  "Matches the arguments of `\\definecolor' from `color'
-package.")
+  '("\\\\definecolor{\\([^}]+\\)}" 1 LaTeX-auto-color-definecolor)
+  "Matches the argument of \\definecolor from color package.")
 
 (defun LaTeX-color-auto-prepare ()
   "Clear `LaTeX-auto-color-definecolor' before parsing."
-  (setq        LaTeX-auto-color-definecolor nil))
-
-(defun LaTeX-color-auto-cleanup ()
-  "Move parsed colors from `LaTeX-auto-color-definecolor' to
-`LaTeX-color-definecolor-list'."
-  ;; \definecolor{<name>}{<model>}{<colour-spec>}
-  ;; color=<name>, ignored=<model>, ignored=<colour-spec>
-  (dolist (color LaTeX-auto-color-definecolor)
-    (add-to-list 'LaTeX-color-definecolor-list (list color))))
+  (setq LaTeX-auto-color-definecolor nil))
 
 (add-hook 'TeX-auto-prepare-hook #'LaTeX-color-auto-prepare t)
-(add-hook 'TeX-auto-cleanup-hook #'LaTeX-color-auto-cleanup t)
 (add-hook 'TeX-update-style-hook #'TeX-auto-parse t)
 
 (defun TeX-arg-color-definecolor (optional &optional prompt)
diff --git a/style/empheq.el b/style/empheq.el
index 268faf4..5618646 100644
--- a/style/empheq.el
+++ b/style/empheq.el
@@ -227,8 +227,8 @@ number of ampersands if possible."
       (when (looking-at "[ \t\n\r%]*\\[")
        (forward-sexp))
       (re-search-forward "[ \t\n\r%]*{\\([^}]+\\)}")
-      (setq match (replace-regexp-in-string "[ \t\n\r%]*" ""
-                                           (match-string-no-properties 1)))
+      (setq match (TeX-replace-regexp-in-string "[ \t\n\r%]" ""
+                                               (match-string-no-properties 1)))
       (if (string-match "=" match)
          (progn
            (setq amsenv (car (split-string match "=")))
diff --git a/style/fancyvrb.el b/style/fancyvrb.el
index e0f7c6a..3b33350 100644
--- a/style/fancyvrb.el
+++ b/style/fancyvrb.el
@@ -1,6 +1,6 @@
 ;;; fancyvrb.el --- AUCTeX style for `fancyvrb.sty' version 2.8.
 
-;; Copyright (C) 2013, 2014, 2016 Free Software Foundation, Inc.
+;; Copyright (C) 2013, 2014, 2016, 2017 Free Software Foundation, Inc.
 
 ;; Maintainer: address@hidden
 ;; Author: Mosè Giordano <address@hidden>
@@ -27,32 +27,43 @@
 
 ;; This file adds support for `fancyvrb.sty' version 2.8.
 
-;;; Code:
+;; This style has some capabilities to parse user defined macros,
+;; environments and saved blocks with `SaveVerbatim' environments and
+;; offer them for completion.  After defining a new macro or
+;; environment, hit `C-c C-n' to parse the document.  In case of
+;; `SaveVerbatim', a second `C-c C-n' might be necessary.
 
-(defvar LaTeX-fancyvrb-macro-regexp
-  (concat "\\\\\\(?:Re\\|\\)CustomVerbatimCommand"
-         "[ \t\n\r]*{?[ \t\n\r]*\\\\\\([A-Za-z]+\\)[ \t\n\r]*}?")
-  "Matches macros by fancyvrb package.")
+;; The command `\CustomVerbatimEnvironment' is not mentioned in the
+;; documenation; hence this command is removed from this style.  Use
+;; `\DefineVerbatimEnvironment' for new environments and customize the
+;; standard ones with `\RecustomVerbatimEnvironment'.
 
-(defvar LaTeX-fancyvrb-environment-regexp
-  (concat "\\\\\\(?:Define\\|Custom\\|Recustom\\)VerbatimEnvironment"
-         "[ \t\n\r]*{[ \t\n\r]*\\([A-Za-z]+\\)[ \t\n\r]*}")
-  "Matches environments by fancyvrb package.")
+;; The entries in `LaTeX-fancyvrb-key-val-options' cover also some
+;; keys which are not mentioned in the manual of the package.
+
+;;; Code:
+
+;; Needed for auto-parsing.
+(require 'tex)
 
 (defvar LaTeX-fancyvrb-key-val-options
-  '(("commentchar")
+  '(("commentchar" ("none"))
     ("gobble")
     ("formatcom")
+    ;; Undocumented key
+    ("formatcom*")
     ("fontfamily" ("tt" "courier" "helvetica"))
-    ("fontsize")
-    ("fontshape")
-    ("fontseries")
+    ("fontsize"   ("auto" "\\tiny" "\\scriptsize"
+                  "\\footnotesize" "\\small" "\\normalsize"
+                  "\\large" "\\Large" "\\LARGE" "\\huge" "\\Huge"))
+    ("fontshape"  ("auto" "n" "it" "sl" "sc" "scit"))
+    ("fontseries" ("auto" "m" "b" "bx" "sb" "c" "l" "lc"))
     ("frame" ("none" "leftline" "topline" "bottomline" "lines" "single"))
     ("framerule")
     ("framesep")
-    ("rulecolor")
-    ("fillcolor")
-    ("label")
+    ("rulecolor" ("none"))
+    ("fillcolor" ("none"))
+    ("label" ("none"))
     ("labelposition" ("none" "topline" "bottomline" "all"))
     ("numbers" ("none" "left" "right"))
     ("numbersep")
@@ -66,37 +77,319 @@
     ("obeytabs" ("true" "false"))
     ("tabsize")
     ("baselinestretch" ("auto" "dimension"))
-    ("commandchars")
+    ("commandchars" ("none"))
     ("xleftmargin")
     ("xrightmargin")
     ("resetmargins" ("true" "false"))
     ("hfuzz")
     ("samepage" ("true" "false"))
     ("codes")
+    ;; Undocumented key
+    ("codes*")
     ("defineactive")
+    ;; Undocumented key
+    ("defineactive*")
     ;; Actually, the following options are used only by the `BVerbatim'
     ;; environment.
     ("boxwidth" ("auto" "dimension"))
-    ("baseline" ("b" "c" "t")))
+    ("baseline" ("b" "c" "t"))
+    ;; The next key applies only to `\SaveVerb' macro.
+    ("aftersave"))
   "Key=value options for fancyvrb macros and environments.")
 
+(defvar LaTeX-fancyvrb-key-val-options-local nil
+  "Buffer-local key=value options for fancyvrb macros and environments.
+This variable is intended for packages like \"fvextra\" which
+provide new key=values for fancyvrb environments.  New key=values
+should be appended to this variable.")
+(make-variable-buffer-local 'LaTeX-fancyvrb-key-val-options-local)
+
+(defvar LaTeX-fancyvrb-base-macros
+  '("VerbatimInput" "BVerbatimInput" "LVerbatimInput"
+    "SaveVerb" "UseVerb" "Verb")
+  "List of base macros available with fancyvrb package.
+Starred versions are not included in this list.")
+
+(defvar LaTeX-fancyvrb-base-environments
+  '("Verbatim" "BVerbatim" "LVerbatim" "SaveVerbatim" "VerbatimOut")
+  "List of base environments available with fancyvrb package.
+Starred versions are not included in this list.")
+
+(defvar LaTeX-fancyvrb-key-val-skip-regexp
+  (concat
+   "\\(?:\\[[^][]*"
+     "\\(?:{[^}{]*"
+       "\\(?:{[^}{]*"
+        "\\(?:{[^}{]*}[^}{]*\\)*"
+       "}[^}{]*\\)*"
+     "}[^][]*\\)*"
+   "\\]\\)?")
+  "Helper regexp to skip over an optional argument.")
+
+;; Setup for defining new Verbatim commands:
+
+(TeX-auto-add-type "fancyvrb-macro" "LaTeX")
+
+(defvar LaTeX-fancyvrb-macro-regexp
+  `(,(concat "\\\\\\(Rec\\|C\\)ustomVerbatimCommand"
+            "[ \t\n\r]*{?[ \t\n\r]*\\\\\\([A-Za-z]+\\)[ \t\n\r]*}?"
+            "[ \t\n\r]*{[ \t\n\r]*\\([A-Za-z]+\\)[ \t\n\r]*}")
+    (2 3 1) LaTeX-auto-fancyvrb-macro)
+  "Matches macros by fancyvrb package.")
+
+;; Setup for defining new Verbatim environments:
+
+(TeX-auto-add-type "fancyvrb-environment" "LaTeX")
+
+(defvar LaTeX-fancyvrb-environment-regexp
+  `(,(concat "\\\\DefineVerbatimEnvironment"
+            "[ \t\n\r]*{[ \t\n\r]*\\([A-Za-z0-9]+\\)[ \t\n\r]*}"
+            "[ \t\n\r]*{[ \t\n\r]*\\([A-Za-z]+\\)[ \t\n\r]*}")
+    (1 2) LaTeX-auto-fancyvrb-environment)
+  "Matches new environments defined by fancyvrb package.")
+
+;; Setup for names in SaveVerb macros:
+
+(TeX-auto-add-type "fancyvrb-saveverb" "LaTeX")
+
+(defvar LaTeX-fancyvrb-saveverb-regexp
+  `(,(concat "\\\\SaveVerb"
+            LaTeX-fancyvrb-key-val-skip-regexp
+            "{\\([^}]+\\)}")
+    1 LaTeX-auto-fancyvrb-saveverb)
+  "Match the name under which verbatim text is saved by SaveVerb macro.")
+
+;; Setup for names in SaveVerbatim environments:
+
+(TeX-auto-add-type "fancyvrb-saveverbatim" "LaTeX")
+
+(defvar LaTeX-fancyvrb-saveverbatim-regexp
+  `(,(concat "\\\\begin{SaveVerbatim}"
+            LaTeX-fancyvrb-key-val-skip-regexp
+            "{\\([^}]+\\)}")
+    1 LaTeX-auto-fancyvrb-saveverbatim)
+  "Match the name under which verbatim text is saved by SaveVerbatim 
environment.")
+
+(defun LaTeX-fancyvrb-auto-prepare ()
+  "Clear various LaTeX-auto-fancyvrb-* variables before parsing."
+  (setq LaTeX-auto-fancyvrb-macro        nil
+       LaTeX-auto-fancyvrb-environment  nil
+       LaTeX-auto-fancyvrb-saveverb     nil
+       LaTeX-auto-fancyvrb-saveverbatim nil))
+
+(defun LaTeX-fancyvrb-auto-cleanup ()
+  "Process parsed elements for fancyvrb package."
+  (LaTeX-fancyvrb-arg-define-macro nil t)
+  (LaTeX-fancyvrb-arg-define-environment nil t))
+
+(add-hook 'TeX-auto-prepare-hook #'LaTeX-fancyvrb-auto-prepare t)
+(add-hook 'TeX-auto-cleanup-hook #'LaTeX-fancyvrb-auto-cleanup t)
+(add-hook 'TeX-update-style-hook #'TeX-auto-parse t)
+
+(defun LaTeX-fancyvrb-arg-define-macro (optional &optional cleanup recustom)
+  "Query and insert a new verbatim macro with fancyvrb package.
+If OPTIONAL is non-nil, insert the arguments in brackets.  If
+CLEANUP is non-nil, do not insert any arguments in the buffer and
+update only various AUCTeX variables for verbatim macros.  If
+RECUSTOM is non-nil, delete macros from the variable
+`TeX-symbol-list' before adding the new ones."
+  (let ((new-mac (unless cleanup
+                  (if recustom
+                      (completing-read
+                       (TeX-argument-prompt optional nil "Verbatim macro: \\" 
t)
+                       (mapcar #'car (apply #'append 
LaTeX-fancyvrb-macro-list)))
+                    (TeX-read-string
+                     (TeX-argument-prompt optional nil "New verbatim macro: 
\\" t)))))
+       (base-mac (unless cleanup
+                   (completing-read (TeX-argument-prompt optional nil "Based 
on macro")
+                                    LaTeX-fancyvrb-base-macros)))
+       (rec-flag (if recustom "Rec" "C")))
+    ;; We are (re-)defining a macro: Insert user queried input and use
+    ;; `LaTeX-add-fancyvrb-macros' on the input
+    (unless cleanup
+      (TeX-argument-insert new-mac optional TeX-esc)
+      (TeX-argument-insert base-mac optional)
+      (TeX-argument-insert
+       (TeX-read-key-val optional LaTeX-fancyvrb-key-val-options-local) 
optional)
+      (LaTeX-add-fancyvrb-macros `(,new-mac ,base-mac ,rec-flag))))
+  ;;
+  ;; Now run the procdure: Do not use the function
+  ;; `LaTeX-fancyvrb-macro-list' here which will remove dupes from the
+  ;; variable `LaTeX-fancyvrb-macro-list' depending on car; we need
+  ;; the variable as is, hence (apply #'append ...);
+  (dolist (elt (apply #'append LaTeX-fancyvrb-macro-list))
+    (let ((mac-name (nth 0 elt))
+         (base-mac (nth 1 elt))
+         (flag     (nth 2 elt)))
+      ;; If we're Rec-ustomizing, delete the entry first from
+      ;; `TeX-symbol-list':
+      (when (string= flag "Rec")
+       (setq TeX-symbol-list
+             (assq-delete-all (car (assoc mac-name (TeX-symbol-list))) 
TeX-symbol-list)))
+      ;; Now add the new item: Start with new macros for loading
+      ;; files:
+      (cond ((member base-mac '("VerbatimInput" "BVerbatimInput" 
"LVerbatimInput"))
+            (TeX-add-symbols
+             `(,mac-name
+               [ TeX-arg-key-val LaTeX-fancyvrb-key-val-options-local ]
+               LaTeX-fancyvrb-arg-file-relative))
+            (when (and (fboundp 'font-latex-add-keywords)
+                       (fboundp 'font-latex-update-font-lock))
+              (font-latex-add-keywords `((,mac-name "[{"))
+                                       'reference)))
+           ;; New macros for saving verbatim text:
+           ((string= base-mac "SaveVerb")
+            (TeX-add-symbols
+             `(,mac-name
+               [ TeX-arg-key-val LaTeX-fancyvrb-key-val-options-local ]
+               (TeX-arg-eval
+                (lambda ()
+                  (let ((name (TeX-read-string
+                               (TeX-argument-prompt optional nil "Save 
name"))))
+                    (LaTeX-add-fancyvrb-saveverbs name)
+                    (format "%s" name))))
+               TeX-arg-verb))
+            (when (and (fboundp 'font-latex-add-keywords)
+                       (fboundp 'font-latex-update-font-lock))
+              (font-latex-add-keywords `((,mac-name "[{"))
+                                       'textual)))
+           ;; New macros for using previously saved text:
+           ((string= base-mac "UseVerb")
+            (TeX-add-symbols
+             `(,mac-name
+               (TeX-arg-eval
+                completing-read
+                (TeX-argument-prompt optional nil "Saved name")
+                (LaTeX-fancyvrb-saveverb-list))))
+            (when (and (fboundp 'font-latex-add-keywords)
+                       (fboundp 'font-latex-update-font-lock))
+              (font-latex-add-keywords `((,mac-name "{"))
+                                       'textual)))
+           ;; Anything else is considered as verbatim typesetting macro:
+           (t
+            (TeX-add-symbols
+             `(mac-name
+               [ TeX-arg-key-val LaTeX-fancyvrb-key-val-options-local ]
+               TeX-arg-verb))
+            (add-to-list 'LaTeX-verbatim-macros-with-delims-local mac-name t)
+            (when (and (fboundp 'font-latex-add-keywords)
+                       (fboundp 'font-latex-update-font-lock))
+              (font-latex-add-keywords `((,mac-name "["))
+                                       'textual))))))
+  ;; Update font-lock:
+  (when (and (fboundp 'font-latex-add-keywords)
+            (fboundp 'font-latex-update-font-lock)
+            (eq TeX-install-font-lock 'font-latex-setup))
+    (font-latex-update-font-lock t)))
+
+(defun LaTeX-fancyvrb-arg-define-environment (optional &optional cleanup)
+  "Query and insert a new verbatim environment with fancyvrb package.
+If OPTIONAL is non-nil, insert the arguments in brackets.  If
+CLEANUP is non-nil, do not insert any arguments in the buffer and
+update only various AUCTeX variables for verbatim environments."
+  (let ((new-env (unless cleanup
+                  (TeX-read-string
+                   (TeX-argument-prompt optional nil "New verbatim 
environment"))))
+       (base-env (unless cleanup
+                   (completing-read (TeX-argument-prompt optional nil "Based 
on environment")
+                                    LaTeX-fancyvrb-base-environments))))
+    ;; We are defining a new env: First insert the arguments and the
+    ;; run `LaTeX-add-fancyvrb-environments' on '(new-env base-env).
+    ;; If base-env is SaveVerbatim, run
+    ;; `LaTeX-add-fancyvrb-saveverbatims' on new-env as well.
+    (unless cleanup
+      (TeX-argument-insert (car new-env) optional)
+      (TeX-argument-insert base-env optional)
+      (TeX-argument-insert
+       (TeX-read-key-val optional LaTeX-fancyvrb-key-val-options-local) 
optional)
+      (LaTeX-add-fancyvrb-environments `(,new-env ,base-env))
+      (when (string= base-env "SaveVerbatim")
+       (LaTeX-add-fancyvrb-saveverbatims new-env)))
+    ;;
+    ;; Now run the procdure:
+    (dolist (elt (LaTeX-fancyvrb-environment-list))
+      (let ((env (car elt))
+           (type (cadr elt)))
+       (cond ((string= type "VerbatimOut")
+              (LaTeX-add-environments
+               `(,env (lambda (env)
+                        (let ((options (TeX-read-key-val t 
LaTeX-fancyvrb-key-val-options-local))
+                              (file (TeX-read-string "Output file: ")))
+                          (LaTeX-insert-environment
+                           env
+                           (concat
+                            (unless (zerop (length options))
+                              (concat LaTeX-optop options LaTeX-optcl))
+                            (concat TeX-grop file TeX-grcl))))))))
+             ((string= type "SaveVerbatim")
+              (TeX-auto-add-regexp `(,(concat "\\\\begin{"
+                                              env
+                                              "}"
+                                              
LaTeX-fancyvrb-key-val-skip-regexp
+                                              "{\\([^}]+\\)}")
+                                     1 LaTeX-auto-fancyvrb-saveverbatim)))
+             (t
+              ;; Regular verbatim environments have a starred
+              ;; version; so add them here; the non-starred additions
+              ;; to `LaTeX-verbatim-environments-local' and
+              ;; `LaTeX-indent-environment-list' are done outside
+              ;; (cond ...):
+              (LaTeX-add-environments
+               `(,env LaTeX-env-args
+                      [ TeX-arg-key-val LaTeX-fancyvrb-key-val-options-local 
]))
+              (LaTeX-add-environments
+               `(,(concat env "*") LaTeX-env-args
+                 [ TeX-arg-key-val LaTeX-fancyvrb-key-val-options-local ]))
+              (add-to-list 'LaTeX-verbatim-environments-local (concat env "*"))
+              (add-to-list 'LaTeX-indent-environment-list
+                           `(,(concat env "*") current-indentation) t)))
+       ;; These apply for all environments defined:
+       (add-to-list 'LaTeX-verbatim-environments-local env)
+       (add-to-list 'LaTeX-indent-environment-list `(,env current-indentation) 
t)))
+    ;; Update font-lock:
+    (when (and (fboundp 'font-latex-add-keywords)
+              (fboundp 'font-latex-update-font-lock)
+              (eq TeX-install-font-lock 'font-latex-setup))
+      (font-latex-update-font-lock t))))
+
+(defun LaTeX-fancyvrb-arg-file-relative (optional)
+  "Query and insert a file name relative to current master file.
+If OPTIONAL is non-nil, insert the file name in brackets."
+  (TeX-argument-insert
+   (file-relative-name
+    (read-file-name (TeX-argument-prompt optional nil "File"))
+    (TeX-master-directory))
+   optional))
+
 (TeX-add-style-hook
  "fancyvrb"
  (lambda ()
-   (TeX-auto-add-regexp `(,LaTeX-fancyvrb-macro-regexp 1 TeX-auto-symbol))
-   (TeX-auto-add-regexp
-    `(,LaTeX-fancyvrb-environment-regexp 1 LaTeX-auto-environment))
+   (TeX-auto-add-regexp LaTeX-fancyvrb-macro-regexp)
+   (TeX-auto-add-regexp LaTeX-fancyvrb-environment-regexp)
+   (TeX-auto-add-regexp LaTeX-fancyvrb-saveverb-regexp)
+   (TeX-auto-add-regexp LaTeX-fancyvrb-saveverbatim-regexp)
    (TeX-run-style-hooks
     "keyval")
+
+   ;; Activate the buffer-local version of key-vals.
+   (setq LaTeX-fancyvrb-key-val-options-local
+        (copy-alist LaTeX-fancyvrb-key-val-options))
+
    (TeX-add-symbols
-    ;;; Verbatim material in footnotes
+    ;; Verbatim material in footnotes
     "VerbatimFootnotes"
-    ;;; Improved verbatim commands
-    '("Verb" [TeX-arg-key-val LaTeX-fancyvrb-key-val-options] TeX-arg-verb)
-    "DefineShortVerb"
-    "UndefineShortVerb"
-    ;;; Verbatim environments
-    '("fvset" (TeX-arg-key-val LaTeX-fancyvrb-key-val-options))
+    ;; Improved verbatim commands
+    '("Verb" [TeX-arg-key-val LaTeX-fancyvrb-key-val-options-local] 
TeX-arg-verb)
+    '("DefineShortVerb" (TeX-arg-eval
+                        TeX-read-string
+                        (TeX-argument-prompt optional nil "Character")
+                        TeX-esc))
+    '("UndefineShortVerb" (TeX-arg-eval
+                          TeX-read-string
+                          (TeX-argument-prompt optional nil "Character")
+                          TeX-esc))
+    ;; Verbatim environments
+    '("fvset" (TeX-arg-key-val LaTeX-fancyvrb-key-val-options-local))
     ;; Changing individual line formatting
     "FancyVerbFormatLine"
     ;; Line numbering
@@ -104,91 +397,137 @@
     ;; Selection of lines to print
     "FancyVerbStartString"
     "FancyVerbStopString"
+
     ;; Personalized environments
-    '("CustomVerbatimEnvironment"
-      (TeX-arg-define-environment "New verbatim environment")
-      (TeX-arg-environment "Basend on environment")
-      (TeX-arg-key-val LaTeX-fancyvrb-key-val-options))
-    '("RecustomVerbatimEnvironment"
-      (TeX-arg-environment "New verbatim environment")
-      (TeX-arg-environment "Basend on environment")
-      (TeX-arg-key-val LaTeX-fancyvrb-key-val-options))
     '("DefineVerbatimEnvironment"
-      (TeX-arg-define-environment "New verbatim environment")
-      (TeX-arg-environment "Basend on environment")
-      (TeX-arg-key-val LaTeX-fancyvrb-key-val-options))
-    '("CustomVerbatimCommand" (TeX-arg-define-macro "New verbatim macro: ")
-      (TeX-arg-eval completing-read "Based on macro: " (TeX-symbol-list))
-      (TeX-arg-key-val LaTeX-fancyvrb-key-val-options))
-    '("RecustomVerbatimCommand" (TeX-arg-macro "New verbatim macro: ")
-      (TeX-arg-eval completing-read "Based on macro: " (TeX-symbol-list))
-      (TeX-arg-key-val LaTeX-fancyvrb-key-val-options))
-    ;;; Saving and restoring verbatim text and environments
-    "SaveVerb"
-    "UseVerb"
-    "SaveVerbatim"
-    "UseVerbatim"
-    "LUseVerbatim"
-    "BUseVerbatim"
-    ;;; Writing and reading verbatim files
-    '("VerbatimInput" [TeX-arg-key-val LaTeX-fancyvrb-key-val-options]
-      (TeX-arg-file))
-    '("BVerbatimInput" [TeX-arg-key-val LaTeX-fancyvrb-key-val-options]
-      (TeX-arg-file))
-    '("LVerbatimInput" [TeX-arg-key-val LaTeX-fancyvrb-key-val-options]
-      (TeX-arg-file)))
+      LaTeX-fancyvrb-arg-define-environment)
+    '("RecustomVerbatimEnvironment"
+      (TeX-arg-eval completing-read
+                   (TeX-argument-prompt optional nil "Verbatim environment")
+                   LaTeX-fancyvrb-base-environments)
+      (TeX-arg-eval completing-read
+                   (TeX-argument-prompt optional nil "Based on environment")
+                   LaTeX-fancyvrb-base-environments)
+      (TeX-arg-key-val LaTeX-fancyvrb-key-val-options-local))
+
+    '("CustomVerbatimCommand"
+      LaTeX-fancyvrb-arg-define-macro)
+    '("RecustomVerbatimCommand"
+      (LaTeX-fancyvrb-arg-define-macro nil t))
+
+    ;; Saving and restoring verbatim text and environments
+    '("SaveVerb"
+      [TeX-arg-key-val LaTeX-fancyvrb-key-val-options-local]
+      (TeX-arg-eval
+       (lambda ()
+        (let ((name (TeX-read-string
+                     (TeX-argument-prompt optional nil "Save name"))))
+          (LaTeX-add-fancyvrb-saveverbs name)
+          (format "%s" name))))
+      TeX-arg-verb)
+    '("UseVerb" (TeX-arg-eval
+                completing-read
+                (TeX-argument-prompt optional nil "Saved name")
+                (LaTeX-fancyvrb-saveverb-list)))
+    '("UseVerbatim" (TeX-arg-eval completing-read
+                                 (TeX-argument-prompt optional nil "Saved 
name")
+                                 (LaTeX-fancyvrb-saveverbatim-list)))
+    '("LUseVerbatim" (TeX-arg-eval completing-read
+                                  (TeX-argument-prompt optional nil "Saved 
name")
+                                  (LaTeX-fancyvrb-saveverbatim-list)))
+    '("BUseVerbatim" (TeX-arg-eval completing-read
+                                  (TeX-argument-prompt optional nil "Saved 
name")
+                                  (LaTeX-fancyvrb-saveverbatim-list)))
+
+    ;; Writing and reading verbatim files
+    '("VerbatimInput" [TeX-arg-key-val LaTeX-fancyvrb-key-val-options-local]
+      LaTeX-fancyvrb-arg-file-relative)
+    '("BVerbatimInput" [TeX-arg-key-val LaTeX-fancyvrb-key-val-options-local]
+      LaTeX-fancyvrb-arg-file-relative)
+    '("LVerbatimInput" [TeX-arg-key-val LaTeX-fancyvrb-key-val-options-local]
+      LaTeX-fancyvrb-arg-file-relative))
+
    (LaTeX-add-environments
     '("Verbatim" LaTeX-env-args
-      [TeX-arg-key-val LaTeX-fancyvrb-key-val-options])
+      [TeX-arg-key-val LaTeX-fancyvrb-key-val-options-local])
+    '("Verbatim*" LaTeX-env-args
+      [TeX-arg-key-val LaTeX-fancyvrb-key-val-options-local])
     '("BVerbatim" LaTeX-env-args
-      [TeX-arg-key-val LaTeX-fancyvrb-key-val-options])
+      [TeX-arg-key-val LaTeX-fancyvrb-key-val-options-local])
+    '("BVerbatim*" LaTeX-env-args
+      [TeX-arg-key-val LaTeX-fancyvrb-key-val-options-local])
     '("LVerbatim" LaTeX-env-args
-      [TeX-arg-key-val LaTeX-fancyvrb-key-val-options])
-    '("SaveVerbatim" LaTeX-env-args
-      [TeX-arg-key-val LaTeX-fancyvrb-key-val-options])
+      [TeX-arg-key-val LaTeX-fancyvrb-key-val-options-local])
+    '("LVerbatim*" LaTeX-env-args
+      [TeX-arg-key-val LaTeX-fancyvrb-key-val-options-local])
+    '("SaveVerbatim"
+      (lambda (env)
+       (let ((options (TeX-read-key-val t 
LaTeX-fancyvrb-key-val-options-local))
+             (name (TeX-read-string "Save name: ")))
+         (LaTeX-insert-environment
+          env
+          (concat
+           (unless (zerop (length options))
+             (concat LaTeX-optop options LaTeX-optcl))
+           (concat TeX-grop name TeX-grcl)))
+         (LaTeX-add-fancyvrb-saveverbatims name))))
     '("VerbatimOut"
       (lambda (env)
-       (let ((options (TeX-read-key-val t LaTeX-fancyvrb-key-val-options))
+       (let ((options (TeX-read-key-val t 
LaTeX-fancyvrb-key-val-options-local))
              (file (TeX-read-string "Output file: ")))
          (LaTeX-insert-environment
           env
           (concat (unless (zerop (length options))
                     (concat LaTeX-optop options LaTeX-optcl))
                   (concat TeX-grop file TeX-grcl)))))))
+
    (LaTeX-add-counters
     "FancyVerbLine")
 
    ;; Filling
    (add-to-list 'LaTeX-verbatim-environments-local "Verbatim")
+   (add-to-list 'LaTeX-verbatim-environments-local "Verbatim*")
    (add-to-list 'LaTeX-verbatim-environments-local "BVerbatim")
+   (add-to-list 'LaTeX-verbatim-environments-local "BVerbatim*")
    (add-to-list 'LaTeX-verbatim-environments-local "LVerbatim")
+   (add-to-list 'LaTeX-verbatim-environments-local "LVerbatim*")
    (add-to-list 'LaTeX-verbatim-environments-local "SaveVerbatim")
    (add-to-list 'LaTeX-verbatim-environments-local "VerbatimOut")
    (make-local-variable 'LaTeX-indent-environment-list)
    (add-to-list 'LaTeX-indent-environment-list '("Verbatim" 
current-indentation) t)
+   (add-to-list 'LaTeX-indent-environment-list '("Verbatim*" 
current-indentation) t)
    (add-to-list 'LaTeX-indent-environment-list '("BVerbatim" 
current-indentation) t)
+   (add-to-list 'LaTeX-indent-environment-list '("BVerbatim*" 
current-indentation) t)
    (add-to-list 'LaTeX-indent-environment-list '("LVerbatim" 
current-indentation) t)
+   (add-to-list 'LaTeX-indent-environment-list '("LVerbatim*" 
current-indentation) t)
    (add-to-list 'LaTeX-indent-environment-list '("SaveVerbatim" 
current-indentation) t)
    (add-to-list 'LaTeX-indent-environment-list '("VerbatimOut" 
current-indentation) t)
    (add-to-list 'LaTeX-verbatim-macros-with-delims-local "Verb")
-   (add-to-list 'LaTeX-verbatim-macros-with-braces-local "Verb")
 
    ;; Fontification
    (when (and (fboundp 'font-latex-add-keywords)
              (fboundp 'font-latex-update-font-lock)
              (eq TeX-install-font-lock 'font-latex-setup))
-     (font-latex-add-keywords '(("DefineVerbatimEnvironment" "{{{")
-                               ("CustomVerbatimEnvironment" "{{{")
-                               ("RecustomVerbatimEnvironment" "{{{"))
+     (font-latex-add-keywords '(("CustomVerbatimCommand"       "{{{")
+                               ("RecustomVerbatimCommand"     "{{{")
+                               ("DefineVerbatimEnvironment"   "{{{")
+                               ("RecustomVerbatimEnvironment" "{{{")
+                               ("DefineShortVerb"   "{")
+                               ("UndefineShortVerb" "{")
+                               ("fvset"             "{"))
                              'function)
-     (font-latex-add-keywords '(("VerbatimInput" "[{")
+     (font-latex-add-keywords '(("VerbatimInput"  "[{")
                                ("BVerbatimInput" "[{")
                                ("LVerbatimInput" "[{"))
                              'reference)
-     (font-latex-add-keywords '(("Verb" "[")) ; The second argument should
+     (font-latex-add-keywords '(("Verb" "[") ; The second argument should
                                        ; actually be verbatim.
+                               ("SaveVerb"     "[{")
+                               ("UseVerb"      "{")
+                               ("UseVerbatim"  "{")
+                               ("LUseVerbatim" "{")
+                               ("BUseVerbatim" "{"))
                              'textual)
-     (font-latex-add-keywords '(("fvset" "{")) 'variable)
      ;; Tell font-lock about the update.
      (font-latex-update-font-lock t)))
  LaTeX-dialect)
diff --git a/style/fvextra.el b/style/fvextra.el
new file mode 100644
index 0000000..6ca2341
--- /dev/null
+++ b/style/fvextra.el
@@ -0,0 +1,139 @@
+;;; fvextra.el --- AUCTeX style for `fvextra.sty' (v1.2.1)
+
+;; Copyright (C) 2017 Free Software Foundation, Inc.
+
+;; Author: Arash Esbati <address@hidden>
+;; Maintainer: address@hidden
+;; Created: 2017-03-05
+;; Keywords: tex
+
+;; This file is part of AUCTeX.
+
+;; AUCTeX is free software; you can redistribute it and/or modify it
+;; under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 3, or (at your option)
+;; any later version.
+
+;; AUCTeX is distributed in the hope that it will be useful, but
+;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;; General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with AUCTeX; see the file COPYING.  If not, write to the Free
+;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+;; 02110-1301, USA.
+
+;;; Commentary:
+
+;; This file adds support for `fvextra.sty' (v1.2.1) from 2016/09/02.
+;; `fvextra.sty' is part of TeXLive.
+
+;;; Code:
+
+;; Needed for compiling `pushnew':
+(eval-when-compile (require 'cl))
+
+(defvar LaTeX-fvextra-key-val-options
+  '(;; 3 General options
+    ("curlyquotes" ("true" "false"))
+    ("highlightcolor")
+    ("highlightlines")
+    ("linenos" ("true" "false"))
+    ("mathescape" ("true" "false"))
+    ("numberfirstline" ("true" "false"))
+    ;; ("numbers" ("none" "left" "right" "both"))
+    ("space" ("\\textvisiblespace"))
+    ("spacecolor" ("none"))
+    ("stepnumberfromfirst" ("true" "false"))
+    ("stepnumberoffsetvalues" ("true" "false"))
+    ("tab" ("\\FancyVerbTab"))
+    ("tabcolor" ("none"))
+    ;; 5.1 Line breaking options
+    ("breakafter" ("none"))
+    ("breakaftergroup" ("true" "false"))
+    ("breakaftersymbolpre")
+    ("breakaftersymbolpost")
+    ("breakanywhere" ("true" "false"))
+    ("breakanywheresymbolpre")
+    ("breakanywheresymbolpost")
+    ("breakautoindent" ("true" "false"))
+    ("breakbefore")
+    ("breakbeforegroup" ("true" "false"))
+    ("breakbeforesymbolpre")
+    ("breakbeforesymbolpost")
+    ("breakindent")
+    ("breaklines" ("true" "false"))
+    ("breaksymbol")
+    ("breaksymbolleft")
+    ("breaksymbolright")
+    ("breaksymbolindent")
+    ("breaksymbolindentleft")
+    ("breaksymbolindentright")
+    ("breaksymbolsep")
+    ("breaksymbolsepleft")
+    ("breaksymbolsepright"))
+  "Key=value options for fvextra macros and environments.")
+
+(defun LaTeX-fvextra-update-key-val ()
+  "Update `LaTeX-fancyvrb-key-val-options-local' with key=vals from 
\"fvextra.sty\"."
+  ;; Delete the key "numbers" from `LaTeX-fancyvrb-key-val-options-local':
+  (setq LaTeX-fancyvrb-key-val-options-local
+       (assq-delete-all (car (assoc "numbers" 
LaTeX-fancyvrb-key-val-options-local))
+                        LaTeX-fancyvrb-key-val-options-local))
+  ;; Add the key with "both" value:
+  (add-to-list 'LaTeX-fancyvrb-key-val-options-local
+              '("numbers" ("none" "left" "right" "both")))
+  ;; Add color values to resp. keys:
+  (when (or (member "xcolor" (TeX-style-list))
+           (member "color" (TeX-style-list)))
+    (let* ((colorcmd (if (member "xcolor" (TeX-style-list))
+                        #'LaTeX-xcolor-definecolor-list
+                      #'LaTeX-color-definecolor-list))
+          (keys '("highlightcolor"
+                  "rulecolor"
+                  "fillcolor"
+                  "tabcolor"
+                  "spacecolor"))
+          (tmp (copy-alist LaTeX-fancyvrb-key-val-options-local)))
+      (dolist (x keys)
+       (assq-delete-all (car (assoc x tmp)) tmp)
+       (if (string= x "highlightcolor")
+           (pushnew (list x (mapcar #'car (funcall colorcmd))) tmp :test 
#'equal)
+         (pushnew (list x (append '("none") (mapcar #'car (funcall 
colorcmd)))) tmp :test #'equal)))
+      (setq LaTeX-fancyvrb-key-val-options-local
+           (copy-alist tmp)))))
+
+(add-hook 'TeX-auto-cleanup-hook #'LaTeX-fvextra-update-key-val t)
+(add-hook 'TeX-update-style-hook #'TeX-auto-parse t)
+
+(TeX-add-style-hook
+ "fvextra"
+ (lambda ()
+
+   ;; Run the style hook for "fancyvrb"
+   (TeX-run-style-hooks "fancyvrb")
+
+   ;; Append `LaTeX-fvextra-key-val' to `LaTeX-fancyvrb-key-val-options-local':
+   (setq LaTeX-fancyvrb-key-val-options-local
+        (append LaTeX-fvextra-key-val-options
+                LaTeX-fancyvrb-key-val-options-local))
+
+   (TeX-add-symbols
+    ;; 4.1 Line and text formatting
+    "FancyVerbFormatText"
+
+    ;; 5.3.2 Breaks within macro arguments
+    "FancyVerbBreakStart"
+    "FancyVerbBreakStop"
+
+    ;; 5.3.3 Customizing break behavior
+    "FancyVerbBreakAnywhereBreak"
+    "FancyVerbBreakBeforeBreak"
+    "FancyVerbBreakAfterBreak"))
+ LaTeX-dialect)
+
+(defvar LaTeX-fvextra-package-options nil
+  "Package options for the fvextra package.")
+
+;;; fvextra.el ends here
diff --git a/style/j-book.el b/style/j-book.el
index 932fe45..1df4bb0 100644
--- a/style/j-book.el
+++ b/style/j-book.el
@@ -5,7 +5,7 @@
 (TeX-add-style-hook
  "j-book"
  (lambda ()
-   (LaTeX-largest-level-set "chapter"))
+   (LaTeX-largest-level-set "part"))
  LaTeX-dialect)
 
 ;;; j-book.el ends here
diff --git a/style/jarticle.el b/style/jarticle.el
index 5d38668..f62bc02 100644
--- a/style/jarticle.el
+++ b/style/jarticle.el
@@ -1,11 +1,23 @@
-;;; jarticle.el - Special code for jarticle style.
+;;; jarticle.el - Special code for jarticle class.
 
 ;;; Code:
 
+(defvar LaTeX-jarticle-class-options
+  '("a4paper" "a5paper" "b4paper" "b5paper" "a4j" "a5j" "b4j" "b5j"
+    "a4p" "b4p" "b5p" "10pt" "11pt" "12pt" "landscape" "tombow" "tombo"
+    "mentuke" "oneside" "twoside" "onecolumn" "twocolumn"
+    "titlepage" "notitlepage" "leqno" "fleqn"
+    "openbib" "disablejfam" "mathrmmc" "draft" "final")
+  "Class options for the jarticle class.")
+
 (TeX-add-style-hook
  "jarticle"
  (lambda ()
-   (LaTeX-largest-level-set "section"))
+   (LaTeX-largest-level-set "section")
+   (LaTeX-add-counters "part" "section" "subsection" "subsubsection" 
"paragraph"
+                      "subparagraph" "figure" "table")
+   (LaTeX-add-pagestyles "headings" "myheadings")
+   (LaTeX-add-environments "abstract"))
  LaTeX-dialect)
 
 ;;; jarticle.el ends here
diff --git a/style/jbook.el b/style/jbook.el
index beb8748..bdb3dad 100644
--- a/style/jbook.el
+++ b/style/jbook.el
@@ -1,11 +1,22 @@
-;;; jbook.el - Special code for jbook style.
+;;; jbook.el - Special code for jbook class.
 
 ;;; Code:
 
+(defvar LaTeX-jbook-class-options
+  '("a4paper" "a5paper" "b4paper" "b5paper" "a4j" "a5j" "b4j" "b5j"
+    "a4p" "b4p" "b5p" "10pt" "11pt" "12pt" "landscape" "tombow" "tombo"
+    "mentuke" "oneside" "twoside" "onecolumn" "twocolumn"
+    "titlepage" "notitlepage" "openright" "openany" "leqno" "fleqn"
+    "openbib" "disablejfam" "mathrmmc" "draft" "final")
+  "Class options for the jbook class.")
+
 (TeX-add-style-hook
  "jbook"
  (lambda ()
-   (LaTeX-largest-level-set "chapter"))
+   (LaTeX-largest-level-set "part")
+   (LaTeX-add-counters "part" "chapter" "section" "subsection" "subsubsection"
+                      "paragraph" "subparagraph" "figure" "table")
+   (LaTeX-add-pagestyles "headings" "myheadings"))
  LaTeX-dialect)
 
 ;;; jbook.el ends here
diff --git a/style/jreport.el b/style/jreport.el
index 751ecc1..77aac32 100644
--- a/style/jreport.el
+++ b/style/jreport.el
@@ -1,12 +1,23 @@
-;;; jreport.el - Special code for jreport style.
+;;; jreport.el - Special code for jreport class.
 
 ;;; Code:
 
+(defvar LaTeX-jreport-class-options
+  '("a4paper" "a5paper" "b4paper" "b5paper" "a4j" "a5j" "b4j" "b5j"
+    "a4p" "b4p" "b5p" "10pt" "11pt" "12pt" "landscape" "tombow" "tombo"
+    "mentuke" "oneside" "twoside" "onecolumn" "twocolumn"
+    "titlepage" "notitlepage" "openright" "openany" "leqno" "fleqn"
+    "openbib" "disablejfam" "mathrmmc" "draft" "final")
+  "Class options for the jreport class.")
+
 (TeX-add-style-hook
  "jreport"
  (lambda ()
-   (LaTeX-largest-level-set "chapter"))
+   (LaTeX-largest-level-set "chapter")
+   (LaTeX-add-counters "part" "chapter" "section" "subsection" "subsubsection"
+                      "paragraph" "subparagraph" "figure" "table")
+   (LaTeX-add-pagestyles "headings" "myheadings")
+   (LaTeX-add-environments "abstract"))
  LaTeX-dialect)
 
-
 ;;; jreport.el ends here
diff --git a/style/jsarticle.el b/style/jsarticle.el
index 9e50fbb..d951cef 100644
--- a/style/jsarticle.el
+++ b/style/jsarticle.el
@@ -1,11 +1,27 @@
-;;; jsarticle.el - Special code for jsarticle style.
+;;; jsarticle.el - Special code for jsarticle class.
 
 ;;; Code:
 
+(defvar LaTeX-jsarticle-class-options
+  '("a3paper" "a4paper" "a5paper" "a6paper" "b4paper" "b5paper" "b6paper"
+    "a4j" "a5j" "b4j" "b5j" "a4var" "b5var" "letterpaper" "legalpaper"
+    "executivepaper" "landscape" "slide"
+    "8pt" "9pt" "10pt" "11pt" "12pt" "14pt" "17pt" "20pt" "21pt" "25pt"
+    "30pt" "36pt" "43pt" "12Q" "14Q" "usemag" "nomag" "nomag*"
+    "tombow" "tombo" "mentuke" "oneside" "twoside" "vartwoside"
+    "onecolumn" "twocolumn" "titlepage" "notitlepage" "leqno" "fleqn"
+    "disablejfam" "draft" "final" "mingoth" "wingoth" "jis"
+    "uplatex" "autodetect-engine" "papersize" "english" "jslogo" "nojslogo")
+  "Class options for the jsarticle class.")
+
 (TeX-add-style-hook
  "jsarticle"
  (lambda ()
-   (LaTeX-largest-level-set "section"))
+   (LaTeX-largest-level-set "section")
+   (LaTeX-add-counters "part" "section" "subsection" "subsubsection" 
"paragraph"
+                      "subparagraph" "figure" "table")
+   (LaTeX-add-pagestyles "headings" "myheadings")
+   (LaTeX-add-environments "abstract"))
  LaTeX-dialect)
 
 ;;; jsarticle.el ends here
diff --git a/style/jsbook.el b/style/jsbook.el
index fae2713..350e8af 100644
--- a/style/jsbook.el
+++ b/style/jsbook.el
@@ -1,11 +1,31 @@
-;;; jsbook.el - Special code for jsbook style.
+;;; jsbook.el - Special code for jsbook class.
 
 ;;; Code:
 
+(defvar LaTeX-jsbook-class-options
+  '("a3paper" "a4paper" "a5paper" "a6paper" "b4paper" "b5paper" "b6paper"
+    "a4j" "a5j" "b4j" "b5j" "a4var" "b5var" "letterpaper" "legalpaper"
+    "executivepaper" "landscape" "report"
+    "8pt" "9pt" "10pt" "11pt" "12pt" "14pt" "17pt" "20pt" "21pt" "25pt"
+    "30pt" "36pt" "43pt" "12Q" "14Q" "usemag" "nomag" "nomag*"
+    "tombow" "tombo" "mentuke" "oneside" "twoside" "vartwoside"
+    "onecolumn" "twocolumn" "titlepage" "notitlepage"
+    "openright" "openleft" "openany" "leqno" "fleqn"
+    "disablejfam" "draft" "final" "mingoth" "wingoth" "jis"
+    "uplatex" "autodetect-engine" "papersize" "english" "jslogo" "nojslogo")
+  "Class options for the jsbook class.")
+
 (TeX-add-style-hook
  "jsbook"
- (lambda () 
-   (LaTeX-largest-level-set "chapter"))
+ (lambda ()
+   (if (LaTeX-provided-class-options-member "jsbook" "report")
+       (progn
+        (LaTeX-largest-level-set "chapter")
+        (LaTeX-add-environments "abstract"))
+     (LaTeX-largest-level-set "part"))
+   (LaTeX-add-counters "part" "chapter" "section" "subsection" "subsubsection"
+                      "paragraph" "subparagraph" "figure" "table")
+   (LaTeX-add-pagestyles "headings" "myheadings"))
  LaTeX-dialect)
 
 ;;; jsbook.el ends here
diff --git a/style/jsreport.el b/style/jsreport.el
new file mode 100644
index 0000000..009a00b
--- /dev/null
+++ b/style/jsreport.el
@@ -0,0 +1,28 @@
+;;; jsreport.el - Special code for jsreport class.
+
+;;; Code:
+
+(defvar LaTeX-jsreport-class-options
+  '("a3paper" "a4paper" "a5paper" "a6paper" "b4paper" "b5paper" "b6paper"
+    "a4j" "a5j" "b4j" "b5j" "a4var" "b5var" "letterpaper" "legalpaper"
+    "executivepaper" "landscape"
+    "8pt" "9pt" "10pt" "11pt" "12pt" "14pt" "17pt" "20pt" "21pt" "25pt"
+    "30pt" "36pt" "43pt" "12Q" "14Q" "usemag" "nomag" "nomag*"
+    "tombow" "tombo" "mentuke" "oneside" "twoside" "vartwoside"
+    "onecolumn" "twocolumn" "titlepage" "notitlepage"
+    "openright" "openleft" "openany" "leqno" "fleqn"
+    "disablejfam" "draft" "final" "mingoth" "wingoth" "jis"
+    "uplatex" "autodetect-engine" "papersize" "english" "jslogo" "nojslogo")
+  "Class options for the jsreport class.")
+
+(TeX-add-style-hook
+ "jsreport"
+ (lambda ()
+   (LaTeX-largest-level-set "chapter")
+   (LaTeX-add-counters "part" "chapter" "section" "subsection" "subsubsection"
+                      "paragraph" "subparagraph" "figure" "table")
+   (LaTeX-add-pagestyles "headings" "myheadings")
+   (LaTeX-add-environments "abstract"))
+ LaTeX-dialect)
+
+;;; jsreport.el ends here
diff --git a/style/listings.el b/style/listings.el
index b2b8f90..e04045e 100644
--- a/style/listings.el
+++ b/style/listings.el
@@ -1,6 +1,6 @@
 ;;; listings.el --- AUCTeX style for `listings.sty'
 
-;; Copyright (C) 2004, 2005, 2009, 2013-2016 Free Software Foundation, Inc.
+;; Copyright (C) 2004, 2005, 2009, 2013-2017 Free Software Foundation, Inc.
 
 ;; Author: Ralf Angeli <address@hidden>
 ;; Maintainer: address@hidden
@@ -34,6 +34,8 @@
 ;; October 2015: The style detects new "styles" defined with
 ;; `\lstdefinestyle' and offers them during key-value query.
 ;;
+;; January 2017: Put label in opt. argument of environment.
+;;
 ;; FIXME: Please make me more sophisticated!
 
 ;;; Code:
@@ -108,7 +110,9 @@
     ;; Captions
     ("title")
     ("caption") ; Insert braces?
-    ("label")
+    ;; Label is inserted as part of environment insertion; see below
+    ;; for "lstlisting" in style hook
+    ;; ("label")
     ("nolol" ("true" "false"))
     ("numberbychapter" ("true" "false"))
     ("captionpos" ("t" "b")) ; Can be a subset of tb.
@@ -252,6 +256,27 @@ from `listings' package.")
   "Matches the argument of \"\\lstdefinestyle\" from
 \"listings\" package.")
 
+;; Setup for parsing the labels inside optional arguments:
+
+(defvar LaTeX-listings-key-val-label-extract
+  (concat
+   "\\(?:\\[[^][]*"
+     "\\(?:{[^}{]*"
+       "\\(?:{[^}{]*"
+         "\\(?:{[^}{]*}[^}{]*\\)*"
+       "}[^}{]*\\)*"
+     "}[^][]*\\)*"
+   "label[ \t]*=[ \t]*{\\([^}]+\\)}"
+   "\\(?:[^]]*\\)*"
+   "\\]\\)")
+  "Helper regexp to extract the label out of optional argument.")
+
+(defvar LaTeX-listings-key-val-label-regexp
+  `(,(concat
+      "\\\\begin{lstlisting}" LaTeX-listings-key-val-label-extract)
+    1 LaTeX-auto-label)
+  "Matches the label inside an optional argument after \\begin{lstlisting}.")
+
 (defun LaTeX-listings-update-style-key ()
   "Update the \"style\" key from `LaTeX-listings-key-val-options-local'
 with user-defined values via the \"lstdefinestyle\" macro."
@@ -280,18 +305,36 @@ with user-defined values via the \"lstdefinestyle\" 
macro."
       (cond (;; opt. 1st argument and mandatory argument(s)
             (and args (not (string-equal args ""))
                  opt  (not (string-equal opt  "")))
-            (add-to-list 'LaTeX-auto-environment
-                         (list env 'LaTeX-env-args (vector "argument")
-                               (1- (string-to-number args)))))
+            (LaTeX-add-environments
+             `(,env
+               LaTeX-env-args
+               [TeX-arg-key-val LaTeX-listings-key-val-options-local]
+               (LaTeX-env-label-as-keyval "caption")
+               ,(1- (string-to-number args)))))
            (;; mandatory argument(s) only
             (and args (not (string-equal args ""))
                  (string-equal opt ""))
-            (add-to-list 'LaTeX-auto-environment
-                         (list env (string-to-number args))))
+            (LaTeX-add-environments
+             (list env (string-to-number args))))
            (t ; No args
-            (add-to-list 'LaTeX-auto-environment (list env))))
+            (LaTeX-add-environments (list env))))
       (add-to-list 'LaTeX-indent-environment-list `(,env current-indentation) 
t)
-      (add-to-list 'LaTeX-verbatim-environments-local env)
+      (add-to-list 'LaTeX-verbatim-environments-local env t)
+      (add-to-list 'LaTeX-label-alist `(,env . LaTeX-listing-label) t)
+      ;; Add new env to parser for labels in opt. argument:
+      (TeX-auto-add-regexp `(,(concat "\\\\begin{" env "}"
+                                     LaTeX-listings-key-val-label-extract)
+                            1 LaTeX-auto-label))
+      ;; Tell RefTeX
+      (when (fboundp 'reftex-add-label-environments)
+       (reftex-add-label-environments
+        `((,env ?l "lst:" "~\\ref{%s}" nil (regexp "[Ll]isting")))))
+      ;; Fontification
+      (when (and (fboundp 'font-latex-add-keywords)
+                (fboundp 'font-latex-update-font-lock)
+                (eq TeX-install-font-lock 'font-latex-setup))
+       ;; Tell font-lock about the update.
+       (font-latex-update-font-lock t))
       ;; Add new env's to `ispell-tex-skip-alist': skip the entire env
       (TeX-ispell-skip-setcdr `(,(cons env (concat "\\\\end{" env "}"))))))
   (when (LaTeX-listings-lstdefinestyle-list)
@@ -308,6 +351,7 @@ with user-defined values via the \"lstdefinestyle\" macro."
    ;; Add to parser:
    (TeX-auto-add-regexp LaTeX-listings-lstnewenvironment-regexp)
    (TeX-auto-add-regexp LaTeX-listings-lstdefinestyle-regexp)
+   (TeX-auto-add-regexp LaTeX-listings-key-val-label-regexp)
 
    ;; Local version of key-val options:
    (setq LaTeX-listings-key-val-options-local
@@ -342,7 +386,12 @@ with user-defined values via the \"lstdefinestyle\" macro."
    ;; New environments
    (LaTeX-add-environments
     '("lstlisting" LaTeX-env-args
-      [TeX-arg-key-val LaTeX-listings-key-val-options-local]))
+      [TeX-arg-key-val LaTeX-listings-key-val-options-local]
+      (LaTeX-env-label-as-keyval "caption")))
+
+   ;; Append "lstlisting" to `LaTeX-label-alist':
+   (add-to-list 'LaTeX-label-alist '("lstlisting" . LaTeX-listing-label) t)
+
    ;; Filling
    (add-to-list (make-local-variable 'LaTeX-indent-environment-list)
                '("lstlisting" current-indentation) t)
@@ -355,8 +404,7 @@ with user-defined values via the \"lstdefinestyle\" macro."
              (eq TeX-install-font-lock 'font-latex-setup))
      (font-latex-add-keywords '(("lstnewenvironment" "{[[{{")) 'function)
      (font-latex-add-keywords '(("lstinputlisting" "[{")) 'reference)
-     (font-latex-add-keywords '(("lstinline" "[{") ; The second argument should
-                                       ; actually be verbatim.
+     (font-latex-add-keywords '(("lstinline" "[")
                                ("lstlistoflistings" ""))
                              'textual)
      (font-latex-add-keywords '(("lstalias" "{{")
diff --git a/style/minted.el b/style/minted.el
index 914ee66..159e853 100644
--- a/style/minted.el
+++ b/style/minted.el
@@ -1,6 +1,6 @@
 ;;; minted.el --- AUCTeX style for `minted.sty' (v2.4.1)
 
-;; Copyright (C) 2014-2016 Free Software Foundation, Inc.
+;; Copyright (C) 2014-2017 Free Software Foundation, Inc.
 
 ;; Author: Tassilo Horn <address@hidden>
 ;; Maintainer: address@hidden
@@ -246,29 +246,46 @@ are loaded."
       (add-to-list 'LaTeX-indent-environment-list `(,env* current-indentation) 
t)
       (add-to-list 'LaTeX-verbatim-environments-local env)
       (add-to-list 'LaTeX-verbatim-environments-local env*)))
-  ;; \newmint{foo}{opts} => \foo|code|
-  ;; \newmint[macname]{foo}{opts} => \macname|code|
+  ;; \newmint{foo}{opts} => \foo[key=vals]|code|
+  ;; \newmint[macname]{foo}{opts} => \macname[key=vals]|code|
   (dolist (name-lang LaTeX-minted-auto-newmint)
     (let ((lang (if (> (length (car name-lang)) 0)
                    (car name-lang)
                  (cadr name-lang))))
-      (add-to-list 'TeX-auto-symbol lang)
-      (add-to-list 'LaTeX-verbatim-macros-with-delims-local lang)))
-  ;; \newmintinline{foo}{opts} => \fooinline|code|
-  ;; \newmintinline[macname]{foo}{opts} => \macname|code|
+      (add-to-list 'TeX-auto-symbol
+                  `(,lang [ TeX-arg-key-val LaTeX-minted-key-val-options-local 
]
+                          TeX-arg-verb))
+      (add-to-list 'LaTeX-verbatim-macros-with-delims-local lang)
+      (when (and (fboundp 'font-latex-add-keywords)
+                (fboundp 'font-latex-update-font-lock)
+                (eq TeX-install-font-lock 'font-latex-setup))
+       (font-latex-add-keywords `((,lang "[")) 'textual))))
+  ;; \newmintinline{foo}{opts} => \fooinline[key=vals]|code| or
+  ;;                              \fooinline[key=vals]{code}
+  ;; \newmintinline[macname]{foo}{opts} => \macname[key=vals]|code| or
+  ;;                                       \macname[key=vals]{code}
   (dolist (name-lang LaTeX-minted-auto-newmintinline)
     (let ((lang (if (> (length (car name-lang)) 0)
                    (car name-lang)
-                 (cadr name-lang))))
-      (add-to-list 'TeX-auto-symbol lang)
-      (add-to-list 'LaTeX-verbatim-macros-with-delims-local (concat lang 
"inline"))))
-  ;; \newmintedfile{foo}{opts} => \foofile{file-name}
-  ;; \newmintedfile[macname]{foo}{opts} => \macname{file-name}
+                 (concat (cadr name-lang) "inline"))))
+      (add-to-list 'TeX-auto-symbol
+                  `(,lang [ TeX-arg-key-val LaTeX-minted-key-val-options-local 
]
+                         TeX-arg-verb))
+      (add-to-list 'LaTeX-verbatim-macros-with-delims-local lang)
+      (add-to-list 'LaTeX-verbatim-macros-with-braces-local lang)
+      (when (and (fboundp 'font-latex-add-keywords)
+                (fboundp 'font-latex-update-font-lock)
+                (eq TeX-install-font-lock 'font-latex-setup))
+       (font-latex-add-keywords `((,lang "[")) 'textual))))
+  ;; \newmintedfile{foo}{opts} => \foofile[key=vals]{file-name}
+  ;; \newmintedfile[macname]{foo}{opts} => \macname[key=vals]{file-name}
   (dolist (name-lang LaTeX-minted-auto-newmintedfile)
     (let ((lang (if (> (length (car name-lang)) 0)
                    (car name-lang)
-                 (cadr name-lang))))
-      (add-to-list 'TeX-auto-symbol (list lang 'TeX-arg-file))))
+                 (concat (cadr name-lang) "file"))))
+      (add-to-list 'TeX-auto-symbol
+                  `(,lang [ TeX-arg-key-val LaTeX-minted-key-val-options-local 
]
+                          TeX-arg-file))))
   (when (and (fboundp 'font-latex-update-font-lock)
             (eq TeX-install-font-lock 'font-latex-setup))
     ;; Refresh font-locking so that the verbatim envs take effect.
@@ -280,6 +297,46 @@ are loaded."
 (add-hook 'TeX-auto-cleanup-hook #'LaTeX-minted-auto-cleanup t)
 (add-hook 'TeX-update-style-hook #'TeX-auto-parse t)
 
+(defun LaTeX-minted-add-syntactic-keywords-extra (type macro)
+  "Add MACRO from minted.sty to `font-latex-syntactic-keywords-extra'.
+TYPE is one of the symbols `brace' or `delim' indicating how
+verbatim text is enclosed after the macro.  MACRO is a string or
+a list of strings."
+  (let ((syntax (if (eq type 'brace)
+                   '((1 "|") (2 "|"))
+                 '((1 "\"") (2 ".") (3 "\""))))
+       regexp)
+    (when (listp macro)
+      (setq macro (regexp-opt macro "\\(?:")))
+    (setq regexp `(,(concat
+                    ;; The backslash
+                    (regexp-quote TeX-esc)
+                    ;; Name of the macro(s)
+                    macro
+                    ;; The optional argument
+                    "\\(?:\\[[^][]*\\(?:\\[[^][]*\\][^][]*\\)*\\]\\)?"
+                    ;; The first mandatory argument
+                    "\\(?:{[^}]+}\\)"
+                    ;; With 'brace, allow braced sub-groups otherwise
+                    ;; we stop matching too early.  With 'delim, copy
+                    ;; font-latex.el:
+                    (if (eq type 'brace)
+                        (concat "\\({\\)"
+                                  "\\(?:[^}{]*"
+                                    "\\(?:{[^}{]*"
+                                      "\\(?:{[^}{]*"
+                                        "\\(?:{[^}{]*}[^}{]*\\)*"
+                                      "}[^}{]*\\)*"
+                                    "}[^}{]*\\)*"
+                                  "\\)"
+                                "\\(}\\)")
+                      (concat
+                       ;; Opening delimiter
+                       "\\(address@hidden).*?"
+                       ;; Closing delimiter
+                       "\\(" (regexp-quote TeX-esc) "*\\)\\(\\1\\)")))))
+    (add-to-list 'font-latex-syntactic-keywords-extra (append regexp syntax))))
+
 (TeX-add-style-hook
  "minted"
  (lambda ()
@@ -290,8 +347,12 @@ are loaded."
 
    ;; New symbols
    (TeX-add-symbols
-    '("mint" LaTeX-arg-minted-language TeX-arg-verb)
-    '("mintinline" LaTeX-arg-minted-language TeX-arg-verb)
+    '("mint"
+      [ TeX-arg-key-val LaTeX-minted-key-val-options-local ]
+      LaTeX-arg-minted-language TeX-arg-verb)
+    '("mintinline"
+      [ TeX-arg-key-val LaTeX-minted-key-val-options-local ]
+      LaTeX-arg-minted-language TeX-arg-verb)
     '("newminted" ["Environment Name"] LaTeX-arg-minted-language
       (TeX-arg-key-val LaTeX-minted-key-val-options-local))
     '("newmint" ["Macro Name"] LaTeX-arg-minted-language
@@ -336,7 +397,7 @@ are loaded."
                      '("listoflistingscaption"))
      (add-to-list (make-local-variable 'LaTeX-indent-environment-list)
                  '("listing" current-indentation) t)
-     (add-to-list 'LaTeX-label-alist '("listing" . "lst:") t)
+     (add-to-list 'LaTeX-label-alist '("listing" . LaTeX-listing-label) t)
      (when (fboundp 'reftex-add-label-environments)
        (reftex-add-label-environments
        '(("listing" ?l "lst:" "~\\ref{%s}" caption nil nil)))))
@@ -351,9 +412,6 @@ are loaded."
    (add-to-list (make-local-variable 'LaTeX-indent-environment-list)
                '("minted" current-indentation) t)
    (add-to-list 'LaTeX-verbatim-environments-local "minted")
-   ;; FIXME: That doesn't work because \mintinline has 2 args and only the
-   ;; second argument is verbatim.
-   ;;(add-to-list 'LaTeX-verbatim-macros-with-delims-local "mintinline")
 
    ;; Fontification
    (when (and (fboundp 'font-latex-add-keywords)
@@ -364,15 +422,21 @@ are loaded."
                                ("setmintedinline" "[{")
                                ("newminted"       "[{{")
                                ("newmint"         "[{{")
-                               ("newmintedinline" "[{{")
-                               ("newmintedfile"   "[{{")
-                               ;; FIXME: Those have the form \mint{lang}|code|
-                               ;; so ideally the verbatim arg should be
-                               ;; recognized.
-                               "mint" "mintinline")
+                               ("newmintinline"   "[{{")
+                               ("newmintedfile"   "[{{"))
                              'function)
-     (font-latex-add-keywords '(("inputminted" "[{{"))
+     (font-latex-add-keywords '(("inputminted" "[{{")
+                               ("mint"        "[{")
+                               ("mintinline"  "[{"))
                              'textual)
+     ;; Add \mint & \mintinline to
+     ;; `font-latex-syntactic-keywords-extra' and cater for their
+     ;; special syntax: \mint[optional]{lang}{verbatim} or
+     ;;                 \mint[optional]{lang}|verbatim|
+     (LaTeX-minted-add-syntactic-keywords-extra 'brace
+                                               '("mint" "mintinline"))
+     (LaTeX-minted-add-syntactic-keywords-extra 'delim
+                                               '("mint" "mintinline"))
      ;; Tell font-lock about the update.
      (font-latex-update-font-lock t)))
  LaTeX-dialect)
diff --git a/style/newfloat.el b/style/newfloat.el
index 8ad5438..5475577 100644
--- a/style/newfloat.el
+++ b/style/newfloat.el
@@ -119,7 +119,7 @@ If `caption.el' is loaded, add the new floating environment 
to
             (LaTeX-add-environments `(,flt ["Float Position"]))
             (add-to-list (make-local-variable 'LaTeX-indent-environment-list)
                          `(,flt current-indentation) t)
-            (add-to-list 'LaTeX-label-alist `(,flt . "lst:") t)
+            (add-to-list 'LaTeX-label-alist `(,flt . LaTeX-listing-label) t)
             (when (fboundp 'reftex-add-label-environments)
               (reftex-add-label-environments
                `((,flt ?l "lst:" "~\\ref{%s}" caption nil nil)))))
diff --git a/style/paracol.el b/style/paracol.el
index 6e64a4c..fdab8ba 100644
--- a/style/paracol.el
+++ b/style/paracol.el
@@ -51,9 +51,10 @@
 If OPTIONAL is non-nil, insert the result in square brackets."
   (let ((col (TeX-read-string
              (TeX-argument-prompt optional nil "Column"))))
-    (save-excursion
-      (backward-char 1)
-      (TeX-argument-insert col optional))))
+    (when (and col (not (string= col "")))
+      (save-excursion
+       (backward-char 1)
+       (TeX-argument-insert col optional)))))
 
 (TeX-add-style-hook
  "paracol"
diff --git a/style/preview.el b/style/preview.el
new file mode 100644
index 0000000..26987e1
--- /dev/null
+++ b/style/preview.el
@@ -0,0 +1,104 @@
+;;; preview.el --- AUCTeX style for `preview.sty' (v2010/02/14)
+
+;; Copyright (C) 2017 Free Software Foundation, Inc.
+
+;; Author: Arash Esbati <address@hidden>
+;; Maintainer: address@hidden
+;; Created: 2017-02-05
+;; Keywords: tex
+
+;; This file is part of AUCTeX.
+
+;; AUCTeX is free software; you can redistribute it and/or modify it
+;; under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 3, or (at your option)
+;; any later version.
+
+;; AUCTeX is distributed in the hope that it will be useful, but
+;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;; General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with AUCTeX; see the file COPYING.  If not, write to the Free
+;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+;; 02110-1301, USA.
+
+;;; Commentary:
+
+;; This file adds support for `preview.sty' v2010/02/14.
+;; `preview.sty' is part of TeXLive.
+
+;;; Code:
+
+(defun LaTeX-preview-arg-ifpreview (_optional)
+  "Insert \\else and \\fi part of \\ifPreview command from preview.sty.
+OPTIONAL is ignored."
+  (indent-according-to-mode)
+  (LaTeX-newline)
+  (indent-according-to-mode)
+  (save-excursion
+    (LaTeX-newline)
+    (indent-according-to-mode)
+    (insert TeX-esc "else")
+    (LaTeX-newline)
+    (LaTeX-newline)
+    (indent-according-to-mode)
+    (insert TeX-esc "fi")))
+
+(TeX-add-style-hook
+ "preview"
+ (lambda ()
+
+   (LaTeX-add-environments
+    '("preview")
+    '("nopreview"))
+
+   (TeX-add-symbols
+    '("PreviewMacro" (TeX-arg-conditional (y-or-n-p "With optional arguments? 
")
+                                         ( [ t ] [ nil ] )
+                                       ())
+      TeX-arg-macro)
+
+    '("PreviewMacro*" (TeX-arg-conditional (y-or-n-p "With optional arguments? 
")
+                                          ( [ t ] [ nil ] )
+                                        ())
+      TeX-arg-macro)
+
+    '("PreviewEnvironment" (TeX-arg-conditional (y-or-n-p "With optional 
arguments? ")
+                                               ( [ t ] [ nil ] )
+                                             ())
+      TeX-arg-environment)
+
+    '("PreviewEnvironment*" (TeX-arg-conditional (y-or-n-p "With optional 
arguments? ")
+                                                ( [ t ] [ nil ] )
+                                              ())
+      TeX-arg-environment)
+
+    '("PreviewSnarfEnvironment" TeX-arg-environment)
+
+    '("PreviewOpen")
+    '("PreviewClose")
+
+    '("ifPreview" LaTeX-preview-arg-ifpreview))
+
+   ;; Fontification
+   (when (and (featurep 'font-latex)
+             (eq TeX-install-font-lock 'font-latex-setup))
+     (font-latex-add-keywords '(("PreviewMacro"            "*[[{")
+                               ("PreviewEnvironment"      "*[[{")
+                               ("PreviewSnarfEnvironment" "{"))
+                             'function)))
+ LaTeX-dialect)
+
+(defvar LaTeX-preview-package-options
+  '("active"      "noconfig"   "psfixbb"
+    "dvips"       "pdftex"     "xetex"
+    "displaymath" "floats"     "textmath"
+    "graphics"    "sections"   "delayed"
+    "auctex"      "showlabels" "tightpage"
+    "lyx"         "counters"   "footnotes"
+    "tracingall"  "showbox")
+  "Package options for the preview package.")
+
+;;; preview.el ends here
diff --git a/style/sourcecodepro.el b/style/sourcecodepro.el
new file mode 100644
index 0000000..4dc0014
--- /dev/null
+++ b/style/sourcecodepro.el
@@ -0,0 +1,80 @@
+;;; sourcecodepro.el --- AUCTeX style for `sourcecodepro.sty' (v2.6)
+
+;; Copyright (C) 2017 Free Software Foundation, Inc.
+
+;; Author: Arash Esbati <address@hidden>
+;; Maintainer: address@hidden
+;; Created: 2017-02-18
+;; Keywords: tex
+
+;; This file is part of AUCTeX.
+
+;; AUCTeX is free software; you can redistribute it and/or modify it
+;; under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 3, or (at your option)
+;; any later version.
+
+;; AUCTeX is distributed in the hope that it will be useful, but
+;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;; General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with AUCTeX; see the file COPYING.  If not, write to the Free
+;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+;; 02110-1301, USA.
+
+;;; Commentary:
+
+;; This file adds support for `sourcecodepro.sty' (v2.6) from 2016/04/18.
+;; `sourcecodepro.sty' is part of TeXLive.
+
+;;; Code:
+
+(TeX-add-style-hook
+ "sourcecodepro"
+ (lambda ()
+
+   ;; Load "fontspec" with package options "opentype" or "otf":
+   (when (or (LaTeX-provided-package-options-member "sourcecodepro" "opentype")
+            (LaTeX-provided-package-options-member "sourcecodepro" 
"opentype=true")
+            (LaTeX-provided-package-options-member "sourcecodepro" "otf")
+            (LaTeX-provided-package-options-member "sourcecodepro" "otf=true"))
+     (TeX-run-style-hooks "fontspec"))
+
+   ;; The next set of macros is only available when package "fontspec"
+   ;; is loaded, by this style or by user.  We just check against
+   ;; "fontspec" and do not go through a check of `TeX-engine':
+   (when (member "fontspec" (TeX-style-list))
+     (TeX-add-symbols
+      '("sourcecodepro"        -1)
+      '("sourcecodepromedium"  -1)
+      '("sourcecodeprolight"   -1)
+      '("sourcecodeproextreme" -1)
+      '("sourcecodeprolf"      -1)))
+
+   ;; Fontification
+   (when (and (featurep 'font-latex)
+             (eq TeX-install-font-lock 'font-latex-setup)
+             (member "fontspec" (TeX-style-list)))
+     (font-latex-add-keywords '(("sourcecodepro"        "")
+                               ("sourcecodepromedium"  "")
+                               ("sourcecodeprolight"   "")
+                               ("sourcecodeproextreme" "")
+                               ("sourcecodeprolf"      ""))
+                             'type-declaration)))
+ LaTeX-dialect)
+
+(defvar LaTeX-sourcecodepro-package-options
+  '("lining" "nf" "lf"
+    "oldstyle" "osf"
+    "black" "semibold" "bold"
+    "light" "extralight"
+    "regular" "medium"
+    "scale" "scaled"
+    "default" "ttdefault" "nottdefault"
+    "type1" "t1"
+    "opentype" "otf")
+  "Prompt for package options for the sourcecodepro package.")
+
+;;; sourcecodepro.el ends here
diff --git a/style/subcaption.el b/style/subcaption.el
index 2893041..6c4405a 100644
--- a/style/subcaption.el
+++ b/style/subcaption.el
@@ -59,14 +59,12 @@ caption, insert only a caption."
     (insert TeX-grop caption TeX-grcl)
     ;; Fill the \subcaption paragraph before inserting the \label:
     (LaTeX-fill-paragraph)
-    (unless star
-      (save-excursion
-       (LaTeX-label currenv 'environment))
+    (when (and (not star)
+              (save-excursion (LaTeX-label currenv 'environment)))
       ;; Move \label into next line if we have one:
-      (when (looking-at (regexp-quote "\\label{"))
-       (LaTeX-newline)
-       (indent-according-to-mode)
-       (end-of-line)))))
+      (LaTeX-newline)
+      (indent-according-to-mode)
+      (end-of-line))))
 
 (defun LaTeX-arg-subcaption-subcaptionbox (optional &optional star)
   "Query for the arguments of \"\\subcaptionbox\" incl. a label and insert 
them.
diff --git a/style/subfiles.el b/style/subfiles.el
index 4099315..4900a38 100644
--- a/style/subfiles.el
+++ b/style/subfiles.el
@@ -36,6 +36,15 @@
 (defvar LaTeX-subfiles-package-options nil
   "Package options for the subfiles package.")
 
+(defun LaTeX-subfiles-class-options ()
+  "Return name of the main file relative to current subfile."
+  (file-relative-name
+   (read-file-name
+    "Main file: " nil nil nil nil
+    (lambda (texfiles)
+      (string-match "\\.tex$" texfiles)))
+   (TeX-master-directory)))
+
 (TeX-add-style-hook
  "subfiles"
  (lambda ()
@@ -43,8 +52,10 @@
    ;; The following code will run `TeX-run-style-hooks' on the subfile
    ;; master file.  Thanks to Mosè Giordano <address@hidden> for
    ;; presenting a better solution using `assoc'.
-   (TeX-run-style-hooks
-    (file-name-base (cadr (assoc "subfiles" LaTeX-provided-class-options))))
+   (let ((master-file (cadr (assoc "subfiles" LaTeX-provided-class-options))))
+     (when (stringp master-file)
+       (TeX-run-style-hooks
+       (file-name-sans-extension master-file))))
 
    (TeX-add-symbols
     '("subfile" TeX-arg-file))
diff --git a/style/tarticle.el b/style/tarticle.el
new file mode 100644
index 0000000..c617fa3
--- /dev/null
+++ b/style/tarticle.el
@@ -0,0 +1,15 @@
+;;; tarticle.el - Special code for tarticle class.
+
+;;; Code:
+
+(TeX-load-style "jarticle")
+(defvar LaTeX-tarticle-class-options LaTeX-jarticle-class-options
+  "Class options for the tarticle class.")
+
+(TeX-add-style-hook
+ "tarticle"
+ (lambda ()
+   (TeX-run-style-hooks "jarticle" "plext"))
+ LaTeX-dialect)
+
+;;; tarticle.el ends here
diff --git a/style/tbook.el b/style/tbook.el
new file mode 100644
index 0000000..530633e
--- /dev/null
+++ b/style/tbook.el
@@ -0,0 +1,15 @@
+;;; tbook.el - Special code for tbook class.
+
+;;; Code:
+
+(TeX-load-style "jbook")
+(defvar LaTeX-tbook-class-options LaTeX-jbook-class-options
+  "Class options for the tbook class.")
+
+(TeX-add-style-hook
+ "tbook"
+ (lambda ()
+   (TeX-run-style-hooks "jbook" "plext"))
+ LaTeX-dialect)
+
+;;; tbook.el ends here
diff --git a/style/tcolorbox.el b/style/tcolorbox.el
index 493565a..77cab08 100644
--- a/style/tcolorbox.el
+++ b/style/tcolorbox.el
@@ -1,4 +1,4 @@
-;;; tcolorbox.el --- AUCTeX style for `tcolorbox.sty' (v3.96)
+;;; tcolorbox.el --- AUCTeX style for `tcolorbox.sty' (v4.00)
 
 ;; Copyright (C) 2015, 2016 Free Software Foundation, Inc.
 
@@ -26,7 +26,7 @@
 
 ;;; Commentary:
 
-;; This file adds support for `tcolorbox.sty' (v3.96) from 2016/11/18.
+;; This file adds support for `tcolorbox.sty' (v4.00) from 2017/02/16.
 
 ;; This style file adds support for core macros and environments and
 ;; their options provided by `tcolorbox.sty'.  Macros and environments
@@ -138,10 +138,12 @@
     ;; 4.7.4 Spacing
     ("boxsep")
     ("left")
+    ("left*")
     ("lefttitle")
     ("leftupper")
     ("leftlower")
     ("right")
+    ("right*")
     ("righttitle")
     ("rightupper")
     ("rightlower")
@@ -259,6 +261,17 @@
     ("grow to left by")
     ("grow to right by")
     ("toggle enlargement" ("none" "forced" "evenpage"))
+    ("spread inwards")
+    ("spread outwards")
+    ("move upwards")
+    ("move upwards*")
+    ;; FIXME: This one should be added w/ `breakable' lib:
+    ;; ("fill downwards")
+    ("spread upwards")
+    ("spread upwards*")
+    ("spread sidewards")
+    ("spread")
+    ("spread downwards")
     ("shrink tight")
     ("extrude left by")
     ("extrude right by")
@@ -299,8 +312,9 @@
     ("check odd page" ("true" "false"))
     ("if odd page")
     ("if odd page or oneside")
-    ;; FIXME: This one should be added w/ `breakable' lib:
+    ;; FIXME: These two should be added w/ `breakable' lib:
     ;; ("if odd page*")
+    ;; ("if odd page or oneside*")
     ;; 4.24 Miscellaneous
     ("reset")
     ("only")
@@ -439,7 +453,7 @@ e.g. \"tcolorboxlib-raster.el\"."
   (when (LaTeX-tcolorbox-tcbuselibrary-list)
     (let (libs)
       (dolist (x (LaTeX-tcolorbox-tcbuselibrary-list))
-       (push (replace-regexp-in-string "[ %\n\r\t]" "" (car x)) libs))
+       (push (TeX-replace-regexp-in-string "[ %\n\r\t]" "" (car x)) libs))
       (setq libs (mapconcat #'identity libs ","))
       (dolist (x (split-string libs "," t))
        (TeX-run-style-hooks (concat "tcolorboxlib-" x)))))
diff --git a/style/treport.el b/style/treport.el
new file mode 100644
index 0000000..e16f423
--- /dev/null
+++ b/style/treport.el
@@ -0,0 +1,15 @@
+;;; treport.el - Special code for treport class.
+
+;;; Code:
+
+(TeX-load-style "jreport")
+(defvar LaTeX-treport-class-options LaTeX-jreport-class-options
+  "Class options for the treport class.")
+
+(TeX-add-style-hook
+ "treport"
+ (lambda ()
+   (TeX-run-style-hooks "jreport" "plext"))
+ LaTeX-dialect)
+
+;;; treport.el ends here
diff --git a/style/xcolor.el b/style/xcolor.el
index 34e2484..771bcff 100644
--- a/style/xcolor.el
+++ b/style/xcolor.el
@@ -1,6 +1,6 @@
 ;; xcolor.el --- AUCTeX style for `xcolor.sty' (v2.12)
 
-;; Copyright (C) 2016 Free Software Foundation, Inc.
+;; Copyright (C) 2016--2017 Free Software Foundation, Inc.
 
 ;; Author: Arash Esbati <address@hidden>
 ;; Maintainer: address@hidden
@@ -233,13 +233,13 @@ remainder."
 (TeX-auto-add-type "xcolor-definecolorset" "LaTeX")
 
 (defvar LaTeX-xcolor-definecolor-regexp
-  `(,(concat "\\\\\\(?:define\\|provide\\|prepare\\)?"
-            "color"
-            "\\(?:let\\)?"
-            "\\(?:\\[\\(?:[^]]*\\)\\]\\)?{\\([^}]+\\)}")
-    1 LaTeX-auto-xcolor-definecolor)
-  "Match the argument of various color defining macros from
-xcolor package.")
+  (eval-when-compile
+    `(,(concat "\\\\"
+              (regexp-opt '("definecolor"  "providecolor"
+                            "preparecolor" "colorlet"))
+              "\\(?:\\[\\(?:[^]]*\\)\\]\\)?{\\([^}]+\\)}")
+      1 LaTeX-auto-xcolor-definecolor))
+  "Match the argument of various color defining macros from xcolor package.")
 
 (defvar LaTeX-xcolor-definecolorset-regexp
   `(,(concat "\\\\\\(?:define\\|provide\\|prepare\\)"
@@ -264,7 +264,7 @@ xcolor package.")
     (let ((head (car colset))
          (tail (cadr colset))
          (cols (split-string
-                (replace-regexp-in-string "[ %\n\r\t]*" "" (nth 2 colset))
+                (TeX-replace-regexp-in-string "[ %\n\r\t]" "" (nth 2 colset))
                 "\\(,[^;]+;\\|,[^;]+$\\)" t)))
       (dolist (color cols)
        (LaTeX-add-xcolor-definecolors (concat head color tail))))))
@@ -395,7 +395,7 @@ xcolor.sty."
     ;; \providecolor[<type>]{<name>}{<model-list>}{<spec-list>}
     '("providecolor" TeX-arg-xcolor-definecolor)
 
-    ;; \colorlet[<type>]{<name>}{<num model>}{<color>}
+    ;; \colorlet[<type>]{<name>}[<num model>]{<color>}
     '("colorlet"
       [ TeX-arg-eval completing-read
                     (TeX-argument-prompt optional nil "Type")
diff --git a/tests/Makefile b/tests/Makefile
index 6f281bc..208ab72 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -1,4 +1,4 @@
-# Copyright (C) 2010-2014 Free Software Foundation, Inc.
+# Copyright (C) 2010-2014, 2017 Free Software Foundation, Inc.
 
 # This file is part of AUCTeX.
 
@@ -23,7 +23,7 @@
 ## filename.log: run tests from filename.el if .log file needs updating
 ## filename: re-run tests from filename.el, with no logging
 
-## Adapted from test/automated/Makefile.in of GNU Emacs.
+## Adapted from test/Makefile.in of GNU Emacs.
 
 ### Code:
 
@@ -77,11 +77,16 @@ endef
 $(foreach test,${TESTS},$(eval $(call test_template,${test})))
 
 ## Re-run all the tests every time.
-check:
-       address@hidden f in */*.log; do test ! -f $$f || mv $$f $$f~; done
-       @${MAKE} ${LOGFILES}
+check: mostlyclean check-doit
 
-.PHONY: clean
+.PHONY: check-doit
+check-doit: ${LOGFILES}
+       $(emacs) -l ert -f ert-summarize-tests-batch-and-exit $^
+
+.PHONY: mostlyclean clean
+
+mostlyclean:
+       address@hidden f in ${LOGFILES}; do test ! -f $$f || mv $$f $$f~; done
 
 clean:
        -rm -f */*.log */*.log~
diff --git a/tests/latex/fontification-verb-macros.tex 
b/tests/latex/fontification-verb-macros.tex
new file mode 100644
index 0000000..519de0a
--- /dev/null
+++ b/tests/latex/fontification-verb-macros.tex
@@ -0,0 +1,143 @@
+\documentclass[a4paper]{article}
+
+\usepackage{minted}
+\usepackage{listings}
+\usepackage{fancyvrb}
+
+\begin{document}
+
+This is a test document for fontification support of verbatim
+\emph{macros} provided by \LaTeX{} and other packages within AUC\TeX.
+As it is not part of \verb|ert|-tests, it does not have an
+\verb|out|-counterpart.  Parsing should be enabled when loading this
+file, namely \verb|(setq TeX-parse-self t)| in \verb|.emacs|.
+
+\section{The problem}
+
+The \verb|verb| macro provided by vanilla \LaTeX{} does not receive
+any special fontification within AUC\TeX.  It is fontified with
+\verb|font-latex-sedate-face|.  Other \verb|verb| macros provided by
+packages like \verb|listings|, \verb|minted| or \verb|fancyvrb| are
+fontified with \verb|font-lock-keyword-face| as they are added to
+\verb|textual| keyword class within \verb|font-latex.el|.
+
+Next issue is that \verb|verb| macros from modern packages take an
+optional argument or even a mandatory argument before the
+\verb|verbatim| content.  This issue was not addressed in
+\verb|font-latex.el|.
+
+\section{The solution}
+
+\subsection{Vanilla \LaTeX}
+
+The issue with fontification of \verb|verb| macro is solved in
+\verb|font-latex.el| by adding \verb|("verb" "*")| to
+\verb|`font-latex-built-in-keyword-classes'|.  This construct
+fontifies only the macro itself---the argument is left out for
+syntactic fontification.
+
+\subsection{Optional argument}
+
+This issue can be fixed in \verb|font-latex.el| by extending the
+regexp for \verb|verb| macros with delimiters/braces in
+\verb|`font-latex-set-syntactic-keywords'| with:
+\begin{quote}
+  \verb|"\\(?:\\[[^][]*\\(?:\\[[^][]*\\][^][]*\\)*\\]\\)?"|
+\end{quote}
+The same line is used for matching optional arguments in verbatim
+environments.
+
+\section{The result}
+
+\subsection{Vanilla \LaTeX}
+
+Some text \verb|verb input|, % comment
+$a+b$ and \verb*"verb input" % comment
+
+\subsection{listings package}
+
+Some text \lstinline|verb input with delims|, % comment
+$a+b$ \lstinline[showspaces,basicstyle=\ttfamily]/verb input with delims/, % 
comment
+%
+\lstinline[%
+basicstyle=\sffamily]!multiline in opt. arg!, % comment
+%
+\lstinline[%
+basicstyle=\sffamily
+]-multiline in opt. arg- % comment
+
+Some text \lstinline{verb input with braces}, % comment
+$a+b$ \lstinline[showspaces]{verb input with braces}, % comment
+%
+\lstinline[%
+basicstyle=\sffamily]{multiline in opt. arg}, % comment
+%
+\lstinline[
+basicstyle=\sffamily
+]{multiline in opt. arg} % comment
+
+\subsection{minted package}
+
+Some text \mint{text}|verb input| % comment
+$a+b$ \mint[showspaces]{text}/verb input/ % comment
+Some text \mint[
+showspaces
+]{text}!verb input! % comment
+Some text \mint[showspaces]{%
+  text%
+}+verb input+ % comment
+
+\newmint{text}{showspaces} %
+\text|verb input| and \text[showspaces=false]|verb input| % comment
+
+\newmint[mytext]{text}{showspaces} %
+\mytext|verb input| and \mytext[%
+showspaces=false
+]|verb input| % comment
+
+Some text \mintinline{text}|verb input| % comment
+$a+b$ \mintinline[showspaces]{text}|verb input| % comment
+Some text \mintinline[
+showspaces
+]{text}|verb input| % comment
+Some text \mintinline[showspaces]{%
+  text%
+}|verb input| % comment
+
+\newmintinline{text}{showspaces} %
+\textinline|verb input with delims| and \textinline[%
+showspaces=false
+]|verb input with delims| % comment
+
+\textinline{verb input with braces} and \textinline[%
+showspaces=false
+]{verb input with braces} % comment
+
+\newmintinline[mytextinline]{text}{showspaces} %
+\mytextinline|verb input with delims| and \mytextinline[%
+showspaces=false
+]|verb input with delims|
+
+\mytextinline{verb input with braces} and \mytextinline[%
+showspaces=false
+]{verb input with braces}
+
+\subsection{fancyvrb package}
+
+Some text \Verb|verb input| and % comment
+\Verb[showspaces]|verb input| and \Verb[
+showspaces
+]|verb input|
+
+Some text \Verb!verb input! and % comment
+\Verb[showspaces]"verb input" and \Verb[
+showspaces
+]#verb input#
+
+\end{document}
+
+%%% Local Variables:
+%%% mode: latex
+%%% TeX-master: t
+%%% TeX-command-extra-options: "-shell-escape"
+%%% End:
diff --git a/tests/latex/latex-filling-in.tex b/tests/latex/latex-filling-in.tex
index 6e7294a..274d03c 100644
--- a/tests/latex/latex-filling-in.tex
+++ b/tests/latex/latex-filling-in.tex
@@ -3,3 +3,26 @@ Lorem ipsum dolor sit amet, consectetur adipisci elit, sed 
eiusmod \(0 = 1\) tem
 \begin{tabular}{| l | l | l | l |}
   Lorem ipsum dolor sit amet, consectetur adipisci & Lorem ipsum dolor sit 
amet, consectetur adipisci & Lorem ipsum dolor sit amet, consectetur adipisci & 
Lorem ipsum dolor sit amet, consectetur adipisci
 \end{tabular}
+
+% Test for unambiguousness of macros starting a paragraph.  E.g.
+% caption vs. captionsetup
+Lorem ipsum dolor sit amet, consectetur adipisci,
+lorem ipsum dolor
+\captionsetup{key=val}
+sit amet, consectetur adipisci
+
+Lorem ipsum dolor sit amet, consectetur adipisci,
+lorem ipsum dolor
+\caption{key=val}
+sit amet, consectetur adipisci
+
+% par vs. parencite
+Lorem ipsum dolor sit amet, consectetur adipisci,
+lorem ipsum dolor
+\parencite{key}
+sit amet, consectetur adipisci
+
+Lorem ipsum dolor sit amet, consectetur adipisci,
+lorem ipsum dolor
+\par
+sit amet, consectetur adipisci
diff --git a/tests/latex/latex-filling-out.tex 
b/tests/latex/latex-filling-out.tex
index b0596f3..764628c 100644
--- a/tests/latex/latex-filling-out.tex
+++ b/tests/latex/latex-filling-out.tex
@@ -7,3 +7,20 @@ consequatur.
 \begin{tabular}{| l | l | l | l |}
   Lorem ipsum dolor sit amet, consectetur adipisci & Lorem ipsum dolor sit 
amet, consectetur adipisci & Lorem ipsum dolor sit amet, consectetur adipisci & 
Lorem ipsum dolor sit amet, consectetur adipisci
 \end{tabular}
+
+% Test for unambiguousness of macros starting a paragraph.  E.g.
+% caption vs. captionsetup
+Lorem ipsum dolor sit amet, consectetur adipisci, lorem ipsum dolor
+\captionsetup{key=val} sit amet, consectetur adipisci
+
+Lorem ipsum dolor sit amet, consectetur adipisci, lorem ipsum dolor
+\caption{key=val}
+sit amet, consectetur adipisci
+
+% par vs. parencite
+Lorem ipsum dolor sit amet, consectetur adipisci, lorem ipsum dolor
+\parencite{key} sit amet, consectetur adipisci
+
+Lorem ipsum dolor sit amet, consectetur adipisci, lorem ipsum dolor
+\par
+sit amet, consectetur adipisci
diff --git a/tests/latex/latex-test.el b/tests/latex/latex-test.el
index 205af00..05ca2c8 100644
--- a/tests/latex/latex-test.el
+++ b/tests/latex/latex-test.el
@@ -1,6 +1,6 @@
 ;;; latex-test.el --- tests for LaTeX mode
 
-;; Copyright (C) 2014--2016 Free Software Foundation, Inc.
+;; Copyright (C) 2014--2017 Free Software Foundation, Inc.
 
 ;; This file is part of AUCTeX.
 
@@ -61,6 +61,10 @@ line and from another directory."
  'tabular-count-ampersands/out
  "tabular-count-ampersands-out.tex")
 
+;; Test for detecting \& in a table cell added; see
+;; https://debbugs.gnu.org/cgi/bugreport.cgi?bug=26010
+;; Test for missing & in row added; see
+;; https://debbugs.gnu.org/cgi/bugreport.cgi?bug=26032
 (ert-deftest LaTeX-indent-tabular ()
   (should (string=
            (with-temp-buffer
@@ -89,15 +93,24 @@ line and from another directory."
 ;; Test LaTeX code with math modes is indented as expected.  This has mostly to
 ;; do with the value of `LaTeX-fill-break-at-separators' and how
 ;; `LaTeX-fill-move-to-break-point' handles it.  If the test fails, try to look
-;; there.
+;; there.  The second part of the test looks for unambiguousness of
+;; macros starting a paragraph
+;; (http://lists.gnu.org/archive/html/auctex/2017-03/msg00009.html)
 (ert-deftest LaTeX-filling ()
   (should (string=
            (with-temp-buffer
              (insert-file-contents LaTeX-filling/in)
              (LaTeX-mode)
             (let ((fill-column 70))
-              (fill-paragraph))
-             (buffer-string))
+              (fill-paragraph)
+              (let ((cmds '("captionsetup" "caption"
+                            "parencite"    "par")))
+                (dolist (cmd cmds)
+                  (search-forward (concat "\\" cmd))
+                  (save-excursion
+                    (end-of-line 0)
+                    (fill-paragraph)))))
+            (buffer-string))
            (with-temp-buffer
              (insert-file-contents LaTeX-filling/out)
              (buffer-string)))))
@@ -137,4 +150,19 @@ line and from another directory."
             (LaTeX-mode)
             (buffer-string)))))
 
+(ert-deftest LaTeX-addbibresource ()
+  "Check parsing of bibliography files added with addbibresource.
+
+In particular, make sure dots are treated correctly and only the
+last extension is stripped."
+  (should
+   (equal
+    (with-temp-buffer
+      (insert "\\addbibresource{../foo-1.bar_2.qux3.ext}")
+      (LaTeX-mode)
+      (let ((TeX-parse-self t))
+       (TeX-update-style t))
+      (LaTeX-bibliography-list))
+    '(("../foo-1.bar_2.qux3")))))
+
 ;;; latex-test.el ends here
diff --git a/tests/latex/tabular-in.tex b/tests/latex/tabular-in.tex
index a8be333..8f75ab7 100644
--- a/tests/latex/tabular-in.tex
+++ b/tests/latex/tabular-in.tex
@@ -38,4 +38,45 @@ detraxit          & no.        & Ne sea doming   & deserunt.
 8 &
 9
 \end{align}
+
+% Next table tests filling with a control symbol \& inside a cell; the
+% function `LaTeX-indent-tabular' now (March 2017) detects \&, see:
+% https://debbugs.gnu.org/cgi/bugreport.cgi?bug=26010
+\begin{tabular}{llll}
+Lorem ipsum dolor & sit amet, ei mei \&
+paulo tation honestatis, \&
+intellegam & accommodare ne vim, ut
+mel solum putant
+atomorum. Posse & dolores has ut,\\
+prompta           & disputando & ne mel, ne
+\& viderer ceteros
+vel.            & No petentium
+\end{tabular}
+
+% Next tables test filling when & (column separator) character is
+% missing in a row; the function `LaTeX-hanging-ampersand-position'
+% now (March 2017) detects this and has a fallback, see:
+% https://debbugs.gnu.org/cgi/bugreport.cgi?bug=26032
+\begin{tabular}{llll}
+\multicolumn{4}{c}{Lorem ipsum dolor sit amet, ei mei} \\
+& paulo tation honestatis,
+intellegam accommodare ne vim, ut \\
+& mel solum putant atomorum. Posse & dolores has ut, \\
+prompta & disputando & ne mel, ne
+\& viderer ceteros vel. \\
+& No petentium
+\end{tabular}
+
+\begin{table}[tbp]
+  \begin{tabular}{llll}
+\multicolumn{4}{c}{Lorem ipsum dolor sit amet, ei mei} \\
+& paulo tation honestatis,
+intellegam accommodare ne vim, ut \\
+& mel solum putant atomorum. Posse & dolores has ut, \\
+prompta & disputando & ne mel, ne
+\& viderer ceteros vel. \\
+& No petentium
+  \end{tabular}
+\end{table}
+
 \end{document}
diff --git a/tests/latex/tabular-out.tex b/tests/latex/tabular-out.tex
index cd5b708..73521d2 100644
--- a/tests/latex/tabular-out.tex
+++ b/tests/latex/tabular-out.tex
@@ -38,4 +38,45 @@
       8 &
           9
 \end{align}
+
+% Next table tests filling with a control symbol \& inside a cell; the
+% function `LaTeX-indent-tabular' now (March 2017) detects \&, see:
+% https://debbugs.gnu.org/cgi/bugreport.cgi?bug=26010
+\begin{tabular}{llll}
+  Lorem ipsum dolor & sit amet, ei mei \&
+                      paulo tation honestatis, \&
+                      intellegam & accommodare ne vim, ut
+                                   mel solum putant
+                                   atomorum. Posse & dolores has ut,\\
+  prompta           & disputando & ne mel, ne
+                                   \& viderer ceteros
+                                   vel.            & No petentium
+\end{tabular}
+
+% Next tables test filling when & (column separator) character is
+% missing in a row; the function `LaTeX-hanging-ampersand-position'
+% now (March 2017) detects this and has a fallback, see:
+% https://debbugs.gnu.org/cgi/bugreport.cgi?bug=26032
+\begin{tabular}{llll}
+  \multicolumn{4}{c}{Lorem ipsum dolor sit amet, ei mei} \\
+  & paulo tation honestatis,
+    intellegam accommodare ne vim, ut \\
+  & mel solum putant atomorum. Posse & dolores has ut, \\
+  prompta & disputando & ne mel, ne
+                         \& viderer ceteros vel. \\
+  & No petentium
+\end{tabular}
+
+\begin{table}[tbp]
+  \begin{tabular}{llll}
+    \multicolumn{4}{c}{Lorem ipsum dolor sit amet, ei mei} \\
+    & paulo tation honestatis,
+      intellegam accommodare ne vim, ut \\
+    & mel solum putant atomorum. Posse & dolores has ut, \\
+    prompta & disputando & ne mel, ne
+                           \& viderer ceteros vel. \\
+    & No petentium
+  \end{tabular}
+\end{table}
+
 \end{document}
diff --git a/tests/tex/command-expansion.el b/tests/tex/command-expansion.el
index ebdb6d1..91b3235 100644
--- a/tests/tex/command-expansion.el
+++ b/tests/tex/command-expansion.el
@@ -33,6 +33,14 @@
                                 'TeX-master-file))
            "%%  \"\\input\"")))
 
+(ert-deftest TeX-command-expansion-errors ()
+  "Test error handling in `TeX-command-expand'."
+  (should-error
+   ;; This error is actually thrown by `TeX-engine-in-engine-alist', but we 
want
+   ;; to be sure that `TeX-command-expand' fails when the engine is not valid.
+   (let ((TeX-engine 'non-existing-engine))
+     (TeX-command-expand "%l" 'TeX-master-file))))
+
 (ert-deftest TeX-view-command-raw-errors ()
   "Tests to trigger errors in `TeX-view-command-raw'."
   ;; Viewer specification should be either a command line string or a Lisp
diff --git a/tex-buf.el b/tex-buf.el
index 6497777..fa05923 100644
--- a/tex-buf.el
+++ b/tex-buf.el
@@ -903,7 +903,7 @@ Does nothing in case the last command hasn't operated on the
 region."
   (when TeX-current-process-region-p
     (let ((region-buf (get-file-buffer (TeX-region-file t)))
-         (current-line (line-number-at-pos)))
+         (current-line (TeX-line-number-at-pos)))
       (when region-buf
        (with-current-buffer region-buf
          (goto-char (point-min))
@@ -2096,7 +2096,7 @@ original file."
        ;; Position point at the line/col that corresponds to point's line in
        ;; orig-buffer in order to make forward search work.
        (let ((line-col (with-current-buffer orig-buffer
-                         (cons (line-number-at-pos)
+                         (cons (TeX-line-number-at-pos)
                                (current-column)))))
           (goto-char (point-min))
           (forward-line (1- (abs (- header-offset (car line-col)))))
diff --git a/tex-info.el b/tex-info.el
index 0433b0a..7eb7970 100644
--- a/tex-info.el
+++ b/tex-info.el
@@ -335,7 +335,7 @@ commands. Return the resulting string."
                 nodes
                 :test (lambda (a b)
                         (when (equal a b)
-                          (push (cons a (line-number-at-pos (point))) dups)
+                          (push (cons a (TeX-line-number-at-pos (point))) dups)
                           t))))
       (when dups
        (display-warning
@@ -618,9 +618,9 @@ value of `Texinfo-mode-hook'."
   (set (make-local-variable 'require-final-newline) t)
   (set (make-local-variable 'indent-tabs-mode) nil)
   (set (make-local-variable 'paragraph-separate)
-       (concat "\b\\|address@hidden \n]\\|" paragraph-separate))
+       (concat "\b\\|@[a-zA-Z]*[ \n]\\|" paragraph-separate))
   (set (make-local-variable 'paragraph-start)
-       (concat "\b\\|address@hidden \n]\\|" paragraph-start))
+       (concat "\b\\|@[a-zA-Z]*[ \n]\\|" paragraph-start))
   (set (make-local-variable 'fill-column) 72)
   (set (make-local-variable 'comment-start) "@c ")
   (set (make-local-variable 'comment-start-skip) "@c +\\|@comment +")
diff --git a/tex-ispell.el b/tex-ispell.el
index 2eb13c0..98615c6 100644
--- a/tex-ispell.el
+++ b/tex-ispell.el
@@ -1,6 +1,6 @@
 ;;; tex-ispell.el --- AUCTeX skip additions for Ispell
 
-;; Copyright (C) 2016 Free Software Foundation, Inc.
+;; Copyright (C) 2016-2017 Free Software Foundation, Inc.
 
 ;; Author: Arash Esbati <address@hidden>
 ;; Maintainer: address@hidden
@@ -44,12 +44,15 @@
 ;; amsmath.sty
 ;; attachfile.sty
 ;; booktabs.sty
+;; breqn.sty
 ;; cleveref.sty
 ;; enumitem.sty
 ;; fancyref.sty
 ;; fancyvrb.sty
+;; filecontents.sty
 ;; fontaxes.sty
 ;; fontspec.sty
+;; hyperref.sty
 ;; listings.sty
 ;; ltxtable.sty
 ;; mdframed.sty
@@ -152,6 +155,21 @@
       ("figureversion" . 1)
       ;; fontspec.sty
       ("addfontfeatures" . 1)
+      ;; hyperref.sty
+      ("hypersetup" . 1)
+      ("href" . 1)
+      ("url" . 1)
+      ("nolinkurl" . 1)
+      ("hyperbaseurl" . 1)
+      ("hyperimage" . 1)
+      ("hyperdef" . 2)
+      ("hyperref" . 3)
+      ("hyperlink" . 1)
+      ("hypertarget" . 1)
+      ("autoref" . 1)
+      ("autoref*" . 1)
+      ("autopageref" . 1)
+      ("autopageref*" . 1)
       ;; listings.sty
       ("lstinputlisting" . 1)
       ("lstset" . 1)
@@ -219,43 +237,88 @@ argument and spell check the mandatory one."))
     "List of LaTeX environments with an opt argument to be skipped."))
 
 
+;; Add new environments which should be skipped entirely here:
+(eval-when-compile
+  (defvar TeX-ispell-skip-envs-list
+    '(;; amsmath.sty
+      "align"
+      "align*"
+      "alignat"
+      "alignat*"
+      "flalign"
+      "flalign*"
+      "gather"
+      "gather*"
+      "multline"
+      "multline*"
+      ;; breqn.sty
+      "darray"
+      "darray*"
+      "dgroup"
+      "dgroup*"
+      "dmath"
+      "dmath*"
+      "dseries"
+      "dseries*"
+      ;; fancyvrb.sty
+      "BVerbatim"
+      "BVerbatim*"
+      "LVerbatim"
+      "LVerbatim*"
+      "SaveVerbatim"
+      "Verbatim"
+      "Verbatim*"
+      "VerbatimOut"
+      ;; listings.sty
+      "lstlisting"
+      ;; minted.sty
+      "minted"
+      ;; tikz.sty
+      "tikzpicture")
+    "List of LaTeX environments which will be skipped entirely.
+Environments for math or verbatim text are candidates for this list."))
+
+
 ;; Add others delimited here:
 (TeX-ispell-skip-setcar
- '(;; LaTeX-base
+ `(;; LaTeX-base
+   ("\\\\(" . "\\\\)")
    ("\\\\raisebox" TeX-ispell-tex-arg-end 1 2 0)
    ;; booktabs.sty
-   ("\\\\cmidrule" . "\\(([^)]*)\\)?{[-0-9]+}")
+   ("\\\\cmidrule" . "{[-0-9]+}")
    ;; fontspec.sty
-   ("\\\\fontspec" TeX-ispell-tex-arg-end 1 1 0)
-   ;; minted.sty
-   ("\\\\mint\\(inline\\)?\\(\\[[^]]*\\]\\)?{\\([^}]+\\)}{" . "}")
-   ("\\\\mint\\(inline\\)?\\(\\[[^]]*\\]\\)?{\\([^}]+\\)}|" . "|")
-   ("\\\\mint\\(inline\\)?\\(\\[[^]]*\\]\\)?{\\([^}]+\\)}#" . "#")
-   ("\\\\mint\\(inline\\)?\\(\\[[^]]*\\]\\)?{\\([^}]+\\)}\\+" . "\\+")
-   ("\\\\mint\\(inline\\)?\\(\\[[^]]*\\]\\)?{\\([^}]+\\)}\\*" . "\\*")))
+   ("\\\\fontspec" TeX-ispell-tex-arg-end 1 1 0)))
+
+
+;; Special setup for verbatim macros:
+(defcustom TeX-ispell-verb-delimiters "!|#~\"/+^-"
+  "String with all delimiters for verbatim macros.
+Characters special in regexps like `^' and `-' must come last and
+not be quoted.  An opening brace `{', asterisk `*' and at-sign
+`@' should not be used as they are not recognized by
+`font-latex.el' correctly."
+  :group 'TeX-misc
+  :type 'string)
+
+;; listings.sty & fancyvrb.sty: With opt. argument only before verb content:
+(TeX-ispell-skip-setcar
+ `((,(concat "\\\\" (regexp-opt '("Verb" "lstinline")))
+    TeX-ispell-tex-arg-verb-end)))
+
+;; minted.sty: With opt. and mandatory argument before verb content:
+(TeX-ispell-skip-setcar
+ `((,(concat "\\\\" (regexp-opt '("mint" "mintinline")))
+    TeX-ispell-tex-arg-verb-end 1)))
 
 
 ;; Add environments here:
 (TeX-ispell-skip-setcdr
- '(;; amsmath.sty
-   ("\\(align\\(\\*\\|at\\*?\\)?\\|flalign\\*?\\)" .
-    "\\\\end{\\(align\\(\\*\\|at\\*?\\)?\\|flalign\\*?\\)}")
-   ("gather\\*?" . "\\\\end{gather\\*?}")
-   ("multline\\*?" . "\\\\end{multline\\*?}")
-   ;; listings.sty
-   ("lstlisting" . "\\\\end{lstlisting}")
-   ;; minted.sty
-   ("minted" . "\\\\end{minted}")
+ '(;; filecontents.sty
+   ("filecontents\\*?" ispell-tex-arg-end)
    ;; tabularx.sty, tabulary.sty, Standard LaTeX tabular*-env
    ("tabular[*xy]" TeX-ispell-tex-arg-end)
    ;; tcolorbox.sty -- raster library
-   ("tcboxed\\(raster\\|itemize\\)" ispell-tex-arg-end)
-   ;; tikz.sty
-   ("tikzpicture" . "\\\\end{tikzpicture}")
-   ;; fancyvrb.sty: In practice, all verbatim environments have a *
-   ;; variant, which sets showspaces=true
-   ("\\(Save\\|[BL]\\)?Verbatim\\(\\*\\|Out\\)?" .
-    "\\\\end{\\(Save\\|[BL]\\)?Verbatim\\(\\*\\|Out\\)?}")))
+   ("tcboxed\\(raster\\|itemize\\)" ispell-tex-arg-end)))
 
 
 ;; No customization below this line
@@ -299,6 +362,11 @@ argument and spell check the mandatory one."))
     (regexp-opt TeX-ispell-skip-envs-opt-arg-list t))
   "Regexp of LaTeX environments with an opt argument to be skipped.")
 
+(defvar TeX-ispell-skip-envs-regexp
+  (eval-when-compile
+    (regexp-opt TeX-ispell-skip-envs-list t))
+  "Regexp of LaTeX environments which will be skipped entirely.")
+
 ;; Make them available to Ispell:
 (TeX-ispell-skip-setcar
  `((,TeX-ispell-skip-cmds-opt-arg-regexp ispell-tex-arg-end 0)
@@ -307,7 +375,9 @@ argument and spell check the mandatory one."))
    (,TeX-ispell-skip-cmds-three-args-regexp ispell-tex-arg-end 3)))
 
 (TeX-ispell-skip-setcdr
- `((,TeX-ispell-skip-envs-opt-arg-regexp ispell-tex-arg-end 0)))
+ `((,TeX-ispell-skip-envs-opt-arg-regexp ispell-tex-arg-end 0)
+   ,(cons TeX-ispell-skip-envs-regexp
+         (concat "\\\\end{" TeX-ispell-skip-envs-regexp "}"))))
 
 (provide 'tex-ispell)
 
diff --git a/tex-jp.el b/tex-jp.el
index cfc37bf..66772aa 100644
--- a/tex-jp.el
+++ b/tex-jp.el
@@ -1,10 +1,12 @@
 ;;; tex-jp.el --- Support for Japanese TeX.  -*- coding: iso-2022-jp-unix; -*-
 
-;; Copyright (C) 1999, 2001-2007, 2012, 2016  Free Software Foundation, Inc.
+;; Copyright (C) 1999, 2001-2008, 2012-2013, 2016-2017
+;;   Free Software Foundation, Inc.
 
 ;; Author:     KOBAYASHI Shinji <address@hidden>,
 ;;             Hidenobu Nabetani <address@hidden>
 ;; Maintainer: Masayuki Ataka <address@hidden>
+;;             Ikumi Keita <address@hidden>
 ;; Keywords: tex
 
 ;; This file is part of AUCTeX.
@@ -111,11 +113,25 @@ For detail, see `TeX-command-list', to which this list is 
appended."
                                     (const :tag "AmSTeX" ams-tex-mode)))
                        (repeat :tag "Menu elements" :inline t sexp))))
 
-;; Define before first use.
-(defvar japanese-TeX-mode nil
-  "Non-nil means the current buffer handles Japanese TeX/LaTeX.")
-(make-variable-buffer-local 'japanese-TeX-mode)
-(put 'japanese-TeX-mode 'permanent-local t)
+;; customize option $B$N=i4|CM$d(B saved value 
$B$=$N$b$N$r2~JQ$7$J$$$h$&$K(B
+;; $B$9$k$?$a!"(Bsetcar $B$N;HMQ$OHr$1$k!#(B
+(setq TeX-command-list
+      ;; `TeX-command-list' $B$HF1$89=B$$N?7$7$$(B list $B$r:n$k!#(B
+      ;; $B3FMWAG$N(B list $B$r(B l $B$H$7$F!"(Bl 
$B$=$N$b$N$r;H$C$?$j!"(Bl $B$r(B
+      ;; $B<address@hidden(B list $B$r:n$C$?$j$7$F(B `mapcar' 
$B$G=8$a$k!#(B
+      (mapcar
+       (lambda (l)
+        (cond
+         ;; l $B$NBh(B1$BMWAG$,(B "BibTeX" $B$d(B "Index" 
address@hidden"(Bl $B$NBh(B2$BMWAG(B
+         ;; address@hidden($?JL$N(B list $B$r:n$k!#(B
+         ((equal (car l) "BibTeX")
+          (append (list (car l) "%(bibtex) %s") (cddr l)))
+         ((equal (car l) "Index")
+          (append (list (car l) "%(makeindex) %s") (cddr l)))
+         ;; $B$=$l0J30$N>l9g$O(B l $B$=$N$b$N$r;H$&!#(B
+         (t
+          l)))
+       TeX-command-list))
 
 ;; $B=gD4$K9T$1$PITMW$K$J$k!#(B
 (setq TeX-command-list
@@ -123,14 +139,15 @@ For detail, see `TeX-command-list', to which this list is 
appended."
              '(("-" "" ignore nil t)) ;; separator for command menu
              TeX-command-list))
 
-;; $B;CDj=hCV!#(Btex.el $B$K<h$j9~$s$G$b$i$($k$H$h$$!#(B
-(setcar (cdr (assoc "BibTeX" TeX-command-list)) "%(bibtex) %s")
-(setcar (cdr (assoc "Index" TeX-command-list)) "%(makeindex) %s")
+;; Define before first use.
+(defvar japanese-TeX-mode nil
+  "Non-nil means the current buffer handles Japanese TeX/LaTeX.")
+(make-variable-buffer-local 'japanese-TeX-mode)
+(put 'japanese-TeX-mode 'permanent-local t)
 
-;; $B;CDj=hCV!#(Btex.el $B$K<h$j9~$s$G$b$i$($k$H$h$$!#(B
-(setq TeX-expand-list
+(setq TeX-expand-list-builtin
       (append
-       TeX-expand-list
+       TeX-expand-list-builtin
        '(
         ;; -kanji $B%*%W%7%g%s$NJ8;zNs$r:n$k!#(B
         ("%(kanjiopt)" (lambda ()
@@ -177,67 +194,57 @@ For detail, see `TeX-command-list', to which this list is 
appended."
 
 ;;; Viewing (new implementation)
 
-(unless (get 'TeX-view-predicate-list 'saved-value)
-  (setq TeX-view-predicate-list
+(setq TeX-view-predicate-list-builtin
+      (append
        '((paper-a4
-          (TeX-match-style
-           "\\`\\(a4j\\|a4paper\\|a4dutch\\|a4wide\\|sem-a4\\)\\'"))
+         (let ((regex 
"\\`\\(?:a4j\\|a4paper\\|a4dutch\\|a4wide\\|sem-a4\\)\\'"))
+           (or (TeX-match-style regex)
+               (and (fboundp 'LaTeX-match-class-option)
+                    (LaTeX-match-class-option regex)))))
          (paper-a5
-          (TeX-match-style
-           "\\`\\(a5j\\|a5paper\\|a5comb\\)\\'"))
+         (let ((regex "\\`\\(?:a5j\\|a5paper\\|a5comb\\)\\'"))
+           (or (TeX-match-style regex)
+               (and (fboundp 'LaTeX-match-class-option)
+                    (LaTeX-match-class-option regex)))))
          ;; jarticle address@hidden(B b4paper, b5paper $B$O(B JIS B 
$B7ONs!#(B
          ;; j-article $B$J$I$NJ}$K$O(B a4j, b5j 
$B$H$$$C$?%*%W%7%g%s$O$J$$!#(B
          (paper-b5    ; ISO B5
-          (and (TeX-match-style "\\`b5paper\\'")
-               (not (memq TeX-engine '(ptex uptex)))))
+          (and (fboundp 'LaTeX-match-class-option)
+              (LaTeX-match-class-option "\\`b5paper\\'")
+               (not (TeX-match-style 
"\\`u?[jt]s?\\(?:article\\|report\\|book\\)\\'"))))
          (paper-b5jis ; JIS B5
-          (or (TeX-match-style "\\`b5j\\'")
-              (and (TeX-match-style "\\`b5paper\\'")
-                   (memq TeX-engine '(ptex uptex)))))
+         (and (fboundp 'LaTeX-match-class-option)
+              (or (LaTeX-match-class-option "\\`b5j\\'")
+                  (and (LaTeX-match-class-option "\\`b5paper\\'")
+                       (TeX-match-style 
"\\`u?[jt]s?\\(?:article\\|report\\|book\\)\\'")))))
          ;; article $B$J$I$K$O(B b4paper $B$H$$$&%*%W%7%g%s$O$J$$!#(B
          ;; b4paper $B$H$$$&%*%W%7%g%s$,$"$C$?$i(B JIS B4 $B$H8+$J$9!#(B
          (paper-b4jis
-          (TeX-match-style "\\`\\(b4j\\|b4paper\\)\\'")))))
-;; jsarticle address@hidden>$K$b$b$C$HH=7?$N%*%W%7%g%s$,$"$k$,!"(B
-;; $BA4ItLLE]8+$F$k$H%-%j$,$J$$$N$G!"$3$l$/address@hidden&!#(B
-;; jsarticle.el $B$d(B jsbook.el 
$B$GDI2CJ,$N=hM}$r;E9~$a$P$$$$$N$+$bCN$l$J$$!#(B
-
-;; $B;CDj=hCV!#(Btex.el $B$K<h$j9~$s$G$b$i$($k$H$h$$!#(B
-(unless (get 'TeX-view-program-list 'saved-value)
-  (setq TeX-view-program-list
-       (cond
-        ;; http://oku.edu.mie-u.ac.jp/~okumura/texwiki/?AUCTeX
-        ;; $B$r;29M$K$7$F$_$?!#(B
-        ((eq system-type 'windows-nt)
-         '(("TeXworks" "TeXworks %o" "texworks")
-           ("MuPDF" "mupdf %o" "mupdf")))
-        ;; $B$3$l$G$$$$$N$+$I$&$+$OIT0B!#(B
-        ((eq system-type 'darwin)
-         '(("TeXShop" "open -a TeXShop.app %o" "open")
-           ("TeXworks" "open -a TeXworks.app %o" "open")
-           ("PictPrinter" "open -a PictPrinter.app %d" "open")
-           ("Mxdvi" "open -a Mxdvi.app %d" "open")))
-        (t
-         (setcar (cadr (assoc "xdvi" TeX-view-program-list-builtin))
-                 "%(xdvi) -unique")
-         '(("TeXworks" "texworks %o" "texworks")
-           ("MuPDF" "mupdf %o" "mupdf"))))))
+         (and (fboundp 'LaTeX-match-class-option)
+              (LaTeX-match-class-option "\\`\\(?:b4j\\|b4paper\\)\\'"))))
+       ;; jsclasses 
address@hidden>$K$b$b$C$HH=7?$N%*%W%7%g%s$,$"$k$,!"A4ItLLE](B
+       ;; $B8+$F$k$H%-%j$,$J$$$N$G!"$3$l$/address@hidden&!#(B
+       ;; jsarticle.el $B$d(B jsbook.el 
$B$GDI2CJ,$N=hM}$r;E9~$a$P$$$$$N$+$bCN$l$J$$!#(B
+       TeX-view-predicate-list-builtin))
+
+(unless (memq system-type '(windows-nt darwin))
+  (let ((l (assoc "xdvi" TeX-view-program-list-builtin)))
+    (when l
+      (setcar (cadr l) "%(xdvi) -unique")
+      (setcdr (cdr l) '("%(xdvi)"))))
+  (setq TeX-view-program-list-builtin
+       (append TeX-view-program-list-builtin
+               '(("MuPDF" "mupdf %o" "mupdf")))))
 
 ;; $B$3$l$O(B tex.el $B$K<h$jF~$l$F$b$i$&$N$OFq$7$$$+!)(B
 ;; tex-jp.el $B$,address@hidden"(Bdvi viewer $B$N%G%U%)%k%H$,(B dviout 
$B$K(B
 ;; $B$J$C$F$7$^$&$N$ODq93$,Bg$-$$$+$b!#(B
 (unless (get 'TeX-view-program-selection 'saved-value)
-  (setq TeX-view-program-selection
-       (append
-        (cond
-         ((eq system-type 'windows-nt)
-          '((output-dvi "dviout")
-            (output-pdf "TeXworks")))
-         ((eq system-type 'darwin)
-          '((output-pdf "Preview.app")))
-         (t
-          nil))
-        TeX-view-program-selection)))
+  (if (eq system-type 'windows-nt)
+      (setq TeX-view-program-selection
+           (append
+            '((output-dvi "dviout"))
+            TeX-view-program-selection))))
 
 (mapc (lambda (dir) (add-to-list 'TeX-macro-global dir t))
       (or (TeX-tree-expand
@@ -251,16 +258,6 @@ For detail, see `TeX-command-list', to which this list is 
appended."
           "jlatex" '("/jtex/" "/jbibtex/bst/"))
          '("/usr/share/texmf/jtex/" "/usr/share/texmf/jbibtex/bst/")))
 
-;; $B=gD4$K9T$1$PITMW$K$J$k!#(B
-(setq LaTeX-command-style
-      (append '(("\\`u[jt]\\(article\\|report\\|book\\)\\'\\|\\`uplatex\\'"
-                "%(PDF)uplatex %S%(PDFout)")
-               ("\\`[jt]s?\\(article\\|report\\|book\\)\\'"
-                "%(PDF)platex %(kanjiopt)%S%(PDFout)")
-               ("\\`j-\\(article\\|report\\|book\\)\\'"
-                "%(PDF)jlatex %S%(PDFout)"))
-             LaTeX-command-style))
-
 (defcustom japanese-TeX-error-messages t
   "*If non-nil, explain TeX error messages in Japanese."
   :group 'AUCTeX-jp
@@ -315,13 +312,20 @@ See also a user custom option 
`TeX-japanese-process-input-coding-system'."
     ;; for upLaTeX
     ("ujarticle") ("ujreport") ("ujbook")
     ("utarticle") ("utreport") ("utbook"))
-  "*List of Japanese document styles."
+  "*List of Japanese document classes."
   :group 'AUCTeX-jp
   :type '(repeat (group (string :format "%v"))))
 
 (setq LaTeX-style-list
       (append japanese-LaTeX-style-list LaTeX-style-list))
 
+;; address@hidden&%4%7%C%/BN;XDj%3%^%s%I$O(B jLaTeX $B$K$O$J$$$h$&$G!"(B
+;; (u)pLaTeX $B$G$7$+;H$($J$$$,!"address@hidden&!#(B
+(setq LaTeX-font-list
+      (append '((?m "\\textmc{" "}" "\\mathmc{" "}")
+                (?g "\\textgt{" "}" "\\mathgt{" "}"))
+             LaTeX-font-list))
+
 ;;; Coding system
 
 (defun japanese-TeX-set-process-coding-system (process)
@@ -355,7 +359,7 @@ See also a user custom option 
`TeX-japanese-process-input-coding-system'."
                   ((eq TeX-engine 'ptex)
                    (cond ((eq system-type 'darwin)
                           'utf-8)
-                         (japanese-TeX-use-kanji-opt-flag
+                         ((and japanese-TeX-use-kanji-opt-flag kanji)
                           kanji)
                          (t 'shift_jis)))
                   ;; jtex $B$J$i(B sjis $B$K8GDj$9$k!#(B
@@ -374,15 +378,38 @@ See also a user custom option 
`TeX-japanese-process-input-coding-system'."
                   ;; address@hidden"(Blocale 
$B$,F|K\8l$r%5%]!<%H$7$J$$>l9g$O(B
                   ;; euc $B$K8GDj$9$k!#(B
                   (t
-                   (if (japanese-TeX-coding-ejsu locale-coding-system)
-                       locale-coding-system 'euc-jp))))))
+                   (let ((lcs
+                          (cond
+                           ((boundp 'locale-coding-system)
+                            locale-coding-system)
+                           ;; XEmacs doesn't have `locale-coding-system'.
+                           ;; Instead xemacs 21.5 has
+                           ;; `get-coding-system-from-locale' and
+                           ;; `current-locale'.  They aren't available on
+                           ;; xemacs 21.4.
+                           ((and
+                             (featurep 'xemacs)
+                             (fboundp 'get-coding-system-from-locale))
+                            (get-coding-system-from-locale
+                             (if (fboundp 'current-locale)
+                                 (current-locale)
+                               ;; I don't know XEmacs well, so incorporate
+                               ;; the suggestion of
+                               ;; 
http://lists.gnu.org/archive/html/auctex-devel/2017-02/msg00079.html
+                               ;; as well.
+                               (or (getenv "LC_ALL")
+                                   (getenv "LC_CTYPE")
+                                   (getenv "LANG")
+                                   "")))))))
+                     (if (and lcs (japanese-TeX-coding-ejsu lcs))
+                         lcs 'euc-jp)))))))
 
           ;; process $B$KM?$($kF~NO$NJ8;z%3!<%I!#(B
           (enc (cond
                 ;; ptex $B$G(B -kanji 
$B%*%W%7%g%s$"$j$J$i!"$=$NJ8;z%3!<%I!#(B
                 ;; $B$J$7$J$i(B utf-8 $B$+(B sjis$B!#(B
                 ((eq TeX-engine 'ptex)
-                 (if japanese-TeX-use-kanji-opt-flag
+                 (if (and japanese-TeX-use-kanji-opt-flag kanji)
                      kanji
                    (if (eq system-type 'windows-nt)
                        'shift_jis 'utf-8)))
@@ -394,9 +421,10 @@ See also a user custom option 
`TeX-japanese-process-input-coding-system'."
                 (t
                  'utf-8))))
        ;; Customize $BCM$,$"address@hidden(B
-       (set-process-coding-system process
-                                  (or 
TeX-japanese-process-output-coding-system dec)
-                                  (or TeX-japanese-process-input-coding-system 
enc))))))
+       (set-process-coding-system
+        process
+        (or TeX-japanese-process-output-coding-system dec)
+        (or TeX-japanese-process-input-coding-system enc))))))
 (when (featurep 'mule)
   (setq TeX-after-start-process-function
         #'japanese-TeX-set-process-coding-system))
@@ -421,16 +449,16 @@ Return nil otherwise."
                 (mule-utf-8 . "utf8") ; for emacs 21, 22
                 ;; utf-8-auto $B$d(B utf-8-emacs 
$B$rF~$l$kI,MW$O$"$k$N$+!)(B
 
-                ;; xemacs $B$G(B jisx0213 $B$O;H$($k$N$+!);H$($k$H$7$F!"(B
-                ;; $B$=$N(B coding system $BL>$O!)(B
+                ;; xemacs 21.5 with mule $B$K$O!"(Bjisx0213 $B$N(B charset 
$B$O(B
+                ;; $B$"$k$,$=$lMQ$N(B coding system $B$O$J$$!#(B
                 (euc-jis-2004 . "euc")
                 (iso-2022-jp-2004 . "jis")
                 (japanese-shift-jis-2004 . "sjis")
 
-                ;; xemacs $B$K(B cp932 $B7O$N(B coding system 
$B$,$"$k$N$+(B
-                ;; $B$I$&$+$b$h$/$o$+$i$J$$!#(B
                 (japanese-cp932 . "sjis")
-                (eucjp-ms . "euc"))))))
+                (eucjp-ms . "euc")
+                (windows-932 . "sjis") ; for xemacs 21.5 with mule
+               )))))
 
 (defun japanese-TeX-get-encoding-string ()
   "Return coding option string for Japanese pTeX family.
@@ -491,14 +519,12 @@ Set `japanese-TeX-mode' to t, and enter `TeX-latex-mode'."
   (when japanese-TeX-mode
 ;    (setq TeX-command-default japanese-LaTeX-command-default)
     (TeX-engine-set
-     ;; class file $BL>address@hidden)(B
-     ;; jLaTeX $B$K$b(B jarticle $B$O0l1~$"$k$7!"(BpLaTeX $B$G$b<+J,$G(B 
j-article $B$r(B
-     ;; $B%$%s%9%H!<%k$7$F;H$C$F$$$1$J$$K!$O$J$$!#(B
      (cond
-      ((TeX-match-style 
"\\`u[jt]\\(article\\|report\\|book\\)\\'\\|\\`uplatex\\'")
+      ((TeX-match-style "\\`u[jt]\\(article\\|report\\|book\\)\\'")
        'uptex)
       ((TeX-match-style "\\`[jt]s?\\(article\\|report\\|book\\)\\'")
-       'ptex)
+       (if (LaTeX-match-class-option "\\`uplatex\\'")
+          'uptex 'ptex))
       ((TeX-match-style "\\`j-\\(article\\|report\\|book\\)\\'")
        'jtex)
       (t japanese-TeX-engine-default)))
@@ -507,6 +533,14 @@ Set `japanese-TeX-mode' to t, and enter `TeX-latex-mode'."
 ;        (if (and (eq TeX-engine 'ptex) (executable-find "pbibtex"))
 ;            "pBibTeX" "jBibTeX"))
 
+    (when (and (fboundp 'font-latex-add-keywords)
+              (eq TeX-install-font-lock 'font-latex-setup))
+      ;; jLaTeX address@hidden,!"$=$l$O$b$&5$$K$7$J$/address@hidden&!#(B
+      (font-latex-add-keywords '(("textgt" "{") ("mathgt" "{"))
+                              'bold-command)
+      (font-latex-add-keywords '("gtfamily")
+                              'bold-declaration))
+
     ;; The value of `major-mode' should be `latex-mode', not
     ;; `japanese-latex-mode', because the name `latex-mode' is hard
     ;; coded in several places of AUCTeX like "(eq major-mode
diff --git a/tex.el b/tex.el
index 02946b9..013e6d1 100644
--- a/tex.el
+++ b/tex.el
@@ -155,6 +155,8 @@ If nil, none is specified."
      :help "Convert DVI file to PDF with dvipdfmx")
     ("Ps2pdf" "ps2pdf %f" TeX-run-ps2pdf nil t
      :help "Convert PostScript file to PDF")
+    ("Glossaries" "makeglossaries %s" TeX-run-command nil
+     t :help "Run makeglossaries to create glossary file")
     ("Index" "makeindex %s" TeX-run-index nil t
      :help "Run makeindex to create index file")
     ("Xindy" "texindy %s" TeX-run-command nil t
@@ -476,8 +478,8 @@ string."
     ("%(file-line-error)"
      (lambda () (if TeX-file-line-error " -file-line-error" "")))
     ("%(o?)" (lambda () (if (eq TeX-engine 'omega) "o" "")))
-    ("%(tex)" (lambda () (eval (nth 2 (assq TeX-engine (TeX-engine-alist))))))
-    ("%(latex)" (lambda () (eval (nth 3 (assq TeX-engine 
(TeX-engine-alist))))))
+    ("%(tex)" (lambda () (eval (nth 2 (TeX-engine-in-engine-alist 
TeX-engine)))))
+    ("%(latex)" (lambda () (eval (nth 3 (TeX-engine-in-engine-alist 
TeX-engine)))))
     ("%(cntxcom)" ConTeXt-expand-command)
     ("%(execopts)" ConTeXt-expand-options)
     ("%(extraopts)" (lambda () TeX-command-extra-options))
@@ -760,7 +762,11 @@ overlays."
             (/ outer-priority 2))
            ((and inner-priority outer-priority)
             (+ (/ (- outer-priority inner-priority) 2) inner-priority))
-           (t TeX-overlay-priority-step)))) )
+           (t TeX-overlay-priority-step))))
+
+  (defun TeX-replace-regexp-in-string (regexp rep string)
+    "Compatibility function mimicking `replace-regexp-in-string' for XEmacs."
+    (replace-in-string string regexp rep)) )
 
 ;; require crm here, because we often do
 ;;
@@ -898,7 +904,9 @@ overlays."
             (/ outer-priority 2))
            ((and inner-priority outer-priority)
             (+ (/ (- outer-priority inner-priority) 2) inner-priority))
-           (t TeX-overlay-priority-step)))) )
+           (t TeX-overlay-priority-step))))
+
+  (defalias #'TeX-replace-regexp-in-string #'replace-regexp-in-string) )
 
 (defun TeX-delete-dups-by-car (alist &optional keep-list)
   "Return a list of all elements in ALIST, but each car only once.
@@ -1165,21 +1173,33 @@ all the regular expressions must match for the element 
to apply."
     (mode-io-correlate
      TeX-source-correlate-mode)
     (paper-landscape
-     (TeX-match-style "\\`landscape\\'"))
+     (and (fboundp 'LaTeX-match-class-option)
+         (LaTeX-match-class-option "\\`landscape\\'")))
     (paper-portrait
-     (not (TeX-match-style "\\`landscape\\'")))
+     (not (and (fboundp 'LaTeX-match-class-option)
+              (LaTeX-match-class-option "\\`landscape\\'"))))
     (paper-a4
-     (TeX-match-style "\\`a4paper\\|a4dutch\\|a4wide\\|sem-a4\\'"))
+     (let ((regex "\\`\\(?:a4paper\\|a4dutch\\|a4wide\\|sem-a4\\)\\'"))
+       (or (TeX-match-style regex)
+          (and (fboundp 'LaTeX-match-class-option)
+               (LaTeX-match-class-option regex)))))
     (paper-a5
-     (TeX-match-style "\\`a5paper\\|a5comb\\'"))
+     (let ((regex "\\`\\(?:a5paper\\|a5comb\\)\\'"))
+       (or (TeX-match-style regex)
+          (and (fboundp 'LaTeX-match-class-option)
+               (LaTeX-match-class-option regex)))))
     (paper-b5
-     (TeX-match-style "\\`b5paper\\'"))
+     (and (fboundp 'LaTeX-match-class-option)
+         (LaTeX-match-class-option "\\`b5paper\\'")))
     (paper-letter
-     (TeX-match-style "\\`letterpaper\\'"))
+     (and (fboundp 'LaTeX-match-class-option)
+         (LaTeX-match-class-option "\\`letterpaper\\'")))
     (paper-legal
-     (TeX-match-style "\\`legalpaper\\'"))
+     (and (fboundp 'LaTeX-match-class-option)
+         (LaTeX-match-class-option "\\`legalpaper\\'")))
     (paper-executive
-     (TeX-match-style "\\`executivepaper\\'")))
+     (and (fboundp 'LaTeX-match-class-option)
+         (LaTeX-match-class-option "\\`executivepaper\\'"))))
   "Alist of built-in predicates for viewer selection and invocation.
 See the doc string of `TeX-view-predicate-list' for a short
 description of each predicate.")
@@ -1313,7 +1333,7 @@ DE is the name of the desktop environment, either 
\"gnome\" or
           (format "org.%s.%s.Window" de app)
           "SyncView"
           (buffer-file-name)
-          (list :struct :int32 (line-number-at-pos)
+          (list :struct :int32 (TeX-line-number-at-pos)
                 :int32 (1+ (current-column)))
           :uint32 0))
       (error "Couldn't find the %s instance for %s" (capitalize app) uri))))
@@ -1650,6 +1670,17 @@ The function appends the built-in engine specs from
 where an entry with the same car exists in the user-defined part."
   (TeX-delete-dups-by-car (append TeX-engine-alist TeX-engine-alist-builtin)))
 
+(defun TeX-engine-in-engine-alist (engine)
+  "Return the `engine' entry in `TeX-engine-alist'.
+
+Throw an error if `engine' is not present in the alist."
+  (or
+   (assq engine (TeX-engine-alist))
+   (error "`%s' is not a known engine.  Valid values are: %s." engine
+         (mapconcat
+          (lambda (x) (prin1-to-string (car x)))
+          (TeX-engine-alist) ", "))))
+
 (defcustom TeX-engine 'default
   (concat "Type of TeX engine to use.
 It should be one of the following symbols:\n\n"
@@ -1895,7 +1926,7 @@ If the Emacs frame isn't raised, customize
                     (url-unhex-string (aref (url-generic-parse-url file) 6)))
                 ;; For Emacs 21 compatibility, which doesn't have the
                 ;; url package.
-                (file-error (replace-regexp-in-string "^file://" "" file))))
+                (file-error (TeX-replace-regexp-in-string "^file://" "" 
file))))
         (flc (or (apply #'TeX-source-correlate-handle-TeX-region file linecol)
                  (apply #'list file linecol)))
         (file (car flc))
@@ -2057,7 +2088,7 @@ enabled and the `synctex' binary is available."
   (let ((synctex-output
         (with-output-to-string
           (call-process "synctex" nil (list standard-output nil) nil "view"
-                        "-i" (format "%s:%s:%s" (line-number-at-pos)
+                        "-i" (format "%s:%s:%s" (TeX-line-number-at-pos)
                                      (current-column)
                                      file)
                         "-o" (TeX-active-master (TeX-output-extension))))))
@@ -4209,7 +4240,7 @@ alter the numbering of any ordinary, non-shy groups.")
        1 TeX-auto-file)
       (,(concat "\\\\mathchardef\\\\\\(" token "+\\)address@hidden")
        1 TeX-auto-symbol)))
-  "List of regular expression matching common LaTeX macro definitions.")
+  "List of regular expression matching common plain TeX macro definitions.")
 
 (defvar TeX-auto-full-regexp-list plain-TeX-auto-regexp-list
   "Full list of regular expression matching TeX macro definitions.")
@@ -6646,6 +6677,30 @@ skipped."
      (message "Error skipping s-expressions at point %d" (point))
      (sit-for 2))))
 
+(defun TeX-ispell-tex-arg-verb-end (&optional arg)
+  "Skip across an optional argument, ARG number of mandatory ones and verbatim 
content.
+This function always checks if one optional argument in brackets
+is given and skips over it.  If ARG is a number, it skips over
+that many mandatory arguments in braces.  Then it checks for
+verbatim content to skip which is enclosed by a character given
+in `TeX-ispell-verb-delimiters' or in braces, otherwise raises an
+error."
+  (condition-case nil
+      (progn
+       (when (looking-at "[ \t\n]*\\[") (forward-sexp))
+       (when (and arg (looking-at "{"))
+         (forward-sexp arg))
+       (cond ((looking-at (concat "[" TeX-ispell-verb-delimiters "]"))
+              (forward-char)
+              (skip-chars-forward (concat "^" (string (char-before))))
+              (forward-char))
+             ((looking-at "{")
+              (forward-sexp))
+             (t (error nil))))
+    (error
+     (message "Verbatim delimiter is not one of %s"
+             (split-string TeX-ispell-verb-delimiters "" t))
+     (sit-for 2))))
 
 ;;; Abbrev mode
 
diff --git a/texmathp.el b/texmathp.el
index 75eb2c0..23e72f8 100644
--- a/texmathp.el
+++ b/texmathp.el
@@ -1,6 +1,6 @@
 ;;; texmathp.el -- Code to check if point is inside LaTeX math environment
 
-;; Copyright (C) 1998, 2004 Free Software Foundation, Inc.
+;; Copyright (C) 1998, 2004, 2017 Free Software Foundation, Inc.
 
 ;; Author: Carsten Dominik <address@hidden>
 ;; Maintainer: address@hidden
@@ -143,7 +143,16 @@
     ("\\text"        arg-off)     ("\\intertext"   arg-off)
 
     ;; mathtools
-    ("\\shortintertext"   arg-off))
+    ("\\shortintertext"   arg-off)
+
+    ;; empheq
+    ("empheq"        env-on)
+    ("AmSequation"   env-on)      ("AmSequation*"  env-on)
+    ("AmSalign"      env-on)      ("AmSalign*"     env-on)
+    ("AmSgather"     env-on)      ("AmSgather*"    env-on)
+    ("AmSmultline"   env-on)      ("AmSmultline*"  env-on)
+    ("AmSflalign"    env-on)      ("AmSflalign*"   env-on)
+    ("AmSalignat"    env-on)      ("AmSalignat*"   env-on))
   "The default entries for `texmathp-tex-commands', which see.")
 
 (defun texmathp-compile ()



reply via email to

[Prev in Thread] Current Thread [Next in Thread]