Initial Commit
[packages] / xemacs-packages / auctex / style / fancyvrb.el
1 ;;; fancyvrb.el --- AUCTeX style for `fancyvrb.sty' version 2.8.
2
3 ;; Copyright (C) 2013 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 `fancyvrb.sty' version 2.8.
29
30 ;;; Code:
31
32 (defvar LaTeX-fancyvrb-macro-regexp
33   (concat "\\\\\\(?:Re\\|\\)CustomVerbatimCommand"
34           "[ \t\n\r]*{?[ \t\n\r]*\\\\\\([A-Za-z]+\\)[ \t\n\r]*}?")
35   "Matches macros by fancyvrb package.")
36
37 (defvar LaTeX-fancyvrb-environment-regexp
38   (concat "\\\\\\(?:Define\\|Custom\\|Recustom\\)VerbatimEnvironment"
39           "[ \t\n\r]*{[ \t\n\r]*\\([A-Za-z]+\\)[ \t\n\r]*}")
40   "Matches environments by fancyvrb package.")
41
42 (defvar LaTeX-fancyvrb-key-val-options
43   '(("commentchar")
44     ("gobble")
45     ("formatcom")
46     ("fontfamily" ("tt" "courier" "helvetica"))
47     ("fontsize")
48     ("fontshape")
49     ("fontseries")
50     ("frame" ("none" "leftline" "topline" "bottomline" "lines" "single"))
51     ("framerule")
52     ("framesep")
53     ("rulecolor")
54     ("fillcolor")
55     ("label")
56     ("labelposition" ("none" "topline" "bottomline" "all"))
57     ("numbers" ("none" "left" "right"))
58     ("numbersep")
59     ("firstnumber" ("auto" "last" "integer"))
60     ("stepnumber")
61     ("numberblanklines" ("true" "false"))
62     ("firstline")
63     ("lastline")
64     ("showspaces" ("true" "false"))
65     ("showtabs" ("true" "false"))
66     ("obeytabs" ("true" "false"))
67     ("tabsize")
68     ("baselinestretch" ("auto" "dimension"))
69     ("commandchars")
70     ("xleftmargin")
71     ("xrightmargin")
72     ("resetmargins" ("true" "false"))
73     ("hfuzz")
74     ("samepage" ("true" "false"))
75     ("codes")
76     ("defineactive")
77     ;; Actually, the following options are used only by the `BVerbatim'
78     ;; environment.
79     ("boxwidth" ("auto" "dimension"))
80     ("baseline" ("b" "c" "t")))
81   "Key=value options for fancyvrb macros and environments.")
82
83 (TeX-add-style-hook
84  "fancyvrb"
85  (lambda ()
86    (TeX-auto-add-regexp `(,LaTeX-fancyvrb-macro-regexp 1 TeX-auto-symbol))
87    (TeX-auto-add-regexp
88     `(,LaTeX-fancyvrb-environment-regexp 1 LaTeX-auto-environment))
89    (TeX-run-style-hooks
90     "keyval")
91    (TeX-add-symbols
92     ;;; Verbatim material in footnotes
93     "VerbatimFootnotes"
94     ;;; Improved verbatim commands
95     '("Verb" [TeX-arg-key-val LaTeX-fancyvrb-key-val-options] TeX-arg-verb)
96     "DefineShortVerb"
97     "UndefineShortVerb"
98     ;;; Verbatim environments
99     '("fvset" (TeX-arg-key-val LaTeX-fancyvrb-key-val-options))
100     ;; Changing individual line formatting
101     "FancyVerbFormatLine"
102     ;; Line numbering
103     "theFancyVerbLine"
104     ;; Selection of lines to print
105     "FancyVerbStartString"
106     "FancyVerbStopString"
107     ;; Personalized environments
108     '("CustomVerbatimEnvironment"
109       (TeX-arg-define-environment "New verbatim environment")
110       (TeX-arg-environment "Basend on environment")
111       (TeX-arg-key-val LaTeX-fancyvrb-key-val-options))
112     '("RecustomVerbatimEnvironment"
113       (TeX-arg-environment "New verbatim environment")
114       (TeX-arg-environment "Basend on environment")
115       (TeX-arg-key-val LaTeX-fancyvrb-key-val-options))
116     '("DefineVerbatimEnvironment"
117       (TeX-arg-define-environment "New verbatim environment")
118       (TeX-arg-environment "Basend on environment")
119       (TeX-arg-key-val LaTeX-fancyvrb-key-val-options))
120     '("CustomVerbatimCommand" (TeX-arg-define-macro "New verbatim macro: ")
121       (TeX-arg-eval completing-read "Based on macro: " (TeX-symbol-list))
122       (TeX-arg-key-val LaTeX-fancyvrb-key-val-options))
123     '("RecustomVerbatimCommand" (TeX-arg-macro "New verbatim macro: ")
124       (TeX-arg-eval completing-read "Based on macro: " (TeX-symbol-list))
125       (TeX-arg-key-val LaTeX-fancyvrb-key-val-options))
126     ;;; Saving and restoring verbatim text and environments
127     "SaveVerb"
128     "UseVerb"
129     "SaveVerbatim"
130     "UseVerbatim"
131     "LUseVerbatim"
132     "BUseVerbatim"
133     ;;; Writing and reading verbatim files
134     '("VerbatimInput" [TeX-arg-key-val LaTeX-fancyvrb-key-val-options]
135       (TeX-arg-file))
136     '("BVerbatimInput" [TeX-arg-key-val LaTeX-fancyvrb-key-val-options]
137       (TeX-arg-file))
138     '("LVerbatimInput" [TeX-arg-key-val LaTeX-fancyvrb-key-val-options]
139       (TeX-arg-file)))
140    (LaTeX-add-environments
141     '("Verbatim" LaTeX-env-args
142       [TeX-arg-key-val LaTeX-fancyvrb-key-val-options])
143     '("BVerbatim" LaTeX-env-args
144       [TeX-arg-key-val LaTeX-fancyvrb-key-val-options])
145     '("LVerbatim" LaTeX-env-args
146       [TeX-arg-key-val LaTeX-fancyvrb-key-val-options])
147     '("SaveVerbatim" LaTeX-env-args
148       [TeX-arg-key-val LaTeX-fancyvrb-key-val-options])
149     '("VerbatimOut"
150       (lambda (env)
151         (let ((options (TeX-read-key-val t LaTeX-fancyvrb-key-val-options))
152               (file (TeX-read-string "Output file: ")))
153           (LaTeX-insert-environment
154            env
155            (concat (unless (zerop (length options))
156                      (concat LaTeX-optop options LaTeX-optcl))
157                    (concat TeX-grop file TeX-grcl)))))))
158    (LaTeX-add-counters
159     "FancyVerbLine")
160
161    ;; Filling
162    (set (make-local-variable 'LaTeX-verbatim-regexp)
163          (concat
164           LaTeX-verbatim-regexp
165           "\\|Verbatim\\|BVerbatim\\|LVerbatim\\|SaveVerbatim\\|VerbatimOut"))
166    (add-to-list 'LaTeX-verbatim-environments-local "Verbatim")
167    (add-to-list 'LaTeX-verbatim-environments-local "BVerbatim")
168    (add-to-list 'LaTeX-verbatim-environments-local "LVerbatim")
169    (add-to-list 'LaTeX-verbatim-environments-local "SaveVerbatim")
170    (add-to-list 'LaTeX-verbatim-environments-local "VerbatimOut")
171    (make-local-variable 'LaTeX-indent-environment-list)
172    (add-to-list 'LaTeX-indent-environment-list '("Verbatim" current-indentation))
173    (add-to-list 'LaTeX-indent-environment-list '("BVerbatim" current-indentation))
174    (add-to-list 'LaTeX-indent-environment-list '("LVerbatim" current-indentation))
175    (add-to-list 'LaTeX-indent-environment-list '("SaveVerbatim" current-indentation))
176    (add-to-list 'LaTeX-indent-environment-list '("VerbatimOut" current-indentation))
177    (add-to-list 'LaTeX-verbatim-macros-with-delims-local "Verb")
178    (add-to-list 'LaTeX-verbatim-macros-with-braces-local "Verb")
179
180    ;; Fontification
181    (when (and (fboundp 'font-latex-add-keywords)
182               (fboundp 'font-latex-set-syntactic-keywords)
183               (eq TeX-install-font-lock 'font-latex-setup))
184      (font-latex-add-keywords '(("DefineVerbatimEnvironment" "{{{")
185                                 ("CustomVerbatimEnvironment" "{{{")
186                                 ("RecustomVerbatimEnvironment" "{{{"))
187                               'function)
188      (font-latex-add-keywords '(("VerbatimInput" "[{")
189                                 ("BVerbatimInput" "[{")
190                                 ("LVerbatimInput" "[{"))
191                               'reference)
192      (font-latex-add-keywords '(("Verb" "[")) ; The second argument should
193                                               ; actually be verbatim.
194                               'textual)
195      (font-latex-add-keywords '(("fvset" "{")) 'variable)
196      ;; For syntactic fontification, e.g. verbatim constructs.
197      (font-latex-set-syntactic-keywords)
198      ;; Tell font-lock about the update.
199      (setq font-lock-set-defaults nil)
200      (font-lock-set-defaults)))
201  LaTeX-dialect)
202
203 (defvar LaTeX-fancyvrb-package-options nil
204   "Package options for the fancyvrb package.")
205
206 ;;; fancyvrb.el ends here