ratpoison-devel
[Top][All Lists]
Advanced

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

[RP] Patch to truncate window title


From: Emilio Lopes
Subject: [RP] Patch to truncate window title
Date: Wed Apr 24 03:48:05 2002
User-agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.5

This patch to version 1.1.0 makes possible to have the window titles
truncated to a certain number of characters specified by an argument
to the escape sequence %t.

Apply this patch, recompile and reinstall. Now do something like

        defwinfmt %n%s%-20t

to truncate the window titles to the last 20 chars.

Indeed you can now pass an argument to all of the escape sequences (it
was simpler to do so), but currently only %t uses it. It would be
straightforward to also have things like %a or %c truncated, but it
doesn't seem really necessary.

Be aware that C is not my mother-tongue, but the patch works for
me anyway.



2002-04-24  Emilio Lopes  <Emilio Lopes <address@hidden>>

        * list.c (format_window_name): escape sequences now accept an
                  argument. Use `trunc' to truncate the window title to
                  arg characters.
        (trunc): new function.

*** list.c.~2~  Mon Apr 22 17:06:26 2002
--- list.c      Mon Apr 22 20:08:40 2002
***************
*** 639,652 ****
                    struct sbuf *buffer)
  {
    int esc = 0;
    char dbuf[10];
  
    for(; *fmt; fmt++)
      {
        if (*fmt == '%' && !esc)
        {
          esc = 1;
!         continue;
        }
  
        if (esc)
--- 639,655 ----
                    struct sbuf *buffer)
  {
    int esc = 0;
+   int arg = 0;
    char dbuf[10];
+   char *tmpstr;
  
    for(; *fmt; fmt++)
      {
        if (*fmt == '%' && !esc)
        {
          esc = 1;
!         fmt++;
!         arg = (int)strtol(fmt, &fmt, 10);
        }
  
        if (esc)
***************
*** 668,674 ****
              break;
  
            case 't':
!             sbuf_concat (buffer, window_name (win));
              break;
  
            case 'a':
--- 671,687 ----
              break;
  
            case 't':
!             if (arg)
!                 {
!                   tmpstr = xmalloc (abs(arg) + 1);
!                   trunc (tmpstr, window_name (win), arg);
!                   sbuf_concat (buffer, tmpstr);
!                   free (tmpstr);
!               }
!             else
!                 {
!                   sbuf_concat (buffer, window_name (win));
!                 }
              break;
  
            case 'a':
***************
*** 765,769 ****
--- 778,804 ----
    if (!strcmp (sbuf_get (buffer), ""))
      {
        sbuf_copy (buffer, MESSAGE_NO_MANAGED_WINDOWS);
+     }
+ }
+ 
+ 
+ /* Copy SRC to DEST truncated to SIZE chars. If SIZE ist negative
+    start counting from the end of SRC. */
+ void trunc (char* dest, const char *src, int size)
+ {
+   if (abs (size) >= strlen (src))
+     {
+       strcpy(dest, src);
+       return;
+     }
+ 
+   if (size >= 0)
+     {
+       strncpy (dest, src, size);
+       dest[size] = '\0';
+     }
+   else if (size < 0)
+     {
+       strcpy(dest, src + strlen (src) + size);
      }
  }

*** list.h.~1~  Mon Apr 22 19:27:02 2002
--- list.h      Mon Apr 22 19:32:57 2002
***************
*** 38,43 ****
--- 38,44 ----
  void goto_window (rp_window *win);
  void set_current_window (rp_window *win);
  void update_window_gravity (rp_window *win);
+ void trunc (char* dest, const char *src, int size);
  char *window_name (rp_window *win);
  
  #if 0

*** ratpoison.texi.~1~  Wed Apr 24 12:14:28 2002
--- ratpoison.texi      Wed Apr 24 12:15:11 2002
***************
*** 457,463 ****
  @item %s
  Window status (current window, last window, etc)
  @item %t
! Window Name
  @item %a
  Application Name
  @item %c
--- 457,467 ----
  @item %s
  Window status (current window, last window, etc)
  @item %t
! Window Name. If an integer follows the `%', it specifies the number of
! characters of the window name to show; zero means the whole name. A
! negative integer means start counting characters from the end of the
! window name, i.e. %-20t specifies the last 20 characters of the window
! name.
  @item %a
  Application Name
  @item %c

*** ratpoison.1.~1~     Wed Apr 24 11:55:15 2002
--- ratpoison.1 Wed Apr 24 12:13:47 2002
***************
*** 234,240 ****
  Window status (current window, last window, etc)
  
  `%t'
! Window Name
  
  `%a'
  Application Name
--- 234,244 ----
  Window status (current window, last window, etc)
  
  `%t'
! Window Name. If an integer follows the `%', it specifies the number of
! characters of the window name to show; zero means the whole name. A
! negative integer means start counting characters from the end of the
! window name, i.e. %-20t specifies the last 20 characters of the window
! name.
  
  `%a'
  Application Name



reply via email to

[Prev in Thread] Current Thread [Next in Thread]