3 source/preferences.c | 64 +++++++++++++++++++++++++++++++--------------------
4 1 file changed, 39 insertions(+), 25 deletions(-)
6 diff --quilt old/source/preferences.c new/source/preferences.c
7 --- old/source/preferences.c
8 +++ new/source/preferences.c
9 @@ -3216,11 +3216,13 @@ the list on the left. To add a new lang
10 RemapDeleteKey(LMDialog.nameW);
11 XtVaSetValues(nameLbl, XmNuserData, LMDialog.nameW, NULL);
13 extLbl = XtVaCreateManagedWidget("extLbl", xmLabelGadgetClass, form,
15 - s1=XmStringCreateSimple("File extensions (separate w/ space)"),
17 +"File extensions or regexes (in single quotes)\n\
18 +(separate w/ space)"),
20 XmNalignment, XmALIGNMENT_BEGINNING,
21 XmNleftAttachment, XmATTACH_POSITION,
22 XmNleftPosition, LIST_RIGHT,
23 XmNtopAttachment, XmATTACH_WIDGET,
24 @@ -4816,51 +4818,63 @@ static int matchLanguageMode(WindowInfo
25 int i, j, fileNameLen, extLen, beginPos, endPos, start;
26 const char *versionExtendedPath;
28 /*... look for an explicit mode statement first */
30 - /* Do a regular expression search on for recognition pattern */
31 - first200 = BufGetRange(window->buffer, 0, 200);
32 - for (i=0; i<NLanguageModes; i++) {
33 - if (LanguageModes[i]->recognitionExpr != NULL) {
34 - if (SearchString(first200, LanguageModes[i]->recognitionExpr,
35 - SEARCH_FORWARD, SEARCH_REGEX, False, 0, &beginPos,
36 - &endPos, NULL, NULL, NULL))
45 /* Look at file extension ("@@/" starts a ClearCase version extended path,
46 which gets appended after the file extension, and therefore must be
47 stripped off to recognize the extension to make ClearCase users happy) */
48 fileNameLen = strlen(window->filename);
50 if (strchr(window->filename, ';') != NULL)
51 - fileNameLen = strchr(window->filename, ';') - window->filename;
52 + fileNameLen = strchr(window->filename, ';') - window->filename;
54 if ((versionExtendedPath = GetClearCaseVersionExtendedPath(window->filename)) != NULL)
55 fileNameLen = versionExtendedPath - window->filename;
57 for (i=0; i<NLanguageModes; i++) {
58 - for (j=0; j<LanguageModes[i]->nExtensions; j++) {
59 - ext = LanguageModes[i]->extensions[j];
60 - extLen = strlen(ext);
61 - start = fileNameLen - extLen;
62 -#if defined(__VMS) && (__VMS_VER >= 70200000)
63 - /* VMS v7.2 has case-preserving filenames */
64 + for (j=0; j<LanguageModes[i]->nExtensions; j++) {
65 + ext = LanguageModes[i]->extensions[j];
66 + extLen = strlen(ext);
67 + if (ext[0] == '\'' && ext[extLen - 1] == '\'') {
68 + char* regex = XtMalloc(extLen);
69 + /* copy everything except the single quotes into regex */
70 + strcpy(regex, &ext[1]);
71 + regex[extLen - 2] = '\0';
72 + if (regexFind(window->filename, regex)) {
79 + start = fileNameLen - extLen;
80 +#if defined(__VMS) && (__VMS_VER >= 70200000)
81 + /* VMS v7.2 has case-preserving filenames */
82 if (start >= 0 && !strncasecmp(&window->filename[start], ext, extLen))
85 - if (start >= 0 && !strncmp(&window->filename[start], ext, extLen))
86 + if (start >= 0 && !strncmp(&window->filename[start], ext, extLen))
94 + /* Do a regular expression search on for recognition pattern */
95 + first200 = BufGetRange(window->buffer, 0, 200);
96 + for (i=0; i<NLanguageModes; i++) {
97 + if (LanguageModes[i]->recognitionExpr != NULL) {
98 + if (SearchString(first200, LanguageModes[i]->recognitionExpr,
99 + SEARCH_FORWARD, SEARCH_REGEX, False, 0, &beginPos,
100 + &endPos, NULL, NULL, NULL)) {
108 /* no appropriate mode was found */
109 return PLAIN_LANGUAGE_MODE;