push up read_from_pipes.patch
[nedit-bw.git] / select_word.patch
blob5be66afe7e3679b29a9da2a77166c0d8d17a7ae3
1 NEdit*text.translations: #override \
2 Ctrl~Meta~Alt<KeyPress>b: select_word()\n\
3 ...
5 ---
7 doc/help.etx | 21 ++++++++++++---------
8 source/highlightData.c | 2 +-
9 source/menu.c | 9 +++++++++
10 source/nedit.c | 2 ++
11 source/text.c | 26 ++++++++++++++++++++++++++
12 source/text.h | 1 +
13 6 files changed, 51 insertions(+), 10 deletions(-)
15 diff --quilt old/doc/help.etx new/doc/help.etx
16 --- old/doc/help.etx
17 +++ new/doc/help.etx
18 @@ -3275,19 +3275,19 @@ Action Routines
19 ----------------------- filter_selection()
20 undo() execute_command()
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 move_document_dialog()
47 @@ -3809,10 +3809,13 @@ Action Routines
48 a secondary selection.
50 **select_all()**
51 Select the entire file.
53 +**select_word()**
54 + Select the word under the cursor.
56 **self_insert()**
57 To be attached to a key-press event, inserts the character
58 equivalent of the key pressed.
61 diff --quilt old/source/highlightData.c new/source/highlightData.c
62 --- old/source/highlightData.c
63 +++ new/source/highlightData.c
64 @@ -551,11 +551,11 @@ static char *DefaultPatternSets[] = {
65 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\
66 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\
67 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\
68 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\
69 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\
70 - 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\
71 + 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\
72 Macro Hooks:\"<(?:post_open|pre_open|post_save|cursor_moved|modified|focus|losing_focus)_hook(?=\\s*\\()\":::Subroutine1::\n\
73 Keyword:\"<(?:break|continue|define|delete|else|for|if|in|return|while)>\":::Keyword::\n\
74 Braces:\"[{}\\[\\]]\":::Keyword::\n\
75 Global Variable:\"\\$[A-Za-z0-9_]+\":::Identifier1::\n\
76 String:\"\"\"\":\"\"\"\":\"\\n\":String::\n\
77 diff --quilt old/source/menu.c new/source/menu.c
78 --- old/source/menu.c
79 +++ new/source/menu.c
80 @@ -260,10 +260,11 @@ static void printSelAP(Widget w, XEvent
81 static void exitAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
82 static void undoAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
83 static void redoAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
84 static void clearAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
85 static void selAllAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
86 +static void selWordAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
87 static void shiftLeftAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
88 static void shiftLeftTabAP(Widget w, XEvent *event, String *args,
89 Cardinal *nArgs);
90 static void shiftRightAP(Widget w, XEvent *event, String *args,
91 Cardinal *nArgs);
92 @@ -478,10 +479,11 @@ static XtActionsRec Actions[] = {
93 {"undo", undoAP},
94 {"redo", redoAP},
95 {"delete", clearAP},
96 {"select-all", selAllAP},
97 {"select_all", selAllAP},
98 + {"select_word", selWordAP},
99 {"shift-left", shiftLeftAP},
100 {"shift_left", shiftLeftAP},
101 {"shift-left-by-tab", shiftLeftTabAP},
102 {"shift_left_by_tab", shiftLeftTabAP},
103 {"shift-right", shiftRightAP},
104 @@ -746,10 +748,12 @@ Widget CreateMenuBar(Widget parent, Wind
105 window->delItem=createMenuItem(menuPane, "delete", "Delete", 'D', doActionCB, "delete_selection",
106 SHORT);
107 XtSetSensitive(window->delItem, window->wasSelected);
108 createMenuItem(menuPane, "selectAll", "Select All", 'A', doActionCB,
109 "select_all", SHORT);
110 + createMenuItem(menuPane, "selectWord", "Select Word", 'W', doActionCB,
111 + "select_word", SHORT);
112 createMenuSeparator(menuPane, "sep2", SHORT);
113 createMenuItem(menuPane, "shiftLeft", "Shift Left", 'L',
114 shiftLeftCB, window, SHORT);
115 createFakeMenuItem(menuPane, "shiftLeftShift", shiftLeftCB, window);
116 createMenuItem(menuPane, "shiftRight", "Shift Right", 'g',
117 @@ -3260,10 +3264,15 @@ static void selAllAP(Widget w, XEvent *e
118 WindowInfo *window = WidgetToWindow(w);
120 BufSelect(window->buffer, 0, window->buffer->length);
123 +static void selWordAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
125 + TextSelectWord(w);
128 static void shiftLeftAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
130 WindowInfo *window = WidgetToWindow(w);
132 if (CheckReadOnly(window))
133 diff --quilt old/source/nedit.c new/source/nedit.c
134 --- old/source/nedit.c
135 +++ new/source/nedit.c
136 @@ -264,10 +264,12 @@ static char *fallbackResources[] = {
137 "*editMenu.pasteColumn.accelerator: Shift Ctrl<Key>v",
138 "*editMenu.pasteColumn.acceleratorText: Ctrl+Shift+V",
139 "*editMenu.delete.acceleratorText: Del",
140 "*editMenu.selectAll.accelerator: Ctrl<Key>a",
141 "*editMenu.selectAll.acceleratorText: Ctrl+A",
142 + "*editMenu.selectWord.accelerator: Ctrl<Key>b",
143 + "*editMenu.selectWord.acceleratorText: Ctrl+B",
144 "*editMenu.shiftLeft.accelerator: Ctrl<Key>9",
145 "*editMenu.shiftLeft.acceleratorText: [Shift]Ctrl+9",
146 "*editMenu.shiftLeftShift.accelerator: Shift Ctrl<Key>9",
147 "*editMenu.shiftRight.accelerator: Ctrl<Key>0",
148 "*editMenu.shiftRight.acceleratorText: [Shift]Ctrl+0",
149 diff --quilt old/source/text.c new/source/text.c
150 --- old/source/text.c
151 +++ new/source/text.c
152 @@ -206,10 +206,12 @@ static void scrollToLineAP(Widget w, XEv
153 Cardinal *nArgs);
154 static void selectAllAP(Widget w, XEvent *event, String *args,
155 Cardinal *nArgs);
156 static void deselectAllAP(Widget w, XEvent *event, String *args,
157 Cardinal *nArgs);
158 +static void selectWordAP(Widget w, XEvent *event, String *args,
159 + Cardinal *nArgs);
160 static void focusInAP(Widget w, XEvent *event, String *args,
161 Cardinal *nArgs);
162 static void focusOutAP(Widget w, XEvent *event, String *args,
163 Cardinal *nArgs);
164 static void checkMoveSelectionChange(Widget w, XEvent *event, int startPos,
165 @@ -563,10 +565,11 @@ static XtActionsRec actionsList[] = {
166 {"scroll_to_line", scrollToLineAP},
167 {"select-all", selectAllAP},
168 {"select_all", selectAllAP},
169 {"deselect-all", deselectAllAP},
170 {"deselect_all", deselectAllAP},
171 + {"select_word", selectWordAP},
172 {"focusIn", focusInAP},
173 {"focusOut", focusOutAP},
174 {"process-return", selfInsertAP},
175 {"process_return", selfInsertAP},
176 {"process-tab", processTabAP},
177 @@ -3459,10 +3462,16 @@ static void deselectAllAP(Widget w, XEve
179 cancelDrag(w);
180 BufUnselect(((TextWidget)w)->text.textD->buffer);
183 +static void selectWordAP(Widget w, XEvent *event, String *args,
184 + Cardinal *nArgs)
186 + TextSelectWord(w);
190 ** Called on the Intrinsic FocusIn event.
192 ** Note that the widget has no internal state about the focus, ie. it does
193 ** not know whether it has the focus or not.
194 @@ -3795,10 +3804,27 @@ static void selectWord(Widget w, int poi
195 insertPos--;
197 BufSelect(buf, startOfWord(tw, insertPos), endOfWord(tw, insertPos));
200 +void TextSelectWord(Widget w)
202 + TextWidget tw = (TextWidget)w;
203 + textBuffer *buf = tw->text.textD->buffer;
204 + int insertPos = TextDGetInsertPosition(tw->text.textD);
206 + if (insertPos > 0
207 + && BufGetCharacter(buf, insertPos) == '\n'
208 + && BufGetCharacter(buf, insertPos-1) != '\n')
209 + insertPos--;
211 + if (insertPos > 0 && insertPos == buf->length)
212 + insertPos--;
214 + BufSelect(buf, startOfWord(tw, insertPos), endOfWord(tw, insertPos));
217 static int startOfWord(TextWidget w, int pos)
219 int startPos;
220 textBuffer *buf = w->text.textD->buffer;
221 char *delimiters=w->text.delimiters;
222 diff --quilt old/source/text.h new/source/text.h
223 --- old/source/text.h
224 +++ new/source/text.h
225 @@ -159,10 +159,11 @@ int TextPosToLineAndCol(Widget w, int po
226 int TextPosToXY(Widget w, int pos, int *x, int *y);
227 int TextGetCursorPos(Widget w);
228 void TextSetCursorPos(Widget w, int pos);
229 void TextGetScroll(Widget w, int *topLineNum, int *horizOffset);
230 void TextSetScroll(Widget w, int topLineNum, int horizOffset);
231 +void TextSelectWord(Widget w);
232 int TextGetMinFontWidth(Widget w, Boolean considerStyles);
233 int TextGetMaxFontWidth(Widget w, Boolean considerStyles);
234 void TextHandleXSelections(Widget w);
235 void TextPasteClipboard(Widget w, Time time);
236 void TextColPasteClipboard(Widget w, Time time);