Allow '>' and '@' to appear in menu items
[nedit-bw.git] / RSunderlineStyle.diff
blob5bbb556eb54df4822446d2a7fc4910a38312bb60
1 From: Tony Balinski <ajbj@free.fr>
2 Subject: Allow rangesets to be displayed underlined.
4 This patch depends on the UnderlineStyle.diff patch (or its derivative).
5 APPLY THAT PATCH FIRST! This patch uses the syntax highlighting style's
6 underlining mechanism (from the earlier patch) to provide an underline for a
7 rangeset.
9 To apply underlining to a rangeset, use the following macro functioon:
11 rangeset_set_underline(id, mode)
13 where mode is one of "leave" (don't change underlining from syntax
14 highlighting's attributes), "remove" (don't show syntax highlighting
15 underlines for the ranges of the set, and "add" (make sure all text in
16 the rangeset is undelined). The ramgeset_info() function will return
17 the underline mode keyword for a set.
19 ---
21 doc/help.etx | 6 ++++
22 source/built-ins.h | 1
23 source/macro.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++---
24 source/rangeset.c | 38 ++++++++++++++++++++++++++++-
25 source/rangeset.h | 5 +++
26 source/textDisp.c | 28 +++++++++++++++++++++
27 6 files changed, 142 insertions(+), 5 deletions(-)
29 diff --quilt old/doc/help.etx new/doc/help.etx
30 --- old/doc/help.etx
31 +++ new/doc/help.etx
32 @@ -3166,6 +3166,12 @@ Rangesets
33 regarding the validity of color: if the color is invalid (a bad name,
34 or not supported by the hardware) this has unpredictable effects.
36 +**rangeset_set_underline( r, mode )**
37 + Change whether text over which the rangeset is defined should be displayed
38 + as underlined. **mode** can be "leave" (the text will show any underlining
39 + according to syntax highlighting settings), "remove" (any underliining is
40 + removed), or "add" (underlining is added to the text).
42 **rangeset_set_name( r, name )**
43 Apply the name to the rangeset r.
45 diff --quilt old/source/macro.c new/source/macro.c
46 --- old/source/macro.c
47 +++ new/source/macro.c
48 @@ -5433,7 +5433,7 @@ static int rangesetInfoMS(WindowInfo *wi
50 RangesetTable *rangesetTable = window->buffer->rangesetTable;
51 Rangeset *rangeset = NULL;
52 - int count, defined;
53 + int count, defined, uline;
54 char *color, *name, *mode;
55 DataValue element;
56 int label = 0;
57 @@ -5450,7 +5450,8 @@ static int rangesetInfoMS(WindowInfo *wi
58 rangeset = RangesetFetch(rangesetTable, label);
61 - RangesetGetInfo(rangeset, &defined, &label, &count, &color, &name, &mode);
62 + RangesetGetInfo(rangeset, &defined, &label, &count, &uline,
63 + &color, &name, &mode);
65 /* set up result */
66 result->tag = ARRAY_TAG;
67 @@ -5484,7 +5485,15 @@ static int rangesetInfoMS(WindowInfo *wi
68 M_FAILURE("Failed to allocate array value \"mode\" in %s");
69 if (!ArrayInsert(result, PERM_ALLOC_STR("mode"), &element))
70 M_FAILURE("Failed to insert array element \"mode\" in %s");
73 + element.tag = STRING_TAG;
74 + element.val.str.rep = (uline < 0) ? PERM_ALLOC_STR("remove") :
75 + (uline > 0) ? PERM_ALLOC_STR("add") :
76 + PERM_ALLOC_STR("leave");
77 + element.val.str.len = strlen(element.val.str.rep);
78 + if (!ArrayInsert(result, PERM_ALLOC_STR("underline"), &element))
79 + M_FAILURE("Failed to insert array element \"count\" in %s");
81 return True;
84 @@ -5657,6 +5666,60 @@ static int rangesetSetColorMS(WindowInfo
88 +** Set underline flag for a range set's ranges. Returns true if the rangeset
89 +** is valid. It takes two arguments: the id of the rangeset to change and
90 +** the underlineMode string, which should be specified as "leave" (let any
91 +** syntax highlighting underlines to appear as undisturbed), "add" or "remove".
92 +*/
93 +static int rangesetSetUnderlineMS(WindowInfo *window, DataValue *argList,
94 + int nArgs, DataValue *result, char **errMsg)
96 + char stringStorage[1][TYPE_INT_STR_SIZE(int)];
97 + textBuffer *buffer = window->buffer;
98 + RangesetTable *rangesetTable = buffer->rangesetTable;
99 + Rangeset *rangeset;
100 + int label = 0;
101 + char *underlineMode;
103 + if (nArgs != 2) {
104 + return wrongNArgsErr(errMsg);
107 + if (!readIntArg(argList[0], &label, errMsg)
108 + || !RangesetLabelOK(label)) {
109 + M_FAILURE("First parameter is an invalid rangeset label in %s");
112 + if (rangesetTable == NULL) {
113 + M_FAILURE("Rangeset does not exist in %s");
116 + rangeset = RangesetFetch(rangesetTable, label);
117 + if (rangeset == NULL) {
118 + M_FAILURE("Rangeset does not exist in %s");
121 + if (readStringArg(argList[1], &underlineMode, stringStorage[0], errMsg)) {
122 + if (strcmp(underlineMode, "leave") == 0)
123 + RangesetAssignUnderline(rangeset, 0);
124 + else
125 + if (strcmp(underlineMode, "remove") == 0)
126 + RangesetAssignUnderline(rangeset, -1);
127 + else
128 + if (strcmp(underlineMode, "add") == 0)
129 + RangesetAssignUnderline(rangeset, 1);
130 + else
131 + M_FAILURE("Second parameter must be \"leave\", \"remove\" or \"add\" in %s");
133 + else
134 + M_FAILURE("Second parameter must be \"leave\", \"remove\" or \"add\" in %s");
136 + /* set up result */
137 + result->tag = NO_TAG;
138 + return True;
142 ** Set the name of a range set's ranges. Returns
143 ** true if the rangeset is valid.
145 diff --quilt old/source/rangeset.c new/source/rangeset.c
146 --- old/source/rangeset.c
147 +++ new/source/rangeset.c
148 @@ -64,6 +64,7 @@ struct _Rangeset {
149 unsigned char label; /* a number 1-63 */
151 signed char color_set; /* 0: unset; 1: set; -1: invalid */
152 + signed char underline; /* underline it? */
153 char *color_name; /* the name of an assigned color */
154 Pixel color; /* the value of a particular color */
155 textBuffer *buf; /* the text buffer of the rangeset */
156 @@ -251,6 +252,7 @@ void RangesetInit(Rangeset *rangeset, in
157 rangeset->color_name = (char *)0;
158 rangeset->name = (char *)0;
159 rangeset->color_set = 0;
160 + rangeset->underline = 0; /* "no change" value */
161 rangeset->buf = buf;
163 rangeset->maxpos = buf->length;
164 @@ -693,12 +695,13 @@ int RangesetGetNRanges(Rangeset *rangese
165 ** Get information about rangeset.
167 void RangesetGetInfo(Rangeset *rangeset, int *defined, int *label,
168 - int *count, char **color, char **name, char **mode)
169 + int *count, int *uline, char **color, char **name, char **mode)
171 if (rangeset == NULL) {
172 *defined = False;
173 *label = 0;
174 *count = 0;
175 + *uline = 0;
176 *color = "";
177 *name = "";
178 *mode = "";
179 @@ -707,6 +710,7 @@ void RangesetGetInfo(Rangeset *rangeset,
180 *defined = True;
181 *label = (int)rangeset->label;
182 *count = rangeset->n_ranges;
183 + *uline = rangeset->underline;
184 *color = rangeset->color_name ? rangeset->color_name : "";
185 *name = rangeset->name ? rangeset->name : "";
186 *mode = rangeset->update_name;
187 @@ -776,6 +780,7 @@ static void rangesetClone(Rangeset *dest
188 destRangeset->last_index = srcRangeset->last_index;
189 destRangeset->n_ranges = srcRangeset->n_ranges;
190 destRangeset->color_set = srcRangeset->color_set;
191 + destRangeset->underline = srcRangeset->underline;
192 destRangeset->color = srcRangeset->color;
194 if (srcRangeset->color_name) {
195 @@ -1109,6 +1114,27 @@ int RangesetAssignColorName(Rangeset *ra
199 +** Assign the underline to a rangeset via the rangeset table.
202 +int RangesetAssignUnderline(Rangeset *rangeset, int under)
204 + rangeset->underline = (0 < under) - (under < 0);
206 + rangesetRefreshAllRanges(rangeset);
207 + return 1;
211 +** Fetch the underline mode value.
214 +int RangesetGetUnderline(Rangeset *rangeset)
216 + return rangeset->underline;
220 ** Assign a name to a rangeset via the rangeset table.
223 @@ -1159,6 +1185,16 @@ char *RangesetGetName(Rangeset *rangeset
227 +** Return the underlining mode.
230 +int RangesetTableGetUnderline(RangesetTable *table, int index)
232 + Rangeset *rangeset = &table->set[index];
233 + return rangeset->underline;
237 ** Return the color validity, if any, and the value in *color.
240 diff --quilt old/source/rangeset.h new/source/rangeset.h
241 --- old/source/rangeset.h
242 +++ new/source/rangeset.h
243 @@ -53,7 +53,7 @@ int RangesetRemove(Rangeset *origSet, Ra
244 int RangesetRemoveBetween(Rangeset *rangeset, int start, int end);
245 int RangesetGetNRanges(Rangeset *rangeset);
246 void RangesetGetInfo(Rangeset *rangeset, int *defined, int *label,
247 - int *count, char **color, char **name, char **mode);
248 + int *count, int *uline, char **color, char **name, char **mode);
249 RangesetTable *RangesetTableAlloc(textBuffer *buf);
250 RangesetTable *RangesetTableFree(RangesetTable *table);
251 RangesetTable *RangesetTableClone(RangesetTable *srcTable,
252 @@ -69,12 +69,15 @@ void RangesetTableUpdatePos(RangesetTabl
253 void RangesetBufModifiedCB(int pos, int nInserted, int nDeleted, int nRestyled,
254 const char *deletedText, void *cbArg);
255 int RangesetIndex1ofPos(RangesetTable *table, int pos, int needs_color);
256 +int RangesetAssignUnderline(Rangeset *rangeset, int under);
257 +int RangesetGetUnderline(Rangeset *rangeset);
258 int RangesetAssignColorName(Rangeset *rangeset, char *color_name);
259 int RangesetAssignColorPixel(Rangeset *rangeset, Pixel color, int ok);
260 char *RangesetGetName(Rangeset *rangeset);
261 int RangesetAssignName(Rangeset *rangeset, char *name);
262 int RangesetGetColorValid(Rangeset *rangeset, Pixel *color);
263 char *RangesetTableGetColorName(RangesetTable *table, int index);
264 +int RangesetTableGetUnderline(RangesetTable *table, int index);
265 int RangesetTableGetColorValid(RangesetTable *table, int index, Pixel *color);
266 int RangesetTableAssignColorPixel(RangesetTable *table, int index, Pixel color,
267 int ok);
268 diff --quilt old/source/textDisp.c new/source/textDisp.c
269 --- old/source/textDisp.c
270 +++ new/source/textDisp.c
271 @@ -184,6 +184,7 @@ static int measurePropChar(const textDis
272 const int colNum, const int pos);
273 static Pixel allocBGColor(Widget w, char *colorName, int *ok);
274 static Pixel getRangesetColor(textDisp *textD, int ind, Pixel bground);
275 +static int getRangesetUnderline(textDisp *textD, int ind, int old);
276 static void textDRedisplayRange(textDisp *textD, int start, int end);
277 static void drawWrapMargin(textDisp *textD);
278 static void redisplayCursor(textDisp *textD);
279 @@ -2277,6 +2278,10 @@ static void drawString(textDisp *textD,
280 gcValues.foreground = gcValues.background = bground;
281 XChangeGC(XtDisplay(textD->w), gc,
282 GCFont | GCForeground | GCBackground, &gcValues);
283 + /* adjust underline according to rangeset underline style */
284 + underlineStyle = getRangesetUnderline(textD,
285 + (style&RANGESET_MASK)>>RANGESET_SHIFT,
286 + underlineStyle);
289 /* Draw blank area rather than text, if that was the request */
290 @@ -4018,6 +4023,29 @@ static Pixel getRangesetColor(textDisp *
294 +** Return an adjusted underline flag. The original flag value (true if needed
295 +** by the syntax highlighting style) is left alone if the rangeset's underline
296 +** mode is 0; cleared if the mode is less than 0, or set if greater.
298 +static int getRangesetUnderline(textDisp *textD, int ind, int old)
300 + textBuffer *buf;
301 + RangesetTable *tab;
302 + int under;
304 + if (ind > 0) {
305 + ind--;
306 + buf = textD->buffer;
307 + tab = buf->rangesetTable;
309 + under = RangesetTableGetUnderline(tab, ind);
310 + if (under != 0)
311 + return under > 0;
313 + return old;
317 ** Read the background color class specification string in str, allocating the
318 ** necessary colors, and allocating and setting up the character->class_no and
319 ** class_no->pixel map arrays, returned via *pp_bgClass and *pp_bgClassPixel
320 diff --quilt old/source/built-ins.h new/source/built-ins.h
321 --- old/source/built-ins.h
322 +++ new/source/built-ins.h
323 @@ -50,6 +50,7 @@ MS(rangeset_info, rangesetInfo)
324 MS(rangeset_range, rangesetRange)
325 MS(rangeset_includes, rangesetIncludesPos)
326 MS(rangeset_set_color, rangesetSetColor)
327 +MS(rangeset_set_underline, rangesetSetUnderline)
328 MS(rangeset_set_name, rangesetSetName)
329 MS(rangeset_set_mode, rangesetSetMode)
330 MS(rangeset_get_by_name, rangesetGetByName)