Initial Commit
[packages] / xemacs-packages / auctex / style / alphanum.el
1 ;;; alphanum.el --- AUCTeX style for `alphanum.sty'
2
3 ;; Copyright (C) 2004 Free Software Foundation, Inc.
4
5 ;; Author: Frank Küster <frank@kuesterei.ch>
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 is file alphanum.el, which makes AUCTeX usable with jura.cls
29 ;; and its style file alphanum.sty.
30 ;;
31 ;; Contributed by Frank Küster <frank@kuesterei.ch>. The code for
32 ;; reftex has been written by Carsten Dominik, the maintainer of
33 ;; reftex, but all the errors are mine.
34
35 ;;; Code:
36
37
38 (defun TeX-arg-none (arg)
39   (insert " "))
40
41 (defun reftex-get-section-level-alphanum ()
42   (save-excursion                       ; preserve position
43     (save-match-data             ; preserve matching data (important!)
44       ;; Go back to the beginning of the sectioning command
45       (goto-char (match-beginning 0))
46       ;; Define an initial level number, depending on the current macro.
47       (let* ((macro (reftex-match-string 3))      ; "toc" or "sub"
48              (lev (cond ((string= macro "toc") 1) ; min level for "toc"
49                         ((string= macro "sub") 2) ; min level for "sub"
50                         (t 0)))
51              ;; Make a regular expression which will match sectioning commands
52              ;; and the levelup macro.
53              (re (concat "\\(^[^%]*\\\\levelup\\>\\)"
54                          "\\|"
55                          "\\(" reftex-section-regexp "\\)")))
56         ;; Now parse backwards for all sectioning and levelup macros,
57         ;; and keep track of the relative level changes.
58         (while (re-search-backward re nil t)
59           (cond
60            ((match-beginning 1)
61             ;; levelup matched, reduce level counter
62             (setq lev (1- lev)))
63            ((string= (reftex-match-string 4) "toc")
64             ;; a toc entry, nothing changes
65             )
66            ((string= (reftex-match-string 4) "sub")
67             ;; a sub entry, increase level counter
68             (setq lev (1+ lev)))))
69         ;; return the level
70         lev))))
71
72 (TeX-add-style-hook
73  "alphanum"
74  (lambda ()
75    (LaTeX-largest-level-set "chapter")
76    (TeX-add-symbols '("levelup" TeX-arg-none))
77    (make-local-variable 'LaTeX-section-list)
78    (LaTeX-section-list-add-locally
79     '(("part" 0)
80       ;; the levels don't make sense with alphanum, I randomly chose 0...
81       ("toc" 0)
82       ("sub" 0)) t)
83    (setq LaTeX-section-label
84          '(("part" . "part:")
85            ("toc" . "sec:")
86            ("sub" . "sec:")))
87    ;;
88    ;; ****************** reftex part ******************
89    ;; this won't work in multifile documents, but at least there is
90    ;; something.
91
92    (if (fboundp 'reftex-add-section-levels)
93        (reftex-add-section-levels
94         '(("toc" .  reftex-get-section-level-alphanum)
95           ("sub" .  reftex-get-section-level-alphanum)))))
96  LaTeX-dialect)
97
98 ;; Local Variables:
99 ;; coding: iso-8859-1
100 ;; End: