File: tex-ispell.el

package info (click to toggle)
auctex 11.91-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 5,952 kB
  • sloc: lisp: 45,907; makefile: 890; sh: 112; perl: 90
file content (390 lines) | stat: -rw-r--r-- 10,547 bytes parent folder | download
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
;;; tex-ispell.el --- AUCTeX skip additions for Ispell

;; Copyright (C) 2016-2017 Free Software Foundation, Inc.

;; Author: Arash Esbati <arash@gnu.org>
;; Maintainer: auctex-devel@gnu.org
;; Keywords: tex, wp, convenience

;; This file 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.

;; This file 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 GNU Emacs; 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 provides additions to skip list of Ispell (in this
;; context, Ispell is synonym for Ispell, Aspell and Hunspell spelling
;; checker programs).  Macro arguments and environments skipped by
;; Ispell are stored in the car and/or cdr of
;; `ispell-tex-skip-alists'.  This file uses two functions
;; `TeX-ispell-skip-setcar' and `TeX-ispell-skip-setcdr' defined in
;; `tex.el' to add new items to this variable.

;; Ispell has a lot of LaTeX macros and environments already built-in.
;; E.g., check this link for Hunspell program:

;; https://github.com/hunspell/hunspell/blob/master/src/parsers/latexparser.cxx

;; Ispell does not check spelling in the preamble of a document.
;; Hence, only document macros and environments should be added here.
;; Currently, this file has support for the following macro packages:

;; acro.sty
;; amsmath.sty
;; attachfile.sty
;; booktabs.sty
;; breqn.sty
;; cleveref.sty
;; empheq.sty
;; enumitem.sty
;; fancyref.sty
;; fancyvrb.sty
;; filecontents.sty
;; fontaxes.sty
;; fontspec.sty
;; hyperref.sty
;; listings.sty
;; ltxtable.sty
;; mdframed.sty
;; minted.sty
;; nameref.sty
;; siunitx.sty
;; splitidx.sty
;; tabularx.sty
;; tabulary.sty
;; tcolorbox.sty
;; tikz.sty
;; varioref.sty

;; If you have further additions, drop a line to <auctex-devel@gnu.org>.

;;; Code:

(require 'tex)

;; Add new macros here:
(eval-when-compile
  (defvar TeX-ispell-skip-cmds-list
    '(;; acro.sty
      ("ac" . 1)
      ("ac*" . 1)
      ("Ac" . 1)
      ("Ac*" . 1)
      ("acs" . 1)
      ("acs*" . 1)
      ("acl" . 1)
      ("acl*" . 1)
      ("Acl" . 1)
      ("Acl*" . 1)
      ("aca" . 1)
      ("aca*" . 1)
      ("acf" . 1)
      ("acf*" . 1)
      ("Acf" . 1)
      ("Acf*" . 1)
      ("acp" . 1)
      ("acp*" . 1)
      ("Acp" . 1)
      ("Acp*" . 1)
      ("acsp" . 1)
      ("acsp*" . 1)
      ("aclp" . 1)
      ("aclp*" . 1)
      ("Aclp" . 1)
      ("Aclp*" . 1)
      ("acap" . 1)
      ("acap*" . 1)
      ("acfp" . 1)
      ("acfp*" . 1)
      ("Acfp" . 1)
      ("Acfp*" . 1)
      ("Iac" . 1)
      ("iacs" . 1)
      ("iacl" . 1)
      ("acflike" . 1)
      ("acflike*" . 1)
      ("acfplike" . 1)
      ("acfplike*" . 1)
      ("acsingle" . 1)
      ("acsingle*" . 1)
      ("Acsingle" . 1)
      ("Acsingle*" . 1)
      ("acreset" . 1)
      ("acuse" . 1)
      ("acsetup" . 1)
      ;; attachfile.sty
      ("attachfile" . 1)
      ("attachfilesetup" . 1)
      ("textattachfile" . 1)
      ;; booktabs.sty
      ("addlinespace" . 0)
      ("specialrule" . 3)
      ;; cleveref.sty
      ("cref" . 1)
      ("Cref" . 1)
      ("cref*" . 1)
      ("Cref*" . 1)
      ("cpageref" . 1)
      ("Cpageref" . 1)
      ("namecref" . 1)
      ("nameCref" . 1)
      ("lcnamecref" . 1)
      ("labelcref" . 1)
      ("crefrange" . 2)
      ("Crefrange" . 2)
      ("cpagerefrange" . 2)
      ("Cpagerefrange" . 2)
      ("crefrange*" . 2)
      ("Crefrange*" . 2)
      ;; empheq.sty
      ("empheqset" . 1)
      ;; fancyref.sty
      ("fref" . 1)
      ("Fref" . 1)
      ;; fancyvrb.sty
      ("fvset" . 1)
      ("VerbatimInput" . 1)
      ;; fontaxes.sty
      ("figureversion" . 1)
      ;; fontspec.sty
      ("addfontfeatures" . 1)
      ;; hyperref.sty
      ("hypersetup" . 1)
      ("href" . 1)
      ("url" . 1)
      ("nolinkurl" . 1)
      ("hyperbaseurl" . 1)
      ("hyperimage" . 1)
      ("hyperdef" . 2)
      ("hyperref" . 3)
      ("hyperlink" . 1)
      ("hypertarget" . 1)
      ("autoref" . 1)
      ("autoref*" . 1)
      ("autopageref" . 1)
      ("autopageref*" . 1)
      ;; listings.sty
      ("lstinputlisting" . 1)
      ("lstset" . 1)
      ;; ltxtable.sty
      ("LTXtable" . 2)
      ;; mdframed.sty
      ("mdfsetup" . 1)
      ("mdfapptodefinestyle" . 2)
      ;; minted.sty
      ("inputminted" . 2)
      ("setminted" . 1)
      ("setmintedinline" . 1)
      ;; nameref.sty
      ("nameref" . 1)
      ("Nameref" . 1)
      ;; siunitx.sty
      ("num" . 1)
      ("si" . 1)
      ("sisetup" . 1)
      ("SI" . 2)
      ;; splitidx.sty
      ("sindex" . 1)
      ;; tcolorbox.sty
      ("tcbox" . 0)
      ("tcbset" . 1)
      ("tcbsetforeverylayer" . 1)
      ;; tcolorbox.sty -- raster library
      ("tcbitem" . 0)
      ;; varioref.sty
      ("vref" . 1)
      ("Vref" . 1)
      ("vref*" . 1)
      ("Ref" . 1)
      ("vpageref" . 1)
      ("vpageref*" . 1)
      ("fullref" . 1)
      ("vrefrange" . 2)
      ("vrefrange*" . 2)
      ("vpagerefrange" . 2)
      ("vpagerefrange*" . 2))
    "List of commands with arguments to be skipped.
Each element of the list is a cons cell with command name
\(string) as car and the number of mandatory arguments to be
skipped as cdr.  If number is 0, then only skip over the optional
argument and spell check the mandatory one."))


;; Add new environments with one optional argument here:
(eval-when-compile
  (defvar TeX-ispell-skip-envs-opt-arg-list
    '(;; enumitem.sty
      "description"
      "description*"
      "enumerate"
      "enumerate*"
      "itemize"
      "itemize*"
      ;; mdframed.sty
      "mdframed"
      ;; tcolorbox.sty
      "tcolorbox"
      ;; tcolorbox.sty -- raster library
      "tcbraster"
      "tcbitemize")
    "List of LaTeX environments with an opt argument to be skipped."))


;; Add new environments which should be skipped entirely here:
(eval-when-compile
  (defvar TeX-ispell-skip-envs-list
    '(;; amsmath.sty
      "align"
      "align*"
      "alignat"
      "alignat*"
      "flalign"
      "flalign*"
      "gather"
      "gather*"
      "multline"
      "multline*"
      ;; breqn.sty
      "darray"
      "darray*"
      "dgroup"
      "dgroup*"
      "dmath"
      "dmath*"
      "dseries"
      "dseries*"
      ;; empheq.sty
      "empheq"
      ;; fancyvrb.sty
      "BVerbatim"
      "BVerbatim*"
      "LVerbatim"
      "LVerbatim*"
      "SaveVerbatim"
      "Verbatim"
      "Verbatim*"
      "VerbatimOut"
      ;; listings.sty
      "lstlisting"
      ;; minted.sty
      "minted"
      ;; tikz.sty
      "tikzpicture")
    "List of LaTeX environments which will be skipped entirely.
Environments for math or verbatim text are candidates for this list."))


;; Add others delimited here:
(TeX-ispell-skip-setcar
 `(;; LaTeX-base
   ("\\\\(" . "\\\\)")
   ("\\\\raisebox" TeX-ispell-tex-arg-end 1 2 0)
   ;; booktabs.sty
   ("\\\\cmidrule" . "{[-0-9]+}")
   ;; fontspec.sty
   ("\\\\fontspec" TeX-ispell-tex-arg-end 1 1 0)))


;; Special setup for verbatim macros:
(defcustom TeX-ispell-verb-delimiters "!|#~\"/+^-"
  "String with all delimiters for verbatim macros.
Characters special in regexps like `^' and `-' must come last and
not be quoted.  An opening brace `{', asterisk `*' and at-sign
`@' should not be used as they are not recognized by
`font-latex.el' correctly."
  :group 'TeX-misc
  :type 'string)

;; listings.sty & fancyvrb.sty: With opt. argument only before verb content:
(TeX-ispell-skip-setcar
 `((,(concat "\\\\" (regexp-opt '("Verb" "lstinline")))
    TeX-ispell-tex-arg-verb-end)))

;; minted.sty: With opt. and mandatory argument before verb content:
(TeX-ispell-skip-setcar
 `((,(concat "\\\\" (regexp-opt '("mint" "mintinline")))
    TeX-ispell-tex-arg-verb-end 1)))


;; Add environments here:
(TeX-ispell-skip-setcdr
 '(;; filecontents.sty
   ("filecontents\\*?" ispell-tex-arg-end)
   ;; tabularx.sty, tabulary.sty, Standard LaTeX tabular*-env
   ("tabular[*xy]" TeX-ispell-tex-arg-end)
   ;; tcolorbox.sty -- raster library
   ("tcboxed\\(raster\\|itemize\\)" ispell-tex-arg-end)))


;; No customization below this line

(eval-when-compile
  (defun TeX-ispell-sort-skip-cmds-list (arg)
    "Return elements from `TeX-ispell-skip-cmds-list' acc. to ARG."
    (when (member arg '(0 1 2 3))
      (let (cmds)
	(dolist (elt TeX-ispell-skip-cmds-list)
	  (when (= (cdr elt) arg)
	    (push (car elt) cmds)))
	cmds))))

(defvar TeX-ispell-skip-cmds-opt-arg-regexp
  (eval-when-compile
    (concat "\\\\"
	    (regexp-opt (TeX-ispell-sort-skip-cmds-list 0) t)))
  "Regexp of LaTeX commands with only optional arguments to be skipped.")

(defvar TeX-ispell-skip-cmds-one-arg-regexp
  (eval-when-compile
    (concat "\\\\"
	    (regexp-opt (TeX-ispell-sort-skip-cmds-list 1) t)))
  "Regexp of LaTeX commands with one argument to be skipped.")

(defvar TeX-ispell-skip-cmds-two-args-regexp
  (eval-when-compile
    (concat "\\\\"
	    (regexp-opt (TeX-ispell-sort-skip-cmds-list 2) t)))
  "Regexp of LaTeX commands with two arguments to be skipped.")

(defvar TeX-ispell-skip-cmds-three-args-regexp
  (eval-when-compile
    (concat "\\\\"
	    (regexp-opt (TeX-ispell-sort-skip-cmds-list 3) t)))
  "Regexp of LaTeX commands with three arguments to be skipped.")

(defvar TeX-ispell-skip-envs-opt-arg-regexp
  (eval-when-compile
    (regexp-opt TeX-ispell-skip-envs-opt-arg-list t))
  "Regexp of LaTeX environments with an opt argument to be skipped.")

(defvar TeX-ispell-skip-envs-regexp
  (eval-when-compile
    (regexp-opt TeX-ispell-skip-envs-list t))
  "Regexp of LaTeX environments which will be skipped entirely.")

;; Make them available to Ispell:
(TeX-ispell-skip-setcar
 `((,TeX-ispell-skip-cmds-opt-arg-regexp ispell-tex-arg-end 0)
   (,TeX-ispell-skip-cmds-one-arg-regexp ispell-tex-arg-end)
   (,TeX-ispell-skip-cmds-two-args-regexp ispell-tex-arg-end 2)
   (,TeX-ispell-skip-cmds-three-args-regexp ispell-tex-arg-end 3)))

(TeX-ispell-skip-setcdr
 `((,TeX-ispell-skip-envs-opt-arg-regexp ispell-tex-arg-end 0)
   ,(cons TeX-ispell-skip-envs-regexp
	  (concat "\\\\end{" TeX-ispell-skip-envs-regexp "}"))))

(provide 'tex-ispell)

;;; tex-ispell.el ends here