Skip to content

Commit 10ff561

Browse files
committed
Case insensitive \ref command lookup
Be little less restrictive as CWL e.g. provides \Ref completion instead of \ref
1 parent ab07471 commit 10ff561

File tree

1 file changed

+12
-75
lines changed

1 file changed

+12
-75
lines changed

latextools/latex_ref_completions.py

Lines changed: 12 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -144,67 +144,52 @@
144144
LABEL_PATTERN = fr"\\(?:{'|'.join(LABELS)})\{{([^\{{\}}]+)\}}"
145145

146146
_ref_prefixes = (
147-
"A"
148-
"|a"
147+
"a"
149148
"|addtocounter"
150149
"|addtocounterpage"
151150
"|addx"
152151
"|aebname"
153152
"|aeq"
154-
"|Aeq"
155153
"|af"
156154
"|alg"
157155
"|algorithm"
158156
"|alias"
159-
"|AMC"
160-
"|AMCpage"
161-
"|AMSeq"
157+
"|amc"
158+
"|amcpage"
159+
"|amseq"
162160
"|annotation"
163161
"|apage"
164-
"|Apage"
165162
"|app"
166163
"|appendix"
167164
"|apx"
168-
"|Apx"
169165
"|argpage"
170166
"|ass"
171167
"|aster"
172168
"|auto"
173-
"|Auto"
174169
"|autopage"
175170
"|av"
176-
"|Av"
177171
"|aveq"
178-
"|Aveq"
179172
"|avpage"
180-
"|Avpage"
181173
"|axiom"
182-
"|B"
183174
"|b"
184175
"|bfull"
185176
"|bracket"
186-
"|C"
187177
"|c"
188178
"|cant"
189179
"|case"
190-
"|Chap"
191180
"|chap"
192181
"|chappage"
193182
"|chaprange"
194-
"|Chaprange"
195183
"|chapter"
196184
"|circled"
197185
"|col"
198186
"|conjecture"
199187
"|corollary"
200-
"|Cpage"
201188
"|cpage"
202189
"|crtc"
203-
"|crtC"
204190
"|crtextract"
205191
"|crtextractc"
206192
"|crthyperc"
207-
"|crthyperC"
208193
"|crtlname"
209194
"|crtname"
210195
"|crtuname"
@@ -217,44 +202,32 @@
217202
"|defpage"
218203
"|desc"
219204
"|e"
220-
"|E"
221205
"|edline"
222206
"|edpage"
223207
"|enumerate"
224-
"|Eq"
225208
"|eq"
226209
"|eqfull"
227210
"|eqpage"
228211
"|eqrange"
229-
"|Eqrange"
230212
"|equation"
231213
"|ex"
232214
"|example"
233-
"|Example"
234215
"|examplemargin"
235216
"|examplename"
236217
"|examples"
237-
"|Examples"
238218
"|examplesname"
239219
"|ext"
240-
"|F"
241220
"|f"
242221
"|fancy"
243222
"|fancysub"
244-
"|Fig"
245223
"|fig"
246224
"|figpage"
247225
"|figrange"
248-
"|Figrange"
249226
"|figure"
250-
"|Figure"
251227
"|figures"
252-
"|Figures"
253-
"|Fn"
254228
"|fn"
255229
"|fnpage"
256230
"|fnrange"
257-
"|Fnrange"
258231
"|foot"
259232
"|footnote"
260233
"|full"
@@ -274,14 +247,10 @@
274247
"|josaeq"
275248
"|josapage"
276249
"|k"
277-
"|kC"
278250
"|kc"
279-
"|kCname"
280251
"|kcname"
281-
"|kCpage"
282252
"|kcpage"
283253
"|knamec"
284-
"|knameC"
285254
"|kpage"
286255
"|labelc"
287256
"|labelcpage"
@@ -293,40 +262,31 @@
293262
"|line"
294263
"|lst"
295264
"|m"
296-
"|mExample"
297265
"|mexample"
298266
"|mtoc"
299267
"|n"
300268
"|name"
301-
"|Name"
302-
"|nameC"
303269
"|namec"
304270
"|noeq"
305271
"|npage"
306272
"|num"
307273
"|object"
308274
"|old"
309275
"|oldvpage"
310-
"|P"
311276
"|p"
312277
"|page"
313278
"|pagex"
314279
"|paragraph"
315280
"|paren"
316281
"|parenroman"
317-
"|parenRoman"
318282
"|parnote"
319-
"|Part"
320283
"|part"
321284
"|partpage"
322285
"|partrange"
323-
"|Partrange"
324286
"|pfull"
325287
"|pg"
326-
"|Pg"
327288
"|pgfmanualpdf"
328289
"|ph"
329-
"|Ph"
330290
"|phyper"
331291
"|plain"
332292
"|pmemlabel"
@@ -347,23 +307,17 @@
347307
"|remark"
348308
"|rn"
349309
"|roman"
350-
"|Roman"
351-
"|RSeq"
352-
"|S"
310+
"|rseq"
353311
"|s"
354312
"|safe"
355313
"|schapter"
356-
"|SE"
357-
"|Sec"
314+
"|se"
358315
"|sec"
359316
"|secpage"
360317
"|secrange"
361-
"|Secrange"
362318
"|sect"
363319
"|section"
364-
"|Section"
365320
"|sections"
366-
"|Sections"
367321
"|sequation"
368322
"|setcounter"
369323
"|setcounterfrom"
@@ -396,7 +350,6 @@
396350
"|stable"
397351
"|step"
398352
"|sub"
399-
"|Sub"
400353
"|subcaption"
401354
"|subfig"
402355
"|subfigure"
@@ -409,16 +362,11 @@
409362
"|subtab"
410363
"|synchro"
411364
"|t"
412-
"|T"
413-
"|Tab"
414365
"|tab"
415366
"|table"
416-
"|Table"
417367
"|tables"
418-
"|Tables"
419368
"|tabpage"
420369
"|tabrange"
421-
"|Tabrange"
422370
"|text"
423371
"|th"
424372
"|thanks"
@@ -428,7 +376,6 @@
428376
"|title"
429377
"|tocname"
430378
"|ukfaq"
431-
"|V"
432379
"|v"
433380
"|vname"
434381
"|vpage"
@@ -453,9 +400,7 @@
453400
)[::-1] # ..ref / ..refs
454401

