Index: source/preferences.c =================================================================== RCS file: /cvsroot/nedit/nedit/source/preferences.c,v retrieving revision 1.126 diff -u -b -r1.126 preferences.c --- source/preferences.c 20 Aug 2004 19:33:20 -0000 1.126 +++ source/preferences.c 9 Sep 2004 18:24:23 -0000 @@ -4201,6 +4201,42 @@ } /* + * Unload the default calltips files for a language mode if it is + * not used by any open document (other than ). + */ +static void unloadDefaultTipsFiles( int mode, WindowInfo *ignore ) +{ + WindowInfo *wi; + + if (mode != PLAIN_LANGUAGE_MODE && LanguageModes[mode]->defTipsFile) { + for (wi = WindowList; wi; wi = wi->next) + if (wi != ignore && wi->languageMode == mode) + break; + if (!wi) { + /* No other window uses this language mode */ + DeleteTagsFile( LanguageModes[mode]->defTipsFile, TIP ); + } else { + return; /* We didn't unload anything, so no need to reload */ + } + } + + /* Make sure we didn't accidentally delete a default calltips file that + also belongs to another language mode */ + for (wi = WindowList; wi; wi = wi->next) { + if (wi == ignore) + continue; + mode = wi->languageMode; + if (mode != PLAIN_LANGUAGE_MODE && LanguageModes[mode]->defTipsFile) + if (AddTagsFile( LanguageModes[mode]->defTipsFile, TIP ) == FALSE) + fprintf( stderr, "Error loading default calltips file\n" + "for language mode \"%s\":\n \"%s\"\n", + LanguageModes[mode]->name, + LanguageModes[mode]->defTipsFile ); + } +} + + +/* ** Change the language mode to the one indexed by "mode", reseting word ** delimiters, syntax highlighting and other mode specific parameters */ @@ -4223,22 +4259,16 @@ /* Unload oldMode's default calltips file if there are no more windows in that mode and the mode has a default file */ - if (oldMode != PLAIN_LANGUAGE_MODE && LanguageModes[oldMode]->defTipsFile) { - for (wi = WindowList; wi; wi = wi->next) - if (wi->languageMode == oldMode) break; - if (!wi) DeleteTagsFile( LanguageModes[oldMode]->defTipsFile, TIP ); - } + unloadDefaultTipsFiles( oldMode, window ); + + /* Load the default tips file for the new mode */ + if (mode != PLAIN_LANGUAGE_MODE && LanguageModes[mode]->defTipsFile) + if (AddTagsFile( LanguageModes[mode]->defTipsFile, TIP ) == FALSE) + fprintf( stderr, "Error loading default calltips file\n" + "for language mode \"%s\":\n \"%s\"\n", + LanguageModes[mode]->name, + LanguageModes[mode]->defTipsFile ); - /* Make sure we didn't accidentally delete a default calltips file that - also belongs another language mode (also load the tips file for the - new lang. mode) */ - for (wi = WindowList; wi; wi = wi->next) { - i = wi->languageMode; - if (i != PLAIN_LANGUAGE_MODE && LanguageModes[i]->defTipsFile) - if (AddTagsFile( LanguageModes[i]->defTipsFile, TIP ) == FALSE) - fprintf( stderr, "Error loading default calltips file:\n" - " \"%s\"\n", LanguageModes[i]->defTipsFile ); - } /* Set delimiters for all text widgets */ if (mode == PLAIN_LANGUAGE_MODE || LanguageModes[mode]->delimiters == NULL) @@ -5591,25 +5621,7 @@ WindowInfo *wi; mode = window->languageMode; - if (mode != PLAIN_LANGUAGE_MODE && LanguageModes[mode]->defTipsFile) { - for (wi = WindowList; wi; wi = wi->next) - if (wi->languageMode == mode && wi != window) - break; - if (!wi) /* If we got to end of WindowList... */ - DeleteTagsFile( LanguageModes[mode]->defTipsFile, TIP ); - } - - /* Make sure we didn't accidentally delete a default calltips file that - also belongs to another language mode */ - for (wi = WindowList; wi; wi = wi->next) { - if (wi == window) - continue; - mode = wi->languageMode; - if (mode != PLAIN_LANGUAGE_MODE && LanguageModes[mode]->defTipsFile) - if (AddTagsFile( LanguageModes[mode]->defTipsFile, TIP ) == FALSE) - fprintf( stderr, "Error loading default calltips file:\n" - " \"%s\"\n", LanguageModes[mode]->defTipsFile ); - } + unloadDefaultTipsFiles( mode, window ); } /******************************************************************************