refresh InterpretDebug5.diff
[nedit-bw.git] / setWindowTitleFormat.diff
blob4f939e8b19cf79d094f6ba43f46c57a453dbd3bd
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.
18 ---
20 doc/help.etx | 7 ++++
21 source/highlightData.c | 2 -
22 source/macro.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++
23 source/nedit.h | 1
24 source/window.c | 25 ++++++++++++---
25 5 files changed, 105 insertions(+), 7 deletions(-)
27 diff --quilt old/doc/help.etx new/doc/help.etx
28 --- old/doc/help.etx
29 +++ new/doc/help.etx
30 @@ -4047,9 +4047,16 @@ Preferences
31 below).
33 **Customize Window Title**
34 +.. ? help~
35 + Opens a dialog where the information to be displayed in the window's title
36 + field can be defined and tested. The Customize_Window_Title_Dialog_ contains
37 + a Help button, providing further information about the options available.
38 +.. ~ help
39 +.. ! help~
40 Opens a dialog where the information to be displayed in the window's title
41 field can be defined and tested. The dialog contains a Help button, providing
42 further information about the options available.
43 +.. ~ help
45 **Searching**
46 Options for controlling the behavior of Find and Replace commands:
47 diff --quilt old/source/macro.c new/source/macro.c
48 --- old/source/macro.c
49 +++ new/source/macro.c
50 @@ -430,6 +430,8 @@ static int filenameDialogMS(WindowInfo*
51 DataValue* result, char** errMsg);
52 static int callMS(WindowInfo *window, DataValue *argList,
53 int nArgs, DataValue *result, char **errMsg);
54 +static int setWindowTitleMS(WindowInfo *window, DataValue *argList,
55 + int nArgs, DataValue *result, char **errMsg);
57 /* Pattern Match Feature */
58 static int getMatchingMS(WindowInfo *window, DataValue *argList, int nArgs,
59 @@ -532,6 +534,7 @@ static const BuiltInSubrName MacroSubrs[
60 { "to_pos", toPosMS },
61 { "to_line", toLineMS },
62 { "to_column", toColumnMS },
63 + { "set_window_title", setWindowTitleMS },
64 { NULL, NULL } /* sentinel */
67 @@ -3792,6 +3795,80 @@ static int defineMS(WindowInfo *window,
68 return True;
71 +/*
72 + * set_window_title(format[, ("text"|"format")])
73 + */
74 +static int setWindowTitleMS(WindowInfo *window, DataValue *argList,
75 + int nArgs, DataValue *result, char **errMsg)
77 + char stringStorage[2][TYPE_INT_STR_SIZE(int)];
78 + char *fmt = NULL;
79 + char *type = NULL;
80 + char *newFmt;
81 + char *from, *to;
82 + int isText = 1;
83 + int perCents;
85 + if (nArgs > 2) {
86 + *errMsg = "subroutine %s called with too many arguments";
87 + return False;
88 + }
89 + if (nArgs > 0 &&
90 + !readStringArg(argList[0], &fmt, stringStorage[0], errMsg)) {
91 + return False;
92 + }
93 + if (nArgs > 1 &&
94 + !readStringArg(argList[1], &type, stringStorage[1], errMsg)) {
95 + return False;
96 + }
97 + if (type) {
98 + if (strcmp(type, "text") == 0)
99 + isText = 1;
100 + else if (strcmp(type, "format") == 0)
101 + isText = 0;
102 + else {
103 + *errMsg = "subroutine %s type value must be \"text\" or \"format\"";
104 + return False;
108 + if (!fmt || !*fmt) {
109 + /* empty string: return tu default behaviour */
110 + XtFree(window->titleFormat);
111 + window->titleFormat = NULL;
112 + UpdateWindowTitle(window);
113 + return True;
116 + perCents = 0;
117 + if (!isText) {
118 + /* measure extra space for '%' */
119 + for (from = fmt; *from; from++)
120 + if ('%' == *from)
121 + ++perCents;
124 + newFmt = XtMalloc(strlen(fmt) + perCents + 1);
125 + if (!newFmt) {
126 + *errMsg = "subroutine %s failed to allocate format value";
127 + return False;
129 + if (isText) {
130 + /* double up any % signs */
131 + for (from = fmt, to = newFmt; *from; *to++ = *from++)
132 + if ('%' == *from)
133 + *to++ = '%';
134 + *to = '\0';
136 + else
137 + strcpy(newFmt, fmt);
139 + XtFree(window->titleFormat);
140 + window->titleFormat = newFmt;
141 + UpdateWindowTitle(window);
142 + return True;
145 /* T Balinski */
146 static int listDialogMS(WindowInfo *window, DataValue *argList, int nArgs,
147 DataValue *result, char **errMsg)
148 diff --quilt old/source/nedit.h new/source/nedit.h
149 --- old/source/nedit.h
150 +++ new/source/nedit.h
151 @@ -459,6 +459,7 @@ typedef struct _WindowInfo {
152 #endif
153 char filename[MAXPATHLEN]; /* name component of file being edited*/
154 char path[MAXPATHLEN]; /* path component of file being edited*/
155 + char *titleFormat; /* custom title format string */
156 unsigned fileMode; /* permissions of file being edited */
157 uid_t fileUid; /* last recorded user id of the file */
158 gid_t fileGid; /* last recorded group id of the file */
159 diff --quilt old/source/window.c new/source/window.c
160 --- old/source/window.c
161 +++ new/source/window.c
162 @@ -253,6 +253,7 @@ WindowInfo *CreateWindow(const char *nam
163 window->writableWindows = NULL;
164 window->nWritableWindows = 0;
165 window->fileChanged = FALSE;
166 + window->titleFormat = NULL;
167 window->fileMode = 0;
168 window->fileUid = 0;
169 window->fileGid = 0;
170 @@ -977,7 +978,13 @@ void CloseWindow(WindowInfo *window)
171 /* Kill shell sub-process and free related memory */
172 AbortShellCommand(window);
173 #endif /*VMS*/
176 + /* drop any custom title */
177 + if (window->titleFormat) {
178 + XtFree(window->titleFormat);
179 + window->titleFormat = NULL;
182 /* Unload the default tips files for this language mode if necessary */
183 UnloadLanguageModeTipsFile(window);
185 @@ -2097,11 +2104,13 @@ void SetWindowModified(WindowInfo *windo
187 void UpdateWindowTitle(const WindowInfo *window)
189 - char *iconTitle, *title;
190 + char *iconTitle, *title, *format, *filename;
192 if (!IsTopDocument(window))
193 return;
195 + format = window->titleFormat ? window->titleFormat : GetPrefTitleFormat();
196 + filename = window->filename;
197 title = FormatWindowTitle(window->filename,
198 window->path,
199 #ifdef VMS
200 @@ -2115,11 +2124,14 @@ void UpdateWindowTitle(const WindowInfo
201 window->lockReasons,
202 window->fileChanged,
203 window->transient,
204 - GetPrefTitleFormat());
206 - iconTitle = XtMalloc(strlen(window->filename) + 2); /* strlen("*")+1 */
207 + format);
209 + if (strcmp(title, format) == 0)
210 + filename = title;
212 + iconTitle = XtMalloc(strlen(filename) + 2); /* strlen("*")+1 */
214 - strcpy(iconTitle, window->filename);
215 + strcpy(iconTitle, filename);
216 if (window->fileChanged && !window->transient)
217 strcat(iconTitle, "*");
218 XtVaSetValues(window->shell, XmNtitle, title, XmNiconName, iconTitle, NULL);
219 @@ -3430,6 +3442,7 @@ WindowInfo* CreateDocument(WindowInfo* s
220 window->nWritableWindows = 0;
221 window->fileChanged = FALSE;
222 window->fileMissing = True;
223 + window->titleFormat = NULL;
224 window->fileMode = 0;
225 window->fileUid = 0;
226 window->fileGid = 0;
227 diff --quilt old/source/highlightData.c new/source/highlightData.c
228 --- old/source/highlightData.c
229 +++ new/source/highlightData.c
230 @@ -551,7 +551,7 @@ static char *DefaultPatternSets[] = {
231 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\
232 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\
233 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\
234 - Built-in Subrs:\"<(?:args|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|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|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\
235 + Built-in Subrs:\"<(?:args|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|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|to_(?:column|line|pos)|tolower|toupper|valid_number|write_file)(?=\\s*\\()\":::Subroutine::\n\
236 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\
237 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\
238 Macro Hooks:\"<(?:(?:pre|post)_(?:open|save)|cursor_moved|modified|(?:losing_)?focus)_hook(?=\\s*\\()\":::Subroutine1::\n\