src/eric7/QScintilla/Lexers/LexerTeX.py

branch
eric7
changeset 9209
b99e7fd55fd3
parent 8881
54e42bc2437a
child 9221
bf71ee032bb4
equal deleted inserted replaced
9208:3fc8dfeb6ebe 9209:b99e7fd55fd3
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2005 - 2022 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a Tex lexer with some additional methods.
8 """
9
10 import contextlib
11
12 from PyQt6.Qsci import QsciLexerTeX
13
14 from .Lexer import Lexer
15 import Preferences
16
17
18 class LexerTeX(Lexer, QsciLexerTeX):
19 """
20 Subclass to implement some additional lexer dependant methods.
21 """
22 def __init__(self, parent=None):
23 """
24 Constructor
25
26 @param parent parent widget of this lexer
27 """
28 QsciLexerTeX.__init__(self, parent)
29 Lexer.__init__(self)
30
31 self.commentString = "%"
32
33 self.keywordSetDescriptions = [
34 self.tr("TeX, eTeX, pdfTeX, Omega"),
35 self.tr("ConTeXt Dutch"),
36 self.tr("ConTeXt English"),
37 self.tr("ConTeXt German"),
38 self.tr("ConTeXt Czech"),
39 self.tr("ConTeXt Italian"),
40 self.tr("ConTeXt Romanian"),
41 self.tr("LaTeX"),
42 ]
43
44 def initProperties(self):
45 """
46 Public slot to initialize the properties.
47 """
48 with contextlib.suppress(AttributeError):
49 self.setFoldCompact(Preferences.getEditor("AllFoldCompact"))
50 self.setFoldComments(Preferences.getEditor("TexFoldComment"))
51 self.setProcessComments(
52 Preferences.getEditor("TexProcessComments"))
53 self.setProcessIf(Preferences.getEditor("TexProcessIf"))
54
55 def isCommentStyle(self, style):
56 """
57 Public method to check, if a style is a comment style.
58
59 @param style style to check (integer)
60 @return flag indicating a comment style (boolean)
61 """
62 return False
63
64 def isStringStyle(self, style):
65 """
66 Public method to check, if a style is a string style.
67
68 @param style style to check (integer)
69 @return flag indicating a string style (boolean)
70 """
71 return style in [QsciLexerTeX.Text]
72
73 def defaultKeywords(self, kwSet):
74 """
75 Public method to get the default keywords.
76
77 @param kwSet number of the keyword set (integer)
78 @return string giving the keywords (string) or None
79 """
80 texKeywords = (
81 "above abovedisplayshortskip abovedisplayskip "
82 "abovewithdelims accent adjdemerits advance afterassignment "
83 "aftergroup atop atopwithdelims badness baselineskip batchmode "
84 "begingroup belowdisplayshortskip belowdisplayskip binoppenalty "
85 "botmark box boxmaxdepth brokenpenalty catcode char chardef "
86 "cleaders closein closeout clubpenalty copy count countdef cr "
87 "crcr csname day deadcycles def defaulthyphenchar defaultskewchar "
88 "delcode delimiter delimiterfactor delimeters delimitershortfall "
89 "delimeters dimen dimendef discretionary displayindent "
90 "displaylimits displaystyle displaywidowpenalty displaywidth "
91 "divide doublehyphendemerits dp dump edef else emergencystretch "
92 "end endcsname endgroup endinput endlinechar eqno errhelp "
93 "errmessage errorcontextlines errorstopmode escapechar everycr "
94 "everydisplay everyhbox everyjob everymath everypar everyvbox "
95 "exhyphenpenalty expandafter fam fi finalhyphendemerits firstmark "
96 "floatingpenalty font fontdimen fontname futurelet gdef global "
97 "group globaldefs halign hangafter hangindent hbadness hbox hfil "
98 "horizontal hfill horizontal hfilneg hfuzz hoffset holdinginserts "
99 "hrule hsize hskip hss horizontal ht hyphenation hyphenchar "
100 "hyphenpenalty hyphen if ifcase ifcat ifdim ifeof iffalse ifhbox "
101 "ifhmode ifinner ifmmode ifnum ifodd iftrue ifvbox ifvmode ifvoid "
102 "ifx ignorespaces immediate indent input inputlineno input insert "
103 "insertpenalties interlinepenalty jobname kern language lastbox "
104 "lastkern lastpenalty lastskip lccode leaders left lefthyphenmin "
105 "leftskip leqno let limits linepenalty line lineskip "
106 "lineskiplimit long looseness lower lowercase mag mark mathaccent "
107 "mathbin mathchar mathchardef mathchoice mathclose mathcode "
108 "mathinner mathop mathopen mathord mathpunct mathrel mathsurround "
109 "maxdeadcycles maxdepth meaning medmuskip message mkern month "
110 "moveleft moveright mskip multiply muskip muskipdef newlinechar "
111 "noalign noboundary noexpand noindent nolimits nonscript "
112 "scriptscript nonstopmode nulldelimiterspace nullfont number "
113 "omit openin openout or outer output outputpenalty over "
114 "overfullrule overline overwithdelims pagedepth pagefilllstretch "
115 "pagefillstretch pagefilstretch pagegoal pageshrink pagestretch "
116 "pagetotal par parfillskip parindent parshape parskip patterns "
117 "pausing penalty postdisplaypenalty predisplaypenalty "
118 "predisplaysize pretolerance prevdepth prevgraf radical raise "
119 "read relax relpenalty right righthyphenmin rightskip "
120 "romannumeral scriptfont scriptscriptfont scriptscriptstyle "
121 "scriptspace scriptstyle scrollmode setbox setlanguage sfcode "
122 "shipout show showbox showboxbreadth showboxdepth showlists "
123 "showthe skewchar skip skipdef spacefactor spaceskip span special "
124 "splitbotmark splitfirstmark splitmaxdepth splittopskip string "
125 "tabskip textfont textstyle the thickmuskip thinmuskip time "
126 "toks toksdef tolerance topmark topskip tracingcommands "
127 "tracinglostchars tracingmacros tracingonline tracingoutput "
128 "tracingpages tracingparagraphs tracingrestores tracingstats "
129 "uccode uchyph underline unhbox unhcopy unkern unpenalty unskip "
130 "unvbox unvcopy uppercase vadjust valign vbadness vbox vcenter "
131 "vfil vfill vfilneg vfuzz voffset vrule vsize vskip vsplit vss "
132 "vtop wd widowpenalty write xdef xleaders xspaceskip year"
133 )
134 etexKeywords = (
135 "beginL beginR botmarks clubpenalties currentgrouplevel "
136 "currentgrouptype currentifbranch currentiflevel currentiftype "
137 "detokenize dimexpr displaywidowpenalties endL endR eTeXrevision "
138 "eTeXversion everyeof firstmarks fontchardp fontcharht fontcharic "
139 "fontcharwd glueexpr glueshrink glueshrinkorder gluestretch "
140 "gluestretchorder gluetomu ifcsname ifdefined iffontchar "
141 "interactionmode interactionmode interlinepenalties lastlinefit "
142 "lastnodetype marks topmarks middle muexpr mutoglue numexpr "
143 "pagediscards parshapedimen parshapeindent parshapelength "
144 "predisplaydirection savinghyphcodes savingvdiscards scantokens "
145 "showgroups showifs showtokens splitdiscards splitfirstmarks "
146 "TeXXeTstate tracingassigns tracinggroups tracingifs "
147 "tracingnesting tracingscantokens unexpanded unless widowpenalties"
148 )
149 pdftexKeywords = (
150 "pdfadjustspacing pdfannot pdfavoidoverfull pdfcatalog "
151 "pdfcompresslevel pdfdecimaldigits pdfdest pdfdestmargin "
152 "pdfendlink pdfendthread pdffontattr pdffontexpand pdffontname "
153 "pdffontobjnum pdffontsize pdfhorigin pdfimageresolution "
154 "pdfincludechars pdfinfo pdflastannot pdflastdemerits pdflastobj "
155 "pdflastvbreakpenalty pdflastxform pdflastximage "
156 "pdflastximagepages pdflastxpos pdflastypos pdflinesnapx "
157 "pdflinesnapy pdflinkmargin pdfliteral pdfmapfile pdfmaxpenalty "
158 "pdfminpenalty pdfmovechars pdfnames pdfobj "
159 "pdfoptionpdfminorversion pdfoutline pdfoutput pdfpageattr "
160 "pdfpageheight pdfpageresources pdfpagesattr pdfpagewidth "
161 "pdfpkresolution pdfprotrudechars pdfrefobj pdfrefxform "
162 "pdfrefximage pdfsavepos pdfsnaprefpoint pdfsnapx pdfsnapy "
163 "pdfstartlink pdfstartthread pdftexrevision pdftexversion "
164 "pdfthread pdfthreadmargin pdfuniqueresname pdfvorigin pdfxform "
165 "pdfximage"
166 )
167 omegaKeywords = (
168 "odelimiter omathaccent omathchar oradical omathchardef omathcode "
169 "odelcode leftghost rightghost charwd charht chardp charit "
170 "localleftbox localrightbox localinterlinepenalty "
171 "localbrokenpenalty pagedir bodydir pardir textdir mathdir boxdir "
172 "nextfakemath pagewidth pageheight pagerightoffset "
173 "pagebottomoffset nullocp nullocplist ocp externalocp ocplist "
174 "pushocplist popocplist clearocplists ocptracelevel "
175 "addbeforeocplist addafterocplist removebeforeocplist "
176 "removeafterocplist OmegaVersion InputTranslation "
177 "OutputTranslation DefaultInputTranslation "
178 "DefaultOutputTranslation noInputTranslation noOutputTranslation "
179 "InputMode OutputMode DefaultInputMode DefaultOutputMode "
180 "noInputMode noOutputMode noDefaultInputMode noDefaultOutputMode"
181 )
182 macros = (
183 "TeX bgroup egroup endgraf space empty null newcount newdimen "
184 "newskip newmuskip newbox newtoks newhelp newread newwrite newfam "
185 "newlanguage newinsert newif maxdimen magstephalf magstep "
186 "frenchspacing nonfrenchspacing normalbaselines obeylines "
187 "obeyspaces raggedright ttraggedright thinspace negthinspace "
188 "enspace enskip quad qquad smallskip medskip bigskip "
189 "removelastskip topglue vglue hglue break nobreak allowbreak "
190 "filbreak goodbreak smallbreak medbreak bigbreak line leftline "
191 "rightline centerline rlap llap underbar strutbox strut cases "
192 "matrix pmatrix bordermatrix eqalign displaylines eqalignno "
193 "leqalignno pageno folio tracingall showhyphens fmtname "
194 "fmtversion hphantom vphantom phantom smash "
195 "eTeX newmarks grouptype interactionmode nodetype iftype "
196 "tracingall loggingall tracingnone"
197 )
198 if kwSet in (1, 2, 3, 4, 5, 6, 7):
199 return (
200 texKeywords + " " + etexKeywords + " " +
201 pdftexKeywords + " " + omegaKeywords + " " + macros
202 )
203
204 if kwSet == 8:
205 return (
206 texKeywords + " " + etexKeywords + " " +
207 pdftexKeywords
208 )
209
210 return None

eric ide

mercurial