1 From: Andrew Hood <ajhood@fl.net.au>
2 Subject: tmp-files in 'Open Previous'
4 This adds nedit.prevOpenFilesMask to the list of items which can be added to
5 .Xdefaults to enable you to stop files being added to the 'Open Previous'
6 menu. It also cleans up any files which have already made it into the list.
10 nedit.prevOpenFilesMask: /tmp/junk/
12 The patch to doc/help.etx is included but not the files which would be
17 http://sourceforge.net/tracker/index.php?func=detail&aid=506324&group_id=11005&atid=311005
18 [ 506324 ] tmp-files in 'Open Previous'
20 Than integrated into this mess:
22 http://sourceforge.net/tracker/index.php?func=detail&aid=1058246&group_id=11005&atid=311005
23 [ 1058246 ] Patch Collection
25 2008-02-21 Bert Wesarg
27 slightly extended and renamed to nedit.prevOpenIgnorePattern
32 source/Makefile.dependencies | 3 +
33 source/menu.c | 76 ++++++++++++++++++++++++++++++++++++++++---
34 source/preferences.c | 9 +++++
35 source/preferences.h | 1
36 5 files changed, 91 insertions(+), 5 deletions(-)
38 diff --quilt old/doc/help.etx new/doc/help.etx
41 @@ -4334,10 +4334,17 @@ X Resources
43 Number of files listed in the Open Previous sub-menu of the File menu.
44 Setting this to zero disables the Open Previous menu item and maintenance of
45 the NEdit file history file.
47 +**nedit.prevOpenIgnorePattern**: (not defined)
49 + Files not to be listed in the Open Previous sub-menu of the File menu.
50 + Setting this to a regular expression causes files matching the expression to
51 + be omitted from the Open Previous menu item and the `nedit.history' file
52 + (see Autoload_Files_).
54 **nedit.printCommand**: (system specific)
56 Command used by the print dialog to print a file, such as, lp, lpr, etc..
57 The command must be capable of accepting input via stdin (standard input).
59 diff --quilt old/source/menu.c new/source/menu.c
62 @@ -50,10 +50,11 @@ static const char CVSID[] = "$Id: menu.c
63 #include "highlight.h"
64 #include "highlightData.h"
65 #include "interpret.h"
66 #include "smartIndent.h"
67 #include "windowTitle.h"
68 +#include "regularExp.h"
69 #include "../util/getfiles.h"
70 #include "../util/DialogF.h"
71 #include "../util/misc.h"
72 #include "../util/fileUtils.h"
73 #include "../util/utils.h"
74 @@ -4590,16 +4591,38 @@ static void invalidatePrevOpenMenus(void
75 void AddToPrevOpenMenu(const char *filename)
80 + const char *ignorePattern;
81 + regexp *ignorePatternRE = NULL;
83 /* If the Open Previous command is disabled, just return */
84 if (GetPrefMaxPrevOpenFiles() < 1) {
88 + /* check new filename against prevOpenIgnorePattern */
89 + if ((ignorePattern = GetPrevOpenIgnorePattern()) && *ignorePattern) {
92 + ignorePatternRE = CompileRE(ignorePattern, &compileMsg,
94 + if (ignorePatternRE == NULL) {
95 + fprintf(stderr, "NEdit: %s\n", compileMsg);
97 + int matches = ExecRE(ignorePatternRE, filename, NULL, False,
98 + '\0', '\0', NULL, NULL, NULL);
99 + free(ignorePatternRE);
101 + /* omitting any files matching prevOpenIgnorePattern */
108 /* Refresh list of previously opened files to avoid Big Race Condition,
109 where two sessions overwrite each other's changes in NEdit's
111 Of course there is still Little Race Condition, which occurs if a
112 Session A reads the list, then Session B reads the list and writes
113 @@ -4942,10 +4965,12 @@ static int cmpStrPtr(const void *strA, c
114 void WriteNEditDB(void)
116 const char* fullName = GetRCFileName(NEDIT_HISTORY);
119 + const char *ignorePattern;
120 + regexp *ignorePatternRE = NULL;
121 static char fileHeader[] =
122 "# File name database for NEdit Open Previous command\n";
124 if (fullName == NULL) {
125 /* GetRCFileName() might return NULL if an error occurs during
126 @@ -4978,23 +5003,43 @@ void WriteNEditDB(void)
132 + /* set up removal of any files matching prevOpenIgnorePattern */
133 + if ((ignorePattern = GetPrevOpenIgnorePattern()) && *ignorePattern) {
136 + ignorePatternRE = CompileRE(ignorePattern, &compileMsg,
138 + if (ignorePatternRE == NULL) {
139 + fprintf(stderr, "NEdit: %s\n", compileMsg);
143 /* write the file header text to the file */
144 fprintf(fp, "%s", fileHeader);
146 /* Write the list of file names */
147 for (i = 0; i < NPrevOpen; ++i) {
148 size_t lineLen = strlen(PrevOpen[i]);
150 + /* omitting any files matching prevOpenIgnorePattern */
151 + if (ignorePatternRE
152 + && ExecRE(ignorePatternRE, PrevOpen[i], NULL, False,
153 + '\0', '\0', NULL, NULL, NULL)) {
157 if (lineLen > 0 && PrevOpen[i][0] != '#' &&
158 strcspn(PrevOpen[i], neditDBBadFilenameChars) == lineLen) {
159 fprintf(fp, "%s\n", PrevOpen[i]);
163 + free(ignorePatternRE);
169 ** Read database of file names for 'Open Previous' submenu.
170 @@ -5014,10 +5059,12 @@ void ReadNEditDB(void)
171 char line[MAXPATHLEN + 2];
173 struct stat attribute;
176 + const char *ignorePattern;
177 + regexp *ignorePatternRE = NULL;
178 static time_t lastNeditdbModTime = 0;
180 /* If the Open Previous command is disabled or the user set the
181 resource to an (invalid) negative value, just return. */
182 if (GetPrefMaxPrevOpenFiles() < 1) {
183 @@ -5067,18 +5114,28 @@ void ReadNEditDB(void)
184 /* Clear previous list. */
185 while (0 != NPrevOpen) {
186 XtFree(PrevOpen[--NPrevOpen]);
189 + /* set up removal of any files matching prevOpenIgnorePattern */
190 + if ((ignorePattern = GetPrevOpenIgnorePattern()) && *ignorePattern) {
193 + ignorePatternRE = CompileRE(ignorePattern, &compileMsg,
195 + if (ignorePatternRE == NULL) {
196 + fprintf(stderr, "NEdit: %s\n", compileMsg);
200 /* read lines of the file, lines beginning with # are considered to be
201 comments and are thrown away. Lines are subject to cursory checking,
202 then just copied to the Open Previous file menu list */
204 if (fgets(line, sizeof(line), fp) == NULL) {
210 if (line[0] == '#') {
214 @@ -5102,19 +5159,30 @@ void ReadNEditDB(void)
215 if (strcspn(line, neditDBBadFilenameChars) != lineLen) {
216 /* non-filename characters */
217 fprintf(stderr, "nedit: History file may be corrupted\n");
221 + /* omitting any files matching prevOpenIgnorePattern */
222 + if (ignorePatternRE
223 + && ExecRE(ignorePatternRE, line, NULL, False, '\0', '\0',
224 + NULL, NULL, NULL)) {
228 nameCopy = XtMalloc(lineLen + 1);
229 strcpy(nameCopy, line);
230 PrevOpen[NPrevOpen++] = nameCopy;
231 if (NPrevOpen >= GetPrefMaxPrevOpenFiles()) {
232 /* too many entries */
240 + free(ignorePatternRE);
244 static void setWindowSizeDefault(int rows, int cols)
247 diff --quilt old/source/preferences.c new/source/preferences.c
248 --- old/source/preferences.c
249 +++ new/source/preferences.c
250 @@ -307,10 +307,11 @@ static struct prefData {
251 int appendLF; /* Whether to append LF at the end of each file */
252 int mapDelete; /* whether to map delete to backspace */
253 int stdOpenDialog; /* w. to retain redundant text field in Open */
254 char tagFile[MAXPATHLEN]; /* name of tags file to look for at startup */
255 int maxPrevOpenFiles; /* limit to size of Open Previous menu */
256 + char prevOpenIgnorePattern[MAXPATHLEN]; /* regex to omit from Open Previous menu */
257 int typingHidesPointer; /* hide mouse pointer when typing */
258 char delimiters[MAX_WORD_DELIMITERS]; /* punctuation characters */
259 char shell[MAXPATHLEN + 1]; /* shell to use for executing commands */
260 char geometry[MAX_GEOM_STRING_LEN]; /* per-application geometry string,
261 only for the clueless */
262 @@ -1059,10 +1060,13 @@ static PrefDescripRec PrefDescrip[] = {
263 PrefData.delimiters, (void *)sizeof(PrefData.delimiters), False},
264 {"serverName", "ServerName", PREF_STRING, "", PrefData.serverName,
265 (void *)sizeof(PrefData.serverName), False},
266 {"maxPrevOpenFiles", "MaxPrevOpenFiles", PREF_INT, "30",
267 &PrefData.maxPrevOpenFiles, NULL, False},
268 + {"prevOpenIgnorePattern", "PrevOpenIgnorePattern", PREF_STRING, "",
269 + PrefData.prevOpenIgnorePattern,
270 + (void *)sizeof(PrefData.prevOpenIgnorePattern), False},
271 {"bgMenuButton", "BGMenuButton" , PREF_STRING,
272 "~Shift~Ctrl~Meta~Alt<Btn3Down>", PrefData.bgMenuBtn,
273 (void *)sizeof(PrefData.bgMenuBtn), False},
274 {"smartTags", "SmartTags", PREF_BOOLEAN, "True",
275 &PrefData.smartTags, NULL, True},
276 @@ -2155,10 +2159,15 @@ char *GetPrefBGMenuBtn(void)
277 int GetPrefMaxPrevOpenFiles(void)
279 return PrefData.maxPrevOpenFiles;
282 +const char *GetPrevOpenIgnorePattern(void)
284 + return PrefData.prevOpenIgnorePattern;
287 int GetPrefTypingHidesPointer(void)
289 return(PrefData.typingHidesPointer);
292 diff --quilt old/source/preferences.h new/source/preferences.h
293 --- old/source/preferences.h
294 +++ new/source/preferences.h
295 @@ -162,10 +162,11 @@ void TabsPrefDialog(Widget parent, Windo
296 void WrapMarginDialog(Widget parent, WindowInfo *forWindow);
297 int GetPrefMapDelete(void);
298 int GetPrefStdOpenDialog(void);
299 char *GetPrefDelimiters(void);
300 int GetPrefMaxPrevOpenFiles(void);
301 +const char *GetPrevOpenIgnorePattern(void);
302 int GetPrefTypingHidesPointer(void);
304 void SetPrefShortMenus(int state);
305 int GetPrefShortMenus(void);
307 diff --quilt old/source/Makefile.dependencies new/source/Makefile.dependencies
308 --- old/source/Makefile.dependencies
309 +++ new/source/Makefile.dependencies
310 @@ -24,11 +24,12 @@ macro.o: macro.c macro.h nedit.h textBuf
311 highlightData.h rangeset.h
312 menu.o: menu.c menu.h nedit.h textBuf.h text.h file.h window.h search.h \
313 selection.h undo.h shift.h help.h help_topic.h preferences.h tags.h \
314 userCmds.h shell.h macro.h highlight.h highlightData.h interpret.h ops.h \
315 rbTree.h smartIndent.h windowTitle.h ../util/getfiles.h \
316 - ../util/DialogF.h ../util/misc.h ../util/fileUtils.h ../util/utils.h
317 + ../util/DialogF.h ../util/misc.h ../util/fileUtils.h ../util/utils.h \
319 nc.o: nc.c server_common.h ../util/fileUtils.h ../util/utils.h \
320 ../util/prefFile.h ../util/system.h ../util/clearcase.h
321 nedit.o: nedit.c nedit.h textBuf.h file.h preferences.h regularExp.h \
322 selection.h tags.h menu.h macro.h server.h window.h interpret.h ops.h \
323 rbTree.h parse.h help.h help_topic.h ../util/misc.h \