summaryrefslogtreecommitdiff
path: root/elpa/auctex-13.1.3/style/csquotes.el
blob: d5714a35300a9cf7853b91407bc0ba3b55644bd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
;;; csquotes.el --- AUCTeX style for `csquotes.sty' (v5.2j)  -*- lexical-binding: t; -*-

;; Copyright (C) 2004--2022 Free Software Foundation, Inc.

;; Author: Ralf Angeli <angeli@caeruleus.net>
;; Maintainer: auctex-devel@gnu.org
;; Created: 2004-11-29
;; Keywords: tex

;; This file is part of AUCTeX.

;; AUCTeX is free software; you can redistribute it and/or modify it
;; under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.

;; AUCTeX is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;; General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with AUCTeX; see the file COPYING.  If not, write to the Free
;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
;; 02110-1301, USA.

;;; Commentary:

;; This file adds support for `csquotes.sty', version 5.2j from
;; 2019/12/06.

;;; Code:

(require 'tex)
(require 'latex)

;; Silence the compiler:
(declare-function font-latex-add-keywords
                  "font-latex"
                  (keywords class))

(defun LaTeX-csquotes-read-language (optional &optional prompt)
  "Read and return a language for csquotes macros.
If OPTIONAL is non-nil, indicate it in minibuffer while reading
user input.  PROMPT replaces the standard one \"Language\".  This
function checks if the functions `LaTeX-babel-active-languages'
or `LaTeX-polyglossia-active-languages' are bound and use them to
retrieve the active languages.  If none available, user is
requested to enter a language."
  (cond ((and (fboundp 'LaTeX-babel-active-languages)
              (LaTeX-babel-active-languages))
         (completing-read
          (TeX-argument-prompt optional prompt "Language")
          (LaTeX-babel-active-languages)))
        ((and (fboundp 'LaTeX-polyglossia-active-languages)
              (LaTeX-polyglossia-active-languages))
         (completing-read
          (TeX-argument-prompt optional prompt "Language")
          (LaTeX-polyglossia-active-languages)))
        (t
         (TeX-read-string
          (TeX-argument-prompt optional prompt "Language")))))

(defun LaTeX-arg-csquotes-language (optional &optional prompt)
  "Insert a language for csquotes macros.
If OPTIONAL is non-nil, insert the language in square brackets.
PROMPT replaces the standard one \"Language\"."
  (TeX-argument-insert
   (LaTeX-csquotes-read-language optional prompt)
   optional))

(TeX-add-style-hook
 "csquotes"
 (lambda ()
   (let ((quote-style-variant-list '(("american")   ("brazilian")
                                     ("british")    ("german")
                                     ("guillemets") ("guillemets*")
                                     ("mexican")    ("portuguese")
                                     ("quotes")     ("quotes*")
                                     ("spanish")    ("swiss")))
         (quote-style-name-list '(("austrian")   ("croatian") ("czech")
                                  ("danish")     ("dutch")    ("english")
                                  ("finnish")    ("french")   ("german")
                                  ("greek")      ("italian")  ("norwegian")
                                  ("portuguese") ("russian")  ("serbian")
                                  ("spanish")    ("swedish"))))
     ;; New symbols
     (TeX-add-symbols

      ;; 3.1 Quoting Regular Text
      '("enquote" 1)
      '("enquote*" 1)

      ;; 3.2 Quoting Text in a Foreign Language
      '("foreignquote"  LaTeX-arg-csquotes-language 1)
      '("foreignquote*" LaTeX-arg-csquotes-language 1)
      '("hyphenquote"   LaTeX-arg-csquotes-language 1)
      '("hyphenquote*"  LaTeX-arg-csquotes-language 1)

      ;; 3.3 Formal Quoting of Regular Text
      '("textquote"  ["Citation"] ["Punctuation"] t)
      '("textquote*" ["Citation"] ["Punctuation"] t)

      ;; 3.4 Formal Quoting of Text in a Foreign Language
      '("foreigntextquote"
        LaTeX-arg-csquotes-language ["Citation"] ["Punctuation"] t)
      '("foreigntextquote*"
        LaTeX-arg-csquotes-language ["Citation"] ["Punctuation"] t)
      '("hyphentextquote"
        LaTeX-arg-csquotes-language ["Citation"] ["Punctuation"] t)
      '("hyphentextquote*"
        LaTeX-arg-csquotes-language ["Citation"] ["Punctuation"] t)

      ;; 3.5 Block Quoting of Regular Text
      '("blockquote" ["Citation"] ["Punctuation"] t)

      ;; 3.6 Block Quoting of Text in a Foreign Language
      '("foreignblockquote"
        LaTeX-arg-csquotes-language ["Citation"] ["Punctuation"] t)
      '("hyphenblockquote"
        LaTeX-arg-csquotes-language ["Citation"] ["Punctuation"] t)
      '("hybridblockquote"
        LaTeX-arg-csquotes-language ["Citation"] ["Punctuation"] t)

      ;; 3.7 Selecting Quote Styles
      `("setquotestyle"
        [ (TeX-arg-eval completing-read "Quote style variant: "
                        ',quote-style-variant-list) ]
        (TeX-arg-eval completing-read "Quote style name or alias: "
                      ',quote-style-name-list))
      "setquotestyle*"

      ;; 4.1 Quoting Regular Text
      '("MakeInnerQuote" "Character")
      '("MakeOuterQuote" "Character")
      '("MakeAutoQuote"  "Opening quotation mark" "Closing quotation mark")
      '("MakeAutoQuote*" "Opening quotation mark" "Closing quotation mark")

      ;; 4.2 Quoting Text in a Foreign Language
      '("MakeForeignQuote" LaTeX-arg-csquotes-language
        "Opening quotation mark" "Closing quotation mark")
      '("MakeForeignQuote*" LaTeX-arg-csquotes-language
        "Opening quotation mark" "Closing quotation mark")

      '("MakeHyphenQuote" LaTeX-arg-csquotes-language
        "Opening quotation mark" "Closing quotation mark")
      '("MakeHyphenQuote" LaTeX-arg-csquotes-language
        "Opening quotation mark" "Closing quotation mark")

      ;; 4.3 Block Quoting of Regular Text
      '("MakeBlockQuote" "Opening quotation mark" "Delimiter for citation"
        "Closing quotation mark")

      ;; 4.4 Block Quoting of Text in a Foreign Language
      '("MakeForeignBlockQuote" LaTeX-arg-csquotes-language
        "Opening quotation mark" "Delimiter for citation" "Closing quotation mark")
      '("MakeHyphenBlockQuote" LaTeX-arg-csquotes-language
        "Opening quotation mark" "Delimiter for citation" "Closing quotation mark")
      '("MakeHybridBlockQuote" LaTeX-arg-csquotes-language
        "Opening quotation mark" "Delimiter for citation" "Closing quotation mark")

      ;; 4.5 Controlling Active Quotes
      "EnableQuotes"
      "DisableQuotes"
      "VerbatimQuotes"
      "DeleteQuotes"

      ;; 5.1 Formal Quoting of Regular Text
      '("textcquote"  ["Pre-note"] ["Post-note"] "Key" ["Punctuation"] t)
      '("textcquote*" ["Pre-note"] ["Post-note"] "Key" ["Punctuation"] t)

      ;; 5.2 Formal Quoting of Text in a Foreign Language
      '("foreigntextcquote" LaTeX-arg-csquotes-language
        ["Pre-note"] ["Post-note"] "Key" ["Punctuation"] t)
      '("foreigntextcquote*" LaTeX-arg-csquotes-language
        ["Pre-note"] ["Post-note"] "Key" ["Punctuation"] t)
      '("hyphentextcquote" LaTeX-arg-csquotes-language
        ["Pre-note"] ["Post-note"] "Key" ["Punctuation"] t)
      '("hyphentextcquote*" LaTeX-arg-csquotes-language
        ["Pre-note"] ["Post-note"] "Key" ["Punctuation"] t)

      ;; 5.3 Block Quoting of Regular Text
      '("blockcquote" ["Pre-note"] ["Post-note"] "Key" ["Punctuation"] t)

      ;; 5.4 Block Quoting of Text in a Foreign Language
      '("foreignblockcquote" LaTeX-arg-csquotes-language
        ["Pre-note"] ["Post-note"] "Key" ["Punctuation"] t)
      '("hyphenblockcquote" LaTeX-arg-csquotes-language
        ["Pre-note"] ["Post-note"] "Key" ["Punctuation"] t)
      '("hybridblockcquote" LaTeX-arg-csquotes-language
        ["Pre-note"] ["Post-note"] "Key" ["Punctuation"] t)

      ;; 7 Auxiliary Commands
      '("textelp" 1)
      '("textelp*" 1)
      '("textins" 1)
      '("textins*" 1)
      '("textdel" 1)

      ;; 8.1 Defining Quote Styles
      `("DeclareQuoteStyle"
        [ (TeX-arg-eval completing-read "Quote style variant: "
                        ',quote-style-variant-list) ]
        (TeX-arg-eval completing-read "Quote style name: "
                      ',quote-style-name-list)
        ["Outer quote initialization"] ["Inner quote initialization"]
        "Opening outer quotation mark" ["Middle outer quotation mark"]
        "Closing outer quotation mark" ["Kerning between adjoining marks"]
        "Opening inner quotation mark" ["Middle inner quotation mark"]
        "Closing inner quotation mark")
      `("DeclareQuoteAlias"
        [ (TeX-arg-eval completing-read "Quote style variant: "
                        ',quote-style-variant-list) ]
        (TeX-arg-eval completing-read "Quote style name: "
                      ',quote-style-name-list)
        "Alias name")
      '("DeclareQuoteOption" 1)
      '("ExecuteQuoteOptions" 1)
      '("DeclarePlainStyle" "Opening outer quotation mark"
        "Closing outer quotation mark" "Opening inner quotation mark"
        "Closing inner quotation mark")
      '("SetBlockThreshold" "Number of lines")
      '("SetBlockEnvironment" "Environment")
      '("SetCiteCommand" "Command")

      ;; 8.7 Hooks for Quotations and Citations
      "mkcitation"
      "mkccitation"
      "mktextquote"
      "mkblockquote"
      "mkbegdispquote"
      "mkenddispquote"

      ;; 8.8 Additional Tests in Quotation Hooks
      '("ifpunctmark" "Character" 2)
      '("ifpunct" 2)
      '("ifterm" 2)
      '("iftextpunctmark" 4)
      '("iftextpunct" 3)
      '("iftextterm" 3)
      '("ifblockquote" 2)
      '("ifblank" 3)
      "unspace"

      ;; 8.9 Configuring Punctuation Look-Ahead
      '("DeclareAutoPunct" "Characters"))

     ;; Don't increase indentation at various \if* macros:
     (let ((exceptions '("ifpunctmark"
                         "ifpunct"
                         "ifterm"
                         "iftextpunctmark"
                         "iftextpunct"
                         "iftextterm"
                         "ifblockquote"
                         "ifblank")))
       (dolist (elt exceptions)
         (add-to-list 'LaTeX-indent-begin-exceptions-list elt t))
       (LaTeX-indent-commands-regexp-make))

     ;; New environments
     (LaTeX-add-environments

      ;; 6.1 Basic Display Environments
      '("displayquote" LaTeX-env-args
        ["Citation"] ["Punctuation"])

      '("foreigndisplayquote" LaTeX-env-args
        LaTeX-arg-csquotes-language ["Citation"] ["Punctuation"])

      '("hyphendisplayquote" LaTeX-env-args
        LaTeX-arg-csquotes-language ["Citation"] ["Punctuation"])

      ;; 6.2 Integrated Display Environments
      '("displaycquote" LaTeX-env-args
        ["Pre-note"] ["Post-note"] "Key" ["Punctuation"])

      '("foreigndisplaycquote" LaTeX-env-args
        LaTeX-arg-csquotes-language["Pre-note"] ["Post-note"] "Key" ["Punctuation"])

      '("hyphendisplaycquote" LaTeX-env-args
        LaTeX-arg-csquotes-language["Pre-note"] ["Post-note"] "Key" ["Punctuation"]))

     ;; Quotation marks
     (when (and (> (length LaTeX-csquotes-open-quote) 0)
                (> (length LaTeX-csquotes-close-quote) 0))
       (setq TeX-quote-language
             `(override ,LaTeX-csquotes-open-quote ,LaTeX-csquotes-close-quote
                        ,LaTeX-csquotes-quote-after-quote)))
     ;; Fontification
     (when (and (featurep 'font-latex)
                (eq TeX-install-font-lock 'font-latex-setup))
       (font-latex-add-keywords '(("EnableQuotes"   "")
                                  ("DisableQuotes"  "")
                                  ("VerbatimQuotes" "")
                                  ("DeleteQuotes"   ""))
                                'function)
       (font-latex-add-keywords '(("enquote"            "*{")
                                  ("foreignquote"       "*{{")
                                  ("hyphenquote"        "*{{")
                                  ("textquote"          "*[[{")
                                  ("foreigntextquote"   "*{[[{")
                                  ("hyphentextquote"    "*{[[{")
                                  ("blockquote"         "[[{")
                                  ("foreignblockquote"  "{[[{")
                                  ("hyphenblockquote"   "{[[{")
                                  ("hybridblockquote"   "{[[{")
                                  ("textcquote"         "*[[{[{")
                                  ("foreigntextcquote"  "*{[[{[{")
                                  ("hyphentextcquote"   "*{[[{[{")
                                  ("blockcquote"        "[[{[{")
                                  ("foreignblockcquote" "{[[{[{")
                                  ("hyphenblockcquote"  "{[[{[{")
                                  ("hybridblockcquote"  "{[[{[{"))
                                'textual)
       (font-latex-add-keywords '(("setquotestyle"         "[{")
                                  ("MakeOuterQuote"        "{")
                                  ("MakeInnerQuote"        "{")
                                  ("MakeAutoQuote"         "*{{")
                                  ("MakeForeignQuote"      "*{{{")
                                  ("MakeHyphenQuote"       "*{{{")
                                  ("MakeBlockQuote"        "{{{")
                                  ("MakeForeignBlockQuote" "{{{{")
                                  ("MakeHyphenBlockQuote"  "{{{{")
                                  ("DeclareQuoteStyle"     "[{[[{[{[{[{")
                                  ("DeclareQuoteAlias"     "[{{")
                                  ("DeclareQuoteOption"    "{")
                                  ("DeclarePlainStyle"     "{{{{")
                                  ("SetBlockThreshold"     "{")
                                  ("SetBlockEnvironment"   "{")
                                  ("SetCiteCommand"        "{"))
                                'variable))))
 TeX-dialect)

(defun LaTeX-csquotes-package-options ()
  "Prompt for package options for the csquotes package."
  (TeX-read-key-val t '(("strict"     ("true" "false"))
                        ("style"      ("american"
                                       "australian"
                                       "austrian"
                                       "brazil"
                                       "brazilian"
                                       "british"
                                       "canadian"
                                       "croatian"
                                       "czech"
                                       "danish"
                                       "dutch"
                                       "english"
                                       "finnish"
                                       "french"
                                       "german"
                                       "greek"
                                       "italian"
                                       "mexican"
                                       "naustrian"
                                       "newzealand"
                                       "ngerman"
                                       "norsk"
                                       "norwegian"
                                       "nswissgerman"
                                       "nynorsk"
                                       "portuges"
                                       "portuguese"
                                       "russian"
                                       "serbian"
                                       "spanish"
                                       "swedish"
                                       "swiss"
                                       "swissgerman"
                                       "UKenglish"
                                       "USenglish"))
                        ("autostyle"  ("true" "false" "try" "once" "tryonce"))
                        ("austrian"   ("quotes" "guillemets"))
                        ("croatian"   ("quotes" "guillemets" "guillemets*"))
                        ("czech"      ("quotes" "guillemets"))
                        ("danish"     ("quotes" "guillemets" "topquotes"))
                        ("english"    ("american" "british"))
                        ("estonian")
                        ("french"     ("quotes" "quotes*" "guillemets" "guillemets*"))
                        ("galician"   ("quotes" "guillemets"))
                        ("german"     ("quotes" "guillemets" "swiss"))
                        ("hungarian")
                        ("italian"    ("guillemets" "quotes"))
                        ("latvian")
                        ("norwegian"  ("guillemets" "quotes"))
                        ("polish"     ("guillemets" "guillemets*"))
                        ("portuguese" ("portuguese" "brazilian"))
                        ("serbian"    ("quotes" "guillemets" "german"))
                        ("spanish"    ("spanish" "mexican"))
                        ("swedish"    ("quotes" "guillemets" "guillemets*"))
                        ("maxlevel")
                        ("autopunct"     ("true" "false"))
                        ("threshold")
                        ("thresholdtype" ("lines" "words"))
                        ("parthreshold"  ("true" "false"))
                        ("splitcomp"     ("true" "false"))
                        ("csdisplay"     ("true" "false"))
                        ("debug"         ("true" "false"))
                        ;; "babel" key is deprecated, replaced by "autostyle":
                        ;; ("babel" ("true" "false" "try" "once" "tryonce"))
                        ("version"       ("4.4" "3.6" "3.0")))))

;;; csquotes.el ends here