shell_command-make-input-parameter-optional.patch: add changes to help.etx
[nedit-bw.git] / timer_macros.patch
blobfebea503c3a71aa52d3fc1005e306f909c60cf9b
1 ---
3 doc/help.etx | 10 ++
4 source/highlightData.c | 2
5 source/macro.c | 170 +++++++++++++++++++++++++++++++++++++++++++++++++
6 3 files changed, 181 insertions(+), 1 deletion(-)
8 diff --quilt old/source/macro.c new/source/macro.c
9 --- old/source/macro.c
10 +++ new/source/macro.c
11 @@ -424,10 +424,14 @@ static int callFuncMS(WindowInfo *window
12 int nArgs, DataValue *result, char **errMsg);
13 static int callFuncWithArgsMS(WindowInfo *window, DataValue *argList,
14 int nArgs, DataValue *result, char **errMsg);
15 static int defineFuncMS(WindowInfo *window, DataValue *argList,
16 int nArgs, DataValue *result, char **errMsg);
17 +static int timerAddMS(WindowInfo *window, DataValue *argList,
18 + int nArgs, DataValue *result, char **errMsg);
19 +static int timerRemoveMS(WindowInfo *window, DataValue *argList,
20 + int nArgs, DataValue *result, char **errMsg);
22 /* Pattern Match Feature */
23 static int getMatchingMS(WindowInfo *window, DataValue *argList, int nArgs,
24 DataValue *result, char **errMsg);
26 @@ -525,10 +529,12 @@ static const BuiltInSubrName MacroSubrs[
27 { "set_window_title", setWindowTitleMS },
28 { "eval", evalMS },
29 { "call_func", callFuncMS },
30 { "call_func_with_args", callFuncWithArgsMS },
31 { "define_func", defineFuncMS },
32 + { "timer_add", timerAddMS },
33 + { "timer_remove", timerRemoveMS },
34 { NULL, NULL } /* sentinel */
37 static const BuiltInSubrName SpecialVars[] = {
38 { "$cursor", cursorMV },
39 @@ -4078,10 +4084,174 @@ static int defineFuncMS(WindowInfo *wind
42 return True;
45 +typedef struct _TimerProcData {
46 + struct _TimerProcData *next;
47 + XtIntervalId id;
48 + WindowInfo *window;
49 + int global;
50 + char name[1];
51 +} TimerProcData;
53 +static TimerProcData *allTimerProcData;
55 +static void macroTimerProc(XtPointer clientData, XtIntervalId *id)
57 + TimerProcData *data = clientData, **s;
58 + WindowInfo *win;
60 + s = &allTimerProcData;
61 + while (*s) {
62 + if ((*s)->id == data->id) {
63 + *s = data->next;
64 + break;
65 + }
66 + s = &(*s)->next;
67 + }
69 + /* check if window is still there, but don't trust the pointer */
70 + for (win = WindowList; win; win = win->next) {
71 + if (win == data->window) {
72 + break;
73 + }
74 + }
75 + if (win != data->window) {
76 + goto out;
77 + }
79 + if (*id != data->id) {
80 + goto out;
81 + }
83 + /* don't call macro if its not a global timer and current top-window is
84 + different from timer_add() window */
85 + if (!data->global && !IsTopDocument(data->window)) {
86 + goto out;
87 + }
89 + MacroApplyHook(data->window, data->name, 0, NULL, NULL);
91 +out:
92 + XtFree((char *)data);
95 +static int timerAddMS(WindowInfo *window, DataValue *argList,
96 + int nArgs, DataValue *result, char **errMsg)
98 + int timeout;
99 + char stringStorage[2][TYPE_INT_STR_SIZE(int)];
100 + char *name = NULL;
101 + int is_global = 0;
102 + char *global;
103 + TimerProcData *data;
105 + if (nArgs > 3) {
106 + *errMsg = "subroutine %s called with too many arguments";
107 + return False;
109 + if (nArgs < 2) {
110 + *errMsg = "subroutine %s called with too few arguments";
111 + return False;
113 + if (!readStringArg(argList[0], &name, stringStorage[0], errMsg)) {
114 + return False;
116 + if (!readIntArg(argList[1], &timeout, errMsg)) {
117 + return False;
119 + if (nArgs >= 3) {
120 + if(!readStringArg(argList[2], &global, stringStorage[1], errMsg)) {
121 + return False;
123 + if (!strcmp(global, "global")) {
124 + is_global = 1;
125 + } else {
126 + *errMsg = "unknown argument for subroutine %s";
127 + return False;
131 + if (timeout < 100) {
132 + *errMsg = "timeout too small";
133 + return False;
136 + data = (TimerProcData *)XtMalloc(sizeof(*data) +
137 + (strlen(name) * sizeof(char)));
138 + if (!data) {
139 + *errMsg = "internal error";
140 + return False;
143 + data->window = window;
144 + data->global = is_global;
145 + strcpy(data->name, name);
147 + data->next = allTimerProcData;
148 + allTimerProcData = data;
150 + data->id = XtAppAddTimeOut(XtWidgetToApplicationContext(window->shell),
151 + timeout, macroTimerProc, data);
153 + result->tag = INT_TAG;
154 + if (data->id != (XtIntervalId)(int)data->id) {
155 + *errMsg = "warning: can't convert from XtIntervalId to int, timer not removable";
156 + result->val.n = 0;
157 + } else {
158 + result->val.n = data->id;
161 + return True;
164 +static int timerRemoveMS(WindowInfo *window, DataValue *argList,
165 + int nArgs, DataValue *result, char **errMsg)
167 + int timerid;
168 + XtIntervalId id;
169 + TimerProcData *data, **s;
171 + if (nArgs > 1) {
172 + *errMsg = "subroutine %s called with too many arguments";
173 + return False;
175 + if (nArgs < 1) {
176 + *errMsg = "subroutine %s called with too few arguments";
177 + return False;
179 + if (!readIntArg(argList[0], &timerid, errMsg)) {
180 + return False;
183 + if (0 == timerid) {
184 + /* we return 0 as timerid when we can't convert the id to int
185 + the timer can therfore not removed and the TimerProcData is freed
186 + when the timer is fired
187 + */
188 + return True;
191 + id = timerid;
193 + XtRemoveTimeOut(id);
195 + s = &allTimerProcData;
196 + while (*s) {
197 + if ((*s)->id == id) {
198 + data = *s;
199 + *s = data->next;
200 + XtFree((char *)data);
201 + break;
203 + s = &(*s)->next;
206 + return True;
209 /* T Balinski */
210 static int listDialogMS(WindowInfo *window, DataValue *argList, int nArgs,
211 DataValue *result, char **errMsg)
213 macroCmdInfo *cmdData;
214 diff --quilt old/source/highlightData.c new/source/highlightData.c
215 --- old/source/highlightData.c
216 +++ new/source/highlightData.c
217 @@ -549,11 +549,11 @@ static char *DefaultPatternSets[] = {
218 README:\"NEdit Macro syntax highlighting patterns, version 2.6, maintainer Thorsten Haude, nedit at thorstenhau.de\":::Flag::D\n\
219 Comment:\"#\":\"$\"::Comment::\n\
220 Built-in Misc Vars:\"(?<!\\Y)\\$(?:active_pane|args|calltip_ID|column|cursor|display_width|empty_array|file_name|file_path|language_mode|line|locked|max_font_width|min_font_width|modified|n_display_lines|n_panes|rangeset_list|read_only|selection_(?:start|end|left|right)|server_name|text_length|top_line|transient|VERSION|NEDIT_HOME)>\":::Identifier::\n\
221 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\
222 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\
223 - Built-in Subrs:\"<(?:append_file|beep|calltip|call_func(?:_with_args)?|clipboard_to_string|define_func|dialog|filename_dialog|dict_(?:insert|complete|save|append|is_element)|eval|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|get_matching|set_transient|set_window_title|shell_command|split|string_compare|string_dialog|string_to_clipboard|substring|t_print|to_(?:column|line|pos)|tolower|toupper|typeof|valid_number|write_file)>\":::Subroutine::\n\
224 + Built-in Subrs:\"<(?:append_file|beep|calltip|call_func(?:_with_args)?|clipboard_to_string|define_func|dialog|filename_dialog|dict_(?:insert|complete|save|append|is_element)|eval|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|get_matching|set_transient|set_window_title|shell_command|split|string_compare|string_dialog|string_to_clipboard|substring|t_print|timer_(?:add|remove)|to_(?:column|line|pos)|tolower|toupper|typeof|valid_number|write_file)>\":::Subroutine::\n\
225 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\
226 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|select_word|deselect-all|deselect_all|focusIn|focusOut|process-return|process_return|process-tab|process_tab|insert-string|insert_string|mouse_pan)>\":::Subroutine::\n\
227 Macro Hooks:\"<(?:post_open|pre_open|post_save|cursor_moved|modified|focus|losing_focus)_hook>\":::Subroutine1::\n\
228 Keyword:\"<(?:break|continue|define|delete|else|for|if|in|return|while)>\":::Keyword::\n\
229 Braces:\"[{}\\[\\]]\":::Keyword::\n\
230 diff --quilt old/doc/help.etx new/doc/help.etx
231 --- old/doc/help.etx
232 +++ new/doc/help.etx
233 @@ -2796,10 +2796,20 @@ Macro Subroutines
234 is beyond the end position, the empty string is returned.
236 **t_print( string1, string2, ... )**
237 Writes strings to the terminal (stdout) from which NEdit was started.
239 +**timer_add( func_name, timeout [, "global"] )**
240 + Install a new timer that call the macro routine ~func_name~ after ~timeout~
241 + milli seconds. The function is only called if the top window is the same as
242 + the window from which ~timer_add()~ was called, this can be overriden with the
243 + optional ~"global"~ parameter. The macro returns a timer ID which can be used
244 + to remove a timer before expiration with ~timer_remove()~.
246 +**timer_remove( timer_ID )**
247 + Removes the timer with ID ~timer_ID~.
249 **to_column( position )**
250 Convert given position to column number in current window.
252 **to_line( position )**
253 Convert given position to line number in current window.