455402
_ref_range_prefixes = (
456-
"C"
457-
"|C"
458-
"|Cpage"
403+
"c"
459404
"|cpage"
460405
)[::-1] # ...refrange
461406

@@ -464,32 +409,25 @@
464409
"|appendix"
465410
"|axiom"
466411
"|c"
467-
"|C"
468412
"|chapter"
469413
"|conjecture"
470414
"|corollary"
471-
"|Cpage"
472415
"|cpage"
473416
"|definition"
474417
"|equation"
475418
"|example"
476419
"|examples"
477-
"|Examples"
478420
"|examplesname"
479421
"|figure"
480422
"|figures"
481-
"|Figures"
482423
"|footnote"
483424
"|item"
484425
"|kc"
485-
"|kC"
486426
"|kcpage"
487-
"|kCpage"
488427
"|labelc"
489428
"|labelcpage"
490429
"|lemma"
491430
"|namec"
492-
"|nameC"
493431
"|noeq"
494432
"|object"
495433
"|paragraph"
@@ -500,21 +438,20 @@
500438
"|subtab"
501439
"|table"
502440
"|tables"
503-
"|Tables"
504441
"|th"
505442
"|theorem"
506443
"|zc"
507444
"|zcheck"
508445
"|zcpage"
509446
)[::-1] # ..ref
510447

511-
OLD_STYLE_REF_REGEX = re.compile(fr"([^_]*_)?(?:(?:[-+]|\*?s?)fer(?:{_ref_prefixes})?)\\")
448+
OLD_STYLE_REF_REGEX = re.compile(fr"([^_]*_)?(?:(?:[-+]|\*?s?)fer(?:{_ref_prefixes})?)\\", re.I)
512449

513-
NEW_STYLE_REF_REGEX = re.compile(fr"([^}}]*)\{{(?:(?:[-+]|\*?s?)fer(?:{_ref_prefixes})?)\\")
450+
NEW_STYLE_REF_REGEX = re.compile(fr"([^}}]*)\{{(?:(?:[-+]|\*?s?)fer(?:{_ref_prefixes})?)\\", re.I)
514451

515-
NEW_STYLE_REF_RANGE_REGEX = re.compile(fr"([^}}]*)\{{(?:\}}[^\}}]*\{{)?\*?egnarfer(?:{_ref_range_prefixes})\\")
452+
NEW_STYLE_REF_RANGE_REGEX = re.compile(fr"([^}}]*)\{{(?:\}}[^\}}]*\{{)?\*?egnarfer(?:{_ref_range_prefixes})\\", re.I)
516453

517-
NEW_STYLE_REF_MULTIVALUE_REGEX = re.compile(fr"([^}},]*)(?:,[^}},]*)*\{{[-+*]?fer(?:{_ref_multivalue_prefixes})\\")
454+
NEW_STYLE_REF_MULTIVALUE_REGEX = re.compile(fr"([^}},]*)(?:,[^}},]*)*\{{[-+*]?fer(?:{_ref_multivalue_prefixes})\\", re.I)
518455

519456
LSTSET_LABEL_REGEX = re.compile(r"label\s*=\s*([^\s,}]*)")
520457

@@ -560,7 +497,7 @@ def get_ref_completions(view):
560497

561498
class RefLatexFillAllPlugin(LatexFillAllPlugin):
562499
def get_auto_completions(self, view, prefix, line):
563-
# Reverse, to simulate having the regex
500+
# Reverse, to simulate having the re
564501
# match backwards (cool trick jps btw!)
565502
line = line[::-1]
566503

0 commit comments

Comments
 (0)