push up:
[nedit-bw.git] / escape_literal_macro.patch
blobcdb476c9874d45699b424de66f1a68ccf1be12b9
1 ---
3 doc/help.etx | 4 +++
4 source/highlightData.c | 2 -
5 source/macro.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++
6 3 files changed, 56 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 @@ -449,10 +449,12 @@ static int toColumnMS(WindowInfo *window
13 static int timerAddMS(WindowInfo *window, DataValue *argList,
14 int nArgs, DataValue *result, char **errMsg);
15 static int timerRemoveMS(WindowInfo *window, DataValue *argList,
16 int nArgs, DataValue *result, char **errMsg);
17 +static int escapeLiteralMS(WindowInfo *window, DataValue *argList,
18 + int nArgs, DataValue *result, char **errMsg);
20 /* Built-in subroutines and variables for the macro language */
21 static const BuiltInSubrName MacroSubrs[] = {
22 { "length", lengthMS },
23 { "get_range", getRangeMS },
24 @@ -523,10 +525,11 @@ static const BuiltInSubrName MacroSubrs[
25 { "to_line", toLineMS },
26 { "to_column", toColumnMS },
27 { "set_window_title", setWindowTitleMS },
28 { "timer_add", timerAddMS },
29 { "timer_remove", timerRemoveMS },
30 + { "escape_literal", escapeLiteralMS },
31 { NULL, NULL } /* sentinel */
34 static const BuiltInSubrName SpecialVars[] = {
35 { "$cursor", cursorMV },
36 @@ -3964,10 +3967,58 @@ static int timerRemoveMS(WindowInfo *win
39 return True;
42 +/*
43 + * escaped_string = escape_literal(string)
44 + */
45 +static int escapeLiteralMS(WindowInfo *window, DataValue *argList, int nArgs,
46 + DataValue *result, char **errMsg)
48 + static const char chars_to_escape[] = "()[]<>{}.\\|^$*+?&";
49 + char stringStorage[TYPE_INT_STR_SIZE(int)];
50 + char *string = NULL;
51 + char *escstring = NULL;
52 + int stringlen;
53 + int escstringlen;
54 + int i;
56 + if (nArgs != 1) {
57 + return wrongNArgsErr(errMsg);
58 + }
60 + if (!readStringArg(argList[0], &string, stringStorage, errMsg)) {
61 + return False;
62 + }
64 + stringlen = strlen(string);
66 + escstringlen = stringlen;
67 + for (i = 0; i < stringlen; i++) {
68 + if (strchr(chars_to_escape, string[i])) {
69 + escstringlen++;
70 + }
71 + }
73 + result->tag = STRING_TAG;
74 + if (!AllocNString(&result->val.str, escstringlen + 1)) {
75 + M_FAILURE("Failed to allocate return value in %s");
76 + }
78 + escstring = result->val.str.rep;
79 + while (*string) {
80 + if (strchr(chars_to_escape, *string)) {
81 + *escstring++ = '\\';
82 + }
83 + *escstring++ = *string++;
84 + }
85 + *escstring = '\0';
87 + return True;
90 /* T Balinski */
91 static int listDialogMS(WindowInfo *window, DataValue *argList, int nArgs,
92 DataValue *result, char **errMsg)
94 macroCmdInfo *cmdData;
95 diff --quilt old/doc/help.etx new/doc/help.etx
96 --- old/doc/help.etx
97 +++ new/doc/help.etx
98 @@ -2680,10 +2680,14 @@ Macro Subroutines
99 Additional optional arguments represent labels for buttons to appear along
100 the bottom of the dialog. Returns the number of the button pressed (the
101 first button is number 1), or 0 if the user closed the dialog via the window
102 close box.
104 +**escape_literal( string )**
105 + Escape special chars in ~string~, so that the string can be searched with a
106 + regular expression.
108 **filename_dialog( [title[, mode[, defaultPath[, filter[, defaultName]]]]] )**
109 Presents a file selection dialog with the given title to the user that
110 prompts for a new or existing file.
112 Options are: ~title~ will be the title of the dialog, defaults to "Choose
113 diff --quilt old/source/highlightData.c new/source/highlightData.c
114 --- old/source/highlightData.c
115 +++ new/source/highlightData.c
116 @@ -549,11 +549,11 @@ static char *DefaultPatternSets[] = {
117 README:\"NEdit Macro syntax highlighting patterns, version 2.6, maintainer Thorsten Haude, nedit at thorstenhau.de\":::Flag::D\n\
118 Comment:\"#\":\"$\"::Comment::\n\
119 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\
120 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\
121 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\
122 - Built-in Subrs:\"<(?:append_file|beep|call|calltip|clipboard_to_string|dialog|filename_dialog|dict_(?:insert|complete|save|append|is_element)|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_(?:line|pos)|tolower|toupper|typeof|valid_number|write_file)(?=\\s*\\()\":::Subroutine::\n\
123 + Built-in Subrs:\"<(?:append_file|beep|call|calltip|clipboard_to_string|dialog|filename_dialog|dict_(?:insert|complete|save|append|is_element)|escape_literal|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_(?:line|pos)|tolower|toupper|typeof|valid_number|write_file)(?=\\s*\\()\":::Subroutine::\n\
124 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\
125 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\
126 Macro Hooks:\"<(?:post_open|pre_open|post_save|cursor_moved|modified|focus|losing_focus)_hook(?=\\s*\\()\":::Subroutine1::\n\
127 Keyword:\"<(?:break|continue|define|delete|else|for|if|in|return|while)>\":::Keyword::\n\
128 Braces:\"[{}\\[\\]]\":::Keyword::\n\