EasyPG 1.07 Released
[packages] / xemacs-packages / auctex / style / array.el
1 ;;; array.el --- AUCTeX style for `array.sty'
2
3 ;; Copyright (C) 2013, 2015 Free Software Foundation, Inc.
4
5 ;; Author: Mads Jensen <mje@inducks.org>
6 ;; Maintainer: auctex-devel@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 `array.sty'
29
30 ;;; Code:
31
32 (require 'tex)
33
34 (TeX-auto-add-type "array-newcolumntype" "LaTeX")
35
36 (defvar LaTeX-array-newcolumntype-regexp
37   '("\\\\newcolumntype{\\([^}]+\\)}"
38     1 LaTeX-auto-array-newcolumntype)
39   "Matches the argument of `\\newcolumntype' from `array'
40 package.")
41
42 (defun LaTeX-array-auto-prepare ()
43   "Clear `LaTeX-auto-array-newcolumntype' before parsing."
44   (setq LaTeX-auto-array-newcolumntype nil))
45
46 (defun LaTeX-array-auto-cleanup ()
47   "Move parsed column specification from
48 `LaTeX-auto-array-newcolumntype' to `LaTeX-array-column-letters'."
49   (when (LaTeX-array-newcolumntype-list)
50     (LaTeX-array-update-column-letters)))
51
52 (defun LaTeX-array-update-column-letters ()
53   "Update and uniquify the value of `LaTeX-array-column-letters'
54 and make it buffer local. "
55   (set (make-local-variable 'LaTeX-array-column-letters)
56        (mapconcat 'identity
57                   (TeX-delete-duplicate-strings
58                    (split-string
59                     (concat LaTeX-array-column-letters
60                             (mapconcat 'car (LaTeX-array-newcolumntype-list) ""))
61                     "" t))
62                   "")))
63
64 (add-hook 'TeX-auto-prepare-hook #'LaTeX-array-auto-prepare t)
65 (add-hook 'TeX-auto-cleanup-hook #'LaTeX-array-auto-cleanup t)
66 (add-hook 'TeX-update-style-hook #'TeX-auto-parse t)
67
68 (TeX-add-style-hook
69  "array"
70  (lambda ()
71
72    (TeX-auto-add-regexp LaTeX-array-newcolumntype-regexp)
73
74    (TeX-add-symbols
75     '("newcolumntype"
76       (TeX-arg-eval
77        (lambda ()
78          (let ((col (TeX-read-string "Column type: ")))
79            (LaTeX-add-array-newcolumntypes col)
80            (LaTeX-array-update-column-letters)
81            (format "%s" col))))
82       [ "Number of arguments" ] t)
83     '("showcols" 0)
84     '("firsthline" 0)
85     '("lasthline" 0))
86
87    ;; `array.sty' adds a couple of new lengths.  They're added here, rather than
88    ;; in the `TeX-add-symbols' block.
89    (LaTeX-add-lengths "extratabsurround" "extrarowheight")
90
91    ;; `array.sty' adds some new column specification letters.
92    (set (make-local-variable 'LaTeX-array-column-letters)
93         (concat LaTeX-array-column-letters "m" "b"))
94
95    ;; Fontification
96    (when (and (featurep 'font-latex)
97               (eq TeX-install-font-lock 'font-latex-setup))
98      (font-latex-add-keywords '(("newcolumntype" "{[{"))
99                               'function)))
100  LaTeX-dialect)
101
102 (defvar LaTeX-array-package-options nil
103   "Package options for array.")
104
105 ;; array.el ends here