jed-users mailing list

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

RE: Patch for %F in the statusline


> -----Original Message-----
> From: John E. Davis [mailto:davis@xxxxxxxxxxxxx]
> Sent: martedì 5 marzo 2002 17.33
> Subject: Re: Patch for %F in the statusline

[showing directories on status line]
> 
> Regarding this particular patch, perhaps it should be rewritten to
> "kick-in" only when the window size exceeds some maximum value.  I
> personally cannot see using it for the standard window size of 80
> columns that I use, but I can imagine others using it for sizes of 200
> columns or more.

I see this check more appropriate for slang code. i.e.:
if (SCREEN_WIDTH > 80)
	set_status_line(" JED %v | %b (%m%a%n%o) %D%f %p", 1);
else
	set_status_line(" JED %v | %b (%m%a%n%o) %f %p", 1);

People not using this (both because uses always small terminals or just
because doesn't want it) don't do it, and everything will work as before.

However having the maximum directory length hard coded is not an option
IMHO. I thought about two diffent solutions: a variable holding the maximum
length, or parsing formats with a length indicator (e.g. %20d).  I have
patches for both. 

With the first one you have %d format for an unlimited path, and %D for a
limited one. The limit is set by the variable DIRECTORY_STATUS_LENGTH. A
user may do:

DIRECTORY_STATUS_LENGTH = SCREEN_WIDTH - 80; % just a guess

And have no or little path when in small terminals, but a bigger one if room
is available.

The second patch is smaller, simpler, and allow different buffers to have
different maximum directory lengths. Futhermore the other format may be
easily extended if needed to take advantage of the size information. This
has only "%d" format, as not using the size specifier means the full path.
you may use:
set_status_line(" JED %v | %b (%m%a%n%o) %40d%f %p", 1);
Or better yet:
set_status_line(" JED %v | %b (%m%a%n%o) %" + string(SCREEN_WIDTH - 80) +
"d%f %p", 1);

For people willing to try this and comment, here are the patches:
-------- First:
--------
diff -ru jed-B0.99-15/doc/tm/rtl/window.tm
jed-B0.99-15-dir/doc/tm/rtl/window.tm
--- jed-B0.99-15/doc/tm/rtl/window.tm	Fri Jun  1 02:23:13 2001
+++ jed-B0.99-15-dir/doc/tm/rtl/window.tm	Fri Mar  8 13:03:48 2002
@@ -80,6 +80,20 @@
 \seealso{set_status_line}
 \done
 
+\variable{DIRECTORY_STATUS_LENGTH}
+\synopsis{Control the display of directory in status line}
+\usage{Int_Type variable{DIRECTORY_STATUS_LENGTH}
+\description
+  The \var{DIRECTORY_STATUS_LENGTH} variable determines how much characters
+  will be show on status line when requested using %D format.
+  If the value of \var{DIRECTORY_STATUS_LENGTH} less or equal to \0, then 
+  no directory information is shown. 
+  When truncation is needed, the last part of the path will be kept, 
+  and three dots are displayed at the beginning to make it clear that
+  a truncation was made.
+\seealso{set_status_line}
+\done
+
 \variable{LINE_NUMBERS}
 \synopsis{Control the display of line and column number information}
 \usage{Int_Type LINE_NUMBERS}
@@ -245,6 +259,8 @@
 #v+
         %b   buffer name
         %f   file name
+        %d   directory
+        %D   directory (only the last characters, see
DIRECTORY_STATUS_LENGTH)
         %v   JED version
         %t   current time --- only used if variable DISPLAY_TIME is
non-zero
         %p   line number or percent string. If LINENUMBERS is 2, this
@@ -265,7 +281,7 @@
         "(Jed %v) EDT: %b   (%m%a%n%o)  %p,%c   Advance   %t"
 #v-
 \seealso{set_mode, narrow, whatbuf, getbuf_info}
-\seealso{DISPLAY_TIME,LINENUMBERS}
+\seealso{DISPLAY_TIME,LINENUMBERS,DIRECTORY_STATUS_LENGTH}
 \done
 
 \function{splitwindow}
diff -ru jed-B0.99-15/src/intrin.c jed-B0.99-15-dir/src/intrin.c
--- jed-B0.99-15/src/intrin.c	Wed Mar  6 17:42:49 2002
+++ jed-B0.99-15-dir/src/intrin.c	Wed Mar  6 17:41:14 2002
@@ -966,6 +966,7 @@
    MAKE_VARIABLE("SCREEN_WIDTH", &Jed_Num_Screen_Cols, INT_TYPE, 1),
    MAKE_VARIABLE("JED_ROOT", &Jed_Root_Dir_Ptr, STRING_TYPE, 1),
    MAKE_VARIABLE("LINENUMBERS", &User_Prefers_Line_Numbers, INT_TYPE, 0),
+   MAKE_VARIABLE("DIRECTORY_STATUS_LENGTH", &User_Directory_Status_Length,
INT_TYPE, 0),
    MAKE_VARIABLE("HIGHLIGHT", &Wants_Attributes, INT_TYPE, 0),
    MAKE_VARIABLE("HORIZONTAL_PAN", &Wants_HScroll, INT_TYPE, 0),
    MAKE_VARIABLE("WANT_SYNTAX_HIGHLIGHT", &Wants_Syntax_Highlight,
INT_TYPE, 0),
diff -ru jed-B0.99-15/src/screen.c jed-B0.99-15-dir/src/screen.c
--- jed-B0.99-15/src/screen.c	Fri Mar  8 10:20:18 2002
+++ jed-B0.99-15-dir/src/screen.c	Fri Mar  8 10:11:54 2002
@@ -63,6 +63,7 @@
 int Cursor_Motion;    /* indicates cursor movement only -1 ^ v +1 < > */
 int Jed_Dollar = '$';
 int User_Prefers_Line_Numbers = 0;
+int User_Directory_Status_Length = 20;
 int Mode_Has_Syntax_Highlight;
 int Wants_Syntax_Highlight = 1;	       /* if non-zero, highlight the
syntax.
 					*/
@@ -651,9 +652,9 @@
 {
    char *v, ch;
    Line *l;
-   int top, rows, narrows;
+   int top, rows, narrows, size;
    char buf [256];
-   char *str;
+   char *str, *p;
    
    v = CBuf->status_line;
    if (*v == 0) v = Default_Status_Line;
@@ -668,15 +669,32 @@
 	       break;
 	     SLsmg_write_nchars (&ch, 1);
 	  }
+
+	for (p = v; isdigit(*v); v++);
+	size = atoi(p);
 	
-	ch = *v++;
-	
-	switch (ch)
+	switch (*v)
 	  {
 	   case 'a':
 	     if (CBuf->flags & ABBREV_MODE) str = " abbrev"; else str =
NULL;
 	     break;
 	   case 'f': str = CBuf->file; break;
+	   case 'D':
+		if (User_Directory_Status_Length > 0) 
+		  {
+		     top = strlen(CBuf->dir) - User_Directory_Status_Length;
+		     if (top > 0) 
+		       {
+			  if (User_Directory_Status_Length >= 4) 
+			    {
+			       str = strcpy(buf, str + top);
+			       str[0] = str[1] = str[2] = '.';
+			    }
+		       } 
+		     else
+		       str = CBuf->dir; 
+		  }
+		break;
 	   case 'n':
 	     narrows = jed_count_narrows ();
 	     if (narrows)
@@ -747,12 +765,13 @@
 	     break;
 	     
 	   case '%': str = "%"; break;
-	   case 0:
-	     return;
-	     
-	   default:
+	   default:		
 	     str = NULL;
+		v = p; /* Ignore digits */
+		if (*v == '\0')
+		  return;
 	  }
+	v++;
 	if (str != NULL)
 	  SLsmg_write_string (str);
      }
diff -ru jed-B0.99-15/src/screen.h jed-B0.99-15-dir/src/screen.h
--- jed-B0.99-15/src/screen.h	Fri Jun  1 02:23:13 2001
+++ jed-B0.99-15-dir/src/screen.h	Wed Mar  6 17:43:13 2002
@@ -61,6 +61,7 @@
 extern void jed_fillmem(char *, char, int);
 extern int Goal_Column;
 extern int User_Prefers_Line_Numbers;
+extern int User_Directory_Status_Length;
 extern int Wants_Attributes;
 extern int Term_Supports_Color;
 extern int Wants_Syntax_Highlight;
--------


-------- Second:
--------
diff -ru jed-B0.99-15/doc/tm/rtl/window.tm
jed-B0.99-15-dir2/doc/tm/rtl/window.tm
--- jed-B0.99-15/doc/tm/rtl/window.tm	Fri Jun  1 02:23:13 2001
+++ jed-B0.99-15-dir2/doc/tm/rtl/window.tm	Fri Mar  8 12:54:27 2002
@@ -245,6 +245,9 @@
 #v+
         %b   buffer name
         %f   file name
+        %d   directory (you can specify a maximum directory length, e.g.
+             %20d would truncate the string to 20 characters, dropping the
+             first exceeding charaters).
         %v   JED version
         %t   current time --- only used if variable DISPLAY_TIME is
non-zero
         %p   line number or percent string. If LINENUMBERS is 2, this
diff -ru jed-B0.99-15/src/screen.c jed-B0.99-15-dir2/src/screen.c
--- jed-B0.99-15/src/screen.c	Fri Mar  8 10:20:18 2002
+++ jed-B0.99-15-dir2/src/screen.c	Fri Mar  8 10:21:06 2002
@@ -651,9 +651,9 @@
 {
    char *v, ch;
    Line *l;
-   int top, rows, narrows;
+   int top, rows, narrows, size;
    char buf [256];
-   char *str;
+   char *str, *p;
    
    v = CBuf->status_line;
    if (*v == 0) v = Default_Status_Line;
@@ -668,15 +668,29 @@
 	       break;
 	     SLsmg_write_nchars (&ch, 1);
 	  }
+
+	for (p = v; isdigit(*v); v++);
+	size = atoi(p);
 	
-	ch = *v++;
-	
-	switch (ch)
+	switch (*v)
 	  {
 	   case 'a':
 	     if (CBuf->flags & ABBREV_MODE) str = " abbrev"; else str =
NULL;
 	     break;
 	   case 'f': str = CBuf->file; break;
+	   case 'd':
+		str = CBuf->dir;
+		if (size > 0) 
+		  {
+		     top = strlen(CBuf->dir) - size;
+		     if (top > 0)
+		       {
+			  str = strcpy(buf, "...");
+			  if (size >= 4) 
+			    strcpy(&buf[3], CBuf->dir + top+3);
+		       }
+		  }
+		break;
 	   case 'n':
 	     narrows = jed_count_narrows ();
 	     if (narrows)
@@ -747,12 +761,13 @@
 	     break;
 	     
 	   case '%': str = "%"; break;
-	   case 0:
-	     return;
-	     
 	   default:
 	     str = NULL;
+		v = p;
+		if (*v == '\0')
+		  return;
 	  }
+	v++;
 	if (str != NULL)
 	  SLsmg_write_string (str);
      }
--------

Later,
					Dino
-- 
Don't worry over what other people are thinking about you. They're too busy
worrying over what you are thinking about them

--------------------------
To unsubscribe send email to <jed-users-request@xxxxxxxxxxx> with
the word "unsubscribe" in the message body.
Need help? Email <jed-users-owner@xxxxxxxxxxx>.


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