Initial Commit
[packages] / xemacs-packages / auctex / style / csquotes.el
1 ;;; csquotes.el --- AUCTeX style for `csquotes.sty'
2
3 ;; Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
4
5 ;; Author: Ralf Angeli <angeli@caeruleus.net>
6 ;; Maintainer: auctex-devel@gnu.org
7 ;; Created: 2004-11-29
8 ;; Keywords: tex
9
10 ;; This file is part of AUCTeX.
11
12 ;; AUCTeX is free software; you can redistribute it and/or modify it
13 ;; under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
15 ;; any later version.
16
17 ;; AUCTeX is distributed in the hope that it will be useful, but
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20 ;; General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with AUCTeX; see the file COPYING.  If not, write to the Free
24 ;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25 ;; 02110-1301, USA.
26
27 ;;; Commentary:
28
29 ;; This file adds support for `csquotes.sty', version 3.7.
30
31
32 ;;; Code:
33
34 ;; FIXME: It would be nice to be able to dump this function in favor
35 ;; of a generalized handling of additional arguments for environments
36 ;; specified via `LaTeX-add-environments'.  `TeX-parse-arguments' and
37 ;; friends would be the functions to be used for that, but those
38 ;; functions currently insert text directly into the buffer.  There
39 ;; would either have to be a way of preventing this and letting them
40 ;; return a string, or the insertion could happen in a temporary buffer
41 ;; and the buffer content be returned.
42 (defun LaTeX-csquotes-insert-environment (env &rest args)
43   "Insert environment ENV considering optional arguments ARGS.
44
45 This is basically a variant of `LaTeX-environment-menu'
46 specialized for csquotes.el.  ARGS can be made up of strings and
47 vectors containing single strings.  Plain strings will be used as
48 prompts for mandatory arguments and strings in vectors as prompts
49 for optional arguments of the environment to be inserted.
50
51 That means, in contrast to `LaTeX-environment-menu' it supports
52 the insertion of optional arguments."
53   (let (env-extra prompt optional user-input)
54     (dolist (elt args)
55       (if (vectorp elt)
56           (setq prompt (aref elt 0)
57                 optional t)
58         (setq prompt elt
59               optional nil))
60       (setq user-input (read-string (TeX-argument-prompt optional prompt nil)))
61       (unless (and optional (zerop (length user-input)))
62         (setq env-extra (concat env-extra
63                                 (if optional LaTeX-optop TeX-grop)
64                                 user-input
65                                 (if optional LaTeX-optcl TeX-grcl)))))
66     (LaTeX-insert-environment env env-extra)))
67
68 (TeX-add-style-hook
69  "csquotes"
70  (lambda ()
71    (let ((quote-style-variant-list '(("quotes") ("guillemets") ("american")
72                                      ("british") ("oldstyle") ("imprimerie")
73                                      ("swiss")))
74          (quote-style-name-list '(("danish") ("dutch") ("english") ("finnish")
75                                   ("french") ("german") ("italian")
76                                   ("norwegian") ("swedish"))))
77      ;; New symbols
78      (TeX-add-symbols
79       '("enquote" 1)
80       '("enquote*" 1)
81       '("foreignquote" 2)
82       '("foreignquote*" 2)
83       '("hyphenquote" 2)
84       '("hyphenquote*" 2)
85       '("textquote" ["Citation"] ["Punctuation"] t)
86       '("textquote*" ["Citation"] ["Punctuation"] t)
87       '("foreigntextquote" "Language" ["Citation"] ["Punctuation"] t)
88       '("foreigntextquote*" "Language" ["Citation"] ["Punctuation"] t)
89       '("hyphentextquote" "Language" ["Citation"] ["Punctuation"] t)
90       '("hyphentextquote*" "Language" ["Citation"] ["Punctuation"] t)
91       '("blockquote" ["Citation"] ["Punctuation"] t)
92       '("foreignblockquote" "Language" ["Citation"] ["Punctuation"] t)
93       '("hyphenblockquote" "Language" ["Citation"] ["Punctuation"] t)
94       `("setquotestyle"
95         [ (TeX-arg-eval completing-read "Quote style variant: "
96                         ',quote-style-variant-list) ]
97         (TeX-arg-eval completing-read "Quote style name or alias: "
98                       ',quote-style-name-list))
99       "setquotestyle*"
100       '("MakeInnerQuote" "Character")
101       '("MakeOuterQuote" "Character")
102       '("MakeAutoQuote" "Opening quotation mark" "Closing quotation mark")
103       '("MakeAutoQuote*" "Opening quotation mark" "Closing quotation mark")
104       '("MakeForeignQuote" "Babel's language name"
105         "Opening quotation mark" "Closing quotation mark")
106       '("MakeForeignQuote*" "Babel's language name"
107         "Opening quotation mark" "Closing quotation mark")
108       '("MakeHyphenQuote" "Babel's language name"
109         "Opening quotation mark" "Closing quotation mark")
110       '("MakeHyphenQuote" "Babel's language name"
111         "Opening quotation mark" "Closing quotation mark")
112       '("MakeBlockQuote" "Opening quotation mark" "Delimiter for citation"
113         "Closing quotation mark")
114       '("MakeForeignBlockQuote" "Language" "Opening quotation mark"
115         "Delimiter for citation" "Closing quotation mark")
116       '("MakeHyphenBlockQuote" "Language" "Opening quotation mark"
117         "Delimiter for citation" "Closing quotation mark")
118       "EnableQuotes"
119       "DisableQuotes"
120       "VerbatimQuotes"
121       "DeleteQuotes"
122       '("textcquote" ["Pre-note"] ["Post-note"] "Key" ["Punctuation"] t)
123       '("textcquote*" ["Pre-note"] ["Post-note"] "Key" ["Punctuation"] t)
124       '("foreigntextcquote" "Language" ["Pre-note"] ["Post-note"] "Key"
125         ["Punctuation"] t)
126       '("foreigntextcquote*" "Language" ["Pre-note"] ["Post-note"] "Key"
127         ["Punctuation"] t)
128       '("hyphentextcquote" "Language" ["Pre-note"] ["Post-note"] "Key"
129         ["Punctuation"] t)
130       '("hyphentextcquote*" "Language" ["Pre-note"] ["Post-note"] "Key"
131         ["Punctuation"] t)
132       '("blockcquote" ["Pre-note"] ["Post-note"] "Key" ["Punctuation"] t)
133       '("foreignblockcquote" "Language" ["Pre-note"] ["Post-note"] "Key"
134         ["Punctuation"] t)
135       '("hyphenblockcquote" "Language" ["Pre-note"] ["Post-note"] "Key"
136         ["Punctuation"] t)
137       `("DeclareQuoteStyle"
138         [ (TeX-arg-eval completing-read "Quote style variant: "
139                         ',quote-style-variant-list) ]
140         (TeX-arg-eval completing-read "Quote style name: "
141                       ',quote-style-name-list)
142         ["Outer quote initialization"] ["Inner quote initialization"]
143         "Opening outer quotation mark" ["Middle outer quotation mark"]
144         "Closing outer quotation mark" ["Kerning between adjoining marks"]
145         "Opening inner quotation mark" ["Middle inner quotation mark"]
146         "Closing inner quotation mark")
147       `("DeclareQuoteAlias"
148         [ (TeX-arg-eval completing-read "Quote style variant: "
149                         ',quote-style-variant-list) ]
150         (TeX-arg-eval completing-read "Quote style name: "
151                       ',quote-style-name-list)
152         "Alias name")
153     '("DeclareQuoteOption" 1)
154     '("ExecuteQuoteOptions" 1)
155     '("DeclarePlainStyle" "Opening outer quotation mark"
156       "Closing outer quotation mark" "Opening inner quotation mark"
157       "Closing inner quotation mark")
158     '("SetBlockThreshold" "Number of lines")
159     '("SetBlockEnvironment" "Environment")
160     '("SetCiteCommand" "Command")
161     "mkcitation"
162     "mkccitation"
163     "mkpreblockpunct"
164     "mkmidblockpunct"
165     "mkfinblockpunct"
166     "mkpretextpunct"
167     "mkmidtextpunct"
168     "mkfintextpunct"
169     "mkpredisppunct"
170     "mkmiddisppunct"
171     "mkfindisppunct"
172     '("ifblockquote" 2)
173     '("ifquotepunct" 2)
174     '("ifquoteterm" 2)
175     '("ifquoteperiod" 2)
176     '("ifquotecomma" 2)
177     '("ifquotesemicolon" 2)
178     '("ifquotecolon" 2)
179     '("ifquoteexclam" 2)
180     '("ifquotequestion" 2)
181     '("ifstringblank" 2)
182     '("BlockquoteDisable" 1))
183    ;; New environments
184    (LaTeX-add-environments
185     "quoteblock"
186     "quotetext"
187     '("displayquote" LaTeX-csquotes-insert-environment ["Citation"]
188       ["Punctuation"])
189     '("foreigndisplayquote" LaTeX-csquotes-insert-environment "Language"
190       ["Citation"] ["Punctuation"])
191     '("hyphendisplayquote" LaTeX-csquotes-insert-environment "Language"
192       ["Citation"] ["Punctuation"])
193     '("displaycquote" LaTeX-csquotes-insert-environment
194       ["Pre-note"] ["Post-note"] "Key" ["Punctuation"])
195     '("foreigndisplaycquote" LaTeX-csquotes-insert-environment
196       "Language" ["Pre-note"] ["Post-note"] "Key" ["Punctuation"])
197     '("hyphendisplaycquote" LaTeX-csquotes-insert-environment
198       "Language" ["Pre-note"] ["Post-note"] "Key" ["Punctuation"]))
199    ;; Quotation marks
200    (when (and (> (length LaTeX-csquotes-open-quote) 0)
201               (> (length LaTeX-csquotes-close-quote) 0))
202      (setq TeX-quote-language
203            `(override ,LaTeX-csquotes-open-quote ,LaTeX-csquotes-close-quote
204                       ,LaTeX-csquotes-quote-after-quote)))
205    ;; Fontification
206    (when (and (featurep 'font-latex)
207               (eq TeX-install-font-lock 'font-latex-setup))
208      (font-latex-add-keywords '(("DisableQuotes" "")
209                                 ("RestoreQuotes" ""))
210                               'function)
211      (font-latex-add-keywords '(("enquote" "*{")
212                                 ("foreignquote" "*{{")
213                                 ("hyphenquote" "*{{")
214                                 ("textcquote" "*[[{[{")
215                                 ("foreigntextcquote" "*{[[{[{")
216                                 ("hyphentextcquote" "*{[[{[{")
217                                 ("textquote" "*[[{")
218                                 ("foreigntextquote" "*{[[{")
219                                 ("hyphentextquote" "*{[[{")
220                                 ("blockquote" "[[{")
221                                 ("foreignblockquote" "{[[{")
222                                 ("hyphenblockquote" "{[[{")
223                                 ("blockcquote" "[[{[{")
224                                 ("foreignblockcquote" "{[[{[{")
225                                 ("hyphenblockcquote" "{[[{[{"))
226                               'textual)
227      (font-latex-add-keywords '(("setquotestyle" "[{")
228                                 ("MakeOuterQuote" "{")
229                                 ("MakeInnerQuote" "{")
230                                 ("MakeAutoQuote" "*{{")
231                                 ("MakeForeignQuote" "*{{{")
232                                 ("MakeHyphenQuote" "*{{{")
233                                 ("MakeBlockQuote" "{{{")
234                                 ("MakeForeignBlockQuote" "{{{{")
235                                 ("MakeHyphenBlockQuote" "{{{{")
236                                 ("DeclareQuoteStyle" "[{[[{[{[{[{")
237                                 ("DeclareQuoteAlias" "[{{")
238                                 ("DeclareQuoteOption" "{")
239                                 ("DeclarePlainStyle" "{{{{")
240                                 ("SetBlockThreshold" "{")
241                                 ("SetBlockEnvironment" "{")
242                                 ("SetCiteCommand" "{"))
243                               'variable))))
244  LaTeX-dialect)
245
246 ;;; csquotes.el ends here