Initial Commit
[packages] / xemacs-packages / auctex / style / longtable.el
1 ;;; longtable.el --- AUCTeX style for `longtable.sty'.
2
3 ;; Copyright (C) 2013, 2014  Free Software Foundation, Inc.
4
5 ;; Maintainer: auctex-devel@gnu.org
6 ;; Author: Mosè Giordano <giordano.mose@libero.it>
7 ;; Keywords: tex
8
9 ;; This file is part of AUCTeX.
10
11 ;; AUCTeX is free software; you can redistribute it and/or modify it
12 ;; under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 3, or (at your option)
14 ;; any later version.
15
16 ;; AUCTeX is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 ;; General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with AUCTeX; see the file COPYING.  If not, write to the Free
23 ;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
24 ;; 02110-1301, USA.
25
26 ;;; Commentary:
27
28 ;; This file adds support for `longtable.sty'.
29
30 ;;; Code:
31
32 (TeX-add-style-hook
33  "longtable"
34  (lambda ()
35    (LaTeX-add-environments
36     '("longtable" (lambda (environment)
37                     (let ((pos (completing-read (TeX-argument-prompt t nil "Position")
38                                                 '(("l") ("r") ("c"))))
39                           (fmt (read-string "Format: " LaTeX-default-format))
40                           (caption (read-string "Caption: ")))
41                       (setq LaTeX-default-format fmt)
42                       (LaTeX-insert-environment environment
43                                                 (concat
44                                                  (unless (zerop (length pos))
45                                                    (concat LaTeX-optop pos LaTeX-optcl))
46                                                  (concat TeX-grop fmt TeX-grcl)))
47                       ;; top caption -- do nothing if user skips caption
48                       (unless (zerop (length caption))
49                         ;; the longtable `\caption' is equivalent to a
50                         ;; `\multicolumn', so it needs a `\\' at the
51                         ;; end of the line
52                         (insert TeX-esc "caption" TeX-grop caption TeX-grcl " \\\\")
53                         (LaTeX-newline)
54                         (indent-according-to-mode)
55                         ;; ask for a label and insert a new line only
56                         ;; if a label is actually inserted
57                         (when (LaTeX-label environment 'environment)
58                           (LaTeX-newline)
59                           (indent-according-to-mode)))))))
60    (TeX-add-symbols
61     ;; Parameters
62     '("LTleft" 0)
63     '("LTright" 0)
64     '("LTpre" 0)
65     '("LTpost" 0)
66     '("LTcapwidth" 0)
67     '("LTchunksize" 0)
68     ;; Commands to end table rows
69     '("endhead" 0)
70     '("endfirsthead" 0)
71     '("endfoot" 0)
72     '("endlastfoot" 0)
73     ;; Caption commands
74     '("caption*" 1))
75
76    ;; Use the enhanced table formatting
77    (add-to-list 'LaTeX-indent-environment-list
78                 '("longtable" LaTeX-indent-tabular))
79
80    ;; Append longtable to `LaTeX-label-alist', in order not to override possible
81    ;; custome values.
82    (add-to-list 'LaTeX-label-alist '("longtable" . LaTeX-table-label) t)
83
84    ;; Fontification
85    (when (and (featurep 'font-latex)
86               (eq TeX-install-font-lock 'font-latex-setup))
87      ;; Actually, `\caption*{}' macro takes only one mandatory
88      ;; argument, not an optional one, the following is a workaround
89      ;; to fontify correctly also the standard `\caption[]{}' macro.
90      (font-latex-add-keywords '(("caption" "*[{"))
91                               'textual)))
92  LaTeX-dialect)
93
94 ;; longtable.el ends here