import parse-define.patch
[nedit-bw.git] / RSunderlineStyle.diff
blobc11e1499cce9a6533982cee31f56ae34949004ef
1 Allow rangesets to be displayed underlined.
3 This patch depends on the UnderlineStyle.diff patch (or its derivative).
4 APPLY THAT PATCH FIRST! This patch uses the syntax highlighting style's
5 underlining mechanism (from the earlier patch) to provide an underline for a
6 rangeset.
8 To apply underlining to a rangeset, use the following macro functioon:
9 rangeset_set_underline(id, mode)
10 where mode is one of "leave" (don't change underlining from syntax
11 highlighting's attributes), "remove" (don't show syntax highlighting
12 underlines for the ranges of the set, and "add" (make sure all text in
13 the rangeset is undelined). The ramgeset_info() function will return
14 the underline mode keyword for a set.
16 ---
18 doc/help.etx | 6 ++++
19 source/macro.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++---
20 source/rangeset.c | 38 +++++++++++++++++++++++++++-
21 source/rangeset.h | 5 +++
22 source/textDisp.c | 28 +++++++++++++++++++++
23 5 files changed, 144 insertions(+), 5 deletions(-)
25 diff --quilt old/doc/help.etx new/doc/help.etx
26 --- old/doc/help.etx
27 +++ new/doc/help.etx
28 @@ -3165,10 +3165,16 @@ Rangesets
29 Attempts to apply the color as a background color to the ranges of r. If
30 color is at empty string, removes the coloring of r. No check is made
31 regarding the validity of color: if the color is invalid (a bad name,
32 or not supported by the hardware) this has unpredictable effects.
34 +**rangeset_set_underline( r, mode )**
35 + Change whether text over which the rangeset is defined should be displayed
36 + as underlined. **mode** can be "leave" (the text will show any underlining
37 + according to syntax highlighting settings), "remove" (any underliining is
38 + removed), or "add" (underlining is added to the text).
40 **rangeset_set_name( r, name )**
41 Apply the name to the rangeset r.
43 **rangeset_set_mode( r, type )**
44 Changes the behaviour of the rangeset r when modifications to the text
45 diff --quilt old/source/macro.c new/source/macro.c
46 --- old/source/macro.c
47 +++ new/source/macro.c
48 @@ -402,10 +402,12 @@ static int rangesetRangeMS(WindowInfo *w
49 DataValue *result, char **errMsg);
50 static int rangesetIncludesPosMS(WindowInfo *window, DataValue *argList,
51 int nArgs, DataValue *result, char **errMsg);
52 static int rangesetSetColorMS(WindowInfo *window, DataValue *argList,
53 int nArgs, DataValue *result, char **errMsg);
54 +static int rangesetSetUnderlineMS(WindowInfo *window, DataValue *argList,
55 + int nArgs, DataValue *result, char **errMsg);
56 static int rangesetSetNameMS(WindowInfo *window, DataValue *argList,
57 int nArgs, DataValue *result, char **errMsg);
58 static int rangesetSetModeMS(WindowInfo *window, DataValue *argList,
59 int nArgs, DataValue *result, char **errMsg);
61 @@ -516,10 +518,11 @@ static const BuiltInSubrName MacroSubrs[
62 { "rangeset_invert", rangesetInvertMS },
63 { "rangeset_info", rangesetInfoMS },
64 { "rangeset_range", rangesetRangeMS },
65 { "rangeset_includes", rangesetIncludesPosMS },
66 { "rangeset_set_color", rangesetSetColorMS },
67 + { "rangeset_set_underline", rangesetSetUnderlineMS },
68 { "rangeset_set_name", rangesetSetNameMS },
69 { "rangeset_set_mode", rangesetSetModeMS },
70 { "rangeset_get_by_name", rangesetGetByNameMS },
71 { "get_pattern_by_name", getPatternByNameMS },
72 { "get_pattern_at_pos", getPatternAtPosMS },
73 @@ -5724,11 +5727,11 @@ static int rangesetInvertMS(WindowInfo *
74 static int rangesetInfoMS(WindowInfo *window, DataValue *argList, int nArgs,
75 DataValue *result, char **errMsg)
77 RangesetTable *rangesetTable = window->buffer->rangesetTable;
78 Rangeset *rangeset = NULL;
79 - int count, defined;
80 + int count, defined, uline;
81 char *color, *name, *mode;
82 DataValue element;
83 int label = 0;
85 if (nArgs != 1)
86 @@ -5741,11 +5744,12 @@ static int rangesetInfoMS(WindowInfo *wi
88 if (rangesetTable != NULL) {
89 rangeset = RangesetFetch(rangesetTable, label);
92 - RangesetGetInfo(rangeset, &defined, &label, &count, &color, &name, &mode);
93 + RangesetGetInfo(rangeset, &defined, &label, &count, &uline,
94 + &color, &name, &mode);
96 /* set up result */
97 result->tag = ARRAY_TAG;
98 result->val.arrayPtr = ArrayNew();
100 @@ -5775,11 +5779,19 @@ static int rangesetInfoMS(WindowInfo *wi
101 element.tag = STRING_TAG;
102 if (!AllocNStringCpy(&element.val.str, mode))
103 M_FAILURE("Failed to allocate array value \"mode\" in %s");
104 if (!ArrayInsert(result, PERM_ALLOC_STR("mode"), &element))
105 M_FAILURE("Failed to insert array element \"mode\" in %s");
108 + element.tag = STRING_TAG;
109 + element.val.str.rep = (uline < 0) ? PERM_ALLOC_STR("remove") :
110 + (uline > 0) ? PERM_ALLOC_STR("add") :
111 + PERM_ALLOC_STR("leave");
112 + element.val.str.len = strlen(element.val.str.rep);
113 + if (!ArrayInsert(result, PERM_ALLOC_STR("underline"), &element))
114 + M_FAILURE("Failed to insert array element \"count\" in %s");
116 return True;
120 ** Built-in macro subroutine for finding the extent of a range in a set.
121 @@ -5948,10 +5960,64 @@ static int rangesetSetColorMS(WindowInfo
122 result->tag = NO_TAG;
123 return True;
127 +** Set underline flag for a range set's ranges. Returns true if the rangeset
128 +** is valid. It takes two arguments: the id of the rangeset to change and
129 +** the underlineMode string, which should be specified as "leave" (let any
130 +** syntax highlighting underlines to appear as undisturbed), "add" or "remove".
132 +static int rangesetSetUnderlineMS(WindowInfo *window, DataValue *argList,
133 + int nArgs, DataValue *result, char **errMsg)
135 + char stringStorage[1][TYPE_INT_STR_SIZE(int)];
136 + textBuffer *buffer = window->buffer;
137 + RangesetTable *rangesetTable = buffer->rangesetTable;
138 + Rangeset *rangeset;
139 + int label = 0;
140 + char *underlineMode;
142 + if (nArgs != 2) {
143 + return wrongNArgsErr(errMsg);
146 + if (!readIntArg(argList[0], &label, errMsg)
147 + || !RangesetLabelOK(label)) {
148 + M_FAILURE("First parameter is an invalid rangeset label in %s");
151 + if (rangesetTable == NULL) {
152 + M_FAILURE("Rangeset does not exist in %s");
155 + rangeset = RangesetFetch(rangesetTable, label);
156 + if (rangeset == NULL) {
157 + M_FAILURE("Rangeset does not exist in %s");
160 + if (readStringArg(argList[1], &underlineMode, stringStorage[0], errMsg)) {
161 + if (strcmp(underlineMode, "leave") == 0)
162 + RangesetAssignUnderline(rangeset, 0);
163 + else
164 + if (strcmp(underlineMode, "remove") == 0)
165 + RangesetAssignUnderline(rangeset, -1);
166 + else
167 + if (strcmp(underlineMode, "add") == 0)
168 + RangesetAssignUnderline(rangeset, 1);
169 + else
170 + M_FAILURE("Second parameter must be \"leave\", \"remove\" or \"add\" in %s");
172 + else
173 + M_FAILURE("Second parameter must be \"leave\", \"remove\" or \"add\" in %s");
175 + /* set up result */
176 + result->tag = NO_TAG;
177 + return True;
181 ** Set the name of a range set's ranges. Returns
182 ** true if the rangeset is valid.
184 static int rangesetSetNameMS(WindowInfo *window, DataValue *argList,
185 int nArgs, DataValue *result, char **errMsg)
186 diff --quilt old/source/rangeset.c new/source/rangeset.c
187 --- old/source/rangeset.c
188 +++ new/source/rangeset.c
189 @@ -62,10 +62,11 @@ struct _Rangeset {
190 int n_ranges; /* how many ranges in ranges */
191 Range *ranges; /* the ranges table */
192 unsigned char label; /* a number 1-63 */
194 signed char color_set; /* 0: unset; 1: set; -1: invalid */
195 + signed char underline; /* underline it? */
196 char *color_name; /* the name of an assigned color */
197 Pixel color; /* the value of a particular color */
198 textBuffer *buf; /* the text buffer of the rangeset */
199 char *name; /* name of rangeset */
201 @@ -249,10 +250,11 @@ void RangesetInit(Rangeset *rangeset, in
202 rangeset->ranges = (Range *)0; /* the ranges table */
204 rangeset->color_name = (char *)0;
205 rangeset->name = (char *)0;
206 rangeset->color_set = 0;
207 + rangeset->underline = 0; /* "no change" value */
208 rangeset->buf = buf;
210 rangeset->maxpos = buf->length;
212 RangesetChangeModifyResponse(rangeset, DEFAULT_UPDATE_FN_NAME);
213 @@ -691,24 +693,26 @@ int RangesetGetNRanges(Rangeset *rangese
216 ** Get information about rangeset.
218 void RangesetGetInfo(Rangeset *rangeset, int *defined, int *label,
219 - int *count, char **color, char **name, char **mode)
220 + int *count, int *uline, char **color, char **name, char **mode)
222 if (rangeset == NULL) {
223 *defined = False;
224 *label = 0;
225 *count = 0;
226 + *uline = 0;
227 *color = "";
228 *name = "";
229 *mode = "";
231 else {
232 *defined = True;
233 *label = (int)rangeset->label;
234 *count = rangeset->n_ranges;
235 + *uline = rangeset->underline;
236 *color = rangeset->color_name ? rangeset->color_name : "";
237 *name = rangeset->name ? rangeset->name : "";
238 *mode = rangeset->update_name;
241 @@ -774,10 +778,11 @@ static void rangesetClone(Rangeset *dest
242 destRangeset->update_name = srcRangeset->update_name;
243 destRangeset->maxpos = srcRangeset->maxpos;
244 destRangeset->last_index = srcRangeset->last_index;
245 destRangeset->n_ranges = srcRangeset->n_ranges;
246 destRangeset->color_set = srcRangeset->color_set;
247 + destRangeset->underline = srcRangeset->underline;
248 destRangeset->color = srcRangeset->color;
250 if (srcRangeset->color_name) {
251 destRangeset->color_name = XtMalloc(strlen(srcRangeset->color_name) +1);
252 strcpy(destRangeset->color_name, srcRangeset->color_name);
253 @@ -1107,10 +1112,31 @@ int RangesetAssignColorName(Rangeset *ra
254 rangesetRefreshAllRanges(rangeset);
255 return 1;
259 +** Assign the underline to a rangeset via the rangeset table.
262 +int RangesetAssignUnderline(Rangeset *rangeset, int under)
264 + rangeset->underline = (0 < under) - (under < 0);
266 + rangesetRefreshAllRanges(rangeset);
267 + return 1;
271 +** Fetch the underline mode value.
274 +int RangesetGetUnderline(Rangeset *rangeset)
276 + return rangeset->underline;
280 ** Assign a name to a rangeset via the rangeset table.
283 int RangesetAssignName(Rangeset *rangeset, char *name)
285 @@ -1157,10 +1183,20 @@ char *RangesetGetName(Rangeset *rangeset
287 return rangeset->name;
291 +** Return the underlining mode.
294 +int RangesetTableGetUnderline(RangesetTable *table, int index)
296 + Rangeset *rangeset = &table->set[index];
297 + return rangeset->underline;
301 ** Return the color validity, if any, and the value in *color.
304 int RangesetGetColorValid(Rangeset *rangeset, Pixel *color)
306 diff --quilt old/source/rangeset.h new/source/rangeset.h
307 --- old/source/rangeset.h
308 +++ new/source/rangeset.h
309 @@ -51,11 +51,11 @@ int RangesetAdd(Rangeset *origSet, Range
310 int RangesetAddBetween(Rangeset *rangeset, int start, int end);
311 int RangesetRemove(Rangeset *origSet, Rangeset *minusSet);
312 int RangesetRemoveBetween(Rangeset *rangeset, int start, int end);
313 int RangesetGetNRanges(Rangeset *rangeset);
314 void RangesetGetInfo(Rangeset *rangeset, int *defined, int *label,
315 - int *count, char **color, char **name, char **mode);
316 + int *count, int *uline, char **color, char **name, char **mode);
317 RangesetTable *RangesetTableAlloc(textBuffer *buf);
318 RangesetTable *RangesetTableFree(RangesetTable *table);
319 RangesetTable *RangesetTableClone(RangesetTable *srcTable,
320 textBuffer *destBuffer);
321 int RangesetFindIndex(RangesetTable *table, int label, int must_be_active);
322 @@ -67,16 +67,19 @@ Rangeset *RangesetFetch(RangesetTable *t
323 unsigned char * RangesetGetList(RangesetTable *table);
324 void RangesetTableUpdatePos(RangesetTable *table, int pos, int n_ins, int n_del);
325 void RangesetBufModifiedCB(int pos, int nInserted, int nDeleted, int nRestyled,
326 const char *deletedText, void *cbArg);
327 int RangesetIndex1ofPos(RangesetTable *table, int pos, int needs_color);
328 +int RangesetAssignUnderline(Rangeset *rangeset, int under);
329 +int RangesetGetUnderline(Rangeset *rangeset);
330 int RangesetAssignColorName(Rangeset *rangeset, char *color_name);
331 int RangesetAssignColorPixel(Rangeset *rangeset, Pixel color, int ok);
332 char *RangesetGetName(Rangeset *rangeset);
333 int RangesetAssignName(Rangeset *rangeset, char *name);
334 int RangesetGetColorValid(Rangeset *rangeset, Pixel *color);
335 char *RangesetTableGetColorName(RangesetTable *table, int index);
336 +int RangesetTableGetUnderline(RangesetTable *table, int index);
337 int RangesetTableGetColorValid(RangesetTable *table, int index, Pixel *color);
338 int RangesetTableAssignColorPixel(RangesetTable *table, int index, Pixel color,
339 int ok);
341 #endif /* rangeset_h_DEFINED */
342 diff --quilt old/source/textDisp.c new/source/textDisp.c
343 --- old/source/textDisp.c
344 +++ new/source/textDisp.c
345 @@ -182,10 +182,11 @@ static int maintainingAbsTopLineNum(text
346 static void resetAbsLineNum(textDisp *textD);
347 static int measurePropChar(const textDisp* textD, const char c,
348 const int colNum, const int pos);
349 static Pixel allocBGColor(Widget w, char *colorName, int *ok);
350 static Pixel getRangesetColor(textDisp *textD, int ind, Pixel bground);
351 +static int getRangesetUnderline(textDisp *textD, int ind, int old);
352 static void textDRedisplayRange(textDisp *textD, int start, int end);
353 static void drawWrapMargin(textDisp *textD);
354 static void redisplayCursor(textDisp *textD);
356 textDisp *TextDCreate(Widget widget, Widget hScrollBar, Widget vScrollBar,
357 @@ -2275,10 +2276,14 @@ static void drawString(textDisp *textD,
358 fground = textD->bgPixel;
359 /* set up gc for clearing using the foreground color entry */
360 gcValues.foreground = gcValues.background = bground;
361 XChangeGC(XtDisplay(textD->w), gc,
362 GCFont | GCForeground | GCBackground, &gcValues);
363 + /* adjust underline according to rangeset underline style */
364 + underlineStyle = getRangesetUnderline(textD,
365 + (style&RANGESET_MASK)>>RANGESET_SHIFT,
366 + underlineStyle);
369 /* Draw blank area rather than text, if that was the request */
370 if (style & FILL_MASK) {
371 /* wipes out to right hand edge of widget */
372 @@ -4016,10 +4021,33 @@ static Pixel getRangesetColor(textDisp *
374 return bground;
378 +** Return an adjusted underline flag. The original flag value (true if needed
379 +** by the syntax highlighting style) is left alone if the rangeset's underline
380 +** mode is 0; cleared if the mode is less than 0, or set if greater.
382 +static int getRangesetUnderline(textDisp *textD, int ind, int old)
384 + textBuffer *buf;
385 + RangesetTable *tab;
386 + int under;
388 + if (ind > 0) {
389 + ind--;
390 + buf = textD->buffer;
391 + tab = buf->rangesetTable;
393 + under = RangesetTableGetUnderline(tab, ind);
394 + if (under != 0)
395 + return under > 0;
397 + return old;
401 ** Read the background color class specification string in str, allocating the
402 ** necessary colors, and allocating and setting up the character->class_no and
403 ** class_no->pixel map arrays, returned via *pp_bgClass and *pp_bgClassPixel
404 ** respectively.
405 ** Note: the allocation of class numbers could be more intelligent: there can