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