emacs-devel
[Top][All Lists]
Advanced

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

Re: suggested feature -- console-mode frame title sets Xterm title


From: Martin Pool
Subject: Re: suggested feature -- console-mode frame title sets Xterm title
Date: Mon, 29 Sep 2003 15:17:30 +1000
User-agent: Mutt/1.5.4i

On 26 Sep 2003, Richard Stallman <address@hidden> wrote:
> Your patch looks good, except that there is no way to turn it on and
> off.  Can you make xterm_title_start and xterm_title_end into Lisp
> variables, and enable this feature if their values are strings?

After a bit more study, I think that a better way to do this is to get
the values from termcap for the terminal's status line.  This new
patch does so.

On systems which are using Eric Raymond's termcap distribution the
xterm title line is not represented as a status line.  (I don't really
understand why, since the absence just encourages programs to hardcode
escape sequences as I originally did.)  So on Debian, to make this
patch do anything, you have to set for example TERM=xterm+sl before
running emacs.  This ought to be explained in the NEWS file if this
feature is accepted.

Perhaps this patch ought to add Lisp variables to set the escape
codes, but there is already a (slightly obscure) way to set them
through the termcap file or $TERMCAP.  I think it would be better to
do that, and hope people fix their termcaps, rather than putting in a
redundant mechanism.  If people disagree I can add the variables.

Incidentally, there is a bit of duplicated code in the implementations
of x_explicitly_set_name and x_set_name for different window systems.
It might be good to factor that out to a higher level, and then
perhaps just make the actual work of setting the title go through a
window system specific hook.

This patch causes trouble with mode-line-frame-identification: the
whole title is displayed on the modeline and it takes up a lot of
space.  Normally terminal frames have a little "F%d" identifier,
which is set into f->name by make_terminal_frame().  

The problem is that the usage of the f->name field is a bit
inconsistent between window system and termcap frames.  On termcap
frames it really is the name of the frame, and usually something brief
like 'F0'.  But x_set_name and x_consider_frame_title expect it to be
the title of the frame, as produced from the frame-title-format.

I'm not sure of the best way to resolve this, but resolving it might
remove the kludge of clearing mode-line-frame-identification on
non-termcap frames.

I renamed x_consider_frame_title because it is no longer X-specific.




diff -rud emacs-21.3/src/dispextern.h emacs-21.3-title/src/dispextern.h
--- emacs-21.3/src/dispextern.h 2002-11-15 00:15:46.000000000 +1100
+++ emacs-21.3-title/src/dispextern.h   2003-09-29 13:02:51.000000000 +1000
@@ -2365,6 +2365,7 @@
 /* Defined in term.c */
 
 extern void ring_bell P_ ((void));
+extern void terminal_set_frame_title P_ ((char *, int));
 extern void set_terminal_modes P_ ((void));
 extern void reset_terminal_modes P_ ((void));
 extern void update_begin P_ ((struct frame *));
diff -rud emacs-21.3/src/term.c emacs-21.3-title/src/term.c
--- emacs-21.3/src/term.c       2001-05-31 18:56:32.000000000 +1000
+++ emacs-21.3-title/src/term.c 2003-09-29 13:51:44.000000000 +1000
@@ -285,6 +285,9 @@
 char *TS_set_window;           /* "wi" (4 params, start and end of window,
                                   each as vpos and hpos) */
 
+char *TS_to_status;             /* "ts", go to status line */
+char *TS_from_status;           /* "fs", go back from status line */
+
 /* Value of the "NC" (no_color_video) capability, or 0 if not
    present.  */
 
@@ -369,9 +372,13 @@
                           TN_standout_width == 0, it means don't bother
                           to write any end-standout cookies.  */
 
+int TF_status;              /* termcap hs flag: has a status line
+                               (title for xterms) */
+
 int TN_standout_width; /* termcap sg number: width occupied by standout
                           markers */
 
+
 static int RPov;       /* # chars to start a TS_repeat */
 
 static int delete_in_insert_mode;      /* delete mode == insert mode */
@@ -472,6 +479,22 @@
 }
 
 void
+terminal_set_frame_title (line, len)
+     char *line;
+     int len;
+{
+  if (!TF_status || !TS_to_status || !TS_from_status)
+    return;                     /* no status line */
+
+  /* XXX: Are there any terminals where we need to explicitly clear
+     the status line after jumping to it? */
+
+  OUTPUT1 (TS_to_status);
+  fwrite (line, 1, len, stdout);
+  OUTPUT1 (TS_from_status);
+}
+
+void
 set_terminal_modes ()
 {
   if (FRAME_TERMCAP_P (XFRAME (selected_frame)))
@@ -2334,6 +2357,9 @@
   TS_cursor_visible = tgetstr ("vs", address);
   TS_cursor_invisible = tgetstr ("vi", address);
   TS_set_window = tgetstr ("wi", address);
+  TS_to_status = tgetstr ("ts", address);
+  TS_from_status = tgetstr ("fs", address);
+  TF_status = tgetflag ("hs");
   
   TS_enter_underline_mode = tgetstr ("us", address);
   TS_exit_underline_mode = tgetstr ("ue", address);
diff -rud emacs-21.3/src/xdisp.c emacs-21.3-title/src/xdisp.c
--- emacs-21.3/src/xdisp.c      2003-01-18 00:45:13.000000000 +1100
+++ emacs-21.3-title/src/xdisp.c        2003-09-29 14:50:09.000000000 +1000
@@ -523,6 +523,11 @@
 
 int cursor_in_non_selected_windows;
 
+/* Non-nil means to try to show frame titles on tty frames.  Whether
+   we can actually do so depends on whether the termcap definition has
+   hardstatus capabilities. */
+Lisp_Object Vtty_frame_title_on_status;
+
 /* A scratch glyph row with contents used for generating truncation
    glyphs.  Also used in direct_output_for_insert.  */
 
@@ -688,7 +693,7 @@
 static int text_outside_line_unchanged_p P_ ((struct window *, int, int));
 static void store_frame_title_char P_ ((char));
 static int store_frame_title P_ ((unsigned char *, int, int));
-static void x_consider_frame_title P_ ((Lisp_Object));
+static void consider_frame_title P_ ((Lisp_Object));
 static void handle_stop P_ ((struct it *));
 static int tool_bar_lines_needed P_ ((struct frame *));
 static int single_display_prop_intangible_p P_ ((Lisp_Object));
@@ -7142,7 +7147,6 @@
  ***********************************************************************/
 
 
-#ifdef HAVE_WINDOW_SYSTEM
 
 /* A buffer for constructing frame titles in it; allocated from the
    heap in init_xdisp and resized as needed in store_frame_title_char.  */
@@ -7211,17 +7215,19 @@
 }
 
 
