⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lexobjc.cxx.svn-base

📁 Notepad++ is a generic source code editor (it tries to be anyway) and Notepad replacement written in
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
	}
	sc.Complete();
}

static bool IsStreamCommentStyle(int style) {
	return style == SCE_C_COMMENT ||
	       style == SCE_C_COMMENTDOC ||
	       style == SCE_C_COMMENTDOCKEYWORD ||
	       style == SCE_C_COMMENTDOCKEYWORDERROR;
}

static bool matchKeyword(unsigned int start, WordList &keywords, Accessor &styler, int keywordtype) {
	bool FoundKeyword = false;

	for (unsigned int i = 0;
	        strlen(keywords[i]) > 0 && !FoundKeyword;
	        i++) {
		if (atoi(keywords[i]) == keywordtype) {
			FoundKeyword = styler.Match(start, ((char *)keywords[i]) + 2);
		}
	}
	return FoundKeyword;
}

static bool IsCommentLine(int line, Accessor &styler) {
	unsigned int Pos = styler.LineStart(line);
	while (styler.GetLine(Pos) == line) {
		int PosStyle = styler.StyleAt(Pos);

		if (	!IsStreamCommentStyle(PosStyle)
		        &&
		        PosStyle != SCE_C_COMMENTLINEDOC
		        &&
		        PosStyle != SCE_C_COMMENTLINE
		        &&
		        !IsASpace(styler.SafeGetCharAt(Pos))
		   )
			return false;
		Pos++;
	}

	return true;
}

static void FoldBoxObjCDoc(unsigned int startPos, int length, int initStyle, WordList *keywordlists[],
                          Accessor &styler) {

	WordList &keywords4 = *keywordlists[3];

	bool foldComment = styler.GetPropertyInt("fold.comment") != 0;
	bool foldPreprocessor = styler.GetPropertyInt("fold.preprocessor") != 0;
	bool foldCompact = styler.GetPropertyInt("fold.compact", 1) != 0;
	bool firstLine = true;
	unsigned int endPos = startPos + length;
	int visibleChars = 0;
	int lineCurrent = styler.GetLine(startPos);
	int levelPrev = styler.LevelAt(lineCurrent) & SC_FOLDLEVELNUMBERMASK;
	int levelCurrent = levelPrev;
	int levelPrevPrev;
	int levelFlags = 0;
	int levelUnindent = 0;
	char chNext = styler[startPos];
	int styleNext = styler.StyleAt(startPos);
	int style = initStyle;

	if (lineCurrent == 0) {
		levelPrevPrev = levelPrev;
	} else {
		levelPrevPrev = styler.LevelAt(lineCurrent - 1) & SC_FOLDLEVELNUMBERMASK;
	}

	for (unsigned int i = startPos; i < endPos; i++) {
		char ch = chNext;
		chNext = styler.SafeGetCharAt(i + 1);
		int stylePrev = style;
		style = styleNext;
		styleNext = styler.StyleAt(i + 1);

		bool atEOL = (ch == '\r' && chNext != '\n') || (ch == '\n');

		if (foldComment && IsStreamCommentStyle(style)) {
			if (!IsStreamCommentStyle(stylePrev)) {
				levelCurrent++;
			} else if (!IsStreamCommentStyle(styleNext) && !atEOL) {
				// Comments don't end at end of line and the next character may be unstyled.
				levelCurrent--;
			}
		}
/*
		if (foldComment && (style == SCE_C_COMMENTLINE)) {
			if ((ch == '/') && (chNext == '/')) {
				char chNext2 = styler.SafeGetCharAt(i + 2);
				if (chNext2 == '{') {
					levelCurrent++;
				} else if (chNext2 == '}') {
					levelCurrent--;
				}
			}
		}
*/
		if (foldPreprocessor && (style == SCE_C_PREPROCESSOR)) {
			if (ch == '#') {
				unsigned int j = i + 1;
				while ((j < endPos) && IsASpaceOrTab(styler.SafeGetCharAt(j))) {
					j++;
				}

				if (styler.Match(j, "region") || styler.Match(j, "if")) {
					levelCurrent++;
				} else if (styler.Match(j, "end")) {
					levelCurrent--;
				}
			}
		}

		if (style == SCE_C_OPERATOR
		        ||
		        style == SCE_C_COMMENT
		        ||
		        style == SCE_C_COMMENTLINE) {

			if (ch == '{') {
				levelCurrent++;
				// Special handling if line has closing brace followed by opening brace.
				if (levelCurrent == levelPrev) {
					if (firstLine)
						levelUnindent = 1;
					else
						levelUnindent = -1;
				}
			} else if (ch == '}') {
				levelCurrent--;
			}
		}

		if (style == SCE_OBJC_DIRECTIVE)
		{
			if (ch == '@') 
			{
				unsigned int j = i + 1;
				if (styler.Match(j, "interface") || styler.Match(j, "implementation") || styler.Match(j, "protocol")) 
				{
					levelCurrent++;
				} 
				else if (styler.Match(j, "end")) 
				{
					levelCurrent--;
				}
			}
		}
		
		/* Check for fold header keyword at beginning of word */
		if ((style == SCE_C_WORD || style == SCE_C_COMMENT || style == SCE_C_COMMENTLINE)
		        &&
		        (style != stylePrev)) {
			if (matchKeyword(i, keywords4, styler, KEYWORD_BOXHEADER)) {
				int line;
				/* Loop backwards all empty or comment lines */
				for (line = lineCurrent - 1;
				        line >= 0
				        &&
				        levelCurrent == (styler.LevelAt(line) & SC_FOLDLEVELNUMBERMASK)
				        &&
				        (styler.LevelAt(line) & SC_FOLDLEVELBOXFOOTERFLAG) == 0
				        &&
				        IsCommentLine(line, styler);
				        line--) {
					/* just loop backwards */;
				}

				line++;
				/* Set Box header flag (if the previous line has no footer line) */
				if ((styler.LevelAt(line) & SC_FOLDLEVELBOXFOOTERFLAG) == 0) {
					if (line == lineCurrent) {
						/* in current line */
						levelFlags |= SC_FOLDLEVELBOXHEADERFLAG;
					} else {
						/* at top of all preceding comment lines */
						styler.SetLevel(line, styler.LevelAt(line)
						                | SC_FOLDLEVELBOXHEADERFLAG);
					}
				}
			}
		}

		if (matchKeyword(i, keywords4, styler, KEYWORD_FOLDCONTRACTED)) {
			levelFlags |= SC_FOLDLEVELCONTRACTED;
		}

		if (atEOL) {
			int lev;
			// Compute level correction for special case: '} else {'
			if (levelUnindent < 0) {
				levelPrev += levelUnindent;
			} else {
				levelCurrent += levelUnindent;
			}

			lev = levelPrev;
			if (visibleChars == 0 && foldCompact)
				lev |= SC_FOLDLEVELWHITEFLAG;
			// Produce additional footer line (e.g. after closed if)
			if (visibleChars == 0
			        &&
			        (levelPrev < levelPrevPrev))
				lev |= SC_FOLDLEVELBOXFOOTERFLAG;
			// Produce footer line at line before (special handling for '} else {'
			if (levelPrev < levelPrevPrev) {
				styler.SetLevel(lineCurrent - 1,
				                styler.LevelAt(lineCurrent - 1) | SC_FOLDLEVELBOXFOOTERFLAG);
			}
			// Mark the fold header (the line that is always visible)
			if ((levelCurrent > levelPrev) && (visibleChars > 0))
				lev |= SC_FOLDLEVELHEADERFLAG;
			// Show a footer line at end of fold
			if (levelCurrent < levelPrev)
				lev |= SC_FOLDLEVELBOXFOOTERFLAG;
			/* Show a footer line at the end of each procedure (level == SC_FOLDLEVELBASE) */
			if ((levelPrev == SC_FOLDLEVELBASE)
			        &&
			        (levelPrevPrev > SC_FOLDLEVELBASE)
			        &&
			        (visibleChars == 0)) {
				lev |= SC_FOLDLEVELBOXFOOTERFLAG;
			}

			lev |= levelFlags;
			if (lev != styler.LevelAt(lineCurrent)) {
				styler.SetLevel(lineCurrent, lev);
			}

			lineCurrent++;
			levelPrevPrev = levelPrev;
			levelPrev = levelCurrent;
			levelUnindent = 0;
			visibleChars = 0;
			levelFlags = 0;
			firstLine = false;
		}

		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 void FoldNoBoxObjCDoc(unsigned int startPos, int length, int initStyle,
                            Accessor &styler) {
	bool foldComment = styler.GetPropertyInt("fold.comment") != 0;
	bool foldPreprocessor = styler.GetPropertyInt("fold.preprocessor") != 0;
	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 styleNext = styler.StyleAt(startPos);
	int style = initStyle;
	for (unsigned int i = startPos; i < endPos; i++) {
		char ch = chNext;
		chNext = styler.SafeGetCharAt(i + 1);
		int stylePrev = style;
		style = styleNext;
		styleNext = styler.StyleAt(i + 1);
		bool atEOL = (ch == '\r' && chNext != '\n') || (ch == '\n');
		if (foldComment && IsStreamCommentStyle(style)) {
			if (!IsStreamCommentStyle(stylePrev)) {
				levelCurrent++;
			} else if (!IsStreamCommentStyle(styleNext) && !atEOL) {
				// Comments don't end at end of line and the next character may be unstyled.
				levelCurrent--;
			}
		}
		/*if (foldComment && (style == SCE_C_COMMENTLINE)) {
			if ((ch == '/') && (chNext == '/')) {
				char chNext2 = styler.SafeGetCharAt(i + 2);
				if (chNext2 == '{') {
					levelCurrent++;
				} else if (chNext2 == '}') {
					levelCurrent--;
				}
			}
		}*/
		if (foldPreprocessor && (style == SCE_C_PREPROCESSOR)) {
			if (ch == '#') {
				unsigned int j = i + 1;
				while ((j < endPos) && IsASpaceOrTab(styler.SafeGetCharAt(j))) {
					j++;
				}
				if (styler.Match(j, "region") || styler.Match(j, "if")) {
					levelCurrent++;
				} else if (styler.Match(j, "end")) {
					levelCurrent--;
				}
			}
		}
		if (style == SCE_C_OPERATOR) {
			if (ch == '{') {
				levelCurrent++;
			} else if (ch == '}') {
				levelCurrent--;
			}
		}
	
		if (style == SCE_OBJC_DIRECTIVE)
		{
			if (ch == '@') 
			{
				unsigned int j = i + 1;
				if (styler.Match(j, "interface") || styler.Match(j, "implementation") || styler.Match(j, "protocol")) 
				{
					levelCurrent++;
				} 
				else if (styler.Match(j, "end")) 
				{
					levelCurrent--;
				}
			}
		}
		
		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 void FoldObjCDoc(unsigned int startPos, int length, int initStyle, WordList *keywordlists[],
                       Accessor &styler) {

	int foldFlags = styler.GetPropertyInt("fold.flags") ;
	bool foldBox = ((foldFlags & SC_FOLDFLAG_BOX) == SC_FOLDFLAG_BOX);

	if (foldBox) {
		FoldBoxObjCDoc(startPos, length, initStyle, keywordlists, styler);
	} else {
		FoldNoBoxObjCDoc(startPos, length, initStyle, styler);
	}
}

static const char * const cppWordLists[] = {
            "Primary keywords and identifiers",
            "Secondary keywords and identifiers",
            "Documentation comment keywords",
            "Fold header keywords",
            0,
        };

static void ColouriseObjCDocSensitive(unsigned int startPos, int length, int initStyle, WordList *keywordlists[],
                                     Accessor &styler) {
	ColouriseObjCDoc(startPos, length, initStyle, keywordlists, styler, true);
}

/*
static void ColouriseCppDocInsensitive(unsigned int startPos, int length, int initStyle, WordList *keywordlists[],
                                       Accessor &styler) {
	ColouriseCppDoc(startPos, length, initStyle, keywordlists, styler, false);
}
*/
LexerModule lmObjC(SCLEX_OBJC, ColouriseObjCDocSensitive, "cpp", FoldObjCDoc, cppWordLists);
//LexerModule lmCPPNoCase(SCLEX_CPPNOCASE, ColouriseCppDocInsensitive, "cppnocase", FoldCppDoc, cppWordLists);
//LexerModule lmTCL(SCLEX_TCL, ColouriseCppDocSensitive, "tcl", FoldCppDoc, cppWordLists);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -