Initial Commit
[packages] / xemacs-packages / auctex / style / acro.el
1 ;;; acro.el --- AUCTeX style for `acro.sty' version 1.2a.
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 `acro.sty' version 1.2a.
29
30 ;;; Code:
31
32 (defvar LaTeX-acro-package-options-list
33   '(;; General Options
34     ("version" ("0" "1"))
35     ("single" ("true" "false"))
36     ("hyperref" ("true" "false"))
37     ("record-pages" ("true" "false"))
38     ("only-used" ("true" "false"))
39     ("mark-as-used" ("first" "any"))
40     ("macros" ("true" "false"))
41     ("xspace" ("true" "false"))
42     ("strict" ("true" "false"))
43     ("sort" ("true" "false"))
44     ("cite" ("all" "first" "none"))
45     ("cite-cmd")
46     ("cite-space")
47     ("index-cmd")
48     ("accsupp" ("true" "false"))
49     ("uc-cmd")
50     ;; Options Regarding Acronyms
51     ("short-format")
52     ("long-format")
53     ("first-long-format")
54     ("list-short-format")
55     ("list-long-format")
56     ("extra-format")
57     ("first-style" ("default" "plain" "empty" "square" "short" "reversed"
58                     "plain-reversed" "footnote" "sidenote"))
59     ("extra-style" ("default" "plain" "comma" "paren" "bracket"))
60     ("plural-ending")
61     ;; Options Regarding the List
62     ("page-ref" ("none" "plain" "comma" "paren"))
63     ("page-name")
64     ("pages-name")
65     ("page-ranges" ("true" "false"))
66     ("next-page")
67     ("next-pages")
68     ("list-type" ("table" "itemize" "description"))
69     ("list-style" ("list" "tabular" "longtable" "extra-tabular" "extra-longtable"
70                    "extra-tabular-rev" "extra-longtable-rev"))
71     ("list-header" ("chapter" "chapter*" "section" "section*" "subsection"
72                     "subsection*" "addchap" "addsec"))
73     ("list-name")
74     ("list-table-width")
75     ("list-caps" ("true" "false")))
76   "Package options for the acro package.")
77
78 (TeX-auto-add-type "acro-acronym" "LaTeX")
79
80 ;; Self Parsing -- see (info "(auctex)Hacking the Parser").
81 (defvar LaTeX-acro-regexp
82   (concat "\\\\DeclareAcronym" "{\\([^\n\r%\\{}]+\\)}")
83   "Matches `acro' acronym definitions.")
84
85 (defvar LaTeX-auto-acro-acronym nil
86   "Temporary for parsing `acro' acronym definitions.")
87
88 (defun LaTeX-acro-prepare ()
89   "Clear `LaTex-auto-acro-acronym' before use."
90   (setq LaTeX-auto-acro-acronym nil))
91
92 (defun LaTeX-acro-cleanup ()
93   "Move acronyms from `LaTeX-auto-acro-acronym' to
94 `LaTeX-acro-list' and to `TeX-auto-symbol' if option `macros' is
95 set to `true'."
96   (mapc (lambda (acronym)
97           (add-to-list 'LaTeX-acro-acronym-list (list acronym)))
98         LaTeX-auto-acro-acronym)
99   (when (or (LaTeX-provided-package-options-member "acro" "macros")
100             (LaTeX-provided-package-options-member "acro" "macros=true"))
101     (add-to-list 'TeX-auto-symbol LaTeX-auto-acro-acronym)))
102
103 ;; FIXME: This does not seem to work unless one does a manual reparse.
104 (add-hook 'TeX-auto-prepare-hook 'LaTeX-acro-prepare)
105 (add-hook 'TeX-auto-cleanup-hook 'LaTeX-acro-cleanup)
106
107 (defvar LaTeX-acro-acronym-history nil
108   "History of acronyms in acro.")
109
110 (defun LaTeX-arg-acro-acronym (optional &optional prompt definition)
111   "Prompt for an acronym completing with known acronyms.
112 If OPTIONAL is non-nil, insert the resulting value as an optional
113 argument, otherwise as a mandatory one.  Use PROMPT as the prompt
114 string.  If DEFINITION is non-nil, add the chosen acronym to the
115 list of defined acronyms."
116   (let ((acronym (completing-read (TeX-argument-prompt optional prompt "Acronym")
117                                   (LaTeX-acro-acronym-list) nil nil nil
118                                   'LaTeX-acro-acronym-history)))
119     (if (and definition (not (string-equal "" acronym)))
120         (LaTeX-add-acro-acronyms acronym))
121     (TeX-argument-insert acronym optional optional)))
122
123 (defun LaTeX-arg-define-acro-acronym (optional &optional prompt)
124   "Prompt for an acronym completing with known acronyms.
125 If OPTIONAL is non-nil, insert the resulting value as an optional
126 argument, otherwise as a mandatory one.  Use PROMPT as the prompt
127 string."
128   (LaTeX-arg-acro-acronym optional prompt t))
129
130 (defvar LaTeX-acro-declareacronym-keys
131   '(("short") ("long") ("short-plural") ("long-plural") ("long-plural-form")
132     ("short-indefinite") ("long-indefinite") ("long-pre") ("long-post") ("alt")
133     ("alt-indefinite") ("extra") ("sort") ("class") ("cite") ("short-format")
134     ("long-format") ("first-long-format") ("pdfstring") ("accsupp")
135     ("index-sort") ("index") ("index-cmd"))
136   "List of keys accepted by `\DeclareAcronym' macro of `acro' package
137 in its second mandatory argument.")
138
139 (defvar LaTeX-acro-printacronyms-keys
140   '(("include-classes") ("exclude-classes") ("name") ("header"))
141   "List of keys accepted by `\printacronyms' macro of `acro' package
142 in its optional argument.")
143
144 (defun LaTeX-arg-acro-key-val (optional prompt key-val-alist)
145   "Prompt for keys and values in KEY-VAL-ALIST.
146 <SPC> key binding in minibuffer is removed temporarily.  Insert
147 the given value as a TeX macro argument.  If OPTIONAL is non-nil,
148 insert it as an optional argument.  Use PROMPT as the prompt
149 string.  KEY-VAL-ALIST is an alist.  The car of each element
150 should be a string representing a key and the optional cdr should
151 be a list with strings to be used as values for the key."
152   ;; Remove <SPC> key binding from map used in `multi-prompt-key-value' (called
153   ;; by `TeX-arg-key-val') with `require-match' set to `nil'.
154   (let ((crm-local-completion-map
155          (remove (assoc 32 crm-local-completion-map) crm-local-completion-map)))
156     (TeX-arg-key-val optional key-val-alist prompt)))
157
158 (TeX-add-style-hook
159  "acro"
160  (lambda ()
161    (TeX-auto-add-regexp `(,LaTeX-acro-regexp 1 LaTeX-auto-acro-acronym))
162    (TeX-add-symbols
163     ;; Creating New Acronyms
164     '("DeclareAcronym" LaTeX-arg-define-acro-acronym
165       (LaTeX-arg-acro-key-val "Definition of acronym (k=v)"
166                               LaTeX-acro-declareacronym-keys))
167     ;; Using the Acronyms
168     '("ac" LaTeX-arg-acro-acronym)
169     '("ac*" LaTeX-arg-acro-acronym)
170     '("Ac" LaTeX-arg-acro-acronym)
171     '("Ac*" LaTeX-arg-acro-acronym)
172     '("acs" LaTeX-arg-acro-acronym)
173     '("acs*" LaTeX-arg-acro-acronym)
174     '("acl" LaTeX-arg-acro-acronym)
175     '("acl*" LaTeX-arg-acro-acronym)
176     '("Acl" LaTeX-arg-acro-acronym)
177     '("Acl*" LaTeX-arg-acro-acronym)
178     '("aca" LaTeX-arg-acro-acronym)
179     '("aca*" LaTeX-arg-acro-acronym)
180     '("acf" LaTeX-arg-acro-acronym)
181     '("acf*" LaTeX-arg-acro-acronym)
182     '("Acf" LaTeX-arg-acro-acronym)
183     '("Acf*" LaTeX-arg-acro-acronym)
184     '("acp" LaTeX-arg-acro-acronym)
185     '("acp*" LaTeX-arg-acro-acronym)
186     '("Acp" LaTeX-arg-acro-acronym)
187     '("Acp*" LaTeX-arg-acro-acronym)
188     '("acsp" LaTeX-arg-acro-acronym)
189     '("acsp*" LaTeX-arg-acro-acronym)
190     '("aclp" LaTeX-arg-acro-acronym)
191     '("aclp*" LaTeX-arg-acro-acronym)
192     '("Aclp" LaTeX-arg-acro-acronym)
193     '("Aclp*" LaTeX-arg-acro-acronym)
194     '("acap" LaTeX-arg-acro-acronym)
195     '("acap*" LaTeX-arg-acro-acronym)
196     '("acfp" LaTeX-arg-acro-acronym)
197     '("acfp*" LaTeX-arg-acro-acronym)
198     '("Acfp" LaTeX-arg-acro-acronym)
199     '("Acfp*" LaTeX-arg-acro-acronym)
200     ;; Indefinite Forms
201     '("iac" LaTeX-arg-acro-acronym)
202     '("iac*" LaTeX-arg-acro-acronym)
203     '("Iac" LaTeX-arg-acro-acronym)
204     '("Iac*" LaTeX-arg-acro-acronym)
205     '("iacs" LaTeX-arg-acro-acronym)
206     '("iacs*" LaTeX-arg-acro-acronym)
207     '("Iacs" LaTeX-arg-acro-acronym)
208     '("Iacs*" LaTeX-arg-acro-acronym)
209     '("iaca" LaTeX-arg-acro-acronym)
210     '("iaca*" LaTeX-arg-acro-acronym)
211     '("Iaca" LaTeX-arg-acro-acronym)
212     '("Iaca*" LaTeX-arg-acro-acronym)
213     '("iacl" LaTeX-arg-acro-acronym)
214     '("iacl*" LaTeX-arg-acro-acronym)
215     '("Iacl" LaTeX-arg-acro-acronym)
216     '("Iacl*" LaTeX-arg-acro-acronym)
217     '("iacf" LaTeX-arg-acro-acronym)
218     '("iacf*" LaTeX-arg-acro-acronym)
219     '("Iacf" LaTeX-arg-acro-acronym)
220     '("Iacf*" LaTeX-arg-acro-acronym)
221     '("iacflike" LaTeX-arg-acro-acronym)
222     '("iacflike*" LaTeX-arg-acro-acronym)
223     '("Iacflike" LaTeX-arg-acro-acronym)
224     '("Iacflike*" LaTeX-arg-acro-acronym)
225     ;; Simulating the First Appearance
226     '("acflike" LaTeX-arg-acro-acronym)
227     '("acflike*" LaTeX-arg-acro-acronym)
228     '("acfplike" LaTeX-arg-acro-acronym)
229     '("acfplike*" LaTeX-arg-acro-acronym)
230     ;; Reset or Mark as Used
231     '("acreset" "List of acronyms")
232     '("acresetall" 0)
233     '("acuse" "List of acronyms")
234     '("acuseall" 0)
235     ;; PDF bookmarks
236     '("acpdfstring" LaTeX-arg-acro-acronym)
237     '("acpdfstringplural" LaTeX-arg-acro-acronym)
238     ;; Printing the List
239     '("printacronyms" [LaTeX-arg-acro-key-val nil LaTeX-acro-printacronyms-keys])
240     ;; Customization
241     '("acsetup" (TeX-arg-key-val LaTeX-acro-package-options-list)))
242    (TeX-run-style-hooks
243     "l3sort"
244     "xspace"
245     "xtemplate"
246     "l3keys2e"
247     "xparse"
248     "expl3")
249
250    ;; Fontification
251    (when (and (featurep 'font-latex)
252               (eq TeX-install-font-lock 'font-latex-setup))
253      (font-latex-add-keywords '(("DeclareAcronym" "{{")
254                                 ("ac" "*{")
255                                 ("Ac" "*{")
256                                 ("acs" "*{")
257                                 ("acl" "*{")
258                                 ("Acl" "*{")
259                                 ("aca" "*{")
260                                 ("acf" "*{")
261                                 ("Acf" "*{")
262                                 ("acp" "*{")
263                                 ("Acp" "*{")
264                                 ("acsp" "*{")
265                                 ("aclp" "*{")
266                                 ("Aclp" "*{")
267                                 ("acap" "*{")
268                                 ("acfp" "*{")
269                                 ("Acfp" "*{")
270                                 ("acflike" "*{")
271                                 ("acfplike" "*{")
272                                 ("iac" "*{")
273                                 ("Iac" "*{")
274                                 ("iacs" "*{")
275                                 ("Iacs" "*{")
276                                 ("iaca" "*{")
277                                 ("Iaca" "*{")
278                                 ("iacl" "*{")
279                                 ("Iacl" "*{")
280                                 ("iacf" "*{")
281                                 ("Iacf" "*{")
282                                 ("iacflike" "*{")
283                                 ("Iacflike" "*{")
284                                 ("acuse" "{"))
285                               'function)))
286  LaTeX-dialect)
287
288 (defun LaTeX-acro-package-options ()
289   "Prompt for package options for the acro package."
290   (TeX-read-key-val t LaTeX-acro-package-options-list))
291
292 ;;; acro.el ends here