jed-users mailing list

[2003 Date Index] [2003 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

Re: Line numbers and Visible Tabs


I wrote MONTHS AGO:

[visible line number & tabs]

> Well, it seems like implementing it directly into the C
> source would be a much cleaner & better way. I hope I find
> some time the next days to look into it.

It just took a few months longer... But this night I had
some time to spare. The patch for both---visible tabs &
spaces AND visible line numbers---is attached. ;)

Using the patched Jed version one gets three more things to
customize in .jedrc:

	WANT_LINE_NUMBERS=1;

to turn on the line numbers on the left side of the screen
(default is 0),

	WANT_VISIBLE_SPACE=1;

to turn on visible tab characters and spaces (default is 0) and

	VISIBLE_SPACE_CHARACTER='.';

to choose the character which should be used to represent a
space when WANT_VISIBLE_SPACE is 1. Default is '.', I
like '·' (a light & centered dot found many latin charsets).
If you just want visible tabs and no visible spaces just
set it to ' ' (a space).

If you want to see the patch in action before trying it,
look here:

	http://www.lillaxsitedesign.de/rob/download/jed1.png
	http://www.lillaxsitedesign.de/rob/download/jed2.png

Comments welcome!

Rob.
-- 
r o b e r t | l i l l a c k
www.lillaxsitedesign.de/rob
secure mail key: 0xE7FFDF77
diff -ur jed-0.99-16.orig/src/buffer.h jed-0.99-16/src/buffer.h
--- jed-0.99-16.orig/src/buffer.h	Fri Jun  6 14:40:27 2003
+++ jed-0.99-16/src/buffer.h	Sun Sep 28 00:17:15 2003
@@ -47,6 +47,7 @@
    struct Line *prev;               /* pointer to prev line */
    unsigned char *data;             /* data for the line */
    int len;                         /* actual length of line */
+   int num;                         /* number of the line */
 #ifdef KEEP_SPACE_INFO
    int space;		       /* space allocated for line */
 #endif
diff -ur jed-0.99-16.orig/src/intrin.c jed-0.99-16/src/intrin.c
--- jed-0.99-16.orig/src/intrin.c	Fri Jun  6 14:40:27 2003
+++ jed-0.99-16/src/intrin.c	Sat Sep 27 23:53:28 2003
@@ -882,6 +882,9 @@
    MAKE_VARIABLE("LASTKEY", &Key_Buffer_Ptr, STRING_TYPE, 1),
    MAKE_VARIABLE("DISPLAY_TIME", &Display_Time, INT_TYPE, 0),
    MAKE_VARIABLE("WANT_EOB", &Want_Eob, INT_TYPE, 0),
+   MAKE_VARIABLE("WANT_LINE_NUMBERS", &Want_Line_Numbers, INT_TYPE, 0),
+   MAKE_VARIABLE("WANT_VISIBLE_SPACE", &Want_Visible_Space, INT_TYPE, 0),
+   MAKE_VARIABLE("VISIBLE_SPACE_CHARACTER", &Visible_Space, INT_TYPE, 0),
    MAKE_VARIABLE("WRAP", &Jed_Wrap_Column, INT_TYPE, 0),
    MAKE_VARIABLE("META_CHAR", &Meta_Char, INT_TYPE, 0),
    MAKE_VARIABLE("DEC_8BIT_HACK", &DEC_8Bit_Hack, INT_TYPE, 0),
diff -ur jed-0.99-16.orig/src/screen.c jed-0.99-16/src/screen.c
--- jed-0.99-16.orig/src/screen.c	Fri Jun  6 14:40:27 2003
+++ jed-0.99-16/src/screen.c	Sun Sep 28 00:18:27 2003
@@ -79,6 +79,11 @@
 int Want_Eob = 0;
 int Display_Time = 1;                  /* Turn on %t processing in status line */
 
+int Want_Line_Numbers = 0;
+int Want_Visible_Space = 0;
+int Line_Number_Width = 6;
+int Visible_Space = '.';
+
 void (*X_Update_Open_Hook)(void);      /* hooks called when starting */
 void (*X_Update_Close_Hook)(void);     /* and finishing update */
 
