CVS rebase
[nedit-bw.git] / macro_hooks.patch
blob41cdd745d95ba48c0e5f2ea16a9f139457005f05
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 @@ -3748,6 +3748,51 @@ Action Routines
20 To be attached to a key-press event, inserts the character
21 equivalent of the key pressed.
24 +Hooks
25 +-----
27 + Hooks are macro routines which are called at specific points in NEdit's
28 + execution. You can use hooks to tie in user-defined functionality at these
29 + points.
31 + No hooks are provided. To use a hook, simply define a macro function with
32 + the name of the hook. The next time the hook will catch, the macro function
33 + is called.
35 + You don't have to provide any hook. If a certain hook does not exist, it is
36 + simply skipped.
38 +**pre_open_hook(~filename~)**
39 + Called before NEdit opens a file using a certain name. The parameter is
40 + the filename NEdit intends to open.
42 + Return a string to use instead of the original filename. Return 0 to tell
43 + NEdit to use the original filename.
45 +**post_open_hook()**
46 + Called when an existing file is opened.
48 +**pre_save_hook()**
49 + Called before a file will be save saved.
51 + Return a string to use this as the file name.
53 +**post_save_hook()**
54 + Called after an file was saved.
56 +**cursor_moved_hook()**
57 + Called when the was cursor moved.
59 +**modified_hook()**
60 + Called when the text buffer changed.
62 +**focus_hook()**
63 + Called when a document gets the input focus.
65 +**losing_focus_hook()**
66 + Called before a document lost the input focus.
68 ----------------------------------------------------------------------
70 Customizing
71 @@ -6036,6 +6081,7 @@ Problems/Defects
72 .. Menu: Rangesets # rangeset
73 .. Menu: Highlighting Information # hiliteInfo
74 .. Menu: Action Routines # actions
75 +.. Menu: H_o_oks # hooks
77 .. Menu: Customizing # customizing
78 .. Menu: Customizing NEdit # customize
79 diff --quilt old/source/Makefile.dependencies new/source/Makefile.dependencies
80 --- old/source/Makefile.dependencies
81 +++ new/source/Makefile.dependencies
82 @@ -4,7 +4,7 @@ calltips.o: calltips.c text.h textBuf.h
83 file.o: file.c file.h nedit.h textBuf.h text.h window.h preferences.h \
84 undo.h menu.h tags.h server.h ../util/misc.h ../util/DialogF.h \
85 ../util/fileUtils.h ../util/getfiles.h ../util/printUtils.h \
86 - ../util/utils.h
87 + ../util/utils.h macro.h
88 help.o: help.c help.h help_topic.h textBuf.h text.h textP.h textDisp.h \
89 textSel.h nedit.h search.h window.h preferences.h help_data.h file.h \
90 highlight.h ../util/misc.h ../util/DialogF.h ../util/system.h
91 @@ -41,7 +41,7 @@ preferences.o: preferences.c preferences
92 help_topic.h regularExp.h smartIndent.h windowTitle.h server.h tags.h \
93 ../util/prefFile.h ../util/misc.h ../util/DialogF.h \
94 ../util/managedList.h ../util/fontsel.h ../util/fileUtils.h \
95 - ../util/utils.h ../util/clearcase.h
96 + ../util/utils.h ../util/clearcase.h macro.h
97 rangeset.o: rangeset.c textBuf.h textDisp.h rangeset.h
98 rbTree.o: rbTree.c rbTree.h
99 regexConvert.o: regexConvert.c regexConvert.h
100 @@ -50,7 +50,7 @@ search.o: search.c search.h nedit.h text
101 server.h window.h preferences.h file.h highlight.h ../util/DialogF.h \
102 ../util/misc.h
103 selection.o: selection.c selection.h nedit.h textBuf.h text.h file.h \
104 - window.h menu.h server.h ../util/DialogF.h ../util/fileUtils.h
105 + window.h menu.h server.h ../util/DialogF.h ../util/fileUtils.h macro.h
106 server.o: server.c server.h window.h nedit.h textBuf.h file.h selection.h \
107 macro.h menu.h preferences.h server_common.h ../util/fileUtils.h \
108 ../util/utils.h
109 diff --quilt old/source/file.c new/source/file.c
110 --- old/source/file.c
111 +++ new/source/file.c
112 @@ -41,6 +41,7 @@ static const char CVSID[] = "$Id: file.c
113 #include "tags.h"
114 #include "server.h"
115 #include "interpret.h"
116 +#include "macro.h"
117 #include "../util/misc.h"
118 #include "../util/DialogF.h"
119 #include "../util/fileUtils.h"
120 @@ -272,6 +273,8 @@ WindowInfo *EditExistingFile(WindowInfo
121 AddRelTagsFile(GetPrefTagFile(), path, TAG);
122 AddToPrevOpenMenu(fullname);
124 + MacroApplyHook(window, "post_open_hook", 0, NULL, NULL);
126 return window;
129 @@ -932,6 +935,18 @@ static int doSave(WindowInfo *window)
130 struct stat statbuf;
131 FILE *fp;
132 int fileLen, result;
133 + DataValue hookResult = {NO_TAG,{0}};
134 + Boolean success;
136 + /* call the "pre_save_hook", if the macro returns a string, interpret this
137 + as the new filename */
138 + success = MacroApplyHook(window, "pre_save_hook", 0, NULL, &hookResult);
139 + if (success && hookResult.tag == STRING_TAG) {
140 + if (ParseFilename(hookResult.val.str.rep,
141 + window->filename, window->path)) {
142 + return FALSE;
146 /* Get the full name of the file */
147 strcpy(fullname, window->path);
148 @@ -1069,6 +1084,9 @@ static int doSave(WindowInfo *window)
149 window->inode = 0;
152 + /* call "post_save_hook" */
153 + MacroApplyHook(window, "post_save_hook", 0, NULL, NULL);
155 return TRUE;
158 diff --quilt old/source/highlightData.c new/source/highlightData.c
159 --- old/source/highlightData.c
160 +++ new/source/highlightData.c
161 @@ -554,6 +554,7 @@ static char *DefaultPatternSets[] = {
162 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\
163 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\
164 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\
165 + Macro Hooks:\"<(?:(?:pre|post)_(?:open|save)|cursor_moved|modified|(?:losing_)?focus)_hook(?=\\s*\\()\":::Subroutine1::\n\
166 Keyword:\"<(?:break|continue|define|delete|else|for|if|in|return|while)>\":::Keyword::\n\
167 Braces:\"[{}\\[\\]]\":::Keyword::\n\
168 Global Variable:\"\\$[A-Za-z0-9_]+\":::Identifier1::\n\
169 diff --quilt old/source/macro.c new/source/macro.c
170 --- old/source/macro.c
171 +++ new/source/macro.c
172 @@ -1280,8 +1280,10 @@ void SafeGC(void)
173 WindowInfo *win;
175 for (win=WindowList; win!=NULL; win=win->next)
176 - if (win->macroCmdData != NULL || InSmartIndentMacros(win))
177 - return;
178 + if (win->macroCmdData != NULL
179 + || InSmartIndentMacros(win)
180 + || win->inMacroHook)
181 + return;
182 GarbageCollectStrings();
185 @@ -6018,3 +6020,60 @@ static int readStringArg(DataValue dv, c
186 *errMsg = "%s called with unknown object";
187 return False;
191 +** call a macro function, if it exists, with the given arguments and store
192 +** the return value in resultDV.
194 +** Currently, only non-preemtable macros are supported.
196 +Boolean MacroApplyHook(WindowInfo *document, const char *hook, int argc,
197 + DataValue *argv, DataValue *resultDV)
199 + Symbol *hookSymbol;
200 + Boolean succ = False;
202 + hookSymbol = LookupSymbol(hook);
203 + if (NULL != hookSymbol && MACRO_FUNCTION_SYM == hookSymbol->type) {
204 + Program *hookProg = hookSymbol->value.val.prog;
205 + RestartData *restartData;
206 + DataValue dummyResultDV;
207 + DataValue *resultDVPtr = &dummyResultDV;
208 + int status;
209 + char *errMsg;
211 + /* ExecuteMacro() can't be called with a NULL resultDV, therefore the
212 + dummyResultDV */
213 + if (resultDV) {
214 + resultDVPtr = resultDV;
217 + /* prevent calling the GC */
218 + document->inMacroHook++;
220 + status = ExecuteMacro(document, hookProg, argc, argv,
221 + resultDVPtr, &restartData, &errMsg);
223 + while (MACRO_TIME_LIMIT == status) {
224 + status = ContinueMacro(restartData, resultDVPtr, &errMsg);
227 + document->inMacroHook--;
229 + /* call the GC only if the caller of this function is not interested
230 + in any result, else it may happen, that strings and arrays are swept
231 + away by the GC. */
232 + if (NULL == resultDV) {
233 + SafeGC();
236 + if (MACRO_PREEMPT == status || MACRO_ERROR == status) {
237 + fprintf(stderr, "nedit: \"%s\" error: %s\n", hook, (MACRO_ERROR == status) ? errMsg : "No dialogs");
238 + } else {
239 + /* Macro is done here without errors */
240 + succ = True;
244 + return succ;
246 diff --quilt old/source/macro.h new/source/macro.h
247 --- old/source/macro.h
248 +++ new/source/macro.h
249 @@ -73,5 +73,8 @@ int CheckMacroString(Widget dialogParent
250 char *GetReplayMacro(void);
251 void ReadMacroInitFile(WindowInfo *window);
252 void ReturnShellCommandOutput(WindowInfo *window, const char *outText, int status);
253 +struct DataValueTag;
254 +Boolean MacroApplyHook(WindowInfo *document, const char *hook, int argc,
255 + struct DataValueTag *argv, struct DataValueTag *resultDV);
257 #endif /* NEDIT_MACRO_H_INCLUDED */
258 diff --quilt old/source/menu.c new/source/menu.c
259 --- old/source/menu.c
260 +++ new/source/menu.c
261 @@ -2849,19 +2849,43 @@ static void openAP(Widget w, XEvent *eve
263 WindowInfo *window = WidgetToWindow(w);
264 char filename[MAXPATHLEN], pathname[MAXPATHLEN];
265 + DataValue fileNameArg;
266 + DataValue resultDV = {NO_TAG, {0}};
267 + Boolean hook_successful = False;
268 + char *fileNameToOpen;
270 if (*nArgs == 0) {
271 fprintf(stderr, "nedit: open action requires file argument\n");
272 return;
274 - if (0 != ParseFilename(args[0], filename, pathname)
276 + /* call "pre_open_hook", use the returned string as the filename to open.
277 + The macro is not executed in the new window. */
278 + fileNameArg.tag = STRING_TAG;
279 + AllocNStringNCpy(&fileNameArg.val.str, args[0], MAXPATHLEN);
280 + hook_successful = MacroApplyHook(window, "pre_open_hook",
281 + 1, &fileNameArg, &resultDV);
283 + if (hook_successful && resultDV.tag == STRING_TAG) {
284 + fileNameToOpen = resultDV.val.str.rep;
285 + } else {
286 + fileNameToOpen = args[0];
289 + if (0 != ParseFilename(fileNameToOpen, filename, pathname)
290 || strlen(filename) + strlen(pathname) > MAXPATHLEN - 1) {
291 fprintf(stderr, "nedit: invalid file name for open action: %s\n",
292 - args[0]);
293 + fileNameToOpen);
294 return;
297 + /* we call the GC, because the "pre_open_hook" argument and possible
298 + return value are strings */
299 + SafeGC();
301 EditExistingFile(window, filename, pathname, 0, NULL, False,
302 NULL, GetPrefOpenInTab(), False);
304 CheckCloseDim();
307 diff --quilt old/source/nedit.c new/source/nedit.c
308 --- old/source/nedit.c
309 +++ new/source/nedit.c
310 @@ -388,7 +388,7 @@ static const char cmdLineHelp[] =
311 int main(int argc, char **argv)
313 int i, lineNum, nRead, fileSpecified = FALSE, editFlags = CREATE;
314 - int gotoLine = False, macroFileRead = False, opts = True;
315 + int gotoLine = False, opts = True;
316 int iconic=False, tabbed = -1, group = 0, isTabbed;
317 char *toDoCommand = NULL, *geometry = NULL, *langMode = NULL;
318 char filename[MAXPATHLEN], pathname[MAXPATHLEN];
319 @@ -567,6 +567,10 @@ int main(int argc, char **argv)
320 IsServer = True;
323 + EditNewFile(NULL, geometry, iconic, langMode, NULL);
324 + ReadMacroInitFile(WindowList);
325 + CheckCloseDim();
327 /* Process any command line arguments (-tags, -do, -read, -create,
328 +<line_number>, -line, -server, and files to edit) not already
329 processed by RestoreNEditPrefs. */
330 @@ -682,10 +686,6 @@ int main(int argc, char **argv)
331 RaiseDocument(lastFile);
334 - if (!macroFileRead) {
335 - ReadMacroInitFile(WindowList);
336 - macroFileRead = True;
338 if (gotoLine)
339 SelectNumberedLine(window, lineNum);
340 if (toDoCommand != NULL) {
341 @@ -739,10 +739,6 @@ int main(int argc, char **argv)
342 RaiseDocument(lastFile);
345 - if (!macroFileRead) {
346 - ReadMacroInitFile(WindowList);
347 - macroFileRead = True;
349 if (gotoLine)
350 SelectNumberedLine(window, lineNum);
351 if (toDoCommand != NULL) {
352 @@ -775,13 +771,9 @@ int main(int argc, char **argv)
354 CheckCloseDim();
356 - /* If no file to edit was specified, open a window to edit "Untitled" */
357 - if (!fileSpecified) {
358 - EditNewFile(NULL, geometry, iconic, langMode, NULL);
359 - ReadMacroInitFile(WindowList);
360 - CheckCloseDim();
361 - if (toDoCommand != NULL)
362 - DoMacro(WindowList, toDoCommand, "-do macro");
363 + /* If no file to edit was specified, do at least the -do macro */
364 + if (!fileSpecified && toDoCommand != NULL) {
365 + DoMacro(WindowList, toDoCommand, "-do macro");
368 /* Begin remembering last command invoked for "Repeat" menu item */
369 diff --quilt old/source/nedit.h new/source/nedit.h
370 --- old/source/nedit.h
371 +++ new/source/nedit.h
372 @@ -566,6 +566,7 @@ typedef struct _WindowInfo {
373 UserBGMenuCache userBGMenuCache; /* shell & macro menu are shared over all
374 "tabbed" documents, while each document
375 has its own background menu. */
376 + int inMacroHook; /* to protect GC in MacroApplyHook() */
377 } WindowInfo;
379 extern WindowInfo *WindowList;
380 diff --quilt old/source/selection.c new/source/selection.c
381 --- old/source/selection.c
382 +++ new/source/selection.c
383 @@ -38,6 +38,8 @@ static const char CVSID[] = "$Id: select
384 #include "menu.h"
385 #include "preferences.h"
386 #include "server.h"
387 +#include "interpret.h"
388 +#include "macro.h"
389 #include "../util/DialogF.h"
390 #include "../util/fileUtils.h"
392 @@ -338,14 +340,32 @@ static void fileCB(Widget widget, Window
393 _XmOSGetDirEntries(pathname, filename, XmFILE_ANY_TYPE, False, True,
394 &nameList, &nFiles, &maxFiles);
395 for (i=0; i<nFiles; i++) {
396 - if (ParseFilename(nameList[i], filename, pathname) != 0) {
397 - XBell(TheDisplay, 0);
399 - else {
400 - EditExistingFile(window, filename, pathname, 0,
401 - NULL, False, NULL, GetPrefOpenInTab(), False);
403 + DataValue fileNameArg;
404 + DataValue resultDV = {NO_TAG, {0}};
405 + Boolean hook_successful = False;
406 + char *fileNameToOpen;
408 + fileNameArg.tag = STRING_TAG;
409 + AllocNStringNCpy(&fileNameArg.val.str, nameList[i],
410 + MAXPATHLEN);
411 + hook_successful = MacroApplyHook(window, "pre_open_hook",
412 + 1, &fileNameArg, &resultDV);
414 + if (hook_successful && resultDV.tag == STRING_TAG) {
415 + fileNameToOpen = resultDV.val.str.rep;
416 + } else {
417 + fileNameToOpen = nameList[i];
420 + if (ParseFilename(fileNameToOpen, filename, pathname) != 0) {
421 + XBell(TheDisplay, 0);
422 + } else {
423 + EditExistingFile(GetPrefOpenInTab() ? window : NULL, filename,
424 + pathname, 0, NULL, False, NULL, GetPrefOpenInTab(),
425 + False);
428 + SafeGC();
429 for (i=0; i<nFiles; i++) {
430 XtFree(nameList[i]);
432 @@ -357,13 +377,32 @@ static void fileCB(Widget widget, Window
434 glob(nameText, GLOB_NOCHECK, NULL, &globbuf);
435 for (i=0; i<(int)globbuf.gl_pathc; i++) {
436 - if (ParseFilename(globbuf.gl_pathv[i], filename, pathname) != 0)
437 - XBell(TheDisplay, 0);
438 - else
439 - EditExistingFile(GetPrefOpenInTab()? window : NULL,
440 - filename, pathname, 0, NULL, False, NULL,
441 - GetPrefOpenInTab(), False);
442 + DataValue fileNameArg;
443 + DataValue resultDV = {NO_TAG, {0}};
444 + Boolean hook_successful = False;
445 + char *fileNameToOpen;
447 + fileNameArg.tag = STRING_TAG;
448 + AllocNStringNCpy(&fileNameArg.val.str, globbuf.gl_pathv[i],
449 + MAXPATHLEN);
450 + hook_successful = MacroApplyHook(window, "pre_open_hook",
451 + 1, &fileNameArg, &resultDV);
453 + if (hook_successful && resultDV.tag == STRING_TAG) {
454 + fileNameToOpen = resultDV.val.str.rep;
455 + } else {
456 + fileNameToOpen = globbuf.gl_pathv[i];
459 + if (ParseFilename(fileNameToOpen, filename, pathname) != 0) {
460 + XBell(TheDisplay, 0);
461 + } else {
462 + EditExistingFile(GetPrefOpenInTab() ? window : NULL, filename,
463 + pathname, 0, NULL, False, NULL, GetPrefOpenInTab(),
464 + False);
467 + SafeGC();
468 globfree(&globbuf);
470 #endif
471 diff --quilt old/source/window.c new/source/window.c
472 --- old/source/window.c
473 +++ new/source/window.c
474 @@ -169,6 +169,7 @@ static void showStatsForm(WindowInfo *wi
475 static void addToWindowList(WindowInfo *window);
476 static void removeFromWindowList(WindowInfo *window);
477 static void focusCB(Widget w, WindowInfo *window, XtPointer callData);
478 +static void losingFocusCB(Widget w, WindowInfo *window, XtPointer callData);
479 static void modifiedCB(int pos, int nInserted, int nDeleted, int nRestyled,
480 const char *deletedText, void *cbArg);
481 static void movedCB(Widget w, WindowInfo *window, XtPointer callData);
482 @@ -325,6 +326,7 @@ WindowInfo *CreateWindow(const char *nam
483 window->tab = NULL;
484 window->device = 0;
485 window->inode = 0;
486 + window->inMacroHook = 0;
488 /* If window geometry was specified, split it apart into a window position
489 component and a window size component. Create a new geometry string
490 @@ -1032,6 +1034,10 @@ void CloseWindow(WindowInfo *window)
491 return;
494 + if (window->inMacroHook) {
495 + fprintf(stderr, "nedit: warning closing window while in MacroHook\n");
498 /* Free syntax highlighting patterns, if any. w/o redisplaying */
499 FreeHighlightingData(window);
501 @@ -2324,6 +2330,8 @@ static Widget createTextArea(Widget pare
503 /* add focus, drag, cursor tracking, and smart indent callbacks */
504 XtAddCallback(text, textNfocusCallback, (XtCallbackProc)focusCB, window);
505 + XtAddCallback(text, textNlosingFocusCallback,
506 + (XtCallbackProc)losingFocusCB, window);
507 XtAddCallback(text, textNcursorMovementCallback, (XtCallbackProc)movedCB,
508 window);
509 XtAddCallback(text, textNdragStartCallback, (XtCallbackProc)dragStartCB,
510 @@ -2376,6 +2384,10 @@ static void movedCB(Widget w, WindowInfo
511 /* Start blinking the caret again. */
512 ResetCursorBlink(textWidget, False);
515 + /* thats a hight frequency hook, should never force a preemptable
516 + context */
517 + MacroApplyHook(window, "cursor_moved_hook", 0, NULL, NULL);
520 static void modifiedCB(int pos, int nInserted, int nDeleted, int nRestyled,
521 @@ -2447,6 +2459,10 @@ static void modifiedCB(int pos, int nIns
523 /* Check if external changes have been made to file and warn user */
524 CheckForChangesToFile(window);
526 + /* thats a hight frequency hook, should never force a preemptable
527 + context */
528 + MacroApplyHook(window, "modified_hook", 0, NULL, NULL);
531 static void focusCB(Widget w, WindowInfo *window, XtPointer callData)
532 @@ -2462,6 +2478,17 @@ static void focusCB(Widget w, WindowInfo
534 /* Check for changes to read-only status and/or file modifications */
535 CheckForChangesToFile(window);
537 + /* thats a hight frequency hook, should never force a preemptable
538 + context */
539 + MacroApplyHook(window, "focus_hook", 0, NULL, NULL);
542 +static void losingFocusCB(Widget w, WindowInfo *window, XtPointer callData)
544 + /* thats a hight frequency hook, should never force a preemptable
545 + context */
546 + MacroApplyHook(window, "losing_focus_hook", 0, NULL, NULL);
549 static void dragStartCB(Widget w, WindowInfo *window, XtPointer callData)
550 @@ -3469,6 +3496,7 @@ WindowInfo* CreateDocument(WindowInfo* s
551 window->bgMenuRedoItem = NULL;
552 window->device = 0;
553 window->inode = 0;
554 + window->inMacroHook = 0;
556 if (window->fontList == NULL)
557 XtVaGetValues(shellWindow->statsLine, XmNfontList,