import jf505 calltipsID.patch and fix the not-found-tip
[nedit-bw.git] / autoload_dotNM_files.patch
blob845f15572eba4883bdfa9dd941a1671e3d2f032b
1 ---
3 source/file.c | 3 ++
4 source/macro.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5 source/macro.h | 1
6 3 files changed, 70 insertions(+)
8 diff --quilt old/source/macro.c new/source/macro.c
9 --- old/source/macro.c
10 +++ new/source/macro.c
11 @@ -925,10 +925,76 @@ int ReadMacroFile(WindowInfo *window, co
12 NULL);
13 XtFree(fileString);
14 return result;
17 +void LoadDotNMFiles(WindowInfo *window)
19 + const char *mode = LanguageModeName(window->languageMode);
20 + char *path;
21 + char *tok, *pos, *last;
22 + char *file;
23 + size_t filenamelen = strlen(".nm");
24 + char *filename = NULL;
25 + char *filename2 = NULL;
27 + if (mode) {
28 + /* for '.<mode>.nm' files */
29 + filenamelen += strlen(mode) + 1;
30 + }
32 + /* a buffer for the file name (".nm" and ".<mode>.nm") */
33 + filename = malloc(filenamelen + 1);
34 + if (!filename)
35 + goto out;
37 + /* filename2 points to the ".nm" of the filenmae */
38 + filename2 = filename;
39 + if (mode) {
40 + filename2 = filename + strlen(mode) + 1;
41 + snprintf(filename, filenamelen + 1, ".%s.nm", mode);
42 + } else {
43 + strcpy(filename, ".nm");
44 + }
46 + /* a carbon copy for the strtok function */
47 + path = strdup(window->path);
48 + if (!path)
49 + goto out_free_filename;
51 + /* good upperbound for longest file, plus one '/' */
52 + file = malloc(strlen(path) + filenamelen + 2);
53 + if (!file)
54 + goto out_free_path;
56 + last = file;
57 + tok = "";
58 + do {
59 + last += sprintf(last, "%s/", tok);
61 + /* ".nm" */
62 + strcpy(last, filename2);
63 + ReadMacroFile(window, file, False);
65 + /* ".<mode>.nm", overwrite ".nm" */
66 + if (mode) {
67 + strcpy(last, filename);
68 + ReadMacroFile(window, file, False);
69 + }
71 + tok = strtok_r(*tok ? NULL : path, "/", &pos);
72 + } while (tok);
74 + free(file);
75 +out_free_path:
76 + free(path);
77 +out_free_filename:
78 + free(filename);
79 +out:
80 + return;
84 ** Parse and execute a macro string including macro definitions. Report
85 ** parsing errors in a dialog posted over window->shell.
87 int ReadMacroString(WindowInfo *window, char *string, const char *errIn)
88 diff --quilt old/source/macro.h new/source/macro.h
89 --- old/source/macro.h
90 +++ new/source/macro.h
91 @@ -65,10 +65,11 @@ void ResumeMacroExecution(WindowInfo *wi
92 void AbortMacroCommand(WindowInfo *window);
93 int MacroWindowCloseActions(WindowInfo *window);
94 void RepeatDialog(WindowInfo *window);
95 void RepeatMacro(WindowInfo *window, const char *command, int how);
96 int ReadMacroFile(WindowInfo *window, const char *fileName, int warnNotExist);
97 +void LoadDotNMFiles(WindowInfo *window);
98 int ReadMacroString(WindowInfo *window, char *string, const char *errIn);
99 int CheckMacroString(Widget dialogParent, char *string, const char *errIn,
100 char **errPos);
101 char *GetReplayMacro(void);
102 void ReadMacroInitFile(WindowInfo *window);
103 diff --quilt old/source/file.c new/source/file.c
104 --- old/source/file.c
105 +++ new/source/file.c
106 @@ -264,10 +264,13 @@ WindowInfo *EditExistingFile(WindowInfo
107 strcat(fullname, name);
108 if(GetPrefAlwaysCheckRelTagsSpecs())
109 AddRelTagsFile(GetPrefTagFile(), path, TAG);
110 AddToPrevOpenMenu(fullname);
112 + /* autoload .nm files from parent directories */
113 + LoadDotNMFiles(window);
115 /* file_open_hook() */
116 MacroApplyHook(window, "post_open_hook", 0, NULL, NULL);
118 return window;