qscilexertex.cpp 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. // This module implements the QsciLexerTeX class.
  2. //
  3. // Copyright (c) 2017 Riverbank Computing Limited <info@riverbankcomputing.com>
  4. //
  5. // This file is part of QScintilla.
  6. //
  7. // This file may be used under the terms of the GNU General Public License
  8. // version 3.0 as published by the Free Software Foundation and appearing in
  9. // the file LICENSE included in the packaging of this file. Please review the
  10. // following information to ensure the GNU General Public License version 3.0
  11. // requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  12. //
  13. // If you do not wish to use this file under the terms of the GPL version 3.0
  14. // then you may purchase a commercial license. For more information contact
  15. // info@riverbankcomputing.com.
  16. //
  17. // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  18. // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  19. #include "Qsci/qscilexertex.h"
  20. #include <qcolor.h>
  21. #include <qfont.h>
  22. #include <qsettings.h>
  23. // The ctor.
  24. QsciLexerTeX::QsciLexerTeX(QObject *parent)
  25. : QsciLexer(parent),
  26. fold_comments(false), fold_compact(true), process_comments(false),
  27. process_if(true)
  28. {
  29. }
  30. // The dtor.
  31. QsciLexerTeX::~QsciLexerTeX()
  32. {
  33. }
  34. // Returns the language name.
  35. const char *QsciLexerTeX::language() const
  36. {
  37. return "TeX";
  38. }
  39. // Returns the lexer name.
  40. const char *QsciLexerTeX::lexer() const
  41. {
  42. return "tex";
  43. }
  44. // Return the string of characters that comprise a word.
  45. const char *QsciLexerTeX::wordCharacters() const
  46. {
  47. return "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\\@";
  48. }
  49. // Returns the foreground colour of the text for a style.
  50. QColor QsciLexerTeX::defaultColor(int style) const
  51. {
  52. switch (style)
  53. {
  54. case Default:
  55. return QColor(0x3f,0x3f,0x3f);
  56. case Special:
  57. return QColor(0x00,0x7f,0x7f);
  58. case Group:
  59. return QColor(0x7f,0x00,0x00);
  60. case Symbol:
  61. return QColor(0x7f,0x7f,0x00);
  62. case Command:
  63. return QColor(0x00,0x7f,0x00);
  64. }
  65. return QsciLexer::defaultColor(style);
  66. }
  67. // Returns the set of keywords.
  68. const char *QsciLexerTeX::keywords(int set) const
  69. {
  70. if (set == 1)
  71. return
  72. "above abovedisplayshortskip abovedisplayskip "
  73. "abovewithdelims accent adjdemerits advance "
  74. "afterassignment aftergroup atop atopwithdelims "
  75. "badness baselineskip batchmode begingroup "
  76. "belowdisplayshortskip belowdisplayskip binoppenalty "
  77. "botmark box boxmaxdepth brokenpenalty catcode char "
  78. "chardef cleaders closein closeout clubpenalty copy "
  79. "count countdef cr crcr csname day deadcycles def "
  80. "defaulthyphenchar defaultskewchar delcode delimiter "
  81. "delimiterfactor delimeters delimitershortfall "
  82. "delimeters dimen dimendef discretionary "
  83. "displayindent displaylimits displaystyle "
  84. "displaywidowpenalty displaywidth divide "
  85. "doublehyphendemerits dp dump edef else "
  86. "emergencystretch end endcsname endgroup endinput "
  87. "endlinechar eqno errhelp errmessage "
  88. "errorcontextlines errorstopmode escapechar everycr "
  89. "everydisplay everyhbox everyjob everymath everypar "
  90. "everyvbox exhyphenpenalty expandafter fam fi "
  91. "finalhyphendemerits firstmark floatingpenalty font "
  92. "fontdimen fontname futurelet gdef global group "
  93. "globaldefs halign hangafter hangindent hbadness "
  94. "hbox hfil horizontal hfill horizontal hfilneg hfuzz "
  95. "hoffset holdinginserts hrule hsize hskip hss "
  96. "horizontal ht hyphenation hyphenchar hyphenpenalty "
  97. "hyphen if ifcase ifcat ifdim ifeof iffalse ifhbox "
  98. "ifhmode ifinner ifmmode ifnum ifodd iftrue ifvbox "
  99. "ifvmode ifvoid ifx ignorespaces immediate indent "
  100. "input inputlineno input insert insertpenalties "
  101. "interlinepenalty jobname kern language lastbox "
  102. "lastkern lastpenalty lastskip lccode leaders left "
  103. "lefthyphenmin leftskip leqno let limits linepenalty "
  104. "line lineskip lineskiplimit long looseness lower "
  105. "lowercase mag mark mathaccent mathbin mathchar "
  106. "mathchardef mathchoice mathclose mathcode mathinner "
  107. "mathop mathopen mathord mathpunct mathrel "
  108. "mathsurround maxdeadcycles maxdepth meaning "
  109. "medmuskip message mkern month moveleft moveright "
  110. "mskip multiply muskip muskipdef newlinechar noalign "
  111. "noboundary noexpand noindent nolimits nonscript "
  112. "scriptscript nonstopmode nulldelimiterspace "
  113. "nullfont number omit openin openout or outer output "
  114. "outputpenalty over overfullrule overline "
  115. "overwithdelims pagedepth pagefilllstretch "
  116. "pagefillstretch pagefilstretch pagegoal pageshrink "
  117. "pagestretch pagetotal par parfillskip parindent "
  118. "parshape parskip patterns pausing penalty "
  119. "postdisplaypenalty predisplaypenalty predisplaysize "
  120. "pretolerance prevdepth prevgraf radical raise read "
  121. "relax relpenalty right righthyphenmin rightskip "
  122. "romannumeral scriptfont scriptscriptfont "
  123. "scriptscriptstyle scriptspace scriptstyle "
  124. "scrollmode setbox setlanguage sfcode shipout show "
  125. "showbox showboxbreadth showboxdepth showlists "
  126. "showthe skewchar skip skipdef spacefactor spaceskip "
  127. "span special splitbotmark splitfirstmark "
  128. "splitmaxdepth splittopskip string tabskip textfont "
  129. "textstyle the thickmuskip thinmuskip time toks "
  130. "toksdef tolerance topmark topskip tracingcommands "
  131. "tracinglostchars tracingmacros tracingonline "
  132. "tracingoutput tracingpages tracingparagraphs "
  133. "tracingrestores tracingstats uccode uchyph "
  134. "underline unhbox unhcopy unkern unpenalty unskip "
  135. "unvbox unvcopy uppercase vadjust valign vbadness "
  136. "vbox vcenter vfil vfill vfilneg vfuzz voffset vrule "
  137. "vsize vskip vsplit vss vtop wd widowpenalty write "
  138. "xdef xleaders xspaceskip year "
  139. "TeX bgroup egroup endgraf space empty null newcount "
  140. "newdimen newskip newmuskip newbox newtoks newhelp "
  141. "newread newwrite newfam newlanguage newinsert newif "
  142. "maxdimen magstephalf magstep frenchspacing "
  143. "nonfrenchspacing normalbaselines obeylines "
  144. "obeyspaces raggedr ight ttraggedright thinspace "
  145. "negthinspace enspace enskip quad qquad smallskip "
  146. "medskip bigskip removelastskip topglue vglue hglue "
  147. "break nobreak allowbreak filbreak goodbreak "
  148. "smallbreak medbreak bigbreak line leftline "
  149. "rightline centerline rlap llap underbar strutbox "
  150. "strut cases matrix pmatrix bordermatrix eqalign "
  151. "displaylines eqalignno leqalignno pageno folio "
  152. "tracingall showhyphens fmtname fmtversion hphantom "
  153. "vphantom phantom smash";
  154. return 0;
  155. }
  156. // Returns the user name of a style.
  157. QString QsciLexerTeX::description(int style) const
  158. {
  159. switch (style)
  160. {
  161. case Default:
  162. return tr("Default");
  163. case Special:
  164. return tr("Special");
  165. case Group:
  166. return tr("Group");
  167. case Symbol:
  168. return tr("Symbol");
  169. case Command:
  170. return tr("Command");
  171. case Text:
  172. return tr("Text");
  173. }
  174. return QString();
  175. }
  176. // Refresh all properties.
  177. void QsciLexerTeX::refreshProperties()
  178. {
  179. setCommentProp();
  180. setCompactProp();
  181. setProcessCommentsProp();
  182. setAutoIfProp();
  183. }
  184. // Read properties from the settings.
  185. bool QsciLexerTeX::readProperties(QSettings &qs, const QString &prefix)
  186. {
  187. int rc = true;
  188. fold_comments = qs.value(prefix + "foldcomments", false).toBool();
  189. fold_compact = qs.value(prefix + "foldcompact", true).toBool();
  190. process_comments = qs.value(prefix + "processcomments", false).toBool();
  191. process_if = qs.value(prefix + "processif", true).toBool();
  192. return rc;
  193. }
  194. // Write properties to the settings.
  195. bool QsciLexerTeX::writeProperties(QSettings &qs, const QString &prefix) const
  196. {
  197. int rc = true;
  198. qs.value(prefix + "foldcomments", fold_comments);
  199. qs.value(prefix + "foldcompact", fold_compact);
  200. qs.value(prefix + "processcomments", process_comments);
  201. qs.value(prefix + "processif", process_if);
  202. return rc;
  203. }
  204. // Set if comments can be folded.
  205. void QsciLexerTeX::setFoldComments(bool fold)
  206. {
  207. fold_comments = fold;
  208. setCommentProp();
  209. }
  210. // Set the "fold.comment" property.
  211. void QsciLexerTeX::setCommentProp()
  212. {
  213. emit propertyChanged("fold.comment", (fold_comments ? "1" : "0"));
  214. }
  215. // Set if folds are compact.
  216. void QsciLexerTeX::setFoldCompact(bool fold)
  217. {
  218. fold_compact = fold;
  219. setCompactProp();
  220. }
  221. // Set the "fold.compact" property.
  222. void QsciLexerTeX::setCompactProp()
  223. {
  224. emit propertyChanged("fold.compact", (fold_compact ? "1" : "0"));
  225. }
  226. // Set if comments are processed
  227. void QsciLexerTeX::setProcessComments(bool enable)
  228. {
  229. process_comments = enable;
  230. setProcessCommentsProp();
  231. }
  232. // Set the "lexer.tex.comment.process" property.
  233. void QsciLexerTeX::setProcessCommentsProp()
  234. {
  235. emit propertyChanged("lexer.tex.comment.process", (process_comments ? "1" : "0"));
  236. }
  237. // Set if \if<unknown> is processed
  238. void QsciLexerTeX::setProcessIf(bool enable)
  239. {
  240. process_if = enable;
  241. setAutoIfProp();
  242. }
  243. // Set the "lexer.tex.auto.if" property.
  244. void QsciLexerTeX::setAutoIfProp()
  245. {
  246. emit propertyChanged("lexer.tex.auto.if", (process_if ? "1" : "0"));
  247. }