@@ -210,6 +210,12 @@ int predisplaylen, postdisplaylen;
210
210
211
211
static zattr default_attr , special_attr , ellipsis_attr ;
212
212
213
+ /*
214
+ * Layer applied to highlighting for special characters
215
+ */
216
+
217
+ static int special_layer ;
218
+
213
219
/*
214
220
* Array of region highlights, no special termination.
215
221
* The first N_SPECIAL_HIGHLIGHTS elements describe special uses of
@@ -337,6 +343,13 @@ zle_set_highlight(void)
337
343
}
338
344
}
339
345
346
+ /* Default layers */
347
+ region_highlights [0 ].layer = 20 ; /* region */
348
+ region_highlights [1 ].layer = 20 ; /* isearch */
349
+ region_highlights [2 ].layer = 10 ; /* suffix */
350
+ region_highlights [3 ].layer = 15 ; /* paste */
351
+ special_layer = 30 ;
352
+
340
353
if (atrs ) {
341
354
for (; * atrs ; atrs ++ ) {
342
355
if (!strcmp (* atrs , "none" )) {
@@ -346,30 +359,34 @@ zle_set_highlight(void)
346
359
paste_attr_set = region_attr_set =
347
360
isearch_attr_set = suffix_attr_set = 1 ;
348
361
} else if (strpfx ("default:" , * atrs )) {
349
- match_highlight (* atrs + 8 , & default_attr );
362
+ match_highlight (* atrs + 8 , & default_attr , NULL );
350
363
} else if (strpfx ("special:" , * atrs )) {
351
- match_highlight (* atrs + 8 , & special_attr );
364
+ match_highlight (* atrs + 8 , & special_attr , & special_layer );
352
365
special_attr_set = 1 ;
353
366
} else if (strpfx ("region:" , * atrs )) {
354
- match_highlight (* atrs + 7 , & region_highlights [0 ].atr );
367
+ match_highlight (* atrs + 7 , & (region_highlights [0 ].atr ),
368
+ & (region_highlights [0 ].layer ));
355
369
region_attr_set = 1 ;
356
370
} else if (strpfx ("isearch:" , * atrs )) {
357
- match_highlight (* atrs + 8 , & (region_highlights [1 ].atr ));
371
+ match_highlight (* atrs + 8 , & (region_highlights [1 ].atr ),
372
+ & (region_highlights [1 ].layer ));
358
373
isearch_attr_set = 1 ;
359
374
} else if (strpfx ("suffix:" , * atrs )) {
360
- match_highlight (* atrs + 7 , & (region_highlights [2 ].atr ));
375
+ match_highlight (* atrs + 7 , & (region_highlights [2 ].atr ),
376
+ & (region_highlights [2 ].layer ));
361
377
suffix_attr_set = 1 ;
362
378
} else if (strpfx ("paste:" , * atrs )) {
363
- match_highlight (* atrs + 6 , & (region_highlights [3 ].atr ));
379
+ match_highlight (* atrs + 6 , & (region_highlights [3 ].atr ),
380
+ & (region_highlights [3 ].layer ));
364
381
paste_attr_set = 1 ;
365
382
} else if (strpfx ("ellipsis:" , * atrs )) {
366
- match_highlight (* atrs + 9 , & ellipsis_attr );
383
+ match_highlight (* atrs + 9 , & ellipsis_attr , NULL );
367
384
ellipsis_attr_set = 1 ;
368
385
}
369
386
}
370
387
}
371
388
372
- /* Defaults */
389
+ /* Default attributes */
373
390
if (!special_attr_set )
374
391
special_attr = TXTSTANDOUT ;
375
392
if (!region_attr_set )
@@ -407,35 +424,32 @@ zle_free_highlight(void)
407
424
char * *
408
425
get_region_highlight (UNUSED (Param pm ))
409
426
{
410
- int arrsize = n_region_highlights ;
427
+ int arrsize = n_region_highlights - N_SPECIAL_HIGHLIGHTS ;
411
428
char * * retarr , * * arrp ;
412
429
struct region_highlight * rhp ;
413
430
414
431
/* region_highlights may not have been set yet */
415
- if (!arrsize )
432
+ if (!n_region_highlights )
416
433
return hmkarray (NULL );
417
- arrsize -= N_SPECIAL_HIGHLIGHTS ;
418
434
DPUTS (arrsize < 0 , "arrsize is negative from n_region_highlights" );
419
435
arrp = retarr = (char * * )zhalloc ((arrsize + 1 )* sizeof (char * ));
420
436
421
437
/* ignore special highlighting */
422
438
for (rhp = region_highlights + N_SPECIAL_HIGHLIGHTS ;
423
439
arrsize -- ;
424
440
rhp ++ , arrp ++ ) {
425
- char digbuf1 [DIGBUFSIZE ], digbuf2 [DIGBUFSIZE ];
426
- int atrlen , alloclen ;
427
- const char memo_equals [] = "memo=" ;
428
-
429
- sprintf (digbuf1 , "%d" , rhp -> start );
430
- sprintf (digbuf2 , "%d" , rhp -> end );
431
-
432
- atrlen = output_highlight (rhp -> atr , NULL );
433
- alloclen = atrlen + strlen (digbuf1 ) + strlen (digbuf2 ) +
434
- 3 ; /* 2 spaces, 1 terminating NUL */
441
+ char digbuf [2 * DIGBUFSIZE ], layerbuf [7 + DIGBUFSIZE ];
442
+ int offset ;
443
+ const char memo_equals [] = " memo=" ;
444
+ int alloclen = sprintf (digbuf , "%d %d" , rhp -> start , rhp -> end ) +
445
+ output_highlight (rhp -> atr , NULL ) +
446
+ 2 ; /* space and terminating NUL */
435
447
if (rhp -> flags & ZRH_PREDISPLAY )
436
- alloclen += 2 ; /* "P " */
448
+ alloclen ++ ; /* "P" */
449
+ if (rhp -> layer != 10 )
450
+ alloclen += sprintf (layerbuf , ",layer=%d" , rhp -> layer );
437
451
if (rhp -> memo )
438
- alloclen += 1 /* space */ + strlen (memo_equals ) + strlen (rhp -> memo );
452
+ alloclen += sizeof (memo_equals ) - 1 + strlen (rhp -> memo );
439
453
* arrp = (char * )zhalloc (alloclen * sizeof (char ));
440
454
/*
441
455
* On input we allow a space after the flags.
@@ -444,13 +458,14 @@ get_region_highlight(UNUSED(Param pm))
444
458
* into three words, and then check the first to
445
459
* see if there are flags. However, it's arguable.
446
460
*/
447
- sprintf (* arrp , "%s%s %s " ,
461
+ offset = sprintf (* arrp , "%s%s " ,
448
462
(rhp -> flags & ZRH_PREDISPLAY ) ? "P" : "" ,
449
- digbuf1 , digbuf2 );
450
- (void )output_highlight (rhp -> atr , * arrp + strlen ( * arrp ) );
463
+ digbuf );
464
+ (void )output_highlight (rhp -> atr , * arrp + offset );
451
465
466
+ if (rhp -> layer != 10 )
467
+ strcat (* arrp , layerbuf );
452
468
if (rhp -> memo ) {
453
- strcat (* arrp , " " );
454
469
strcat (* arrp , memo_equals );
455
470
strcat (* arrp , rhp -> memo );
456
471
}
@@ -459,12 +474,10 @@ get_region_highlight(UNUSED(Param pm))
459
474
return retarr ;
460
475
}
461
476
462
-
463
477
/*
464
478
* The parameter system requires the pm argument, but this
465
479
* may be NULL if called directly.
466
480
*/
467
-
468
481
/**/
469
482
void
470
483
set_region_highlight (UNUSED (Param pm ), char * * aval )
@@ -523,7 +536,8 @@ set_region_highlight(UNUSED(Param pm), char **aval)
523
536
while (inblank (* strp ))
524
537
strp ++ ;
525
538
526
- strp = (char * ) match_highlight (strp , & rhp -> atr );
539
+ rhp -> layer = 10 ; /* default */
540
+ strp = (char * ) match_highlight (strp , & rhp -> atr , & rhp -> layer );
527
541
528
542
while (inblank (* strp ))
529
543
strp ++ ;
@@ -1180,27 +1194,40 @@ zrefresh(void)
1180
1194
rpms .s = nbuf [rpms .ln = 0 ] + lpromptw ;
1181
1195
rpms .sen = * nbuf + winw ;
1182
1196
for (t = tmpline , tmppos = 0 ; tmppos < tmpll ; t ++ , tmppos ++ ) {
1183
- unsigned ireg ;
1184
1197
zattr base_attr = mixattrs (default_attr , prompt_attr );
1185
1198
zattr all_attr ;
1186
1199
struct region_highlight * rhp ;
1200
+ int layer , nextlayer = 0 ;
1187
1201
/*
1188
1202
* Calculate attribute based on region.
1189
1203
*/
1190
- for (ireg = 0 , rhp = region_highlights ;
1191
- ireg < n_region_highlights ;
1192
- ireg ++ , rhp ++ ) {
1193
- int offset ;
1194
- if (rhp -> flags & ZRH_PREDISPLAY )
1195
- offset = 0 ; /* include predisplay in start end */
1196
- else
1197
- offset = predisplaylen ; /* increment over it */
1198
- if (rhp -> start + offset <= tmppos &&
1199
- tmppos < rhp -> end + offset ) {
1200
- base_attr = mixattrs (rhp -> atr , base_attr );
1204
+ do {
1205
+ unsigned ireg ;
1206
+ layer = nextlayer ;
1207
+ nextlayer = special_layer ;
1208
+ for (ireg = 0 , rhp = region_highlights ;
1209
+ ireg < n_region_highlights ;
1210
+ ireg ++ , rhp ++ ) {
1211
+ if (rhp -> layer == layer ) {
1212
+ int offset ;
1213
+ if (rhp -> flags & ZRH_PREDISPLAY )
1214
+ offset = 0 ; /* include predisplay in start end */
1215
+ else
1216
+ offset = predisplaylen ; /* increment over it */
1217
+ if (rhp -> start + offset <= tmppos &&
1218
+ tmppos < rhp -> end + offset ) {
1219
+ base_attr = mixattrs (rhp -> atr , base_attr );
1220
+ if (layer > special_layer )
1221
+ all_attr = mixattrs (rhp -> atr , all_attr );
1222
+ }
1223
+ } else if (rhp -> layer > layer && rhp -> layer < nextlayer ) {
1224
+ nextlayer = rhp -> layer ;
1225
+ }
1201
1226
}
1202
- }
1203
- all_attr = mixattrs (special_attr , base_attr );
1227
+ if (special_layer == layer ) {
1228
+ all_attr = mixattrs (special_attr , base_attr );
1229
+ }
1230
+ } while (nextlayer > layer );
1204
1231
1205
1232
if (t == scs ) /* if cursor is here, remember it */
1206
1233
rpms .nvcs = rpms .s - nbuf [rpms .nvln = rpms .ln ];
0 commit comments