+
 /* Set the title of FRAME, if it has changed.  The title format is
    Vicon_title_format if FRAME is iconified, otherwise it is
    frame_title_format.  */
 
 static void
-x_consider_frame_title (frame)
+consider_frame_title (frame)
      Lisp_Object frame;
 {
   struct frame *f = XFRAME (frame);
 
   if (FRAME_WINDOW_P (f)
+      || FRAME_TERMCAP_P (f)
       || FRAME_MINIBUF_ONLY_P (f)
       || f->explicit_name)
     {
@@ -7266,18 +7272,31 @@
         display_mode_element, then we might need to optimize at a
         higher level than this.)  */
       if (! STRINGP (f->name) 
-         || STRING_BYTES (XSTRING (f->name)) != len
-         || bcmp (frame_title_buf, XSTRING (f->name)->data, len) != 0)
-       x_implicitly_set_name (f, make_string (frame_title_buf, len), Qnil);
+          || STRING_BYTES (XSTRING (f->name)) != len
+          || bcmp (frame_title_buf, XSTRING (f->name)->data, len) != 0)
+        {
+#ifdef HAVE_WINDOW_SYSTEM
+          /* Even if we're compiled with a window system, we might not be
+             using it for this frame... */
+          /* TODO: There is some common logic across all terminal
+             types that could be factored out of
+             x_implicitly_set_name() */
+          if (FRAME_WINDOW_P (f))
+            x_implicitly_set_name (f, make_string (frame_title_buf, len), 
Qnil);
+#endif
+          if (FRAME_TERMCAP_P (f)
+              && !NILP (Vtty_frame_title_on_status))
+            {
+              terminal_set_frame_title (frame_title_buf, len);
+              f->name =  make_string (frame_title_buf, len);
+            }
+
+          /* There are other possibilities, e.g. a nongraphical window
+             on Windows NT.  We don't handle that at the moment. */
+        }
     }
 }
 
-#else /* not HAVE_WINDOW_SYSTEM */
-
-#define frame_title_ptr ((char *)0)
-#define store_frame_title(str, mincol, maxcol) 0
-
-#endif /* not HAVE_WINDOW_SYSTEM */
 
 
 
@@ -7307,7 +7326,6 @@
   /* Update all frame titles based on their buffer names, etc.  We do
      this before the menu bars so that the buffer-menu will show the
      up-to-date frame titles.  */
-#ifdef HAVE_WINDOW_SYSTEM
   if (windows_or_buffers_changed || update_mode_lines)
     {
       Lisp_Object tail, frame;
@@ -7317,10 +7335,9 @@
          f = XFRAME (frame);
          if (!EQ (frame, tooltip_frame)
              && (FRAME_VISIBLE_P (f) || FRAME_ICONIFIED_P (f)))
-           x_consider_frame_title (frame);
+           consider_frame_title (frame);
        }
     }
-#endif /* HAVE_WINDOW_SYSTEM */
 
   /* Update the menu bar item lists, if appropriate.  This has to be
      done before any actual redisplay or generation of display lines.  */
@@ -14955,6 +14972,14 @@
                                                               Qnil)))),
                           Qnil)));
 
+  DEFVAR_BOOL ("tty-frame-title-on-status", &Vtty_frame_title_on_status,
+"Non-nil means that the title of a text terminal frame is shown in the\n\
+terminal's \"hard status\" line or a terminal emulator's title bar, if\n\
+the terminal has that capability.\n\
+The terminal must have the \"hs\", \"ts\" and \"fs\" termcap capabilies\n\
+for this to work.");
+  Vtty_frame_title_on_status = Qt;
+
   DEFVAR_LISP ("message-log-max", &Vmessage_log_max,
     "Maximum number of lines to keep in the message log buffer.\n\
 If nil, disable message logging.  If t, log messages but don't truncate\n\
@@ -15120,7 +15145,6 @@
        default_invis_vector[i] = make_number ('.');
     }
 
-#ifdef HAVE_WINDOW_SYSTEM
   {
     /* Allocate the buffer for frame titles.  */
     int size = 100;
@@ -15128,7 +15152,6 @@
     frame_title_buf_end = frame_title_buf + size;
     frame_title_ptr = NULL;
   }
-#endif /* HAVE_WINDOW_SYSTEM */
   
   help_echo_showing_p = 0;
 }



-- 
Martin 

Attachment: pgp9VN7mP0vV_.pgp
Description: PGP signature


reply via email to

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