push up calltip_ignore_arg.patch
[nedit-bw.git] / newMacroFnRegistration.patch
blob3bedebb0a3f349113734f6a1784075a0d9a931dd
1 Change the registration of macro built-ins to improve maintenance
3 The association of name and value (either a function pointer or an integer)
4 is made explicit here. It also allows for other tables of such associations
5 elsewhere, allowing for separate (theme-based) macro function definition
6 files. It makes macro definition more like the action routine naming too.
8 ---
10 source/macro.c | 280 +++++++++++++++++++++++++++++++++++++--------------------
11 source/macro.h | 22 ++++
12 2 files changed, 203 insertions(+), 99 deletions(-)
14 diff --quilt old/source/macro.c new/source/macro.c
15 --- old/source/macro.c
16 +++ new/source/macro.c
17 @@ -405,90 +405,140 @@ static int getStyleAtPosMS(WindowInfo *w
18 DataValue *result, char **errMsg);
19 static int filenameDialogMS(WindowInfo* window, DataValue* argList, int nArgs,
20 DataValue* result, char** errMsg);
22 /* Built-in subroutines and variables for the macro language */
23 -static BuiltInSubr MacroSubrs[] = {lengthMS, getRangeMS, tPrintMS,
24 - dialogMS, stringDialogMS, replaceRangeMS, replaceSelectionMS,
25 - setCursorPosMS, getCharacterMS, minMS, maxMS, searchMS,
26 - searchStringMS, substringMS, replaceSubstringMS, readFileMS,
27 - writeFileMS, appendFileMS, beepMS, getSelectionMS, validNumberMS,
28 - replaceInStringMS, selectMS, selectRectangleMS, focusWindowMS,
29 - shellCmdMS, stringToClipboardMS, clipboardToStringMS, toupperMS,
30 - tolowerMS, listDialogMS, getenvMS,
31 - stringCompareMS, splitMS, calltipMS, killCalltipMS,
32 -/* DISABLED for 5.4 setBacklightStringMS,*/
33 - rangesetCreateMS, rangesetDestroyMS,
34 - rangesetAddMS, rangesetSubtractMS, rangesetInvertMS,
35 - rangesetInfoMS, rangesetRangeMS, rangesetIncludesPosMS,
36 - rangesetSetColorMS, rangesetSetNameMS, rangesetSetModeMS,
37 - rangesetGetByNameMS,
38 - getPatternByNameMS, getPatternAtPosMS,
39 - getStyleByNameMS, getStyleAtPosMS, filenameDialogMS
40 - };
41 -#define N_MACRO_SUBRS (sizeof MacroSubrs/sizeof *MacroSubrs)
42 -static const char *MacroSubrNames[N_MACRO_SUBRS] = {"length", "get_range", "t_print",
43 - "dialog", "string_dialog", "replace_range", "replace_selection",
44 - "set_cursor_pos", "get_character", "min", "max", "search",
45 - "search_string", "substring", "replace_substring", "read_file",
46 - "write_file", "append_file", "beep", "get_selection", "valid_number",
47 - "replace_in_string", "select", "select_rectangle", "focus_window",
48 - "shell_command", "string_to_clipboard", "clipboard_to_string",
49 - "toupper", "tolower", "list_dialog", "getenv",
50 - "string_compare", "split", "calltip", "kill_calltip",
51 -/* DISABLED for 5.4 "set_backlight_string", */
52 - "rangeset_create", "rangeset_destroy",
53 - "rangeset_add", "rangeset_subtract", "rangeset_invert",
54 - "rangeset_info", "rangeset_range", "rangeset_includes",
55 - "rangeset_set_color", "rangeset_set_name", "rangeset_set_mode",
56 - "rangeset_get_by_name",
57 - "get_pattern_by_name", "get_pattern_at_pos",
58 - "get_style_by_name", "get_style_at_pos", "filename_dialog"
59 - };
60 -static BuiltInSubr SpecialVars[] = {cursorMV, lineMV, columnMV,
61 - fileNameMV, filePathMV, lengthMV, selectionStartMV, selectionEndMV,
62 - selectionLeftMV, selectionRightMV, wrapMarginMV, tabDistMV,
63 - emTabDistMV, useTabsMV, languageModeMV, modifiedMV,
64 - statisticsLineMV, incSearchLineMV, showLineNumbersMV,
65 - autoIndentMV, wrapTextMV, highlightSyntaxMV,
66 - makeBackupCopyMV, incBackupMV, showMatchingMV, matchSyntaxBasedMV,
67 - overTypeModeMV, readOnlyMV, lockedMV, fileFormatMV,
68 - fontNameMV, fontNameItalicMV,
69 - fontNameBoldMV, fontNameBoldItalicMV, subscriptSepMV,
70 - minFontWidthMV, maxFontWidthMV, topLineMV, numDisplayLinesMV,
71 - displayWidthMV, activePaneMV, nPanesMV, emptyArrayMV,
72 - serverNameMV, calltipIDMV,
73 -/* DISABLED for 5.4 backlightStringMV, */
74 - rangesetListMV, versionMV
75 - };
76 -#define N_SPECIAL_VARS (sizeof SpecialVars/sizeof *SpecialVars)
77 -static const char *SpecialVarNames[N_SPECIAL_VARS] = {"$cursor", "$line", "$column",
78 - "$file_name", "$file_path", "$text_length", "$selection_start",
79 - "$selection_end", "$selection_left", "$selection_right",
80 - "$wrap_margin", "$tab_dist", "$em_tab_dist", "$use_tabs",
81 - "$language_mode", "$modified",
82 - "$statistics_line", "$incremental_search_line", "$show_line_numbers",
83 - "$auto_indent", "$wrap_text", "$highlight_syntax",
84 - "$make_backup_copy", "$incremental_backup", "$show_matching", "$match_syntax_based",
85 - "$overtype_mode", "$read_only", "$locked", "$file_format",
86 - "$font_name", "$font_name_italic",
87 - "$font_name_bold", "$font_name_bold_italic", "$sub_sep",
88 - "$min_font_width", "$max_font_width", "$top_line", "$n_display_lines",
89 - "$display_width", "$active_pane", "$n_panes", "$empty_array",
90 - "$server_name", "$calltip_ID",
91 -/* DISABLED for 5.4 "$backlight_string", */
92 - "$rangeset_list", "$VERSION"
93 - };
95 -/* Global symbols for returning values from built-in functions */
96 -#define N_RETURN_GLOBALS 5
97 -enum retGlobalSyms {STRING_DIALOG_BUTTON, SEARCH_END, READ_STATUS,
98 - SHELL_CMD_STATUS, LIST_DIALOG_BUTTON};
99 -static const char *ReturnGlobalNames[N_RETURN_GLOBALS] = {"$string_dialog_button",
100 - "$search_end", "$read_status", "$shell_cmd_status",
101 - "$list_dialog_button"};
102 -static Symbol *ReturnGlobals[N_RETURN_GLOBALS];
103 +static const BuiltInSubrName MacroSubrs[] = {
104 + { "length", lengthMS },
105 + { "get_range", getRangeMS },
106 + { "t_print", tPrintMS },
107 + { "dialog", dialogMS },
108 + { "string_dialog", stringDialogMS },
109 + { "replace_range", replaceRangeMS },
110 + { "replace_selection", replaceSelectionMS },
111 + { "set_cursor_pos", setCursorPosMS },
112 + { "get_character", getCharacterMS },
113 + { "min", minMS },
114 + { "max", maxMS },
115 + { "search", searchMS },
116 + { "search_string", searchStringMS },
117 + { "substring", substringMS },
118 + { "replace_substring", replaceSubstringMS },
119 + { "read_file", readFileMS },
120 + { "write_file", writeFileMS },
121 + { "append_file", appendFileMS },
122 + { "beep", beepMS },
123 + { "get_selection", getSelectionMS },
124 + { "valid_number", validNumberMS },
125 + { "replace_in_string", replaceInStringMS },
126 + { "select", selectMS },
127 + { "select_rectangle", selectRectangleMS },
128 + { "focus_window", focusWindowMS },
129 + { "shell_command", shellCmdMS },
130 + { "string_to_clipboard", stringToClipboardMS },
131 + { "clipboard_to_string", clipboardToStringMS },
132 + { "toupper", toupperMS },
133 + { "tolower", tolowerMS },
134 + { "list_dialog", listDialogMS },
135 + { "getenv", getenvMS },
136 + { "string_compare", stringCompareMS },
137 + { "split", splitMS },
138 + { "calltip", calltipMS },
139 + { "kill_calltip", killCalltipMS },
140 +/* DISABLED for 5.4
141 + { "set_backlight_string", setBacklightStringMS },
143 + { "rangeset_create", rangesetCreateMS },
144 + { "rangeset_destroy", rangesetDestroyMS },
145 + { "rangeset_add", rangesetAddMS },
146 + { "rangeset_subtract", rangesetSubtractMS },
147 + { "rangeset_invert", rangesetInvertMS },
148 + { "rangeset_info", rangesetInfoMS },
149 + { "rangeset_range", rangesetRangeMS },
150 + { "rangeset_includes", rangesetIncludesPosMS },
151 + { "rangeset_set_color", rangesetSetColorMS },
152 + { "rangeset_set_name", rangesetSetNameMS },
153 + { "rangeset_set_mode", rangesetSetModeMS },
154 + { "rangeset_get_by_name", rangesetGetByNameMS },
155 + { "get_pattern_by_name", getPatternByNameMS },
156 + { "get_pattern_at_pos", getPatternAtPosMS },
157 + { "get_style_by_name", getStyleByNameMS },
158 + { "get_style_at_pos", getStyleAtPosMS },
159 + { "filename_dialog", filenameDialogMS },
160 + { NULL, NULL } /* sentinel */
163 +static const BuiltInSubrName SpecialVars[] = {
164 + { "$cursor", cursorMV },
165 + { "$line", lineMV },
166 + { "$column", columnMV },
167 + { "$file_name", fileNameMV },
168 + { "$file_path", filePathMV },
169 + { "$text_length", lengthMV },
170 + { "$selection_start", selectionStartMV },
171 + { "$selection_end", selectionEndMV },
172 + { "$selection_left", selectionLeftMV },
173 + { "$selection_right", selectionRightMV },
174 + { "$wrap_margin", wrapMarginMV },
175 + { "$tab_dist", tabDistMV },
176 + { "$em_tab_dist", emTabDistMV },
177 + { "$use_tabs", useTabsMV },
178 + { "$language_mode", languageModeMV },
179 + { "$modified", modifiedMV },
180 + { "$statistics_line", statisticsLineMV },
181 + { "$incremental_search_line", incSearchLineMV },
182 + { "$show_line_numbers", showLineNumbersMV },
183 + { "$auto_indent", autoIndentMV },
184 + { "$wrap_text", wrapTextMV },
185 + { "$highlight_syntax", highlightSyntaxMV },
186 + { "$make_backup_copy", makeBackupCopyMV },
187 + { "$incremental_backup", incBackupMV },
188 + { "$show_matching", showMatchingMV },
189 + { "$match_syntax_based", matchSyntaxBasedMV },
190 + { "$overtype_mode", overTypeModeMV },
191 + { "$read_only", readOnlyMV },
192 + { "$locked", lockedMV },
193 + { "$file_format", fileFormatMV },
194 + { "$font_name", fontNameMV },
195 + { "$font_name_italic", fontNameItalicMV },
196 + { "$font_name_bold", fontNameBoldMV },
197 + { "$font_name_bold_italic", fontNameBoldItalicMV },
198 + { "$sub_sep", subscriptSepMV },
199 + { "$min_font_width", minFontWidthMV },
200 + { "$max_font_width", maxFontWidthMV },
201 + { "$top_line", topLineMV },
202 + { "$n_display_lines", numDisplayLinesMV },
203 + { "$display_width", displayWidthMV },
204 + { "$active_pane", activePaneMV },
205 + { "$n_panes", nPanesMV },
206 + { "$empty_array", emptyArrayMV },
207 + { "$server_name", serverNameMV },
208 + { "$calltip_ID", calltipIDMV },
209 +/* DISABLED for 5.4
210 + { "$backlight_string", backlightStringMV },
212 + { "$rangeset_list", rangesetListMV },
213 + { "$VERSION", versionMV },
214 + { NULL, NULL } /* sentinel */
217 +/* Global symbols for "returning" secondary values from built-in functions */
218 +static int STRING_DIALOG_BUTTON, SEARCH_END, READ_STATUS,
219 + SHELL_CMD_STATUS, LIST_DIALOG_BUTTON;
221 +static ReturnGlobalName ReturnGlobalNames[] = {
222 + /* name, pIndex: *pIndex will be set to the symbol's
223 + index in ReturnGlobals */
224 + { "$string_dialog_button", &STRING_DIALOG_BUTTON },
225 + { "$search_end", &SEARCH_END },
226 + { "$read_status", &READ_STATUS },
227 + { "$shell_cmd_status", &SHELL_CMD_STATUS },
228 + { "$list_dialog_button", &LIST_DIALOG_BUTTON },
229 + { NULL, NULL } /* sentinel */
232 +static Symbol **ReturnGlobals = NULL;
234 /* List of actions not useful when learning a macro sequence (also see below) */
235 static char* IgnoredActions[] = {"focusIn", "focusOut"};
237 /* List of actions intended to be attached to mouse buttons, which the user
238 @@ -526,34 +576,70 @@ static WindowInfo *MacroRecordWindow = N
239 /* Arrays for translating escape characters in escapeStringChars */
240 static char ReplaceChars[] = "\\\"ntbrfav";
241 static char EscapeChars[] = "\\\"\n\t\b\r\f\a\v";
244 +** Installs a set of built-in macro subroutines as symbols of given type.
246 +void RegisterMacroSubroutineSet(const BuiltInSubrName *set, enum symTypes type)
248 + static DataValue subrPtr = {NO_TAG, {0}};
249 + unsigned i;
251 + for (i = 0; set[i].name; i++) {
252 + subrPtr.val.subr = set[i].macroSubr;
253 + InstallSymbol(set[i].name, type, subrPtr);
258 +** Installs a set of built-in macro secondary return values as symbols of
259 +** given type.
261 +void RegisterGlobalReturnValuesSet(ReturnGlobalName *set, enum symTypes type)
263 + int n, i, oldn;
264 + Symbol **newRetGlobals;
265 + static DataValue noValue = {NO_TAG, {0}};
267 + n = oldn = 0;
269 + /* count the entries in the new table */
270 + while (set[n].name) n++;
271 + /* and existing entries if any */
272 + while (ReturnGlobals && ReturnGlobals[oldn]) oldn++;
274 + /* reallocate symbol reference table with space for a sentinel at the end */
275 + newRetGlobals = realloc(ReturnGlobals, (oldn + n + 1) * sizeof(Symbol *));
276 + if (!newRetGlobals) {
277 + fprintf(stderr, "nedit: failed to build macro return globals table\n");
278 + exit(EXIT_FAILURE);
281 + ReturnGlobals = newRetGlobals;
282 + /* now assign the (new) symbols at the newly allocated end of the table
283 + and store the indices in set */
284 + for (i = 0, n = oldn; set[i].name; i++, n++) {
285 + ReturnGlobals[n] = InstallSymbol(set[i].name, type, noValue);
286 + *set[i].pIndex = n;
288 + /* add the sentinel */
289 + ReturnGlobals[n] = NULL;
293 ** Install built-in macro subroutines and special variables for accessing
294 ** editor information
296 void RegisterMacroSubroutines(void)
298 - static DataValue subrPtr = {NO_TAG, {0}}, noValue = {NO_TAG, {0}};
299 - unsigned i;
301 /* Install symbols for built-in routines and variables, with pointers
302 to the appropriate c routines to do the work */
303 - for (i=0; i<N_MACRO_SUBRS; i++) {
304 - subrPtr.val.subr = MacroSubrs[i];
305 - InstallSymbol(MacroSubrNames[i], C_FUNCTION_SYM, subrPtr);
307 - for (i=0; i<N_SPECIAL_VARS; i++) {
308 - subrPtr.val.subr = SpecialVars[i];
309 - InstallSymbol(SpecialVarNames[i], PROC_VALUE_SYM, subrPtr);
312 - /* Define global variables used for return values, remember their
313 - locations so they can be set without a LookupSymbol call */
314 - for (i=0; i<N_RETURN_GLOBALS; i++)
315 - ReturnGlobals[i] = InstallSymbol(ReturnGlobalNames[i], GLOBAL_SYM,
316 - noValue);
317 + RegisterMacroSubroutineSet(MacroSubrs, C_FUNCTION_SYM);
318 + RegisterMacroSubroutineSet(SpecialVars, PROC_VALUE_SYM);
319 + /* Define global variables used for return values */
320 + RegisterGlobalReturnValuesSet(ReturnGlobalNames, GLOBAL_SYM);
323 #define MAX_LEARN_MSG_LEN ((2 * MAX_ACCEL_LEN) + 60)
324 void BeginLearn(WindowInfo *window)
326 diff --quilt old/source/macro.h new/source/macro.h
327 --- old/source/macro.h
328 +++ new/source/macro.h
329 @@ -26,17 +26,35 @@
330 *******************************************************************************/
332 #ifndef NEDIT_MACRO_H_INCLUDED
333 #define NEDIT_MACRO_H_INCLUDED
335 -#include "nedit.h"
336 +#include "interpret.h"
338 #include <X11/Intrinsic.h>
340 #define REPEAT_TO_END -1
341 #define REPEAT_IN_SEL -2
344 +typedef struct BuiltInSubrNameTag {
345 + const char *name; /* its macro identifier */
346 + BuiltInSubr macroSubr; /* pointer to the function to call */
347 +} BuiltInSubrName;
349 +/* Structure used to build an initialized static array, each entry describing a
350 +** macro built-in global result variable's symbol. The array should provide the
351 +** macro identifier eg "$search_end", and a value for pIndex, pointing to a
352 +** static integer variable to store its index. As the macro identifiers are
353 +** registered (creating symbols), by scanning the static array, each one is
354 +** given a unique index value to be able to retrieve the symbol using a direct
355 +** array lookup.
357 +typedef struct ReturnGlobalNameTag {
358 + const char *name; /* macro identifier eg "$search_end" */
359 + int *pIndex; /* a place to store its index */
360 +} ReturnGlobalName;
362 void RegisterMacroSubroutines(void);
363 void AddLastCommandActionHook(XtAppContext context);
364 void BeginLearn(WindowInfo *window);
365 void FinishLearn(void);
366 void CancelMacroOrLearn(WindowInfo *window);