drops and reorders
[nedit-bw.git] / RSunderlineStyle.diff
blob85b50b9b0996811fc078d774bc73af219397e4ce
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/macro.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++---
23 source/rangeset.c | 38 +++++++++++++++++++++++++++-
24 source/rangeset.h | 5 +++
25 source/textDisp.c | 28 +++++++++++++++++++++
26 5 files changed, 144 insertions(+), 5 deletions(-)
28 diff --quilt old/doc/help.etx new/doc/help.etx
29 --- old/doc/help.etx
30 +++ new/doc/help.etx
31 @@ -3166,6 +3166,12 @@ Rangesets
32 regarding the validity of color: if the color is invalid (a bad name,
33 or not supported by the hardware) this has unpredictable effects.
35 +**rangeset_set_underline( r, mode )**
36 + Change whether text over which the rangeset is defined should be displayed
37 + as underlined. **mode** can be "leave" (the text will show any underlining
38 + according to syntax highlighting settings), "remove" (any underliining is
39 + removed), or "add" (underlining is added to the text).
41 **rangeset_set_name( r, name )**
42 Apply the name to the rangeset r.
44 diff --quilt old/source/macro.c new/source/macro.c
45 --- old/source/macro.c
46 +++ new/source/macro.c
47 @@ -408,6 +408,8 @@ static int rangesetIncludesPosMS(WindowI
48 int nArgs, DataValue *result, char **errMsg);
49 static int rangesetSetColorMS(WindowInfo *window, DataValue *argList,
50 int nArgs, DataValue *result, char **errMsg);
51 +static int rangesetSetUnderlineMS(WindowInfo *window, DataValue *argList,
52 + int nArgs, DataValue *result, char **errMsg);
53 static int rangesetSetNameMS(WindowInfo *window, DataValue *argList,
54 int nArgs, DataValue *result, char **errMsg);
55 static int rangesetSetModeMS(WindowInfo *window, DataValue *argList,
56 @@ -524,6 +526,7 @@ static const BuiltInSubrName MacroSubrs[
57 { "rangeset_range", rangesetRangeMS },
58 { "rangeset_includes", rangesetIncludesPosMS },
59 { "rangeset_set_color", rangesetSetColorMS },
60 + { "rangeset_set_underline", rangesetSetUnderlineMS },
61 { "rangeset_set_name", rangesetSetNameMS },
62 { "rangeset_set_mode", rangesetSetModeMS },
63 { "rangeset_get_by_name", rangesetGetByNameMS },
64 @@ -5799,7 +5802,7 @@ static int rangesetInfoMS(WindowInfo *wi
66 RangesetTable *rangesetTable = window->buffer->rangesetTable;
67 Rangeset *rangeset = NULL;
68 - int count, defined;
69 + int count, defined, uline;
70 char *color, *name, *mode;
71 DataValue element;
72 int label = 0;
73 @@ -5816,7 +5819,8 @@ static int rangesetInfoMS(WindowInfo *wi
74 rangeset = RangesetFetch(rangesetTable, label);
77 - RangesetGetInfo(rangeset, &defined, &label, &count, &color, &name, &mode);
78 + RangesetGetInfo(rangeset, &defined, &label, &count, &uline,
79 + &color, &name, &mode);
81 /* set up result */
82 result->tag = ARRAY_TAG;
83 @@ -5850,7 +5854,15 @@ static int rangesetInfoMS(WindowInfo *wi
84 M_FAILURE("Failed to allocate array value \"mode\" in %s");
85 if (!ArrayInsert(result, PERM_ALLOC_STR("mode"), &element))
86 M_FAILURE("Failed to insert array element \"mode\" in %s");
89 + element.tag = STRING_TAG;
90 + element.val.str.rep = (uline < 0) ? PERM_ALLOC_STR("remove") :
91 + (uline > 0) ? PERM_ALLOC_STR("add") :
92 + PERM_ALLOC_STR("leave");
93 + element.val.str.len = strlen(element.val.str.rep);
94 + if (!ArrayInsert(result, PERM_ALLOC_STR("underline"), &element))
95 + M_FAILURE("Failed to insert array element \"count\" in %s");
97 return True;
100 @@ -6023,6 +6035,60 @@ static int rangesetSetColorMS(WindowInfo
104 +** Set underline flag for a range set's ranges. Returns true if the rangeset
105 +** is valid. It takes two arguments: the id of the rangeset to change and
106 +** the underlineMode string, which should be specified as "leave" (let any
107 +** syntax highlighting underlines to appear as undisturbed), "add" or "remove".
109 +static int rangesetSetUnderlineMS(WindowInfo *window, DataValue *argList,
110 + int nArgs, DataValue *result, char **errMsg)
112 + char stringStorage[1][TYPE_INT_STR_SIZE(int)];
113 + textBuffer *buffer = window->buffer;
114 + RangesetTable *rangesetTable = buffer->rangesetTable;
115 + Rangeset *rangeset;
116 + int label = 0;
117 + char *underlineMode;
119 + if (nArgs != 2) {
120 + return wrongNArgsErr(errMsg);
123 + if (!readIntArg(argList[0], &label, errMsg)
124 + || !RangesetLabelOK(label)) {
125 + M_FAILURE("First parameter is an invalid rangeset label in %s");
128 + if (rangesetTable == NULL) {
129 + M_FAILURE("Rangeset does not exist in %s");
132 + rangeset = RangesetFetch(rangesetTable, label);
133 + if (rangeset == NULL) {
134 + M_FAILURE("Rangeset does not exist in %s");
137 + if (readStringArg(argList[1], &underlineMode, stringStorage[0], errMsg)) {
138 + if (strcmp(underlineMode, "leave") == 0)
139 + RangesetAssignUnderline(rangeset, 0);
140 + else
141 + if (strcmp(underlineMode, "remove") == 0)
142 + RangesetAssignUnderline(rangeset, -1);
143 + else
144 + if (strcmp(underlineMode, "add") == 0)
145 + RangesetAssignUnderline(rangeset, 1);
146 + else
147 + M_FAILURE("Second parameter must be \"leave\", \"remove\" or \"add\" in %s");
149 + else
150 + M_FAILURE("Second parameter must be \"leave\", \"remove\" or \"add\" in %s");
152 + /* set up result */
153 + result->tag = NO_TAG;
154 + return True;
158 ** Set the name of a range set's ranges. Returns
159 ** true if the rangeset is valid.
161 diff --quilt old/source/rangeset.c new/source/rangeset.c
162 --- old/source/rangeset.c
163 +++ new/source/rangeset.c
164 @@ -64,6 +64,7 @@ struct _Rangeset {
165 unsigned char label; /* a number 1-63 */
167 signed char color_set; /* 0: unset; 1: set; -1: invalid */
168 + signed char underline; /* underline it? */
169 char *color_name; /* the name of an assigned color */
170 Pixel color; /* the value of a particular color */
171 textBuffer *buf; /* the text buffer of the rangeset */
172 @@ -251,6 +252,7 @@ void RangesetInit(Rangeset *rangeset, in
173 rangeset->color_name = (char *)0;
174 rangeset->name = (char *)0;
175 rangeset->color_set = 0;
176 + rangeset->underline = 0; /* "no change" value */
177 rangeset->buf = buf;
179 rangeset->maxpos = buf->length;
180 @@ -693,12 +695,13 @@ int RangesetGetNRanges(Rangeset *rangese
181 ** Get information about rangeset.
183 void RangesetGetInfo(Rangeset *rangeset, int *defined, int *label,
184 - int *count, char **color, char **name, char **mode)
185 + int *count, int *uline, char **color, char **name, char **mode)
187 if (rangeset == NULL) {
188 *defined = False;
189 *label = 0;
190 *count = 0;
191 + *uline = 0;
192 *color = "";
193 *name = "";
194 *mode = "";
195 @@ -707,6 +710,7 @@ void RangesetGetInfo(Rangeset *rangeset,
196 *defined = True;
197 *label = (int)rangeset->label;
198 *count = rangeset->n_ranges;
199 + *uline = rangeset->underline;
200 *color = rangeset->color_name ? rangeset->color_name : "";
201 *name = rangeset->name ? rangeset->name : "";
202 *mode = rangeset->update_name;
203 @@ -776,6 +780,7 @@ static void rangesetClone(Rangeset *dest
204 destRangeset->last_index = srcRangeset->last_index;
205 destRangeset->n_ranges = srcRangeset->n_ranges;
206 destRangeset->color_set = srcRangeset->color_set;
207 + destRangeset->underline = srcRangeset->underline;
208 destRangeset->color = srcRangeset->color;
210 if (srcRangeset->color_name) {
211 @@ -1109,6 +1114,27 @@ int RangesetAssignColorName(Rangeset *ra
215 +** Assign the underline to a rangeset via the rangeset table.
218 +int RangesetAssignUnderline(Rangeset *rangeset, int under)
220 + rangeset->underline = (0 < under) - (under < 0);
222 + rangesetRefreshAllRanges(rangeset);
223 + return 1;
227 +** Fetch the underline mode value.
230 +int RangesetGetUnderline(Rangeset *rangeset)
232 + return rangeset->underline;
236 ** Assign a name to a rangeset via the rangeset table.
239 @@ -1159,6 +1185,16 @@ char *RangesetGetName(Rangeset *rangeset
243 +** Return the underlining mode.
246 +int RangesetTableGetUnderline(RangesetTable *table, int index)
248 + Rangeset *rangeset = &table->set[index];
249 + return rangeset->underline;
253 ** Return the color validity, if any, and the value in *color.
256 diff --quilt old/source/rangeset.h new/source/rangeset.h
257 --- old/source/rangeset.h
258 +++ new/source/rangeset.h
259 @@ -53,7 +53,7 @@ int RangesetRemove(Rangeset *origSet, Ra
260 int RangesetRemoveBetween(Rangeset *rangeset, int start, int end);
261 int RangesetGetNRanges(Rangeset *rangeset);
262 void RangesetGetInfo(Rangeset *rangeset, int *defined, int *label,
263 - int *count, char **color, char **name, char **mode);
264 + int *count, int *uline, char **color, char **name, char **mode);
265 RangesetTable *RangesetTableAlloc(textBuffer *buf);
266 RangesetTable *RangesetTableFree(RangesetTable *table);
267 RangesetTable *RangesetTableClone(RangesetTable *srcTable,
268 @@ -69,12 +69,15 @@ void RangesetTableUpdatePos(RangesetTabl
269 void RangesetBufModifiedCB(int pos, int nInserted, int nDeleted, int nRestyled,
270 const char *deletedText, void *cbArg);
271 int RangesetIndex1ofPos(RangesetTable *table, int pos, int needs_color);
272 +int RangesetAssignUnderline(Rangeset *rangeset, int under);
273 +int RangesetGetUnderline(Rangeset *rangeset);
274 int RangesetAssignColorName(Rangeset *rangeset, char *color_name);
275 int RangesetAssignColorPixel(Rangeset *rangeset, Pixel color, int ok);
276 char *RangesetGetName(Rangeset *rangeset);
277 int RangesetAssignName(Rangeset *rangeset, char *name);
278 int RangesetGetColorValid(Rangeset *rangeset, Pixel *color);
279 char *RangesetTableGetColorName(RangesetTable *table, int index);
280 +int RangesetTableGetUnderline(RangesetTable *table, int index);
281 int RangesetTableGetColorValid(RangesetTable *table, int index, Pixel *color);
282 int RangesetTableAssignColorPixel(RangesetTable *table, int index, Pixel color,
283 int ok);
284 diff --quilt old/source/textDisp.c new/source/textDisp.c
285 --- old/source/textDisp.c
286 +++ new/source/textDisp.c
287 @@ -184,6 +184,7 @@ static int measurePropChar(const textDis
288 const int colNum, const int pos);
289 static Pixel allocBGColor(Widget w, char *colorName, int *ok);
290 static Pixel getRangesetColor(textDisp *textD, int ind, Pixel bground);
291 +static int getRangesetUnderline(textDisp *textD, int ind, int old);
292 static void textDRedisplayRange(textDisp *textD, int start, int end);
293 static void drawWrapMargin(textDisp *textD);
294 static void redisplayCursor(textDisp *textD);
295 @@ -2277,6 +2278,10 @@ static void drawString(textDisp *textD,
296 gcValues.foreground = gcValues.background = bground;
297 XChangeGC(XtDisplay(textD->w), gc,
298 GCFont | GCForeground | GCBackground, &gcValues);
299 + /* adjust underline according to rangeset underline style */
300 + underlineStyle = getRangesetUnderline(textD,
301 + (style&RANGESET_MASK)>>RANGESET_SHIFT,
302 + underlineStyle);
305 /* Draw blank area rather than text, if that was the request */
306 @@ -4018,6 +4023,29 @@ static Pixel getRangesetColor(textDisp *
310 +** Return an adjusted underline flag. The original flag value (true if needed
311 +** by the syntax highlighting style) is left alone if the rangeset's underline
312 +** mode is 0; cleared if the mode is less than 0, or set if greater.
314 +static int getRangesetUnderline(textDisp *textD, int ind, int old)
316 + textBuffer *buf;
317 + RangesetTable *tab;
318 + int under;
320 + if (ind > 0) {
321 + ind--;
322 + buf = textD->buffer;
323 + tab = buf->rangesetTable;
325 + under = RangesetTableGetUnderline(tab, ind);
326 + if (under != 0)
327 + return under > 0;
329 + return old;
333 ** Read the background color class specification string in str, allocating the
334 ** necessary colors, and allocating and setting up the character->class_no and
335 ** class_no->pixel map arrays, returned via *pp_bgClass and *pp_bgClassPixel