visible tabs and trailing spaces



moin,

visible tabs help putting the tabs where you want them, particularly
when changing existing text.
making trailing whitespace visible helps avoiding it, if the editor has
no automatic trailing whitespace removal (which, in itself, is a feature
in certain situations).

i wanted the visibility to be as subtle as possible. therefore just
changing the background color (see leading tabs in Makefile highlite)
was no option. so i paint tabs as excerpts of <------> and spaces as
dots. to make it really subtle, i paint it bright blue on dark blue (the
regular background) - this is hardly visible, unless you are looking for
it. i know of no way to make it equally subtle on monochrome displays,
so the feature is disabled alltogether there.
an option to disable it is missing. volunteers sought.
the highlite color is not defined by syntax highliting, but by an
extra palette entry. i think this makes sense.
the whitespace becomes invisible when the text is selected, as there is
no possibility to merge colors. it'd be nice to fix this generally.

-- 
Hi! I'm a .signature virus! Copy me into your ~/.signature, please!
--
Chaos, panic, and disorder - my work here is done.
Index: src/color.c
===================================================================
RCS file: /cvsroot/mc/mc/src/color.c,v
retrieving revision 1.40
diff -U2 -r1.40 color.c
--- src/color.c	24 Sep 2004 22:22:35 -0000	1.40
+++ src/color.c	13 Feb 2005 11:40:35 -0000
@@ -97,7 +97,8 @@
     { "editbold=",       0, 0 },	/* search->found */
     { "editmarked=",     0, 0 },	/* marked/selected */
+    { "editwhitespace=", 0, 0 },	/* whitespace */
 
-/* error dialog colors start at 37 */
-    { "errdhotnormal=",  0, 0 }, /* Error dialog normal/hot */ /* 37 */
+/* error dialog colors start at 38 */
+    { "errdhotnormal=",  0, 0 }, /* Error dialog normal/hot */ /* 38 */
     { "errdhotfocus=",   0, 0 }, /* Error dialog focused/hot */
 };
@@ -162,4 +163,5 @@
 "editbold=yellow,blue:"
 "editmarked=black,cyan:"
+"editwhitespace=brightblue,blue:"
 "errdhotnormal=yellow,red:"
 "errdhotfocus=yellow,lightgray";
Index: src/color.h
===================================================================
RCS file: /cvsroot/mc/mc/src/color.h,v
retrieving revision 1.21
diff -U2 -r1.21 color.h
--- src/color.h	3 Dec 2004 19:17:47 -0000	1.21
+++ src/color.h	13 Feb 2005 11:40:35 -0000
@@ -79,8 +79,9 @@
 #define EDITOR_BOLD_COLOR            IF_COLOR (35, A_BOLD)
 #define EDITOR_MARKED_COLOR          IF_COLOR (36, A_REVERSE)
+#define EDITOR_WHITESPACE_COLOR      IF_COLOR (37, 0 /* irrelevant */)
 
 /* Error dialog colors */
-#define ERROR_HOT_NORMAL   IF_COLOR (37, 0)
-#define ERROR_HOT_FOCUS    IF_COLOR (38, 0)
+#define ERROR_HOT_NORMAL   IF_COLOR (38, 0)
+#define ERROR_HOT_FOCUS    IF_COLOR (39, 0)
 
 #ifdef HAVE_SLANG
Index: edit/editdraw.c
===================================================================
RCS file: /cvsroot/mc/mc/edit/editdraw.c,v
retrieving revision 1.38
diff -U2 -r1.38 editdraw.c
--- edit/editdraw.c	7 Feb 2005 07:31:19 -0000	1.38
+++ edit/editdraw.c	13 Feb 2005 11:40:35 -0000
@@ -39,4 +39,5 @@
 #define MOD_MARKED		(1 << 10)
 #define MOD_CURSOR		(1 << 11)
+#define MOD_WHITESPACE		(1 << 12)
 
 #define FONT_OFFSET_X 0
@@ -224,10 +225,24 @@
 	}
 
-	if (style & MOD_BOLD) {
-	    set_color (EDITOR_BOLD_COLOR);
-	} else if (style & MOD_MARKED) {
-	    set_color (EDITOR_MARKED_COLOR);
+	if (style & MOD_WHITESPACE) {
+	    if (style & MOD_MARKED) {
+		textchar = ' ';
+		set_color (EDITOR_MARKED_COLOR);
+	    } else {
+		if (color == EDITOR_NORMAL_COLOR)
+		    set_color (EDITOR_WHITESPACE_COLOR);
+		else {
+		    textchar = ' ';
+		    lowlevel_set_color (color);
+		}
+	    }
 	} else {
-	    lowlevel_set_color (color);
+	    if (style & MOD_BOLD) {
+		set_color (EDITOR_BOLD_COLOR);
+	    } else if (style & MOD_MARKED) {
+		set_color (EDITOR_MARKED_COLOR);
+	    } else {
+		lowlevel_set_color (color);
+	    }
 	}
 
@@ -244,5 +259,5 @@
     static unsigned int line[MAX_LINE_LEN];
     unsigned int *p = line;
-    long m1 = 0, m2 = 0, q, c1, c2;
+    long m1 = 0, m2 = 0, q, c1, c2, tws;
     int col, start_col_real;
     unsigned int c;
@@ -267,4 +282,10 @@
 
 	if (row <= edit->total_lines - edit->start_line) {
+	    if (use_colors) {
+		tws = edit_eol (edit, b);
+		while (tws > b && edit_get_byte (edit, tws - 1) == ' ')
+		    tws--;
+	    }
+
 	    while (col <= end_col - edit->start_col) {
 		*p = 0;
@@ -293,5 +314,4 @@
 		    *p |= book_mark << 16;
 		}
-		q++;
 		switch (c) {
 		case '\n':
@@ -301,10 +321,31 @@
 		case '\t':
 		    i = TAB_SIZE - ((int) col % TAB_SIZE);
-		    *p |= ' ';
-		    c = *(p++) & ~MOD_CURSOR;
 		    col += i;
-		    while (--i)
-			*(p++) = c;
+		    if (use_colors) {
+			c = (*p & ~MOD_CURSOR) | MOD_WHITESPACE;
+			if (i > 2) {
+			    *(p++) |= '<' | MOD_WHITESPACE;
+			    while (--i > 1)
+				*(p++) = c | '-';
+			    *(p++) = c | '>';
+			} else if (i > 1) {
+			    *(p++) |= '<' | MOD_WHITESPACE;
+			    *(p++) = c | '>';
+			} else
+			    *(p++) |= '>' | MOD_WHITESPACE;
+		    } else {
+			*p |= ' ';
+			c = *(p++) & ~MOD_CURSOR;
+			while (--i)
+			    *(p++) = c;
+		    }
 		    break;
+		case ' ':
+		    if (use_colors && q >= tws) {
+			*(p++) |= '.' | MOD_WHITESPACE;
+			col++;
+			break;
+		    }
+		    /* fallthrough */
 		default:
 		    c = convert_to_display_c (c);
@@ -332,4 +373,5 @@
 		    break;
 		}
+		q++;
 	    }
 	}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]