EasyPG 1.07 Released
[packages] / xemacs-packages / auctex / style / longtable.el
1 ;;; longtable.el --- AUCTeX style for `longtable.sty'.
2
3 ;; Copyright (C) 2013--2017  Free Software Foundation, Inc.
4
5 ;; Maintainer: auctex-devel@gnu.org
6 ;; Author: Mosè Giordano <mose@gnu.org>
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 (defvar LaTeX-longtable-skipping-regexp
33   (regexp-opt '("[l]" "[r]" "[c]" ""))
34   "Regexp matching between \\begin{longtable} and column specification.
35 For longtable environments only.")
36
37 (defun LaTeX-item-longtable (&optional suppress)
38   "Insert line break macro on the last line and suitable number of &'s.
39 For longtable environments.  If SUPPRESS is non-nil, do not
40 insert line break macro."
41   (unless suppress
42     (save-excursion
43       (end-of-line 0)
44       (just-one-space)
45       (TeX-insert-macro "\\")))
46   (LaTeX-insert-ampersands
47    LaTeX-longtable-skipping-regexp #'LaTeX-array-count-columns))
48
49 (defun LaTeX-env-longtable (environment)
50   "Insert a longtable-like ENVIRONMENT with caption and label."
51   (let* ((pos (completing-read (TeX-argument-prompt t nil "Position")
52                                '(("l") ("r") ("c"))))
53          (fmt (TeX-read-string "Format: " LaTeX-default-format))
54          (caption (TeX-read-string "Caption: "))
55          (short-caption (when (>= (length caption) LaTeX-short-caption-prompt-length)
56                           (TeX-read-string "(Optional) Short caption: "))))
57     (setq LaTeX-default-format fmt)
58     (LaTeX-insert-environment environment
59                               (concat
60                                (unless (zerop (length pos))
61                                  (concat LaTeX-optop pos LaTeX-optcl))
62                                (concat TeX-grop fmt TeX-grcl)))
63     ;; top caption -- do nothing if user skips caption
64     (unless (zerop (length caption))
65       ;; insert `\caption[short-caption]{caption':
66       (insert TeX-esc "caption")
67       (when (and short-caption (not (string= short-caption "")))
68         (insert LaTeX-optop short-caption LaTeX-optcl))
69       (insert TeX-grop caption)
70       ;; ask for a label and insert it
71       (LaTeX-label environment 'environment)
72       ;; the longtable `\caption' is equivalent to a
73       ;; `\multicolumn', so it needs a `\\' at the
74       ;; end of the line.  Prior to that, add } to
75       ;; close `\caption{'
76       (insert TeX-grcl "\\\\")
77       ;; fill the caption
78       (LaTeX-fill-paragraph)
79       ;; Insert a new line and indent
80       (LaTeX-newline)
81       (indent-according-to-mode))
82     ;; Insert suitable number of &'s, suppress line break
83     (LaTeX-item-longtable t)))
84
85 (TeX-add-style-hook
86  "longtable"
87  (lambda ()
88    (LaTeX-add-environments
89     '("longtable" LaTeX-env-longtable))
90
91    (TeX-add-symbols
92     ;; Commands to end table rows
93     '("endhead" 0)
94     '("endfirsthead" 0)
95     '("endfoot" 0)
96     '("endlastfoot" 0)
97     ;; Caption commands
98     '("caption*" 1))
99
100    ;; These parameters are set with \setlength
101    (LaTeX-add-lengths
102     "LTleft" "LTright" "LTpre" "LTpost" "LTcapwidth")
103
104    ;; This parameter is set with \setcounter
105    (LaTeX-add-counters "LTchunksize")
106
107    ;; Use the enhanced table formatting.  Append to
108    ;; `LaTeX-indent-environment-list' in order not to override custom settings.
109    (add-to-list (make-local-variable 'LaTeX-indent-environment-list)
110                 '("longtable" LaTeX-indent-tabular) t)
111
112    ;; Append longtable to `LaTeX-label-alist', in order not to override possible
113    ;; custome values.
114    (add-to-list 'LaTeX-label-alist '("longtable" . LaTeX-table-label) t)
115
116    ;; Append longtable to `LaTeX-item-list' with `LaTeX-item-longtable'
117    (add-to-list 'LaTeX-item-list '("longtable" . LaTeX-item-longtable) t)
118
119    ;; Fontification
120    (when (and (featurep 'font-latex)
121               (eq TeX-install-font-lock 'font-latex-setup))
122      ;; Actually, `\caption*{}' macro takes only one mandatory
123      ;; argument, not an optional one, the following is a workaround
124      ;; to fontify correctly also the standard `\caption[]{}' macro.
125      (font-latex-add-keywords '(("caption" "*[{"))
126                               'textual)))
127  LaTeX-dialect)
128
129 ;; `longtable.sty' has two options "errorshow" and "pausing", both for
130 ;; debugging purposes.  We ignore them both in order to make package
131 ;; loading faster in a buffer.
132 (defvar LaTeX-longtable-package-options nil
133   "Package options for the longtable package.")
134
135 ;; longtable.el ends here