remove calltip_ignore_arg.patch
[nedit-bw.git] / macro_hooks.patch
blobced2fcf18ffcb50cb4058af330e10290a6ed2f9a
1 ---
3 doc/help.etx | 46 ++++++++++++++++++++++++++++++
4 source/Makefile.dependencies | 6 +--
5 source/file.c | 18 +++++++++++
6 source/highlightData.c | 1
7 source/macro.c | 63 ++++++++++++++++++++++++++++++++++++++++-
8 source/macro.h | 3 +
9 source/menu.c | 28 +++++++++++++++++-
10 source/nedit.c | 24 +++++----------
11 source/nedit.h | 1
12 source/selection.c | 65 ++++++++++++++++++++++++++++++++++---------
13 source/window.c | 28 ++++++++++++++++++
14 11 files changed, 247 insertions(+), 36 deletions(-)
16 diff --quilt old/doc/help.etx new/doc/help.etx
17 --- old/doc/help.etx
18 +++ new/doc/help.etx
19 @@ -3746,10 +3746,55 @@ Action Routines
21 **self_insert()**
22 To be attached to a key-press event, inserts the character
23 equivalent of the key pressed.
26 +Hooks
27 +-----
29 + Hooks are macro routines which are called at specific points in NEdit's
30 + execution. You can use hooks to tie in user-defined functionality at these
31 + points.
33 + No hooks are provided. To use a hook, simply define a macro function with
34 + the name of the hook. The next time the hook will catch, the macro function
35 + is called.
37 + You don't have to provide any hook. If a certain hook does not exist, it is
38 + simply skipped.
40 +**pre_open_hook(~filename~)**
41 + Called before NEdit opens a file using a certain name. The parameter is
42 + the filename NEdit intends to open.
44 + Return a string to use instead of the original filename. Return 0 to tell
45 + NEdit to use the original filename.
47 +**post_open_hook()**
48 + Called when an existing file is opened.
50 +**pre_save_hook()**
51 + Called before a file will be save saved.
53 + Return a string to use this as the file name.
55 +**post_save_hook()**
56 + Called after an file was saved.
58 +**cursor_moved_hook()**
59 + Called when the was cursor moved.
61 +**modified_hook()**
62 + Called when the text buffer changed.
64 +**focus_hook()**
65 + Called when a document gets the input focus.
67 +**losing_focus_hook()**
68 + Called before a document lost the input focus.
70 ----------------------------------------------------------------------
72 Customizing
73 ===========
75 @@ -6034,10 +6079,11 @@ Problems/Defects
76 .. Menu: Macro Language # macro_lang
77 .. Menu: M_a_cro Subroutines # macro_subrs
78 .. Menu: Rangesets # rangeset
79 .. Menu: Highlighting Information # hiliteInfo
80 .. Menu: Action Routines # actions
81 +.. Menu: H_o_oks # hooks
83 .. Menu: Customizing # customizing
84 .. Menu: Customizing NEdit # customize
85 .. Menu: Preferences # preferences
86 .. Menu: X Resources # resources
87 diff --quilt old/source/Makefile.dependencies new/source/Makefile.dependencies
88 --- old/source/Makefile.dependencies
89 +++ new/source/Makefile.dependencies
90 @@ -2,11 +2,11 @@
91 calltips.o: calltips.c text.h textBuf.h textP.h textDisp.h calltips.h \
92 nedit.h ../util/misc.h
93 file.o: file.c file.h nedit.h textBuf.h text.h window.h preferences.h \
94 undo.h menu.h tags.h server.h ../util/misc.h ../util/DialogF.h \
95 ../util/fileUtils.h ../util/getfiles.h ../util/printUtils.h \
96 - ../util/utils.h
97 + ../util/utils.h macro.h
98 help.o: help.c help.h help_topic.h textBuf.h text.h textP.h textDisp.h \
99 textSel.h nedit.h search.h window.h preferences.h help_data.h file.h \
100 highlight.h ../util/misc.h ../util/DialogF.h ../util/system.h
101 highlight.o: highlight.c highlight.h nedit.h textBuf.h textDisp.h text.h \
102 textP.h regularExp.h highlightData.h preferences.h window.h \
103 @@ -39,20 +39,20 @@ parse_noyacc.o: parse_noyacc.c parse.h i
104 preferences.o: preferences.c preferences.h nedit.h textBuf.h text.h \
105 search.h window.h userCmds.h highlight.h highlightData.h help.h \
106 help_topic.h regularExp.h smartIndent.h windowTitle.h server.h tags.h \
107 ../util/prefFile.h ../util/misc.h ../util/DialogF.h \
108 ../util/managedList.h ../util/fontsel.h ../util/fileUtils.h \
109 - ../util/utils.h ../util/clearcase.h
110 + ../util/utils.h ../util/clearcase.h macro.h
111 rangeset.o: rangeset.c textBuf.h textDisp.h rangeset.h
112 rbTree.o: rbTree.c rbTree.h
113 regexConvert.o: regexConvert.c regexConvert.h
114 regularExp.o: regularExp.c regularExp.h
115 search.o: search.c search.h nedit.h textBuf.h regularExp.h text.h \
116 server.h window.h preferences.h file.h highlight.h ../util/DialogF.h \
117 ../util/misc.h
118 selection.o: selection.c selection.h nedit.h textBuf.h text.h file.h \
119 - window.h menu.h server.h ../util/DialogF.h ../util/fileUtils.h
120 + window.h menu.h server.h ../util/DialogF.h ../util/fileUtils.h macro.h
121 server.o: server.c server.h window.h nedit.h textBuf.h file.h selection.h \
122 macro.h menu.h preferences.h server_common.h ../util/fileUtils.h \
123 ../util/utils.h
124 server_common.o: server_common.c textBuf.h nedit.h server_common.h \
125 ../util/utils.h
126 diff --quilt old/source/file.c new/source/file.c
127 --- old/source/file.c
128 +++ new/source/file.c
129 @@ -39,10 +39,11 @@ static const char CVSID[] = "$Id: file.c
130 #include "undo.h"
131 #include "menu.h"
132 #include "tags.h"
133 #include "server.h"
134 #include "interpret.h"
135 +#include "macro.h"
136 #include "../util/misc.h"
137 #include "../util/DialogF.h"
138 #include "../util/fileUtils.h"
139 #include "../util/getfiles.h"
140 #include "../util/printUtils.h"
141 @@ -248,10 +249,12 @@ WindowInfo *EditExistingFile(WindowInfo
142 strcat(fullname, name);
143 if(GetPrefAlwaysCheckRelTagsSpecs())
144 AddRelTagsFile(GetPrefTagFile(), path, TAG);
145 AddToPrevOpenMenu(fullname);
147 + MacroApplyHook(window, "post_open_hook", 0, NULL, NULL);
149 return window;
152 void RevertToSaved(WindowInfo *window)
154 @@ -908,10 +911,22 @@ static int doSave(WindowInfo *window)
155 char *fileString = NULL;
156 char fullname[MAXPATHLEN];
157 struct stat statbuf;
158 FILE *fp;
159 int fileLen, result;
160 + DataValue hookResult = {NO_TAG,{0}};
161 + Boolean success;
163 + /* call the "pre_save_hook", if the macro returns a string, interpret this
164 + as the new filename */
165 + success = MacroApplyHook(window, "pre_save_hook", 0, NULL, &hookResult);
166 + if (success && hookResult.tag == STRING_TAG) {
167 + if (ParseFilename(hookResult.val.str.rep,
168 + window->filename, window->path)) {
169 + return FALSE;
173 /* Get the full name of the file */
174 strcpy(fullname, window->path);
175 strcat(fullname, window->filename);
177 @@ -1045,10 +1060,13 @@ static int doSave(WindowInfo *window)
178 window->fileMissing = TRUE;
179 window->device = 0;
180 window->inode = 0;
183 + /* call "post_save_hook" */
184 + MacroApplyHook(window, "post_save_hook", 0, NULL, NULL);
186 return TRUE;
190 ** Create a backup file for the current window. The name for the backup file
191 diff --quilt old/source/highlightData.c new/source/highlightData.c
192 --- old/source/highlightData.c
193 +++ new/source/highlightData.c
194 @@ -552,10 +552,11 @@ static char *DefaultPatternSets[] = {
195 Built-in Pref Vars:\"(?<!\\Y)\\$(?:auto_indent|em_tab_dist|file_format|font_name|font_name_bold|font_name_bold_italic|font_name_italic|highlight_syntax|incremental_backup|incremental_search_line|make_backup_copy|match_syntax_based|overtype_mode|show_line_numbers|show_matching|statistics_line|tab_dist|use_tabs|wrap_margin|wrap_text)>\":::Identifier2::\n\
196 Built-in Special Vars:\"(?<!\\Y)\\$(?:[1-9]|list_dialog_button|n_args|read_status|search_end|shell_cmd_status|string_dialog_button|sub_sep)>\":::String1::\n\
197 Built-in Subrs:\"<(?:append_file|beep|call|calltip|clipboard_to_string|dialog|filename_dialog|focus_window|get_character|get_pattern_(by_name|at_pos)|get_range|get_selection|get_style_(by_name|at_pos)|getenv|highlight_calltip_line|kill_calltip|length|list_dialog|max|min|rangeset_(?:add|create|destroy|get_by_name|includes|info|invert|range|set_color|set_mode|set_name|subtract)|read_file|replace_in_string|replace_range|replace_selection|replace_substring|search|search_string|select|select_rectangle|set_cursor_pos|shell_command|split|string_compare|string_dialog|string_to_clipboard|substring|t_print|tolower|toupper|valid_number|write_file)(?=\\s*\\()\":::Subroutine::\n\
198 Menu Actions:\"<(?:new(?:_tab|_opposite)?|open|open-dialog|open_dialog|open-selected|open_selected|close|save|save-as|save_as|save-as-dialog|save_as_dialog|revert-to-saved|revert_to_saved|revert_to_saved_dialog|include-file|include_file|include-file-dialog|include_file_dialog|load-macro-file|load_macro_file|load-macro-file-dialog|load_macro_file_dialog|load-tags-file|load_tags_file|load-tags-file-dialog|load_tags_file_dialog|unload_tags_file|load_tips_file|load_tips_file_dialog|unload_tips_file|print|print-selection|print_selection|exit|undo|redo|delete|select-all|select_all|shift-left|shift_left|shift-left-by-tab|shift_left_by_tab|shift-right|shift_right|shift-right-by-tab|shift_right_by_tab|find|find-dialog|find_dialog|find-again|find_again|find-selection|find_selection|find_incremental|start_incremental_find|replace|replace-dialog|replace_dialog|replace-all|replace_all|replace-in-selection|replace_in_selection|replace-again|replace_again|replace_find|replace_find_same|replace_find_again|goto-line-number|goto_line_number|goto-line-number-dialog|goto_line_number_dialog|goto-selected|goto_selected|mark|mark-dialog|mark_dialog|goto-mark|goto_mark|goto-mark-dialog|goto_mark_dialog|match|select_to_matching|goto_matching|find-definition|find_definition|show_tip|split-pane|split_pane|close-pane|close_pane|detach_document(?:_dialog)?|move_document_dialog|(?:next|previous|last)_document|uppercase|lowercase|fill-paragraph|fill_paragraph|control-code-dialog|control_code_dialog|filter-selection-dialog|filter_selection_dialog|filter-selection|filter_selection|execute-command|execute_command|execute-command-dialog|execute_command_dialog|execute-command-line|execute_command_line|shell-menu-command|shell_menu_command|macro-menu-command|macro_menu_command|bg_menu_command|post_window_bg_menu|post_tab_context_menu|beginning-of-selection|beginning_of_selection|end-of-selection|end_of_selection|repeat_macro|repeat_dialog|raise_window|focus_pane|set_statistics_line|set_incremental_search_line|set_show_line_numbers|set_auto_indent|set_wrap_text|set_wrap_margin|set_highlight_syntax|set_make_backup_copy|set_incremental_backup|set_show_matching|set_match_syntax_based|set_overtype_mode|set_locked|set_tab_dist|set_em_tab_dist|set_use_tabs|set_fonts|set_language_mode)(?=\\s*\\()\":::Subroutine::\n\
199 Text Actions:\"<(?:self-insert|self_insert|grab-focus|grab_focus|extend-adjust|extend_adjust|extend-start|extend_start|extend-end|extend_end|secondary-adjust|secondary_adjust|secondary-or-drag-adjust|secondary_or_drag_adjust|secondary-start|secondary_start|secondary-or-drag-start|secondary_or_drag_start|process-bdrag|process_bdrag|move-destination|move_destination|move-to|move_to|move-to-or-end-drag|move_to_or_end_drag|end_drag|copy-to|copy_to|copy-to-or-end-drag|copy_to_or_end_drag|exchange|process-cancel|process_cancel|paste-clipboard|paste_clipboard|copy-clipboard|copy_clipboard|cut-clipboard|cut_clipboard|copy-primary|copy_primary|cut-primary|cut_primary|newline|newline-and-indent|newline_and_indent|newline-no-indent|newline_no_indent|delete-selection|delete_selection|delete-previous-character|delete_previous_character|delete-next-character|delete_next_character|delete-previous-word|delete_previous_word|delete-next-word|delete_next_word|delete-to-start-of-line|delete_to_start_of_line|delete-to-end-of-line|delete_to_end_of_line|forward-character|forward_character|backward-character|backward_character|key-select|key_select|process-up|process_up|process-down|process_down|process-shift-up|process_shift_up|process-shift-down|process_shift_down|process-home|process_home|forward-word|forward_word|backward-word|backward_word|forward-paragraph|forward_paragraph|backward-paragraph|backward_paragraph|beginning-of-line|beginning_of_line|end-of-line|end_of_line|beginning-of-file|beginning_of_file|end-of-file|end_of_file|next-page|next_page|previous-page|previous_page|page-left|page_left|page-right|page_right|toggle-overstrike|toggle_overstrike|scroll-up|scroll_up|scroll-down|scroll_down|scroll_left|scroll_right|scroll-to-line|scroll_to_line|select-all|select_all|deselect-all|deselect_all|focusIn|focusOut|process-return|process_return|process-tab|process_tab|insert-string|insert_string|mouse_pan)(?=\\s*\\()\":::Subroutine::\n\
200 + Macro Hooks:\"<(?:(?:pre|post)_(?open|save)|cursor_moved|modified|(?:losing_)?focus)_hook(?=\\s*\\()\":::Subroutine1::\n\
201 Keyword:\"<(?:break|continue|define|delete|else|for|if|in|return|while)>\":::Keyword::\n\
202 Braces:\"[{}\\[\\]]\":::Keyword::\n\
203 Global Variable:\"\\$[A-Za-z0-9_]+\":::Identifier1::\n\
204 String sq:\"'\":\"'\"::String::\n\
205 String:\"\"\"\":\"\"\"\":\"\\n\":String::\n\
206 diff --quilt old/source/macro.c new/source/macro.c
207 --- old/source/macro.c
208 +++ new/source/macro.c
209 @@ -1278,12 +1278,14 @@ static void finishMacroCmdExecution(Wind
210 void SafeGC(void)
212 WindowInfo *win;
214 for (win=WindowList; win!=NULL; win=win->next)
215 - if (win->macroCmdData != NULL || InSmartIndentMacros(win))
216 - return;
217 + if (win->macroCmdData != NULL
218 + || InSmartIndentMacros(win)
219 + || win->inMacroHook)
220 + return;
221 GarbageCollectStrings();
225 ** Executes macro string "macro" using the lastFocus pane in "window".
226 @@ -6016,5 +6018,62 @@ static int readStringArg(DataValue dv, c
227 return True;
229 *errMsg = "%s called with unknown object";
230 return False;
234 +** call a macro function, if it exists, with the given arguments and store
235 +** the return value in resultDV.
237 +** Currently, only non-preemtable macros are supported.
239 +Boolean MacroApplyHook(WindowInfo *document, const char *hook, int argc,
240 + DataValue *argv, DataValue *resultDV)
242 + Symbol *hookSymbol;
243 + Boolean succ = False;
245 + hookSymbol = LookupSymbol(hook);
246 + if (NULL != hookSymbol && MACRO_FUNCTION_SYM == hookSymbol->type) {
247 + Program *hookProg = hookSymbol->value.val.prog;
248 + RestartData *restartData;
249 + DataValue dummyResultDV;
250 + DataValue *resultDVPtr = &dummyResultDV;
251 + int status;
252 + char *errMsg;
254 + /* ExecuteMacro() can't be called with a NULL resultDV, therefore the
255 + dummyResultDV */
256 + if (resultDV) {
257 + resultDVPtr = resultDV;
260 + /* prevent calling the GC */
261 + document->inMacroHook++;
263 + status = ExecuteMacro(document, hookProg, argc, argv,
264 + resultDVPtr, &restartData, &errMsg);
266 + while (MACRO_TIME_LIMIT == status) {
267 + status = ContinueMacro(restartData, resultDVPtr, &errMsg);
270 + document->inMacroHook--;
272 + /* call the GC only if the caller of this function is not interested
273 + in any result, else it may happen, that strings and arrays are swept
274 + away by the GC. */
275 + if (NULL == resultDV) {
276 + SafeGC();
279 + if (MACRO_PREEMPT == status || MACRO_ERROR == status) {
280 + fprintf(stderr, "nedit: \"%s\" error: %s\n", hook, (MACRO_ERROR == status) ? errMsg : "No dialogs");
281 + } else {
282 + /* Macro is done here without errors */
283 + succ = True;
287 + return succ;
289 diff --quilt old/source/macro.h new/source/macro.h
290 --- old/source/macro.h
291 +++ new/source/macro.h
292 @@ -71,7 +71,10 @@ int ReadMacroString(WindowInfo *window,
293 int CheckMacroString(Widget dialogParent, char *string, const char *errIn,
294 char **errPos);
295 char *GetReplayMacro(void);
296 void ReadMacroInitFile(WindowInfo *window);
297 void ReturnShellCommandOutput(WindowInfo *window, const char *outText, int status);
298 +struct DataValueTag;
299 +Boolean MacroApplyHook(WindowInfo *document, const char *hook, int argc,
300 + struct DataValueTag *argv, struct DataValueTag *resultDV);
302 #endif /* NEDIT_MACRO_H_INCLUDED */
303 diff --quilt old/source/menu.c new/source/menu.c
304 --- old/source/menu.c
305 +++ new/source/menu.c
306 @@ -2847,23 +2847,47 @@ static void openDialogAP(Widget w, XEven
308 static void openAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
310 WindowInfo *window = WidgetToWindow(w);
311 char filename[MAXPATHLEN], pathname[MAXPATHLEN];
312 + DataValue fileNameArg;
313 + DataValue resultDV = {NO_TAG, {0}};
314 + Boolean hook_successful = False;
315 + char *fileNameToOpen;
317 if (*nArgs == 0) {
318 fprintf(stderr, "nedit: open action requires file argument\n");
319 return;
321 - if (0 != ParseFilename(args[0], filename, pathname)
323 + /* call "pre_open_hook", use the returned string as the filename to open.
324 + The macro is not executed in the new window. */
325 + fileNameArg.tag = STRING_TAG;
326 + AllocNStringNCpy(&fileNameArg.val.str, args[0], MAXPATHLEN);
327 + hook_successful = MacroApplyHook(window, "pre_open_hook",
328 + 1, &fileNameArg, &resultDV);
330 + if (hook_successful && resultDV.tag == STRING_TAG) {
331 + fileNameToOpen = resultDV.val.str.rep;
332 + } else {
333 + fileNameToOpen = args[0];
336 + if (0 != ParseFilename(fileNameToOpen, filename, pathname)
337 || strlen(filename) + strlen(pathname) > MAXPATHLEN - 1) {
338 fprintf(stderr, "nedit: invalid file name for open action: %s\n",
339 - args[0]);
340 + fileNameToOpen);
341 return;
344 + /* we call the GC, because the "pre_open_hook" argument and possible
345 + return value are strings */
346 + SafeGC();
348 EditExistingFile(window, filename, pathname, 0, NULL, False,
349 NULL, GetPrefOpenInTab(), False);
351 CheckCloseDim();
354 static void openSelectedAP(Widget w, XEvent *event, String *args,
355 Cardinal *nArgs)
356 diff --quilt old/source/nedit.c new/source/nedit.c
357 --- old/source/nedit.c
358 +++ new/source/nedit.c
359 @@ -386,11 +386,11 @@ static const char cmdLineHelp[] =
360 #endif /*VMS*/
362 int main(int argc, char **argv)
364 int i, lineNum, nRead, fileSpecified = FALSE, editFlags = CREATE;
365 - int gotoLine = False, macroFileRead = False, opts = True;
366 + int gotoLine = False, opts = True;
367 int iconic=False, tabbed = -1, group = 0, isTabbed;
368 char *toDoCommand = NULL, *geometry = NULL, *langMode = NULL;
369 char filename[MAXPATHLEN], pathname[MAXPATHLEN];
370 XtAppContext context;
371 XrmDatabase prefDB;
372 @@ -565,10 +565,14 @@ int main(int argc, char **argv)
374 if (strcmp(GetPrefServerName(), "") != 0) {
375 IsServer = True;
378 + EditNewFile(NULL, geometry, iconic, langMode, NULL);
379 + ReadMacroInitFile(WindowList);
380 + CheckCloseDim();
382 /* Process any command line arguments (-tags, -do, -read, -create,
383 +<line_number>, -line, -server, and files to edit) not already
384 processed by RestoreNEditPrefs. */
385 fileSpecified = FALSE;
386 for (i=1; i<argc; i++) {
387 @@ -680,14 +684,10 @@ int main(int argc, char **argv)
388 if (lastFile && window->shell != lastFile->shell) {
389 CleanUpTabBarExposeQueue(lastFile);
390 RaiseDocument(lastFile);
393 - if (!macroFileRead) {
394 - ReadMacroInitFile(WindowList);
395 - macroFileRead = True;
397 if (gotoLine)
398 SelectNumberedLine(window, lineNum);
399 if (toDoCommand != NULL) {
400 DoMacro(window, toDoCommand, "-do macro");
401 toDoCommand = NULL;
402 @@ -737,14 +737,10 @@ int main(int argc, char **argv)
403 if (lastFile && window->shell != lastFile->shell) {
404 CleanUpTabBarExposeQueue(lastFile);
405 RaiseDocument(lastFile);
408 - if (!macroFileRead) {
409 - ReadMacroInitFile(WindowList);
410 - macroFileRead = True;
412 if (gotoLine)
413 SelectNumberedLine(window, lineNum);
414 if (toDoCommand != NULL) {
415 DoMacro(window, toDoCommand, "-do macro");
416 toDoCommand = NULL;
417 @@ -773,17 +769,13 @@ int main(int argc, char **argv)
418 CleanUpTabBarExposeQueue(lastFile);
419 RaiseDocument(lastFile);
421 CheckCloseDim();
423 - /* If no file to edit was specified, open a window to edit "Untitled" */
424 - if (!fileSpecified) {
425 - EditNewFile(NULL, geometry, iconic, langMode, NULL);
426 - ReadMacroInitFile(WindowList);
427 - CheckCloseDim();
428 - if (toDoCommand != NULL)
429 - DoMacro(WindowList, toDoCommand, "-do macro");
430 + /* If no file to edit was specified, do at least the -do macro */
431 + if (!fileSpecified && toDoCommand != NULL) {
432 + DoMacro(WindowList, toDoCommand, "-do macro");
435 /* Begin remembering last command invoked for "Repeat" menu item */
436 AddLastCommandActionHook(context);
438 diff --quilt old/source/nedit.h new/source/nedit.h
439 --- old/source/nedit.h
440 +++ new/source/nedit.h
441 @@ -564,10 +564,11 @@ typedef struct _WindowInfo {
442 #endif
443 UserMenuCache *userMenuCache; /* cache user menus: */
444 UserBGMenuCache userBGMenuCache; /* shell & macro menu are shared over all
445 "tabbed" documents, while each document
446 has its own background menu. */
447 + int inMacroHook; /* to protect GC in MacroApplyHook() */
448 } WindowInfo;
450 extern WindowInfo *WindowList;
451 extern Display *TheDisplay;
452 extern Widget TheAppShell;
453 diff --quilt old/source/selection.c new/source/selection.c
454 --- old/source/selection.c
455 +++ new/source/selection.c
456 @@ -36,10 +36,12 @@ static const char CVSID[] = "$Id: select
457 #include "file.h"
458 #include "window.h"
459 #include "menu.h"
460 #include "preferences.h"
461 #include "server.h"
462 +#include "interpret.h"
463 +#include "macro.h"
464 #include "../util/DialogF.h"
465 #include "../util/fileUtils.h"
467 #include <stdlib.h>
468 #include <stdio.h>
469 @@ -336,18 +338,36 @@ static void fileCB(Widget widget, Window
470 return;
472 _XmOSGetDirEntries(pathname, filename, XmFILE_ANY_TYPE, False, True,
473 &nameList, &nFiles, &maxFiles);
474 for (i=0; i<nFiles; i++) {
475 - if (ParseFilename(nameList[i], filename, pathname) != 0) {
476 - XBell(TheDisplay, 0);
478 - else {
479 - EditExistingFile(window, filename, pathname, 0,
480 - NULL, False, NULL, GetPrefOpenInTab(), False);
482 + DataValue fileNameArg;
483 + DataValue resultDV = {NO_TAG, {0}};
484 + Boolean hook_successful = False;
485 + char *fileNameToOpen;
487 + fileNameArg.tag = STRING_TAG;
488 + AllocNStringNCpy(&fileNameArg.val.str, nameList[i],
489 + MAXPATHLEN);
490 + hook_successful = MacroApplyHook(window, "pre_open_hook",
491 + 1, &fileNameArg, &resultDV);
493 + if (hook_successful && resultDV.tag == STRING_TAG) {
494 + fileNameToOpen = resultDV.val.str.rep;
495 + } else {
496 + fileNameToOpen = nameList[i];
499 + if (ParseFilename(fileNameToOpen, filename, pathname) != 0) {
500 + XBell(TheDisplay, 0);
501 + } else {
502 + EditExistingFile(GetPrefOpenInTab() ? window : NULL, filename,
503 + pathname, 0, NULL, False, NULL, GetPrefOpenInTab(),
504 + False);
507 + SafeGC();
508 for (i=0; i<nFiles; i++) {
509 XtFree(nameList[i]);
511 XtFree((char *)nameList);
513 @@ -355,17 +375,36 @@ static void fileCB(Widget widget, Window
514 { glob_t globbuf;
515 int i;
517 glob(nameText, GLOB_NOCHECK, NULL, &globbuf);
518 for (i=0; i<(int)globbuf.gl_pathc; i++) {
519 - if (ParseFilename(globbuf.gl_pathv[i], filename, pathname) != 0)
520 - XBell(TheDisplay, 0);
521 - else
522 - EditExistingFile(GetPrefOpenInTab()? window : NULL,
523 - filename, pathname, 0, NULL, False, NULL,
524 - GetPrefOpenInTab(), False);
525 + DataValue fileNameArg;
526 + DataValue resultDV = {NO_TAG, {0}};
527 + Boolean hook_successful = False;
528 + char *fileNameToOpen;
530 + fileNameArg.tag = STRING_TAG;
531 + AllocNStringNCpy(&fileNameArg.val.str, globbuf.gl_pathv[i],
532 + MAXPATHLEN);
533 + hook_successful = MacroApplyHook(window, "pre_open_hook",
534 + 1, &fileNameArg, &resultDV);
536 + if (hook_successful && resultDV.tag == STRING_TAG) {
537 + fileNameToOpen = resultDV.val.str.rep;
538 + } else {
539 + fileNameToOpen = globbuf.gl_pathv[i];
542 + if (ParseFilename(fileNameToOpen, filename, pathname) != 0) {
543 + XBell(TheDisplay, 0);
544 + } else {
545 + EditExistingFile(GetPrefOpenInTab() ? window : NULL, filename,
546 + pathname, 0, NULL, False, NULL, GetPrefOpenInTab(),
547 + False);
550 + SafeGC();
551 globfree(&globbuf);
553 #endif
554 CheckCloseDim();
556 diff --quilt old/source/window.c new/source/window.c
557 --- old/source/window.c
558 +++ new/source/window.c
559 @@ -167,10 +167,11 @@ static void showStats(WindowInfo *window
560 static void showISearch(WindowInfo *window, int state);
561 static void showStatsForm(WindowInfo *window);
562 static void addToWindowList(WindowInfo *window);
563 static void removeFromWindowList(WindowInfo *window);
564 static void focusCB(Widget w, WindowInfo *window, XtPointer callData);
565 +static void losingFocusCB(Widget w, WindowInfo *window, XtPointer callData);
566 static void modifiedCB(int pos, int nInserted, int nDeleted, int nRestyled,
567 const char *deletedText, void *cbArg);
568 static void movedCB(Widget w, WindowInfo *window, XtPointer callData);
569 static void dragStartCB(Widget w, WindowInfo *window, XtPointer callData);
570 static void dragEndCB(Widget w, WindowInfo *window, dragEndCBStruct *callData);
571 @@ -320,10 +321,11 @@ WindowInfo *CreateWindow(const char *nam
572 window->findLastRegexCase = TRUE;
573 window->findLastLiteralCase = FALSE;
574 window->tab = NULL;
575 window->device = 0;
576 window->inode = 0;
577 + window->inMacroHook = 0;
579 /* If window geometry was specified, split it apart into a window position
580 component and a window size component. Create a new geometry string
581 containing the position component only. Rows and cols are stripped off
582 because we can't easily calculate the size in pixels from them until the
583 @@ -1009,10 +1011,14 @@ void CloseWindow(WindowInfo *window)
584 RefreshTabState(window);
585 updateLineNumDisp(window);
586 return;
589 + if (window->inMacroHook) {
590 + fprintf(stderr, "nedit: warning closing window while in MacroHook\n");
593 /* Free syntax highlighting patterns, if any. w/o redisplaying */
594 FreeHighlightingData(window);
596 /* remove the buffer modification callbacks so the buffer will be
597 deallocated when the last text widget is destroyed */
598 @@ -2301,10 +2307,12 @@ static Widget createTextArea(Widget pare
599 XtVaSetValues(sw, XmNworkWindow, frame, XmNhorizontalScrollBar,
600 hScrollBar, XmNverticalScrollBar, vScrollBar, NULL);
602 /* add focus, drag, cursor tracking, and smart indent callbacks */
603 XtAddCallback(text, textNfocusCallback, (XtCallbackProc)focusCB, window);
604 + XtAddCallback(text, textNlosingFocusCallback,
605 + (XtCallbackProc)losingFocusCB, window);
606 XtAddCallback(text, textNcursorMovementCallback, (XtCallbackProc)movedCB,
607 window);
608 XtAddCallback(text, textNdragStartCallback, (XtCallbackProc)dragStartCB,
609 window);
610 XtAddCallback(text, textNdragEndCallback, (XtCallbackProc)dragEndCB,
611 @@ -2353,10 +2361,14 @@ static void movedCB(Widget w, WindowInfo
612 if (0 != textWidget->text.cursorBlinkProcID)
614 /* Start blinking the caret again. */
615 ResetCursorBlink(textWidget, False);
618 + /* thats a hight frequency hook, should never force a preemptable
619 + context */
620 + MacroApplyHook(window, "cursor_moved_hook", 0, NULL, NULL);
623 static void modifiedCB(int pos, int nInserted, int nDeleted, int nRestyled,
624 const char *deletedText, void *cbArg)
626 @@ -2424,10 +2436,14 @@ static void modifiedCB(int pos, int nIns
627 /* Update # of bytes, and line and col statistics */
628 UpdateStatsLine(window);
630 /* Check if external changes have been made to file and warn user */
631 CheckForChangesToFile(window);
633 + /* thats a hight frequency hook, should never force a preemptable
634 + context */
635 + MacroApplyHook(window, "modified_hook", 0, NULL, NULL);
638 static void focusCB(Widget w, WindowInfo *window, XtPointer callData)
640 /* record which window pane last had the keyboard focus */
641 @@ -2439,10 +2455,21 @@ static void focusCB(Widget w, WindowInfo
642 /* finish off the current incremental search */
643 EndISearch(window);
645 /* Check for changes to read-only status and/or file modifications */
646 CheckForChangesToFile(window);
648 + /* thats a hight frequency hook, should never force a preemptable
649 + context */
650 + MacroApplyHook(window, "focus_hook", 0, NULL, NULL);
653 +static void losingFocusCB(Widget w, WindowInfo *window, XtPointer callData)
655 + /* thats a hight frequency hook, should never force a preemptable
656 + context */
657 + MacroApplyHook(window, "losing_focus_hook", 0, NULL, NULL);
660 static void dragStartCB(Widget w, WindowInfo *window, XtPointer callData)
662 /* don't record all of the intermediate drag steps for undo */
663 @@ -3446,10 +3473,11 @@ WindowInfo* CreateDocument(WindowInfo* s
664 window->tab = NULL;
665 window->bgMenuUndoItem = NULL;
666 window->bgMenuRedoItem = NULL;
667 window->device = 0;
668 window->inode = 0;
669 + window->inMacroHook = 0;
671 if (window->fontList == NULL)
672 XtVaGetValues(shellWindow->statsLine, XmNfontList,
673 &window->fontList,NULL);