drop extend-if-key-in-array-syntax.patch add yacc debug
[nedit-bw.git] / select_word.patch
blobb6e2770bdd31dedbed475e8ff21a00c9eaa10866
1 Subject: select_word() action routine
3 NEdit*text.translations: #override \
4 Ctrl~Meta~Alt<KeyPress>b: select_word()\n\
5 ...
7 ---
9 doc/help.etx | 21 ++++++++++++---------
10 source/highlightData.c | 2 +-
11 source/menu.c | 9 +++++++++
12 source/nedit.c | 2 ++
13 source/text.c | 26 ++++++++++++++++++++++++++
14 source/text.h | 1 +
15 6 files changed, 51 insertions(+), 10 deletions(-)
17 diff --quilt old/doc/help.etx new/doc/help.etx
18 --- old/doc/help.etx
19 +++ new/doc/help.etx
20 @@ -3288,15 +3288,15 @@ Action Routines
21 redo() execute_command_dialog()
22 delete() execute_command_line()
23 select_all() shell_menu_command()
24 - shift_left()
25 - shift_left_by_tab() Macro Menu
26 - shift_right() -------------------------
27 - shift_right_by_tab() macro_menu_command()
28 - uppercase() repeat_macro()
29 - lowercase() repeat_dialog()
30 - fill_paragraph()
31 - control_code_dialog() Windows Menu
32 - -------------------------
33 + select_word()
34 + shift_left() Macro Menu
35 + shift_left_by_tab() -------------------------
36 + shift_right() macro_menu_command()
37 + shift_right_by_tab() repeat_macro()
38 + uppercase() repeat_dialog()
39 + lowercase()
40 + fill_paragraph() Windows Menu
41 + control_code_dialog() -------------------------
42 split_pane()
43 close_pane()
44 detach_document()
45 @@ -3822,6 +3822,9 @@ Action Routines
46 **select_all()**
47 Select the entire file.
49 +**select_word()**
50 + Select the word under the cursor.
52 **self_insert()**
53 To be attached to a key-press event, inserts the character
54 equivalent of the key pressed.
55 diff --quilt old/source/highlightData.c new/source/highlightData.c
56 --- old/source/highlightData.c
57 +++ new/source/highlightData.c
58 @@ -553,7 +553,7 @@ static char *DefaultPatternSets[] = {
59 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\
60 Built-in Subrs:\"<(?:args|append_file|beep|call|calltip|clipboard_to_string|define|dialog|filename_dialog|dict_(?:insert|complete|save|append|is_element)|escape_literal|focus_window|get_character|get_matching|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|n_args|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|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|valid_number|write_file)(?=\\s*\\()\":::Subroutine::\n\
61 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\
62 - 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\
63 + 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\
64 Macro Hooks:\"<(?:(?:pre|post)_(?:open|save)|cursor_moved|modified|(?:losing_)?focus)_hook(?=\\s*\\()\":::Subroutine1::\n\
65 Keyword:\"<(?:break|continue|define|delete|do|else|for|if|in|return|typeof|while)>\":::Keyword::\n\
66 Braces:\"[{}\\[\\]]\":::Keyword::\n\
67 diff --quilt old/source/menu.c new/source/menu.c
68 --- old/source/menu.c
69 +++ new/source/menu.c
70 @@ -261,6 +261,7 @@ static void undoAP(Widget w, XEvent *eve
71 static void redoAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
72 static void clearAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
73 static void selAllAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
74 +static void selWordAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
75 static void shiftLeftAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
76 static void shiftLeftTabAP(Widget w, XEvent *event, String *args,
77 Cardinal *nArgs);
78 @@ -479,6 +480,7 @@ static XtActionsRec Actions[] = {
79 {"delete", clearAP},
80 {"select-all", selAllAP},
81 {"select_all", selAllAP},
82 + {"select_word", selWordAP},
83 {"shift-left", shiftLeftAP},
84 {"shift_left", shiftLeftAP},
85 {"shift-left-by-tab", shiftLeftTabAP},
86 @@ -747,6 +749,8 @@ Widget CreateMenuBar(Widget parent, Wind
87 XtSetSensitive(window->delItem, window->wasSelected);
88 createMenuItem(menuPane, "selectAll", "Select All", 'A', doActionCB,
89 "select_all", SHORT);
90 + createMenuItem(menuPane, "selectWord", "Select Word", 'W', doActionCB,
91 + "select_word", SHORT);
92 createMenuSeparator(menuPane, "sep2", SHORT);
93 createMenuItem(menuPane, "shiftLeft", "Shift Left", 'L',
94 shiftLeftCB, window, SHORT);
95 @@ -3251,6 +3255,11 @@ static void selAllAP(Widget w, XEvent *e
96 BufSelect(window->buffer, 0, window->buffer->length);
99 +static void selWordAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
101 + TextSelectWord(w);
104 static void shiftLeftAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
106 WindowInfo *window = WidgetToWindow(w);
107 diff --quilt old/source/nedit.c new/source/nedit.c
108 --- old/source/nedit.c
109 +++ new/source/nedit.c
110 @@ -266,6 +266,8 @@ static char *fallbackResources[] = {
111 "*editMenu.delete.acceleratorText: Del",
112 "*editMenu.selectAll.accelerator: Ctrl<Key>a",
113 "*editMenu.selectAll.acceleratorText: Ctrl+A",
114 + "*editMenu.selectWord.accelerator: Ctrl<Key>b",
115 + "*editMenu.selectWord.acceleratorText: Ctrl+B",
116 "*editMenu.shiftLeft.accelerator: Ctrl<Key>9",
117 "*editMenu.shiftLeft.acceleratorText: [Shift]Ctrl+9",
118 "*editMenu.shiftLeftShift.accelerator: Shift Ctrl<Key>9",
119 diff --quilt old/source/text.c new/source/text.c
120 --- old/source/text.c
121 +++ new/source/text.c
122 @@ -208,6 +208,8 @@ static void selectAllAP(Widget w, XEvent
123 Cardinal *nArgs);
124 static void deselectAllAP(Widget w, XEvent *event, String *args,
125 Cardinal *nArgs);
126 +static void selectWordAP(Widget w, XEvent *event, String *args,
127 + Cardinal *nArgs);
128 static void focusInAP(Widget w, XEvent *event, String *args,
129 Cardinal *nArgs);
130 static void focusOutAP(Widget w, XEvent *event, String *args,
131 @@ -565,6 +567,7 @@ static XtActionsRec actionsList[] = {
132 {"select_all", selectAllAP},
133 {"deselect-all", deselectAllAP},
134 {"deselect_all", deselectAllAP},
135 + {"select_word", selectWordAP},
136 {"focusIn", focusInAP},
137 {"focusOut", focusOutAP},
138 {"process-return", selfInsertAP},
139 @@ -3451,6 +3454,12 @@ static void deselectAllAP(Widget w, XEve
140 BufUnselect(((TextWidget)w)->text.textD->buffer);
143 +static void selectWordAP(Widget w, XEvent *event, String *args,
144 + Cardinal *nArgs)
146 + TextSelectWord(w);
150 ** Called on the Intrinsic FocusIn event.
152 @@ -3784,6 +3793,23 @@ static void selectWord(Widget w, int poi
153 BufSelect(buf, startOfWord(tw, insertPos), endOfWord(tw, insertPos));
156 +void TextSelectWord(Widget w)
158 + TextWidget tw = (TextWidget)w;
159 + textBuffer *buf = tw->text.textD->buffer;
160 + int insertPos = TextDGetInsertPosition(tw->text.textD);
162 + if (insertPos > 0
163 + && BufGetCharacter(buf, insertPos) == '\n'
164 + && BufGetCharacter(buf, insertPos-1) != '\n')
165 + insertPos--;
167 + if (insertPos > 0 && insertPos == buf->length)
168 + insertPos--;
170 + BufSelect(buf, startOfWord(tw, insertPos), endOfWord(tw, insertPos));
173 static int startOfWord(TextWidget w, int pos)
175 int startPos;
176 diff --quilt old/source/text.h new/source/text.h
177 --- old/source/text.h
178 +++ new/source/text.h
179 @@ -157,6 +157,7 @@ int TextGetCursorPos(Widget w);
180 void TextSetCursorPos(Widget w, int pos);
181 void TextGetScroll(Widget w, int *topLineNum, int *horizOffset);
182 void TextSetScroll(Widget w, int topLineNum, int horizOffset);
183 +void TextSelectWord(Widget w);
184 int TextGetMinFontWidth(Widget w, Boolean considerStyles);
185 int TextGetMaxFontWidth(Widget w, Boolean considerStyles);
186 void TextHandleXSelections(Widget w);