1 From: Tony Balinski <ajbj@free.fr>
2 Subject: Allow a macro to set the document's window title or title format
4 This is done by allowing the document window to carry a custom version
5 of the title format string. The new macro function,
6 set_window_title_format(), is called as follows:
8 set_window_title_format(string)
9 set_window_title_format(string, "text")
10 set_window_title_format(string, "format")
12 The string will be interpreted as a title format if the "format" keyword is
13 supplied, or as a fixed title string otherwise. The format directives are
14 those used in Preferences> Default Settings> Customize Window Title...
15 dialog. If an empty string is used, the default format (from the
16 Preferences) is applied.
21 source/highlightData.c | 2 -
22 source/macro.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++
24 source/window.c | 25 ++++++++++++---
25 5 files changed, 105 insertions(+), 7 deletions(-)
27 diff --quilt old/doc/help.etx new/doc/help.etx
30 @@ -4046,13 +4046,20 @@ Preferences
32 Add/remove items from the Shell, Macro, and window background menus (see
35 **Customize Window Title**
37 + Opens a dialog where the information to be displayed in the window's title
38 + field can be defined and tested. The Customize_Window_Title_Dialog_ contains
39 + a Help button, providing further information about the options available.
42 Opens a dialog where the information to be displayed in the window's title
43 field can be defined and tested. The dialog contains a Help button, providing
44 further information about the options available.
48 Options for controlling the behavior of Find and Replace commands:
51 diff --quilt old/source/macro.c new/source/macro.c
52 --- old/source/macro.c
53 +++ new/source/macro.c
54 @@ -424,10 +424,12 @@ static int getStyleAtPosMS(WindowInfo *w
55 DataValue *result, char **errMsg);
56 static int filenameDialogMS(WindowInfo* window, DataValue* argList, int nArgs,
57 DataValue* result, char** errMsg);
58 static int callMS(WindowInfo *window, DataValue *argList,
59 int nArgs, DataValue *result, char **errMsg);
60 +static int setWindowTitleMS(WindowInfo *window, DataValue *argList,
61 + int nArgs, DataValue *result, char **errMsg);
63 /* Pattern Match Feature */
64 static int getMatchingMS(WindowInfo *window, DataValue *argList, int nArgs,
65 DataValue *result, char **errMsg);
67 @@ -524,10 +526,11 @@ static const BuiltInSubrName MacroSubrs[
68 { "dict_is_element", dictiselementMS },
69 { "define", defineMS },
70 { "to_pos", toPosMS },
71 { "to_line", toLineMS },
72 { "to_column", toColumnMS },
73 + { "set_window_title", setWindowTitleMS },
74 { NULL, NULL } /* sentinel */
77 static const BuiltInSubrName SpecialVars[] = {
78 { "$cursor", cursorMV },
79 @@ -3718,10 +3721,84 @@ static int defineMS(WindowInfo *window,
86 + * set_window_title(format[, ("text"|"format")])
88 +static int setWindowTitleMS(WindowInfo *window, DataValue *argList,
89 + int nArgs, DataValue *result, char **errMsg)
91 + char stringStorage[2][TYPE_INT_STR_SIZE(int)];
100 + *errMsg = "subroutine %s called with too many arguments";
104 + !readStringArg(argList[0], &fmt, stringStorage[0], errMsg)) {
108 + !readStringArg(argList[1], &type, stringStorage[1], errMsg)) {
112 + if (strcmp(type, "text") == 0)
114 + else if (strcmp(type, "format") == 0)
117 + *errMsg = "subroutine %s type value must be \"text\" or \"format\"";
122 + if (!fmt || !*fmt) {
123 + /* empty string: return tu default behaviour */
124 + XtFree(window->titleFormat);
125 + window->titleFormat = NULL;
126 + UpdateWindowTitle(window);
132 + /* measure extra space for '%' */
133 + for (from = fmt; *from; from++)
138 + newFmt = XtMalloc(strlen(fmt) + perCents + 1);
140 + *errMsg = "subroutine %s failed to allocate format value";
144 + /* double up any % signs */
145 + for (from = fmt, to = newFmt; *from; *to++ = *from++)
151 + strcpy(newFmt, fmt);
153 + XtFree(window->titleFormat);
154 + window->titleFormat = newFmt;
155 + UpdateWindowTitle(window);
160 static int listDialogMS(WindowInfo *window, DataValue *argList, int nArgs,
161 DataValue *result, char **errMsg)
163 macroCmdInfo *cmdData;
164 diff --quilt old/source/nedit.h new/source/nedit.h
165 --- old/source/nedit.h
166 +++ new/source/nedit.h
167 @@ -457,10 +457,11 @@ typedef struct _WindowInfo {
168 short menus on and off */
169 int nToggleShortItems;
171 char filename[MAXPATHLEN]; /* name component of file being edited*/
172 char path[MAXPATHLEN]; /* path component of file being edited*/
173 + char *titleFormat; /* custom title format string */
174 unsigned fileMode; /* permissions of file being edited */
175 uid_t fileUid; /* last recorded user id of the file */
176 gid_t fileGid; /* last recorded group id of the file */
177 int fileFormat; /* whether to save the file straight
178 (Unix format), or convert it to
179 diff --quilt old/source/window.c new/source/window.c
180 --- old/source/window.c
181 +++ new/source/window.c
182 @@ -251,10 +251,11 @@ WindowInfo *CreateWindow(const char *nam
183 window->multiFileReplSelected = FALSE;
184 window->multiFileBusy = FALSE;
185 window->writableWindows = NULL;
186 window->nWritableWindows = 0;
187 window->fileChanged = FALSE;
188 + window->titleFormat = NULL;
189 window->fileMode = 0;
192 window->filenameSet = FALSE;
193 window->fileFormat = UNIX_FILE_FORMAT;
194 @@ -976,11 +977,17 @@ void CloseWindow(WindowInfo *window)
197 /* Kill shell sub-process and free related memory */
198 AbortShellCommand(window);
202 + /* drop any custom title */
203 + if (window->titleFormat) {
204 + XtFree(window->titleFormat);
205 + window->titleFormat = NULL;
208 /* Unload the default tips files for this language mode if necessary */
209 UnloadLanguageModeTipsFile(window);
211 /* If a window is closed while it is on the multi-file replace dialog
212 list of any other window (or even the same one), we must update those
213 @@ -2098,15 +2105,17 @@ void SetWindowModified(WindowInfo *windo
214 ** Update the window title to reflect the filename, read-only, and modified
215 ** status of the window data structure
217 void UpdateWindowTitle(const WindowInfo *window)
219 - char *iconTitle, *title;
220 + char *iconTitle, *title, *format, *filename;
222 if (!IsTopDocument(window))
225 + format = window->titleFormat ? window->titleFormat : GetPrefTitleFormat();
226 + filename = window->filename;
227 title = FormatWindowTitle(window->filename,
232 @@ -2116,15 +2125,18 @@ void UpdateWindowTitle(const WindowInfo
238 - GetPrefTitleFormat());
240 - iconTitle = XtMalloc(strlen(window->filename) + 2); /* strlen("*")+1 */
243 + if (strcmp(title, format) == 0)
246 + iconTitle = XtMalloc(strlen(filename) + 2); /* strlen("*")+1 */
248 - strcpy(iconTitle, window->filename);
249 + strcpy(iconTitle, filename);
250 if (window->fileChanged && !window->transient)
251 strcat(iconTitle, "*");
252 XtVaSetValues(window->shell, XmNtitle, title, XmNiconName, iconTitle, NULL);
254 /* If there's a find or replace dialog up in "Keep Up" mode, with a
255 @@ -3431,10 +3443,11 @@ WindowInfo* CreateDocument(WindowInfo* s
256 window->multiFileBusy = FALSE;
257 window->writableWindows = NULL;
258 window->nWritableWindows = 0;
259 window->fileChanged = FALSE;
260 window->fileMissing = True;
261 + window->titleFormat = NULL;
262 window->fileMode = 0;
265 window->filenameSet = FALSE;
266 window->fileFormat = UNIX_FILE_FORMAT;
267 diff --quilt old/source/highlightData.c new/source/highlightData.c
268 --- old/source/highlightData.c
269 +++ new/source/highlightData.c
270 @@ -549,11 +549,11 @@ static char *DefaultPatternSets[] = {
271 README:\"NEdit Macro syntax highlighting patterns, version 2.6, maintainer Thorsten Haude, nedit at thorstenhau.de\":::Flag::D\n\
272 Comment:\"#\":\"$\"::Comment::\n\
273 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\
274 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\
275 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\
276 - 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_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|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|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\
277 + 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_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|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|to_(?:column|line|pos)|tolower|toupper|valid_number|write_file)(?=\\s*\\()\":::Subroutine::\n\
278 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\
279 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\
280 Macro Hooks:\"<(?:(?:pre|post)_(?:open|save)|cursor_moved|modified|(?:losing_)?focus)_hook(?=\\s*\\()\":::Subroutine1::\n\
281 Keyword:\"<(?:break|continue|define|delete|else|for|if|in|return|typeof|while)>\":::Keyword::\n\
282 Braces:\"[{}\\[\\]]\":::Keyword::\n\