import shell in help output
[nedit-bw.git] / langmoderegex.patch
blob181202581e2e6686c2f6529f098f024cbc1f4320
1 ---
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 @@ -3215,11 +3215,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,
14 XmNlabelString,
15 - s1=XmStringCreateSimple("File extensions (separate w/ space)"),
16 + s1=MKSTRING(
17 +"File extensions or regexes (in single quotes)\n\
18 +(separate w/ space)"),
19 XmNmnemonic, 'F',
20 XmNalignment, XmALIGNMENT_BEGINNING,
21 XmNleftAttachment, XmATTACH_POSITION,
22 XmNleftPosition, LIST_RIGHT,
23 XmNtopAttachment, XmATTACH_WIDGET,
24 @@ -4815,51 +4817,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))
37 - {
38 - XtFree(first200);
39 - return i;
40 - }
41 - }
42 - }
43 - XtFree(first200);
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);
49 #ifdef VMS
50 if (strchr(window->filename, ';') != NULL)
51 - fileNameLen = strchr(window->filename, ';') - window->filename;
52 + fileNameLen = strchr(window->filename, ';') - window->filename;
53 #else
54 if ((versionExtendedPath = GetClearCaseVersionExtendedPath(window->filename)) != NULL)
55 fileNameLen = versionExtendedPath - window->filename;
56 #endif
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)) {
73 + XtFree(regex);
74 + return i;
75 + } else {
76 + XtFree(regex);
77 + }
78 + } else {
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))
83 return i;
84 #else
85 - if (start >= 0 && !strncmp(&window->filename[start], ext, extLen))
86 + if (start >= 0 && !strncmp(&window->filename[start], ext, extLen))
87 return i;
88 #endif
89 - }
90 + }
91 + }
92 + }
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)) {
101 + XtFree(first200);
102 + return i;
106 + XtFree(first200);
108 /* no appropriate mode was found */
109 return PLAIN_LANGUAGE_MODE;