@@ -111,6 +116,48 @@
 #define FIX_CHAR_WIDTH \
      if (SLsmg_Display_Eight_Bit != Display_Eight_Bit) fix_char_width ()
 
+void my_write_nchars (char *str, int len, int color)
+{
+   int i, j, x, lnw;
+   char tab, tabend, space;
+   
+   if (Want_Line_Numbers)
+     lnw = Line_Number_Width;
+   else
+     lnw = 0;
+   
+   if (Want_Visible_Space)
+     {
+	tab = '-';
+	tabend = '>';
+	space = (char) Visible_Space;
+     }
+   else
+     tab = tabend = space = ' ';
+        
+   SLsmg_set_color (color);
+   for (i = x = 0; i < len; i++, x++)
+     {
+        if (str[i] == '\t')
+	  {
+	     if (color == 0) SLsmg_set_color (JDOTS_COLOR);
+	     for (j = (SLsmg_get_column() - lnw) % SLsmg_Tab_Width; j < SLsmg_Tab_Width - 1; j++)
+	       {
+		  SLsmg_write_char (tab);
+		  x++;
+	       }
+	     SLsmg_write_char (tabend);
+	     SLsmg_set_color (color);
+	  } else if (str[i] == ' ') {
+	     if (color == 0) SLsmg_set_color (JDOTS_COLOR);
+	     SLsmg_write_char (space);
+	     SLsmg_set_color (color);
+	  } else {
+             SLsmg_write_char (str[i]);
+	  }
+     }
+   SLsmg_set_color (0);
+}
 
 static void display_line (Line *line, int sy, int sx)
 {
@@ -118,6 +165,7 @@
    int hscroll_col;
    int is_mini;
    Screen_Type *s;
+   char linenumbuf[5];
 #if JED_HAS_LINE_MARKS
    Mark *line_marks;
 #endif
@@ -125,9 +173,36 @@
    SLsmg_Tab_Width = Buffer_Local.tab;
    is_mini = (sy + 1 == Jed_Num_Screen_Rows);
    
-   SLsmg_gotorc (sy, sx);
-   SLsmg_set_color (0);
-   
+   if (Want_Line_Numbers && !is_mini)
+     {
+	SLsmg_gotorc (sy, sx);
+        if (line && (line->next || line->prev))
+	  {
+	     if (line == CBuf->beg)
+	       {
+		  line->num = 1;
+	       }
+	     else
+	       {
+		  line->num = line->prev->num + 1;
+	       }
+	     sprintf (linenumbuf, "%4d ", line->num);
+	  }
+	else
+	  {
+	     sprintf (linenumbuf, "     ");
+	  }
+	
+        SLsmg_set_color (JCOM_COLOR);
+        SLsmg_write_nchars (linenumbuf, Line_Number_Width - 1);
+        SLsmg_set_color (0);
+        SLsmg_write_nchars (" ", 1);
+     }
+   else
+     {
+	SLsmg_gotorc (sy, sx);
+     }
+      
    s = JScreen + sy;
 
    s->line = line;
@@ -135,6 +210,7 @@
    
    if (line == NULL)
      {
+	SLsmg_set_color (0);
 	SLsmg_erase_eol ();
 	return;
      }
@@ -155,6 +231,7 @@
    
    if (is_mini)
      {
+	SLsmg_set_color (0);
 	SLsmg_write_string ((char *)Mini_Info.prompt);
 	SLsmg_Newline_Behavior = SLSMG_NEWLINE_PRINTABLE;
      }
@@ -190,15 +267,13 @@
 	    && Wants_Syntax_Highlight)
 	  write_syntax_highlight (line, len);
 	else
