InterpretDebug-mods: calculate OpName length
[nedit-bw.git] / setWindowTitleFormat.diff
blobcd896ea42ec0efe0c4025f5bafc4167b188096b9
1 Allow a macro to set the document's window title or title format
3 This is done by allowing the document window to carry a custom version
4 of the title format string. The new macro function,
5 set_window_title_format(), is called as follows:
6 set_window_title_format(<I>string</I>)
7 set_window_title_format(<I>string</I>, "text")
8 set_window_title_format(<I>string</I>, "format")
9 The string will be interpreted as a title format if the "format" keyword is
10 supplied, or as a fixed title string otherwise. The format directives are
11 those used in Preferences> Default Settings> Customize Window Title...
12 dialog. If an empty string is used, the default format (from the
13 Preferences) is applied.
15 ---
17 doc/help.etx | 7 ++++
18 source/highlightData.c | 2 -
19 source/macro.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++
20 source/nedit.h | 1
21 source/window.c | 25 ++++++++++++---
22 5 files changed, 105 insertions(+), 7 deletions(-)
24 diff --quilt old/doc/help.etx new/doc/help.etx
25 --- old/doc/help.etx
26 +++ new/doc/help.etx
27 @@ -4023,13 +4023,20 @@ Preferences
28 **Customize Menus**
29 Add/remove items from the Shell, Macro, and window background menus (see
30 below).
32 **Customize Window Title**
33 +.. ? help~
34 + Opens a dialog where the information to be displayed in the window's title
35 + field can be defined and tested. The Customize_Window_Title_Dialog_ contains
36 + a Help button, providing further information about the options available.
37 +.. ~ help
38 +.. ! help~
39 Opens a dialog where the information to be displayed in the window's title
40 field can be defined and tested. The dialog contains a Help button, providing
41 further information about the options available.
42 +.. ~ help
44 **Searching**
45 Options for controlling the behavior of Find and Replace commands:
47 ~Verbose~ -
48 diff --quilt old/source/macro.c new/source/macro.c
49 --- old/source/macro.c
50 +++ new/source/macro.c
51 @@ -414,10 +414,12 @@ static int getStyleAtPosMS(WindowInfo *w
52 DataValue *result, char **errMsg);
53 static int filenameDialogMS(WindowInfo* window, DataValue* argList, int nArgs,
54 DataValue* result, char** errMsg);
55 static int callMS(WindowInfo *window, DataValue *argList,
56 int nArgs, DataValue *result, char **errMsg);
57 +static int setWindowTitleMS(WindowInfo *window, DataValue *argList,
58 + int nArgs, DataValue *result, char **errMsg);
60 /* Pattern Match Feature */
61 static int getMatchingMS(WindowInfo *window, DataValue *argList, int nArgs,
62 DataValue *result, char **errMsg);
64 @@ -514,10 +516,11 @@ static const BuiltInSubrName MacroSubrs[
65 { "dict_is_element", dictiselementMS },
66 { "define", defineMS },
67 { "to_pos", toPosMS },
68 { "to_line", toLineMS },
69 { "to_column", toColumnMS },
70 + { "set_window_title", setWindowTitleMS },
71 { NULL, NULL } /* sentinel */
74 static const BuiltInSubrName SpecialVars[] = {
75 { "$cursor", cursorMV },
76 @@ -3844,10 +3847,84 @@ static int defineMS(WindowInfo *window,
79 return True;
82 +/*
83 + * set_window_title(format[, ("text"|"format")])
84 + */
85 +static int setWindowTitleMS(WindowInfo *window, DataValue *argList,
86 + int nArgs, DataValue *result, char **errMsg)
88 + char stringStorage[2][TYPE_INT_STR_SIZE(int)];
89 + char *fmt = NULL;
90 + char *type = NULL;
91 + char *newFmt;
92 + char *from, *to;
93 + int isText = 1;
94 + int perCents;
96 + if (nArgs > 2) {
97 + *errMsg = "subroutine %s called with too many arguments";
98 + return False;
99 + }
100 + if (nArgs > 0 &&
101 + !readStringArg(argList[0], &fmt, stringStorage[0], errMsg)) {
102 + return False;
104 + if (nArgs > 1 &&
105 + !readStringArg(argList[1], &type, stringStorage[1], errMsg)) {
106 + return False;
108 + if (type) {
109 + if (strcmp(type, "text") == 0)
110 + isText = 1;
111 + else if (strcmp(type, "format") == 0)
112 + isText = 0;
113 + else {
114 + *errMsg = "subroutine %s type value must be \"text\" or \"format\"";
115 + return False;
119 + if (!fmt || !*fmt) {
120 + /* empty string: return tu default behaviour */
121 + XtFree(window->titleFormat);
122 + window->titleFormat = NULL;
123 + UpdateWindowTitle(window);
124 + return True;
127 + perCents = 0;
128 + if (!isText) {
129 + /* measure extra space for '%' */
130 + for (from = fmt; *from; from++)
131 + if ('%' == *from)
132 + ++perCents;
135 + newFmt = XtMalloc(strlen(fmt) + perCents + 1);
136 + if (!newFmt) {
137 + *errMsg = "subroutine %s failed to allocate format value";
138 + return False;
140 + if (isText) {
141 + /* double up any % signs */
142 + for (from = fmt, to = newFmt; *from; *to++ = *from++)
143 + if ('%' == *from)
144 + *to++ = '%';
145 + *to = '\0';
147 + else
148 + strcpy(newFmt, fmt);
150 + XtFree(window->titleFormat);
151 + window->titleFormat = newFmt;
152 + UpdateWindowTitle(window);
153 + return True;
156 /* T Balinski */
157 static int listDialogMS(WindowInfo *window, DataValue *argList, int nArgs,
158 DataValue *result, char **errMsg)
160 macroCmdInfo *cmdData;
161 diff --quilt old/source/nedit.h new/source/nedit.h
162 --- old/source/nedit.h
163 +++ new/source/nedit.h
164 @@ -458,10 +458,11 @@ typedef struct _WindowInfo {
165 short menus on and off */
166 int nToggleShortItems;
167 #endif
168 char filename[MAXPATHLEN]; /* name component of file being edited*/
169 char path[MAXPATHLEN]; /* path component of file being edited*/
170 + char *titleFormat; /* custom title format string */
171 unsigned fileMode; /* permissions of file being edited */
172 uid_t fileUid; /* last recorded user id of the file */
173 gid_t fileGid; /* last recorded group id of the file */
174 int fileFormat; /* whether to save the file straight
175 (Unix format), or convert it to
176 diff --quilt old/source/window.c new/source/window.c
177 --- old/source/window.c
178 +++ new/source/window.c
179 @@ -248,10 +248,11 @@ WindowInfo *CreateWindow(const char *nam
180 window->multiFileReplSelected = FALSE;
181 window->multiFileBusy = FALSE;
182 window->writableWindows = NULL;
183 window->nWritableWindows = 0;
184 window->fileChanged = FALSE;
185 + window->titleFormat = NULL;
186 window->fileMode = 0;
187 window->fileUid = 0;
188 window->fileGid = 0;
189 window->filenameSet = FALSE;
190 window->fileFormat = UNIX_FILE_FORMAT;
191 @@ -955,11 +956,17 @@ void CloseWindow(WindowInfo *window)
193 #ifndef VMS
194 /* Kill shell sub-process and free related memory */
195 AbortShellCommand(window);
196 #endif /*VMS*/
199 + /* drop any custom title */
200 + if (window->titleFormat) {
201 + XtFree(window->titleFormat);
202 + window->titleFormat = NULL;
205 /* Unload the default tips files for this language mode if necessary */
206 UnloadLanguageModeTipsFile(window);
208 /* If a window is closed while it is on the multi-file replace dialog
209 list of any other window (or even the same one), we must update those
210 @@ -2075,15 +2082,17 @@ void SetWindowModified(WindowInfo *windo
211 ** Update the window title to reflect the filename, read-only, and modified
212 ** status of the window data structure
214 void UpdateWindowTitle(const WindowInfo *window)
216 - char *iconTitle, *title;
217 + char *iconTitle, *title, *format, *filename;
219 if (!IsTopDocument(window))
220 return;
222 + format = window->titleFormat ? window->titleFormat : GetPrefTitleFormat();
223 + filename = window->filename;
224 title = FormatWindowTitle(window->filename,
225 window->path,
226 #ifdef VMS
227 NULL,
228 #else
229 @@ -2093,15 +2102,18 @@ void UpdateWindowTitle(const WindowInfo
230 IsServer,
231 window->filenameSet,
232 window->lockReasons,
233 window->fileChanged,
234 window->transient,
235 - GetPrefTitleFormat());
237 - iconTitle = XtMalloc(strlen(window->filename) + 2); /* strlen("*")+1 */
238 + format);
240 + if (strcmp(title, format) == 0)
241 + filename = title;
243 + iconTitle = XtMalloc(strlen(filename) + 2); /* strlen("*")+1 */
245 - strcpy(iconTitle, window->filename);
246 + strcpy(iconTitle, filename);
247 if (window->fileChanged && !window->transient)
248 strcat(iconTitle, "*");
249 XtVaSetValues(window->shell, XmNtitle, title, XmNiconName, iconTitle, NULL);
251 /* If there's a find or replace dialog up in "Keep Up" mode, with a
252 @@ -3415,10 +3427,11 @@ WindowInfo* CreateDocument(WindowInfo* s
253 window->multiFileBusy = FALSE;
254 window->writableWindows = NULL;
255 window->nWritableWindows = 0;
256 window->fileChanged = FALSE;
257 window->fileMissing = True;
258 + window->titleFormat = NULL;
259 window->fileMode = 0;
260 window->fileUid = 0;
261 window->fileGid = 0;
262 window->filenameSet = FALSE;
263 window->fileFormat = UNIX_FILE_FORMAT;
264 diff --quilt old/source/highlightData.c new/source/highlightData.c
265 --- old/source/highlightData.c
266 +++ new/source/highlightData.c
267 @@ -549,11 +549,11 @@ static char *DefaultPatternSets[] = {
268 README:\"NEdit Macro syntax highlighting patterns, version 2.6, maintainer Thorsten Haude, nedit at thorstenhau.de\":::Flag::D\n\
269 Comment:\"#\":\"$\"::Comment::\n\
270 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\
271 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\
272 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\
273 - Built-in Subrs:\"<(?:append_file|beep|call|calltip|clipboard_to_string|define|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|valid_number|write_file)(?=\\s*\\()\":::Subroutine::\n\
274 + Built-in Subrs:\"<(?:append_file|beep|call|calltip|clipboard_to_string|define|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|to_(?:column|line|pos)|tolower|toupper|valid_number|write_file)(?=\\s*\\()\":::Subroutine::\n\
275 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\
276 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\
277 Macro Hooks:\"<(?:post_open|pre_open|post_save|cursor_moved|modified|focus|losing_focus)_hook(?=\\s*\\()\":::Subroutine1::\n\
278 Keyword:\"<(?:break|continue|define|delete|else|for|if|in|return|typeof|while)>\":::Keyword::\n\
279 Braces:\"[{}\\[\\]]\":::Keyword::\n\