4 source/highlightData.c | 2
5 source/macro.c | 163 +++++++++++++++++++++++++++++++++++++++++++++++++
6 3 files changed, 171 insertions(+), 1 deletion(-)
8 diff --quilt old/source/macro.c new/source/macro.c
10 +++ new/source/macro.c
11 @@ -418,10 +418,14 @@ static int typeofMS(WindowInfo* window,
12 DataValue* result, char** errMsg);
13 static int setWindowTitleMS(WindowInfo *window, DataValue *argList,
14 int nArgs, DataValue *result, char **errMsg);
15 static int evalMS(WindowInfo *window, DataValue *argList,
16 int nArgs, DataValue *result, char **errMsg);
17 +static int callFuncMS(WindowInfo *window, DataValue *argList,
18 + int nArgs, DataValue *result, char **errMsg);
19 +static int callFuncWithArgsMS(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 @@ -516,10 +520,12 @@ static const BuiltInSubrName MacroSubrs[
27 { "to_pos", toPosMS },
28 { "to_line", toLineMS },
29 { "to_column", toColumnMS },
30 { "set_window_title", setWindowTitleMS },
32 + { "call_func", callFuncMS },
33 + { "call_func_with_args", callFuncWithArgsMS },
34 { NULL, NULL } /* sentinel */
37 static const BuiltInSubrName SpecialVars[] = {
38 { "$cursor", cursorMV },
39 @@ -3812,10 +3818,167 @@ static int evalMS(WindowInfo *window, Da
40 runMacro(window, prog);
46 + * call_func(func_name, ...)
48 +static int callFuncMS(WindowInfo *window, DataValue *argList,
49 + int nArgs, DataValue *result, char **errMsg)
51 + char stringStorage[TYPE_INT_STR_SIZE(int)];
56 + return tooFewArgsErr(errMsg);
58 + if (!readStringArg(argList[0], &func, stringStorage, errMsg)) {
62 + /* remove function name from argument list */
66 + sym = LookupSymbol(func);
68 + *errMsg = "Function not found.";
72 + switch (sym->type) {
73 + case MACRO_FUNCTION_SYM: {
74 + Program *prog = sym->value.val.prog;
75 + RestartData* restartData;
79 + status = ExecuteMacro(window, prog, nArgs, argList, result,
80 + &restartData, errMsg);
82 + while (MACRO_TIME_LIMIT == status) {
83 + status = ContinueMacro(restartData, result, errMsg);
86 + if (MACRO_PREEMPT == status || MACRO_ERROR == status) {
87 + fprintf(stderr, "nedit: \"%s\" error: %s\n", func, *errMsg);
95 + case C_FUNCTION_SYM: {
96 + BuiltInSubr subr = sym->value.val.subr;
97 + return subr(window, argList, nArgs, result, errMsg);
101 + case ACTION_ROUTINE_SYM: {
102 + XtActionProc xtproc = sym->value.val.xtproc;
103 + String argListString[nArgs];
104 + Cardinal nArgsString = 0;
105 + XKeyEvent key_event;
110 + /* Create a fake event with a timestamp suitable for actions which need
111 + timestamps, a marker to indicate that the call was from a macro
112 + (to stop shell commands from putting up their own separate banner) */
113 + disp = XtDisplay(window->shell);
114 + win = XtWindow(window->shell);
116 + key_event.type = KeyPress;
117 + key_event.send_event = MACRO_EVENT_MARKER;
118 + key_event.time=XtLastTimestampProcessed(disp);
120 + /* The following entries are just filled in to avoid problems
121 + in strange cases, like calling "self_insert()" directly from the
122 + macro menu. In fact the display was sufficient to cure this crash. */
123 + key_event.display = disp;
124 + key_event.window = key_event.root = key_event.subwindow = win;
126 + for (i = 0; i < nArgs; i--) {
127 + char *stringArg = NULL;
128 + if (!readStringArg(argList[i], &stringArg, stringStorage, errMsg)) {
129 + for (i = 0; i < nArgsString; i++) {
130 + free(argListString[i]);
132 + *errMsg = "Try to call an action routine with an none string argument.";
135 + argListString[nArgsString++] = strdup(stringArg);
138 + /* Call the action routine */
139 + xtproc(window->lastFocus, (XEvent *)&key_event, argListString,
142 + for (i = 0; i < nArgsString; i++) {
143 + free(argListString[i]);
151 + *errMsg = "Try to call an uncallable function.";
158 + * call_func_with_args(func_name, arg_array)
160 +static int callFuncWithArgsMS(WindowInfo *window, DataValue *argList,
161 + int nArgs, DataValue *result, char **errMsg)
163 + DataValue *argListNew = NULL;
164 + int nArgsNew = 0, nArgsNewReal;
166 + char keyStorage[TYPE_INT_STR_SIZE(int)];
170 + return wrongNArgsErr(errMsg);
172 + if (argList[1].tag != ARRAY_TAG) {
173 + *errMsg = "subroutine %s called with wrong second argument";
176 + args = &argList[1];
178 + /* only upper bound, one for the function name */
179 + nArgsNew = 1 + ArraySize(args);
181 + argListNew = (DataValue *)XtMalloc(nArgsNew * sizeof(*argListNew));
183 + /* first argument is function name */
184 + argListNew[0] = argList[0];
186 + /* get array items starting with "1" until break in sequence */
187 + for (nArgsNewReal = 1; nArgsNewReal < nArgsNew; nArgsNewReal++) {
188 + sprintf(keyStorage, "%d", nArgsNewReal);
189 + if (!ArrayGet(args, keyStorage, &argListNew[nArgsNewReal])) {
194 + ret = callFuncMS(window, argListNew, nArgsNewReal, result, errMsg);
197 + XtFree((char *)argListNew);
203 static int listDialogMS(WindowInfo *window, DataValue *argList, int nArgs,
204 DataValue *result, char **errMsg)
206 macroCmdInfo *cmdData;
207 diff --quilt old/source/highlightData.c new/source/highlightData.c
208 --- old/source/highlightData.c
209 +++ new/source/highlightData.c
210 @@ -549,11 +549,11 @@ static char *DefaultPatternSets[] = {
211 README:\"NEdit Macro syntax highlighting patterns, version 2.6, maintainer Thorsten Haude, nedit at thorstenhau.de\":::Flag::D\n\
212 Comment:\"#\":\"$\"::Comment::\n\
213 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\
214 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\
215 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\
216 - Built-in Subrs:\"<(?:append_file|beep|calltip|clipboard_to_string|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)(?=\\s*\\()\":::Subroutine::\n\
217 + Built-in Subrs:\"<(?:append_file|beep|calltip|call_func(?:_with_args)?|clipboard_to_string|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)(?=\\s*\\()\":::Subroutine::\n\
218 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\
219 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)(?=\\s*\\()\":::Subroutine::\n\
220 Macro Hooks:\"<(?:post_open|pre_open|post_save|cursor_moved|modified|focus|losing_focus)_hook(?=\\s*\\()\":::Subroutine1::\n\
221 Keyword:\"<(?:break|continue|define|delete|else|for|if|in|return|while)>\":::Keyword::\n\
222 Braces:\"[{}\\[\\]]\":::Keyword::\n\
223 diff --quilt old/doc/help.etx new/doc/help.etx
226 @@ -2574,10 +2574,17 @@ Macro Subroutines
228 Returns the ID of the calltip if it was found and/or displayed correctly, 0
229 otherwise, in this case a calltp will be shown with an error messages, which
230 can be supressed with the "ignore" argument.
232 +**call_func( func_name, ... )**
233 + Call the macro function or action routine specified in ~func_name~ with the
234 + remainig arguments in ~...~.
236 +**call_func_with_args( func_name, args )**
237 + Same as ~call_func~ but with the arguments from the array ~args~.
239 **clipboard_to_string()**
240 Returns the contents of the clipboard as a macro string. Returns empty
243 **dialog( message, btn_1_label, btn_2_label, ... )**