revert parser stuff from enhenced patch
[nedit-bw.git] / pos_line_convert.patch
blob641b63fff36260b1f3d7016815e29dd2ceef5fd1
1 ---
3 doc/help.etx | 14 +++
4 source/highlightData.c | 2
5 source/macro.c | 210 +++++++++++++++++++++++++++++++++++++++++++++++++
6 source/selection.c | 9 +-
7 4 files changed, 232 insertions(+), 3 deletions(-)
9 diff --quilt old/doc/help.etx new/doc/help.etx
10 --- old/doc/help.etx
11 +++ new/doc/help.etx
12 @@ -2772,10 +2772,24 @@ Macro Subroutines
13 is beyond the end position, the empty string is returned.
15 **t_print( string1, string2, ... )**
16 Writes strings to the terminal (stdout) from which NEdit was started.
18 +**to_column( position )**
19 + Convert given position to column number in current window.
21 +**to_line( position )**
22 + Convert given position to line number in current window.
24 +**to_pos( [line-number] [, column-number] )**
25 + Convert given line number and column number to position in current
26 + window. Parameters of "to_pos" follow the same syntax than parameters
27 + of subroutine "goto_line_number".
28 + Examples: 'to_pos(10)' returns position of first character of line
29 + number 10; 'to_pos(",2")' or 'to_pos(-1, 2)' returns position of
30 + column number 2 of the line, where the cursor currently resides.
32 **tolower( string )**
33 Return an all lower-case version of string.
35 **toupper( string )**
36 Return an all upper-case version of string.
37 diff --quilt old/source/highlightData.c new/source/highlightData.c
38 --- old/source/highlightData.c
39 +++ new/source/highlightData.c
40 @@ -549,11 +549,11 @@ static char *DefaultPatternSets[] = {
41 README:\"NEdit Macro syntax highlighting patterns, version 2.6, maintainer Thorsten Haude, nedit at thorstenhau.de\":::Flag::D\n\
42 Comment:\"#\":\"$\"::Comment::\n\
43 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\
44 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\
45 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\
46 - Built-in Subrs:\"<(?:append_file|beep|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|shell_command|split|string_compare|string_dialog|string_to_clipboard|substring|t_print|tolower|toupper|typeof|valid_number|write_file)(?=\\s*\\()\":::Subroutine::\n\
47 + Built-in Subrs:\"<(?:append_file|beep|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|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\
48 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\
49 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\
50 Macro Hooks:\"<(?:post_open|pre_open|post_save|cursor_moved|modified|focus|losing_focus)_hook(?=\\s*\\()\":::Subroutine1::\n\
51 Keyword:\"<(?:break|continue|define|delete|else|for|if|in|return|while)>\":::Keyword::\n\
52 Braces:\"[{}\\[\\]]\":::Keyword::\n\
53 diff --quilt old/source/macro.c new/source/macro.c
54 --- old/source/macro.c
55 +++ new/source/macro.c
56 @@ -430,10 +430,21 @@ static int dictsaveMS(WindowInfo *window
57 static int dictappendMS(WindowInfo *window, DataValue *argList, int nArgs,
58 DataValue *result, char **errMsg);
59 static int dictiselementMS(WindowInfo *window, DataValue *argList, int nArgs,
60 DataValue *result, char **errMsg);
62 +/*
63 + * UL convertPos patch:
64 + * add "to_pos", "to_line", "to_column" macro subroutines
65 + */
66 +static int toPosMS(WindowInfo *window, DataValue *argList, int nArgs,
67 + DataValue *result, char **errMsg);
68 +static int toLineMS(WindowInfo *window, DataValue *argList, int nArgs,
69 + DataValue *result, char **errMsg);
70 +static int toColumnMS(WindowInfo *window, DataValue *argList, int nArgs,
71 + DataValue *result, char **errMsg);
73 /* Built-in subroutines and variables for the macro language */
74 static const BuiltInSubrName MacroSubrs[] = {
75 { "length", lengthMS },
76 { "get_range", getRangeMS },
77 { "t_print", tPrintMS },
78 @@ -496,10 +507,13 @@ static const BuiltInSubrName MacroSubrs[
79 { "dict_insert", dictinsertMS },
80 { "dict_complete", dictcompleteMS },
81 { "dict_save", dictsaveMS },
82 { "dict_append", dictappendMS },
83 { "dict_is_element", dictiselementMS },
84 + { "to_pos", toPosMS },
85 + { "to_line", toLineMS },
86 + { "to_column", toColumnMS },
87 { NULL, NULL } /* sentinel */
90 static const BuiltInSubrName SpecialVars[] = {
91 { "$cursor", cursorMV },
92 @@ -6268,10 +6282,206 @@ static int dictcompleteMS(WindowInfo *wi
94 return True;
96 /* end of new macros for dictionary Christian Merkwirth 2000 */
98 +/*
99 +** UL convertPos patch:
100 +** translate given line / column parameter to text buffer position.
102 +static int toPosMS(WindowInfo *window, DataValue *argList, int nArgs,
103 + DataValue *result, char **errMsg)
105 + char *lineStr, stringStorage1[TYPE_INT_STR_SIZE(int)];
106 + char *colStr , stringStorage2[TYPE_INT_STR_SIZE(int)];
107 + char *lineColString;
108 + char *allocStringBuf = NULL;
109 + int line, column, curCol;
110 + int pos;
111 + Widget w = window->lastFocus;
113 + /*
114 + * Get arguments and convert it to related cursor position
115 + */
116 + if (nArgs == 0)
118 + *errMsg = "%s subroutine called with no arguments";
119 + return False;
121 + else if (nArgs > 2)
123 + return wrongNArgsErr(errMsg);
125 + else if (nArgs == 1)
127 + /*
128 + * 1 Argument: treat it as string to allow e.g. argument like
129 + * "line : column" (similar to goto_line_number).
130 + */
131 + if (!readStringArg(argList[0], &lineColString, stringStorage1, errMsg))
132 + return False;
134 + else
136 + /*
137 + * 2 Arguments: 1st holds line, 2nd holds column;
138 + * build arg. string of form "line, column" to cover negative
139 + * values, too (readIntArg doesn't allow negative values).
140 + */
141 + if (!readStringArg(argList[0], &lineStr, stringStorage1, errMsg))
142 + return False;
144 + if (!readStringArg(argList[1], &colStr, stringStorage2, errMsg))
145 + return False;
147 + allocStringBuf = XtMalloc(strlen(lineStr)+strlen(colStr)+3);
148 + lineColString = allocStringBuf;
150 + sprintf(lineColString, "%s, %s", lineStr, colStr);
153 + if (StringToLineAndCol(lineColString, &line, &column) == -1)
155 + *errMsg = "%s subroutine must hold valid line and/or column string";
156 + return False;
159 + /*
160 + * Free eventually allocated buffer
161 + */
162 + if (allocStringBuf != NULL)
163 + XtFree(allocStringBuf);
165 + if (line == -1)
167 + /*
168 + * User specified column, but not line number
169 + */
170 + pos = TextGetCursorPos(w);
171 + if (!TextPosToLineAndCol(w, pos, &line, &curCol))
173 + /*
174 + * Should never occur
175 + */
176 + *errMsg = "current cursor position is not visible";
177 + return False;
180 + else if (column == -1)
182 + /*
183 + * User didn't specify a column
184 + */
185 + column = 0;
188 + pos = TextLineAndColToPos(w, line, column );
190 + /*
191 + * Return determined position
192 + */
193 + result->tag = INT_TAG;
194 + result->val.n = pos;
196 + return True;
200 +** UL convertPos patch:
201 +** translate given text buffer position to line number.
203 +static int toLineMS(WindowInfo *window, DataValue *argList, int nArgs,
204 + DataValue *result, char **errMsg)
206 + int line, column;
207 + int pos;
209 + /*
210 + * Get text buffer position argument
211 + */
212 + if (nArgs == 0)
214 + *errMsg = "%s subroutine called with no arguments";
215 + return False;
217 + else if (nArgs > 1)
219 + return wrongNArgsErr(errMsg);
222 + if (!readIntArg(argList[0], &pos, errMsg))
224 + return False;
227 + /*
228 + * Convert text buffer position to related line number
229 + */
230 + if (!TextPosToLineAndCol(window->lastFocus, pos, &line, &column))
232 + line = BufCountLines(window->buffer, 0, pos) + 1;
235 + /*
236 + * Return determined line number
237 + */
238 + result->tag = INT_TAG;
239 + result->val.n = line;
241 + return True;
245 +** UL convertPos patch:
246 +** translate given text buffer position to column number.
248 +static int toColumnMS(WindowInfo *window, DataValue *argList, int nArgs,
249 + DataValue *result, char **errMsg)
251 + int line, column;
252 + int pos;
253 + textBuffer *buf = window->buffer;
255 + /*
256 + * Get text buffer position argument
257 + */
258 + if (nArgs == 0)
260 + *errMsg = "%s subroutine called with no arguments";
261 + return False;
263 + else if (nArgs > 1)
265 + return wrongNArgsErr(errMsg);
268 + if (!readIntArg(argList[0], &pos, errMsg))
270 + return False;
273 + /*
274 + * Convert text buffer position to related column number
275 + */
276 + if (!TextPosToLineAndCol(window->lastFocus, pos, &line, &column))
278 + column =
279 + BufCountDispChars(
280 + buf,
281 + BufStartOfLine(buf, pos),
282 + pos);
285 + /*
286 + * Return determined line number
287 + */
288 + result->tag = INT_TAG;
289 + result->val.n = column;
291 + return True;
294 static int wrongNArgsErr(char **errMsg)
296 *errMsg = "Wrong number of arguments to function %s";
297 return False;
299 diff --quilt old/source/selection.c new/source/selection.c
300 --- old/source/selection.c
301 +++ new/source/selection.c
302 @@ -99,27 +99,32 @@ int StringToLineAndCol(const char *text,
304 /* Get line number */
305 tempNum = strtol( text, &endptr, 10 );
307 /* If user didn't specify a line number, set lineNum to -1 */
309 + /* UL convertPos patch: negative values are interpreted as */
310 + /* not specified (i.s.o. line nbr. "0") */
311 if ( endptr == text ) { *lineNum = -1; }
312 else if ( tempNum >= INT_MAX ) { *lineNum = INT_MAX; }
313 - else if ( tempNum < 0 ) { *lineNum = 0; }
314 + else if ( tempNum < 0 ) { *lineNum = -1; }
315 else { *lineNum = tempNum; }
317 /* Find the next digit */
318 for ( textLen = strlen( endptr ); textLen > 0; endptr++, textLen-- ) {
319 if (isdigit((int) *endptr ) || *endptr == '-' || *endptr == '+') {
320 break;
324 + /* UL convertPos patch: negative values are interpreted as */
325 + /* not specified (i.s.o. column nbr. "0") */
326 /* Get column */
327 if ( *endptr != '\0' ) {
328 tempNum = strtol( endptr, NULL, 10 );
329 if ( tempNum >= INT_MAX ) { *column = INT_MAX; }
330 - else if ( tempNum < 0 ) { *column = 0; }
331 + else if ( tempNum < 0 ) { *column = -1; }
332 else { *column = tempNum; }
334 else { *column = -1; }
336 return *lineNum == -1 && *column == -1 ? -1 : 0;