-	  SLsmg_write_nchars ((char *)line->data, len);
+	  my_write_nchars ((char *)line->data, len, 0);
      }
 #if JED_HAS_LINE_ATTRIBUTES
    if ((line->next != NULL)
        && (line->next->flags & JED_LINE_HIDDEN))
      {
-	SLsmg_set_color (JDOTS_COLOR);
-	SLsmg_write_nchars ("...", 3);
-	SLsmg_set_color (0);
+	my_write_nchars ("...", 3, JDOTS_COLOR);
      }
 #endif
    SLsmg_erase_eol ();
@@ -210,14 +285,12 @@
 	if (sx + hscroll_col + Jed_Num_Screen_Cols <= SLsmg_get_column ())
 	  {
 	     SLsmg_gotorc (sy, hscroll_col + Jed_Num_Screen_Cols - 1);
-	     SLsmg_set_color (JDOLLAR_COLOR);
-	     SLsmg_write_nchars (&dollar, 1);
+	     my_write_nchars (&dollar, 1, JDOLLAR_COLOR);
 	  }
 	if (hscroll_col)
 	  {
 	     SLsmg_gotorc (sy, sx + hscroll_col);
-	     SLsmg_set_color (JDOLLAR_COLOR);
-	     SLsmg_write_nchars (&dollar, 1);
+	     my_write_nchars (&dollar, 1, JDOLLAR_COLOR);
 	  }
      }
 
@@ -234,16 +307,15 @@
 	     c = jed_compute_effective_length (line->data, s->hi0);
 	     if (is_mini)
 	       c += Mini_Info.effective_prompt_len;
+	     else if (Want_Line_Numbers)
+	       c += Line_Number_Width;
 	     SLsmg_gotorc (sy, c + sx);
-	     SLsmg_set_color (JREGION_COLOR);
-	     SLsmg_write_nchars ((char *)s->hi0, len);
+	     my_write_nchars ((char *)s->hi0, len, JREGION_COLOR);
 	  }
      }
    
    if (hscroll_col + sx)
      SLsmg_set_screen_start (NULL, NULL);
-   
-   SLsmg_set_color (0);
 }
 
 #if JED_HAS_LINE_ATTRIBUTES
@@ -546,6 +618,9 @@
    if (JWindow->trashed) return;
 
    cline = CLine;
+   
+   if (CBuf != MiniBuffer && Want_Line_Numbers) c += Line_Number_Width;
+   
 #if JED_HAS_LINE_ATTRIBUTES
    if (cline->flags & JED_LINE_HIDDEN)
      {
diff -ur jed-0.99-16.orig/src/screen.h jed-0.99-16/src/screen.h
--- jed-0.99-16.orig/src/screen.h	Fri Jun  6 14:40:27 2003
+++ jed-0.99-16/src/screen.h	Sat Sep 27 23:55:47 2003
@@ -40,6 +40,9 @@
 extern int Wants_Syntax_Highlight;
 extern int Display_Time;
 extern int Want_Eob;
+extern int Want_Line_Numbers;
+extern int Want_Visible_Space;
+extern int Visible_Space;
 extern void set_status_format(char *, int *);
 
 extern void init_syntax_highlight (void);
Only in jed-0.99-16/src: screen.h~
Only in jed-0.99-16/src: screen.o
diff -ur jed-0.99-16.orig/src/syntax.c jed-0.99-16/src/syntax.c
--- jed-0.99-16.orig/src/syntax.c	Fri Jun  6 14:40:27 2003
+++ jed-0.99-16/src/syntax.c	Sun Sep 28 00:15:10 2003
@@ -22,13 +22,13 @@
 static char **Keywords = NULL;	       /* array of keywords */
 static int Keyword_Not_Case_Sensitive;
 
+extern void my_write_nchars(char *, int, int);
+
 static unsigned char *write_using_color (unsigned char *p,
 					 unsigned char *pmax,
 					 int color)
 {
-   SLsmg_set_color (color);
-   SLsmg_write_nchars ((char *)p, (unsigned int) (pmax - p));
-   SLsmg_set_color (0);
+   my_write_nchars ((char *)p, (unsigned int) (pmax - p), color);
    return pmax;
 }
 

[2003 date index] [2003 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]