add newTabTab.patch
[nedit-bw.git] / PrevOpenIgnoreMask.patch
blob9283ed72e420f1ed1efa5f2f0c067cbddab2552c
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.
8 E.g.:
10 nedit.prevOpenFilesMask: /tmp/junk/
12 The patch to doc/help.etx is included but not the files which would be
13 generated from it.
15 Original from here:
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
29 ---
31 doc/help.etx | 7 +++
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
39 --- old/doc/help.etx
40 +++ new/doc/help.etx
41 @@ -4336,6 +4336,13 @@ X Resources
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 diff --quilt old/source/menu.c new/source/menu.c
56 --- old/source/menu.c
57 +++ new/source/menu.c
58 @@ -52,6 +52,7 @@ static const char CVSID[] = "$Id: menu.c
59 #include "interpret.h"
60 #include "smartIndent.h"
61 #include "windowTitle.h"
62 +#include "regularExp.h"
63 #include "../util/getfiles.h"
64 #include "../util/DialogF.h"
65 #include "../util/misc.h"
66 @@ -4592,12 +4593,34 @@ void AddToPrevOpenMenu(const char *filen
67 int i;
68 char *nameCopy;
69 WindowInfo *w;
70 + const char *ignorePattern;
71 + regexp *ignorePatternRE = NULL;
73 /* If the Open Previous command is disabled, just return */
74 if (GetPrefMaxPrevOpenFiles() < 1) {
75 return;
78 + /* check new filename against prevOpenIgnorePattern */
79 + if ((ignorePattern = GetPrevOpenIgnorePattern()) && *ignorePattern) {
80 + char *compileMsg;
82 + ignorePatternRE = CompileRE(ignorePattern, &compileMsg,
83 + REDFLT_STANDARD);
84 + if (ignorePatternRE == NULL) {
85 + fprintf(stderr, "NEdit: %s\n", compileMsg);
86 + } else {
87 + int matches = ExecRE(ignorePatternRE, filename, NULL, False,
88 + '\0', '\0', NULL, NULL, NULL);
89 + free(ignorePatternRE);
91 + /* omitting any files matching prevOpenIgnorePattern */
92 + if (matches) {
93 + return;
94 + }
95 + }
96 + }
98 /* Refresh list of previously opened files to avoid Big Race Condition,
99 where two sessions overwrite each other's changes in NEdit's
100 history file.
101 @@ -4944,6 +4967,8 @@ void WriteNEditDB(void)
102 const char* fullName = GetRCFileName(NEDIT_HISTORY);
103 FILE *fp;
104 int i;
105 + const char *ignorePattern;
106 + regexp *ignorePatternRE = NULL;
107 static char fileHeader[] =
108 "# File name database for NEdit Open Previous command\n";
110 @@ -4980,6 +5005,17 @@ void WriteNEditDB(void)
111 #endif
114 + /* set up removal of any files matching prevOpenIgnorePattern */
115 + if ((ignorePattern = GetPrevOpenIgnorePattern()) && *ignorePattern) {
116 + char *compileMsg;
118 + ignorePatternRE = CompileRE(ignorePattern, &compileMsg,
119 + REDFLT_STANDARD);
120 + if (ignorePatternRE == NULL) {
121 + fprintf(stderr, "NEdit: %s\n", compileMsg);
125 /* write the file header text to the file */
126 fprintf(fp, "%s", fileHeader);
128 @@ -4987,12 +5023,21 @@ void WriteNEditDB(void)
129 for (i = 0; i < NPrevOpen; ++i) {
130 size_t lineLen = strlen(PrevOpen[i]);
132 + /* omitting any files matching prevOpenIgnorePattern */
133 + if (ignorePatternRE
134 + && ExecRE(ignorePatternRE, PrevOpen[i], NULL, False,
135 + '\0', '\0', NULL, NULL, NULL)) {
136 + continue;
139 if (lineLen > 0 && PrevOpen[i][0] != '#' &&
140 strcspn(PrevOpen[i], neditDBBadFilenameChars) == lineLen) {
141 fprintf(fp, "%s\n", PrevOpen[i]);
145 + free(ignorePatternRE);
147 fclose(fp);
150 @@ -5016,6 +5061,8 @@ void ReadNEditDB(void)
151 struct stat attribute;
152 FILE *fp;
153 size_t lineLen;
154 + const char *ignorePattern;
155 + regexp *ignorePatternRE = NULL;
156 static time_t lastNeditdbModTime = 0;
158 /* If the Open Previous command is disabled or the user set the
159 @@ -5069,14 +5116,24 @@ void ReadNEditDB(void)
160 XtFree(PrevOpen[--NPrevOpen]);
163 + /* set up removal of any files matching prevOpenIgnorePattern */
164 + if ((ignorePattern = GetPrevOpenIgnorePattern()) && *ignorePattern) {
165 + char *compileMsg;
167 + ignorePatternRE = CompileRE(ignorePattern, &compileMsg,
168 + REDFLT_STANDARD);
169 + if (ignorePatternRE == NULL) {
170 + fprintf(stderr, "NEdit: %s\n", compileMsg);
174 /* read lines of the file, lines beginning with # are considered to be
175 comments and are thrown away. Lines are subject to cursory checking,
176 then just copied to the Open Previous file menu list */
177 while (True) {
178 if (fgets(line, sizeof(line), fp) == NULL) {
179 /* end of file */
180 - fclose(fp);
181 - return;
182 + goto out;
184 if (line[0] == '#') {
185 /* comment */
186 @@ -5104,15 +5161,26 @@ void ReadNEditDB(void)
187 fprintf(stderr, "nedit: History file may be corrupted\n");
188 continue;
191 + /* omitting any files matching prevOpenIgnorePattern */
192 + if (ignorePatternRE
193 + && ExecRE(ignorePatternRE, line, NULL, False, '\0', '\0',
194 + NULL, NULL, NULL)) {
195 + continue;
198 nameCopy = XtMalloc(lineLen + 1);
199 strcpy(nameCopy, line);
200 PrevOpen[NPrevOpen++] = nameCopy;
201 if (NPrevOpen >= GetPrefMaxPrevOpenFiles()) {
202 /* too many entries */
203 - fclose(fp);
204 - return;
205 + goto out;
209 +out:
210 + free(ignorePatternRE);
211 + fclose(fp);
214 static void setWindowSizeDefault(int rows, int cols)
215 diff --quilt old/source/preferences.c new/source/preferences.c
216 --- old/source/preferences.c
217 +++ new/source/preferences.c
218 @@ -309,6 +309,7 @@ static struct prefData {
219 int stdOpenDialog; /* w. to retain redundant text field in Open */
220 char tagFile[MAXPATHLEN]; /* name of tags file to look for at startup */
221 int maxPrevOpenFiles; /* limit to size of Open Previous menu */
222 + char prevOpenIgnorePattern[MAXPATHLEN]; /* regex to omit from Open Previous menu */
223 int typingHidesPointer; /* hide mouse pointer when typing */
224 char delimiters[MAX_WORD_DELIMITERS]; /* punctuation characters */
225 char shell[MAXPATHLEN + 1]; /* shell to use for executing commands */
226 @@ -1061,6 +1062,9 @@ static PrefDescripRec PrefDescrip[] = {
227 (void *)sizeof(PrefData.serverName), False},
228 {"maxPrevOpenFiles", "MaxPrevOpenFiles", PREF_INT, "30",
229 &PrefData.maxPrevOpenFiles, NULL, False},
230 + {"prevOpenIgnorePattern", "PrevOpenIgnorePattern", PREF_STRING, "",
231 + PrefData.prevOpenIgnorePattern,
232 + (void *)sizeof(PrefData.prevOpenIgnorePattern), False},
233 {"bgMenuButton", "BGMenuButton" , PREF_STRING,
234 "~Shift~Ctrl~Meta~Alt<Btn3Down>", PrefData.bgMenuBtn,
235 (void *)sizeof(PrefData.bgMenuBtn), False},
236 @@ -2156,6 +2160,11 @@ int GetPrefMaxPrevOpenFiles(void)
237 return PrefData.maxPrevOpenFiles;
240 +const char *GetPrevOpenIgnorePattern(void)
242 + return PrefData.prevOpenIgnorePattern;
245 int GetPrefTypingHidesPointer(void)
247 return(PrefData.typingHidesPointer);
248 diff --quilt old/source/preferences.h new/source/preferences.h
249 --- old/source/preferences.h
250 +++ new/source/preferences.h
251 @@ -164,6 +164,7 @@ int GetPrefMapDelete(void);
252 int GetPrefStdOpenDialog(void);
253 char *GetPrefDelimiters(void);
254 int GetPrefMaxPrevOpenFiles(void);
255 +const char *GetPrevOpenIgnorePattern(void);
256 int GetPrefTypingHidesPointer(void);
257 #ifdef SGI_CUSTOM
258 void SetPrefShortMenus(int state);
259 diff --quilt old/source/Makefile.dependencies new/source/Makefile.dependencies
260 --- old/source/Makefile.dependencies
261 +++ new/source/Makefile.dependencies
262 @@ -26,7 +26,8 @@ menu.o: menu.c menu.h nedit.h textBuf.h
263 selection.h undo.h shift.h help.h help_topic.h preferences.h tags.h \
264 userCmds.h shell.h macro.h highlight.h highlightData.h interpret.h ops.h \
265 rbTree.h smartIndent.h windowTitle.h ../util/getfiles.h \
266 - ../util/DialogF.h ../util/misc.h ../util/fileUtils.h ../util/utils.h
267 + ../util/DialogF.h ../util/misc.h ../util/fileUtils.h ../util/utils.h \
268 + regularExp.h
269 nc.o: nc.c server_common.h ../util/fileUtils.h ../util/utils.h \
270 ../util/prefFile.h ../util/system.h ../util/clearcase.h
271 nedit.o: nedit.c nedit.h textBuf.h file.h preferences.h regularExp.h \