Initial Commit
[packages] / xemacs-packages / auctex / style / acronym.el
1 ;;; acronym.el --- AUCTeX style for `acronym.sty' version 1.38.
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 `acronym.sty' version 1.38.
29
30 ;;; Code:
31
32 (TeX-auto-add-type "acronym" "LaTeX")
33
34 ;; Self Parsing -- see (info "(auctex)Hacking the Parser").
35 (defvar LaTeX-acronym-regexp
36   (concat "\\\\\\(?:acro\\|newacro\\|acrodef\\)" "{\\([^\n\r%\\{}]+\\)}")
37   "Matches acronyms by `acronym' package.")
38
39 (defvar LaTeX-auto-acronym nil
40   "Temporary for parsing acronym by `acronym' package.")
41
42 (defun LaTeX-acronym-prepare ()
43   "Clear `LaTex-auto-acronym' before use."
44   (setq LaTeX-auto-acronym nil))
45
46 (defun LaTeX-acronym-cleanup ()
47   "Move acronyms from `LaTeX-auto-acronym' to `LaTeX-acronym-list'."
48   (mapc (lambda (acronym)
49           (add-to-list 'LaTeX-acronym-list (list acronym)))
50         LaTeX-auto-acronym))
51
52 ;; FIXME: This does not seem to work unless one does a manual reparse.
53 (add-hook 'TeX-auto-prepare-hook 'LaTeX-acronym-prepare)
54 (add-hook 'TeX-auto-cleanup-hook 'LaTeX-acronym-cleanup)
55
56 (defvar LaTeX-acronym-acronym-history nil
57   "History of acronyms in acronym.")
58
59 ;; The former `acronym' stands for package name, the latter stands for the
60 ;; argument of the macro calling this function.
61 (defun LaTeX-arg-acronym-acronym (optional &optional prompt definition)
62   "Prompt for an acronym completing with known acronyms.
63 If OPTIONAL is non-nil, insert the resulting value as an optional
64 argument, otherwise as a mandatory one.  Use PROMPT as the prompt
65 string.  If DEFINITION is non-nil, add the chosen acronym to the
66 list of defined acronyms."
67   (let ((acronym (completing-read (TeX-argument-prompt optional prompt "Acronym")
68                                   (LaTeX-acronym-list) nil nil nil
69                                   'LaTeX-acronym-acronym-history)))
70     (if (and definition (not (string-equal "" acronym)))
71         (LaTeX-add-acronyms acronym))
72     (TeX-argument-insert acronym optional optional)))
73
74 (defun LaTeX-arg-define-acronym-acronym (optional &optional prompt)
75   "Prompt for an acronym completing with known acronyms.
76 If OPTIONAL is non-nil, insert the resulting value as an optional
77 argument, otherwise as a mandatory one.  Use PROMPT as the prompt
78 string."
79   (LaTeX-arg-acronym-acronym optional prompt t))
80
81 (TeX-add-style-hook
82  "acronym"
83  (lambda ()
84    (TeX-auto-add-regexp `(,LaTeX-acronym-regexp 1 LaTeX-auto-acronym))
85    (LaTeX-add-environments
86     '("acronym" LaTeX-env-args
87       [TeX-arg-string "Longest acronym"]))
88    (TeX-add-symbols
89     ;; Acronyms in the Text
90     '("ac" LaTeX-arg-acronym-acronym)
91     '("acresetall" 0)
92     '("acf" LaTeX-arg-acronym-acronym)
93     '("acs" LaTeX-arg-acronym-acronym)
94     '("acl" LaTeX-arg-acronym-acronym)
95     '("acp" LaTeX-arg-acronym-acronym)
96     '("acfp" LaTeX-arg-acronym-acronym)
97     '("acsp" LaTeX-arg-acronym-acronym)
98     '("aclp" LaTeX-arg-acronym-acronym)
99     '("acfi" LaTeX-arg-acronym-acronym)
100     '("acused" LaTeX-arg-acronym-acronym)
101     '("acsu" LaTeX-arg-acronym-acronym)
102     '("aclu" LaTeX-arg-acronym-acronym)
103     '("iac" LaTeX-arg-acronym-acronym)
104     '("Iac" LaTeX-arg-acronym-acronym)
105     '("ac*" LaTeX-arg-acronym-acronym)
106     '("acf*" LaTeX-arg-acronym-acronym)
107     '("acs*" LaTeX-arg-acronym-acronym)
108     '("acl*" LaTeX-arg-acronym-acronym)
109     '("acp*" LaTeX-arg-acronym-acronym)
110     '("acfp*" LaTeX-arg-acronym-acronym)
111     '("acsp*" LaTeX-arg-acronym-acronym)
112     '("aclp*" LaTeX-arg-acronym-acronym)
113     '("acfi*" LaTeX-arg-acronym-acronym)
114     '("acsu*" LaTeX-arg-acronym-acronym)
115     '("aclu*" LaTeX-arg-acronym-acronym)
116     '("iac*" LaTeX-arg-acronym-acronym)
117     '("Iac*" LaTeX-arg-acronym-acronym)
118     ;; Customization
119     '("acsfont" 1)
120     '("acffont" 1)
121     '("acfsfont" 1)
122     ;; Defining Acronyms
123     '("acro" LaTeX-arg-define-acronym-acronym [ "Short name" ] "Full name")
124     '("acroextra" "Additional info")
125     '("newacro" LaTeX-arg-define-acronym-acronym [ "Short name" ] "Full name")
126     '("acrodef" LaTeX-arg-define-acronym-acronym [ "Short name" ] "Full name")
127     ;; Non standard indefinite articles
128     '("acroindefinite" LaTeX-arg-acronym-acronym
129       "Short indefinite article" "Long indefinite article")
130     '("acrodefindefinite" LaTeX-arg-acronym-acronym
131       "Short indefinite article" "Long indefinite article")
132     '("newacroindefinite" LaTeX-arg-acronym-acronym
133       "Short indefinite article" "Long indefinite article")
134     ;; Non standard and foreign plural forms
135     '("acroplural" LaTeX-arg-acronym-acronym [ "Short plural" ] "Long plural")
136     '("acrodefplural" LaTeX-arg-acronym-acronym [ "Short plural" ] "Long plural")
137     '("newacroplural" LaTeX-arg-acronym-acronym [ "Short plural" ] "Long plural"))
138    (TeX-run-style-hooks
139     "relsize"
140     "xstring"
141     "suffix")
142
143    ;; Fontification
144    (when (and (featurep 'font-latex)
145               (eq TeX-install-font-lock 'font-latex-setup))
146      (font-latex-add-keywords '(("ac" "*{")
147                                 ("acf" "*{")
148                                 ("acs" "*{")
149                                 ("acl" "*{")
150                                 ("acp" "*{")
151                                 ("acfp" "*{")
152                                 ("acsp" "*{")
153                                 ("aclp" "*{")
154                                 ("acfi" "*{")
155                                 ("acused" "{")
156                                 ("acsu" "*{")
157                                 ("aclu" "*{")
158                                 ("iac" "*{")
159                                 ("Iac" "*{")
160                                 ("acro" "{[{")
161                                 ("acroextra" "{")
162                                 ("newacro" "{[{")
163                                 ("acrodef" "{[{")
164                                 ("acroindefinite" "{{{")
165                                 ("acrodefindefinite" "{{{")
166                                 ("newacroindefinite" "{{{")
167                                 ("acroplural" "{[{")
168                                 ("acrodefplural" "{[{")
169                                 ("newacroplural" "{[{"))
170                               'function)))
171  LaTeX-dialect)
172
173 (defvar LaTeX-acronym-package-options
174   '("footnote" "nohyperlinks" "printonlyused" "withpage" "smaller" "dua" "nolist")
175   "Package options for the acronym package.")
176
177 ;; acronym.el ends here