ref: 1922f2108488c615d9a0c898bf19906cc94693ab
parent: 5fb6fe21b0c27fb69be41f590bf1069b63237285
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Sun Feb 16 10:26:10 EST 2020
plan9: (un)comment a block with # instead of filling it all
--- a/plan9.c
+++ b/plan9.c
@@ -476,10 +476,29 @@
static void
selset(Rune key)
{
- int y;
+ int y, commented;
- for (y = cury; y < cury+selh && y < field.height; y++)
- memset(&field.buffer[curx + field.width*y], key, MIN(field.width-curx, selw));
+ if (key == '#') {
+ commented = 1;
+ for (y = cury; y < cury+selh && y < field.height && commented; y++) {
+ commented =
+ field.buffer[curx + field.width*y] == key &&
+ field.buffer[MIN(field.width-1, curx + selw-1) + field.width*y] == key;
+ }
+ if (commented)
+ key = '.';
+ } else {
+ commented = 0;
+ }
+
+ for (y = cury; y < cury+selh && y < field.height; y++) {
+ if (key == '#' || commented) {
+ field.buffer[curx + field.width*y] = key;
+ field.buffer[MIN(field.width-1, curx + selw-1) + field.width*y] = key;
+ } else {
+ memset(&field.buffer[curx + field.width*y], key, MIN(field.width-curx, selw));
+ }
+ }
}
static void