📄 lextex.cxx.svn-base
字号:
(ch == '(') || (ch == ')') || (ch == '[') ||
(ch == ']') || (ch == '{') || (ch == '}');
}
static inline bool ismath(int ch) {
return (ch == '$');
}
static inline bool iswordchar(int ch) {
return ((ch >= 'a') && (ch <= 'z')) || ((ch >= 'A') && (ch <= 'Z'));
}
static inline bool issymbol(int ch){
return (ch == '~') || (ch == '`') || (ch == '\'')|| (ch == '~') ||
(ch == '#') || (ch == '^') || (ch == '&') || (ch == '+') ||
(ch == '-') || (ch == '=') || (ch == '>') || (ch == '<');
}
/**************************************************
** Function:
**
**
***************************************************/
// pos is "\"
// return length of command in text
int ParseCommand(unsigned int pos, Accessor &styler, char *command)
{
int length=0;
char ch=styler.SafeGetCharAt(pos+1);
if(ch==',' || ch==':' || ch==';' || ch=='%'){
command[0]=ch;
command[1]=0;
return 1;
}
// find end
while(iswordchar(ch) && !isnumber(ch) && ch!='_' && ch!='.'){
command[length]=ch;
length++;
ch=styler.SafeGetCharAt(pos+length+1);
}
command[length]='\0';
if(!length) return 0;
return length+1;
}
// pos is letter
// return length of word
int ParseWord(unsigned int pos, Accessor &styler, char *word)
{
int length=0;
char ch=styler.SafeGetCharAt(pos);
*word=0;
while(isletterfunction(ch)){
word[length]=ch;
length++;
ch=styler.SafeGetCharAt(pos+length);
}
word[length]=0;
return length;
}
// pos is letter
// return length of word
int ParseAlphaWord(unsigned int pos, Accessor &styler, char *word)
{
int length=0;
char ch=styler.SafeGetCharAt(pos);
*word=0;
while(isalpha(ch)){
word[length]=ch;
length++;
ch=styler.SafeGetCharAt(pos+length);
}
word[length]=0;
return length;
}
// pos is "%"
// return length of comment
int ParseComment(int pos, int endPos, Accessor &styler)
{
int length=1;
char ch=styler.SafeGetCharAt(pos+length);
while(ch!='\n' && ch!='\r' && ch!='\0' && pos+length<endPos){
length++;
ch=styler.SafeGetCharAt(pos+length);
}
return (length-1) ? length : 1;
}
// Brace Group ----------------------------------------------------
// pos is "{"
// return length group
int ParseBraceGroup(int pos, char *word, Accessor &styler)
{
int length=0;
char ch=styler.SafeGetCharAt(pos+1);
if(ch=='}') return 0; // {}
while(ch!='}' && ch!='\0' && ch!='\n' && ch!='\r' && ch!=' '){
word[length]=ch;
length++;
ch=styler.SafeGetCharAt(pos+length+1);
}
if(ch!='}') return 0; // unmached
word[length]='\0';
return length+1;
}
// String ----------------------------------------------------
// pos is "\""
// return length group
int ParseString(int pos, int endPos, Accessor &styler, int *flag)
{
int length=0;
char ch=styler.SafeGetCharAt(pos+1);
if(ch=='\"'){
*flag=1;
return 2; // ""
}
if(ch=='\0' || ch=='\n' || ch=='\r' || pos+length+1==endPos){
*flag=0;
return 1;
}
while(ch!='\"' && ch!='\0' && ch!='\n' && ch!='\r' && pos+length<endPos){
if(ch=='\\'){
ch=styler.SafeGetCharAt(pos+length+1);
length++;
}
length++;
ch=styler.SafeGetCharAt(pos+length+1);
}
if(ch!='\"') *flag=0; // unmached
else *flag=1;
return length+2;
}
int ParseChar(int pos, int endPos, Accessor &styler, int *flag)
{
int length=0;
char ch=styler.SafeGetCharAt(pos+1);
if(ch=='\''){
*flag=1;
return 2; // ""
}
if(ch=='\0' || ch=='\n' || ch=='\r' || pos+length+1==endPos){
*flag=0;
return 1;
}
while(ch!='\'' && ch!='\0' && ch!='\n' && ch!='\r' && pos+length<endPos){
if(ch=='\\'){
ch=styler.SafeGetCharAt(pos+length+1);
length++;
}
length++;
ch=styler.SafeGetCharAt(pos+length+1);
}
if(ch!='\'') *flag=0; // unmached
else *flag=1;
return length+2;
}
// classifyFoldPointTeX: borrowed from VisualTeX with modifications
static int classifyFoldPointTeX(const char* s) {
int lev=0;
if (!(isdigit(s[0]) || (s[0] == '.'))){
if (strcmp(s, "begin")==0||strcmp(s,"StartFolding")==0||
strcmp(s,"section")==0||strcmp(s,"chapter")==0||
strcmp(s,"part")==0||strcmp(s,"subsection")==0||
strcmp(s,"subsubsection")==0||strcmp(s,"CJKfamily")==0||
strcmp(s,"title")==0||strcmp(s,"documentclass")==0)
lev=1;
if (strcmp(s,"EndFolding")==0||strcmp(s, "end")==0||
strcmp(s,"maketitle")==0)
lev=-1;
}
return lev;
}
bool iscommandstyle(int style)
{
return (style==TEX_COMMAND) || (style==TEX_COMMAND1) || (style==TEX_COMMAND2) || (style==TEX_COMMAND3) || (style==TEX_COMMAND4);
}
// FoldTeXDoc: borrowed from VisualTeX with modifications
static void FoldTexDoc(unsigned int startPos, int length, int initStyle, WordList *[], Accessor &styler)
{
bool foldCompact = styler.GetPropertyInt("fold.compact", 1) != 0;
unsigned int endPos = startPos+length;
int visibleChars=0;
int lineCurrent=styler.GetLine(startPos);
int levelPrev=styler.LevelAt(lineCurrent) & SC_FOLDLEVELNUMBERMASK;
int levelCurrent=levelPrev;
char chNext=styler[startPos];
int style=initStyle;
char buffer[100]="";
for (unsigned int i=startPos; i < endPos; i++) {
char ch=chNext;
chNext=styler.SafeGetCharAt(i+1);
style = styler.StyleAt(i);
bool atEOL = (ch == '\r' && chNext != '\n') || (ch == '\n');
if(ch=='\\' && iscommandstyle(style)) {
ParseCommand(i, styler, buffer);
levelCurrent += classifyFoldPointTeX(buffer);
}
//--------------------------------- Added by instanton ---------------------------------------
char chNext2;
char chNext3;
char chNext4;
char chNext5;
char chNext6;
chNext2=styler.SafeGetCharAt(i+2);
chNext3=styler.SafeGetCharAt(i+3);
chNext4=styler.SafeGetCharAt(i+4);
chNext5=styler.SafeGetCharAt(i+5);
chNext6=styler.SafeGetCharAt(i+6);
bool atEOSec = (ch == '\r' || ch=='\n') &&
(chNext == '\\') && (chNext2=='s') &&
((chNext3=='e'&& chNext4=='c' && chNext5=='t')||
(chNext3=='u' && chNext4=='b' && chNext5=='s'));
bool atEOChap = (ch == '\r' || ch=='\n') &&
(chNext == '\\') && (chNext2=='c') &&
(chNext3=='h')&& (chNext4=='a') && (chNext5=='p');
bool atBeginMark = (ch== '%') && (chNext == '\\') && (chNext2 == 'b') &&
(chNext3 =='e') && (chNext4 =='g') && (chNext5 =='i') &&
(chNext6 =='n');
bool atEndMark = (ch=='%') && (chNext == '\\') && (chNext2 =='e') &&
(chNext3 =='n') && (chNext4 =='d');
bool atEOCJK = (ch=='\r'|| ch=='\n') && (chNext == '\\') &&
(chNext2=='C') && (chNext3=='J')&& (chNext4=='K') &&
(chNext5=='f') && (chNext6 =='a');
if(atBeginMark){
levelCurrent+=1;
}
if(atEOSec || atEOChap || atEndMark || atEOCJK){
// if(atEOSec || atEOChap || atEndMark){
levelCurrent-=1;
}
if(ch=='\\' && chNext=='['){
levelCurrent+=1;
}
if(ch=='\\' && chNext==']'){
levelCurrent-=1;
}
//---------------------------------------------------------------------------------------------
if (atEOL) {
int lev = levelPrev;
if (visibleChars == 0 && foldCompact)
lev |= SC_FOLDLEVELWHITEFLAG;
if ((levelCurrent > levelPrev) && (visibleChars > 0))
lev |= SC_FOLDLEVELHEADERFLAG;
if (lev != styler.LevelAt(lineCurrent)) {
styler.SetLevel(lineCurrent, lev);
}
lineCurrent++;
levelPrev = levelCurrent;
visibleChars = 0;
}
if (!isspacechar(ch))
visibleChars++;
}
// Fill in the real level of the next line, keeping the current flags as they will be filled in later
int flagsNext = styler.LevelAt(lineCurrent) & ~SC_FOLDLEVELNUMBERMASK;
styler.SetLevel(lineCurrent, levelPrev | flagsNext);
}
static const char * const texWordListDesc[] = {
"TeX, eTeX, pdfTeX, Omega",
"ConTeXt Dutch",
"ConTeXt English",
"ConTeXt German",
"ConTeXt Czech",
"ConTeXt Italian",
"ConTeXt Romanian",
0,
} ;
LexerModule lmTeX(SCLEX_TEX, ColouriseTeXDoc, "tex", FoldTexDoc, texWordListDesc);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -