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

📄 highlight.c

📁 nedit 是一款linux下的开发源码的功能强大的编辑器
💻 C
📖 第 1 页 / 共 5 页
字号:
       display(s) of window, and redisplay without highlighting */    RemoveWidgetHighlight(window->textArea);    for (i=0; i<window->nPanes; i++)	RemoveWidgetHighlight(window->textPanes[i]);            /* Re-size the window to fit the primary font properly & tell the window       manager about the potential line-height change as well */    updateWindowHeight(window, oldFontHeight);    UpdateWMSizeHints(window);    UpdateMinPaneHeights(window);}/*** Free highlighting data from a window destined for destruction, without** redisplaying.*/void FreeHighlightingData(WindowInfo *window){    int i;        if (window->highlightData == NULL)	return;        /* Free and remove the highlight data from the window */    freeHighlightData((windowHighlightData *)window->highlightData);    window->highlightData = NULL;        /* The text display may make a last desperate attempt to access highlight       information when it is destroyed, which would be a disaster. */    ((TextWidget)window->textArea)->text.textD->styleBuffer = NULL;    for (i=0; i<window->nPanes; i++)	((TextWidget)window->textPanes[i])->text.textD->styleBuffer = NULL;}/*** Attach style information from a window's highlight data to a** text widget and redisplay.*/void AttachHighlightToWidget(Widget widget, WindowInfo *window){    windowHighlightData *highlightData =    	    (windowHighlightData *)window->highlightData;        TextDAttachHighlightData(((TextWidget)widget)->text.textD,    	    highlightData->styleBuffer, highlightData->styleTable,    	    highlightData->nStyles, UNFINISHED_STYLE, handleUnparsedRegionCB,    	    window);}/*** Remove style information from a text widget and redisplay it.*/void RemoveWidgetHighlight(Widget widget){    TextDAttachHighlightData(((TextWidget)widget)->text.textD,    	    NULL, NULL, 0, UNFINISHED_STYLE, NULL, NULL);}/*** Change highlight fonts and/or styles in a highlighted window, without** re-parsing.*/void UpdateHighlightStyles(WindowInfo *window){    patternSet *patterns;    windowHighlightData *highlightData;    windowHighlightData *oldHighlightData =    	    (windowHighlightData *)window->highlightData;    textBuffer *styleBuffer;    int i;        /* Do nothing if window not highlighted */    if (window->highlightData == NULL)    	return;    /* Find the pattern set for the window's current language mode */    patterns = findPatternsForWindow(window, False);    if (patterns == NULL) {    	StopHighlighting(window);    	return;    }        /* Build new patterns */    highlightData = createHighlightData(window, patterns);    if (highlightData == NULL) {    	StopHighlighting(window);    	return;    }    /* Update highlight pattern data in the window data structure, but       preserve all of the effort that went in to parsing the buffer       by swapping it with the empty one in highlightData (which is then       freed in freeHighlightData) */    styleBuffer = oldHighlightData->styleBuffer;    oldHighlightData->styleBuffer = highlightData->styleBuffer;    freeHighlightData(oldHighlightData);    highlightData->styleBuffer = styleBuffer;    window->highlightData = highlightData;        /* Attach new highlight information to text widgets in each pane       (and redraw) */    AttachHighlightToWidget(window->textArea, window);    for (i=0; i<window->nPanes; i++)	AttachHighlightToWidget(window->textPanes[i], window);}/*** Do a test compile of patterns in "patSet" and report problems to the** user via dialog.  Returns True if patterns are ok.**** This is somewhat kludgy in that it uses createHighlightData, which** requires a window to find the fonts to use, and just uses a random** window from the window list.  Since the window is used to get the** dialog parent as well, in non-popups-under-pointer mode, these dialogs** will appear in odd places on the screen.*/int TestHighlightPatterns(patternSet *patSet){    windowHighlightData *highlightData;        /* Compile the patterns (passing a random window as a source for fonts, and       parent for dialogs, since we really don't care what fonts are used) */    highlightData = createHighlightData(WindowList, patSet);    if (highlightData == NULL)    	return False;    freeHighlightData(highlightData);    return True;}/*** Returns the highlight style of the character at a given position of a ** window. To avoid breaking encapsulation, the highlight style is converted ** to a void* pointer (no other module has to know that characters are used** to represent highlight styles; that would complicate future extensions).** Returns NULL if the window has highlighting turned off.** The only guarantee that this function offers, is that when the same** pointer is returned for two positions, the corresponding characters have** the same highlight style.**/void* GetHighlightInfo(WindowInfo *window, int pos){    int style;    highlightDataRec *pattern = NULL;    windowHighlightData *highlightData = 	(windowHighlightData *)window->highlightData;     if (!highlightData)	return NULL;        /* Be careful with signed/unsigned conversions. NO conversion here! */    style = (int)BufGetCharacter(highlightData->styleBuffer, pos);        /* Beware of unparsed regions. */    if (style == UNFINISHED_STYLE) {	handleUnparsedRegion(window, highlightData->styleBuffer, pos);	style = (int)BufGetCharacter(highlightData->styleBuffer, pos);    }	        if (highlightData->pass1Patterns) {       pattern = patternOfStyle(highlightData->pass1Patterns, style);    }        if (!pattern && highlightData->pass2Patterns) {	pattern = patternOfStyle(highlightData->pass2Patterns, style);    }        if (!pattern) {	return NULL;    }    return (void*)pattern->userStyleIndex;    }    /*** Free allocated memory associated with highlight data, including compiled** regular expressions, style buffer and style table.  Note: be sure to** NULL out the widget references to the objects in this structure before** calling this.  Because of the slow, multi-phase destruction of** widgets, this data can be referenced even AFTER destroying the widget.*/static void freeHighlightData(windowHighlightData *hd){    if (hd == NULL)    	return;    if (hd->pass1Patterns != NULL)    	freePatterns(hd->pass1Patterns);    if (hd->pass2Patterns != NULL)    	freePatterns(hd->pass2Patterns);    XtFree(hd->parentStyles);    BufFree(hd->styleBuffer);    XtFree((char *)hd->styleTable);    XtFree((char *)hd);}/*** Find the pattern set matching the window's current language mode, or** tell the user if it can't be done (if warn is True) and return NULL.*/static patternSet *findPatternsForWindow(WindowInfo *window, int warn){    patternSet *patterns;    char *modeName;        /* Find the window's language mode.  If none is set, warn user */    modeName = LanguageModeName(window->languageMode);    if (modeName == NULL) {    	if (warn)    	    DialogF(DF_WARN, window->shell, 1, "Language Mode",                    "No language-specific mode has been set for this file.\n\n"                    "To use syntax highlighting in this window, please select a\n"                    "language from the Preferences -> Language Modes menu.\n\n"                    "New language modes and syntax highlighting patterns can be\n"                    "added via Preferences -> Default Settings -> Language Modes,\n"                    "and Preferences -> Default Settings -> Syntax Highlighting.",                    "Dismiss");    	return NULL;    }        /* Look up the appropriate pattern for the language */    patterns = FindPatternSet(modeName);    if (patterns == NULL)    {        if (warn)        {            DialogF(DF_WARN, window->shell, 1, "Language Mode",                    "Syntax highlighting is not available in language\n"                    "mode %s.\n\n"                    "You can create new syntax highlight patterns in the\n"                    "Preferences -> Default Settings -> Syntax Highlighting\n"                    "dialog, or choose a different language mode from:\n"                    "Preferences -> Language Mode.", "Dismiss", modeName);            return NULL;        }    }        return patterns;}/*** Create complete syntax highlighting information from "patternSrc", using** highlighting fonts from "window", includes pattern compilation.  If errors** are encountered, warns user with a dialog and returns NULL.  To free the** allocated components of the returned data structure, use freeHighlightData.*/static windowHighlightData *createHighlightData(WindowInfo *window,    	patternSet *patSet){    highlightPattern *patternSrc = patSet->patterns;    int nPatterns = patSet->nPatterns;    int contextLines = patSet->lineContext;    int contextChars = patSet->charContext;    int i, nPass1Patterns, nPass2Patterns;    int noPass1, noPass2;    char *parentStyles, *parentStylesPtr, *parentName;    highlightPattern *pass1PatternSrc, *pass2PatternSrc, *p1Ptr, *p2Ptr;    styleTableEntry *styleTable, *styleTablePtr;    textBuffer *styleBuf;    highlightDataRec *pass1Pats, *pass2Pats;    windowHighlightData *highlightData;        /* The highlighting code can't handle empty pattern sets, quietly say no */    if (nPatterns == 0)    {        return NULL;    }    /* Check that the styles and parent pattern names actually exist */    if (!NamedStyleExists("Plain"))    {        DialogF(DF_WARN, window->shell, 1, "Highlight Style",                "Highlight style \"plain\" is missing", "Dismiss");        return NULL;    }    for (i=0; i<nPatterns; i++)    {        if (patternSrc[i].subPatternOf != NULL                && indexOfNamedPattern(patternSrc, nPatterns,                        patternSrc[i].subPatternOf) == -1)        {            DialogF(DF_WARN, window->shell, 1, "Parent Pattern",                    "Parent field \"%s\" in pattern \"%s\"\n"                    "does not match any highlight patterns in this set",                    "Dismiss", patternSrc[i].subPatternOf, patternSrc[i].name);            return NULL;        }    }    for (i=0; i<nPatterns; i++)    {        if (!NamedStyleExists(patternSrc[i].style))        {            DialogF(DF_WARN, window->shell, 1, "Highlight Style",                    "Style \"%s\" named in pattern \"%s\"\n"                    "does not match any existing style", "Dismiss",                    patternSrc[i].style, patternSrc[i].name);            return NULL;        }    }        /* Make DEFER_PARSING flags agree with top level patterns (originally,       individual flags had to be correct and were checked here, but dialog now       shows this setting only on top patterns which is much less confusing) */    for (i = 0; i < nPatterns; i++)    {        if (patternSrc[i].subPatternOf != NULL)        {            int parentindex;            parentindex=findTopLevelParentIndex(patternSrc, nPatterns, i);            if (parentindex==-1)            {                DialogF(DF_WARN, window->shell, 1, "Parent Pattern",                        "Pattern \"%s\" does not have valid parent", "Dismiss",                        patternSrc[i].name);                return NULL;            }            if (patternSrc[parentindex].flags & DEFER_PARSING)            {                patternSrc[i].flags |= DEFER_PARSING;            } else            {                patternSrc[i].flags &= ~DEFER_PARSING;            }        }    }    /* Sort patterns into those to be used in pass 1 parsing, and those to       be used in pass 2, and add default pattern (0) to each list */    nPass1Patterns = 1;    nPass2Patterns = 1;    for (i=0; i<nPatterns; i++)    	if (patternSrc[i].flags & DEFER_PARSING)    	    nPass2Patterns++;    	else    	    nPass1Patterns++;    p1Ptr = pass1PatternSrc = (highlightPattern *)XtMalloc(    	    sizeof(highlightPattern) * nPass1Patterns);    p2Ptr = pass2PatternSrc = (highlightPattern *)XtMalloc(    	    sizeof(highlightPattern) * nPass2Patterns);    p1Ptr->name = p2Ptr->name = "top";    p1Ptr->startRE = p2Ptr->startRE = NULL;    p1Ptr->endRE = p2Ptr->endRE = NULL;    p1Ptr->errorRE = p2Ptr->errorRE = NULL;

⌨️ 快捷键说明

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