From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Martin Pool Newsgroups: gmane.emacs.devel Subject: Re: suggested feature -- console-mode frame title sets Xterm title Date: Thu, 2 Oct 2003 16:34:00 +1000 Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <20031002063338.GA25969@vexed.ozlabs.hp.com> References: <87r8j9n6v4.fsf@blarg.net> <200206152147.g5FLlUB10968@aztec.santafe.edu> <20030929051617.GB7359@vexed.ozlabs.hp.com> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1065076991 5206 80.91.224.253 (2 Oct 2003 06:43:11 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 2 Oct 2003 06:43:11 +0000 (UTC) Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Thu Oct 02 08:43:09 2003 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1A4xB7-00018m-00 for ; Thu, 02 Oct 2003 08:43:09 +0200 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1A4xB6-0005HU-00 for ; Thu, 02 Oct 2003 08:43:08 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1A4x5N-0000hA-AY for emacs-devel@quimby.gnus.org; Thu, 02 Oct 2003 02:37:13 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.24) id 1A4x44-0007t9-Ap for emacs-devel@gnu.org; Thu, 02 Oct 2003 02:35:52 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.24) id 1A4x3X-0007S6-36 for emacs-devel@gnu.org; Thu, 02 Oct 2003 02:35:50 -0400 Original-Received: from [192.6.86.111] (helo=sngrel7.hp.com) by monty-python.gnu.org with esmtp (Exim 4.24) id 1A4x3V-0007QX-Qa for emacs-devel@gnu.org; Thu, 02 Oct 2003 02:35:18 -0400 Original-Received: from XAUBRG2.AUS.HP.COM (xaubrg2.aus.hp.com [15.23.69.43]) by sngrel7.hp.com (Postfix) with SMTP id 2BE12147 for ; Thu, 2 Oct 2003 14:35:13 +0800 (SGP) Original-Received: from 15.23.69.43 by XAUBRG2.AUS.HP.COM (InterScan E-Mail VirusWall NT); Thu, 02 Oct 2003 16:35:12 +1000 Original-Received: from XAUBRG2.AUS.HP.COM (localhost [127.0.0.1]) by XAUBRG2.AUS.HP.COM with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2656.59) id TTGLNWVP; Thu, 2 Oct 2003 16:35:12 +1000 Original-Received: from 16.176.65.141 by XAUBRG2.AUS.HP.COM (InterScan E-Mail VirusWall NT); Thu, 02 Oct 2003 16:35:11 +1000 Original-Received: from mbp by vexed with local (Exim 3.36 #1 (Debian)) id 1A4x2G-0000Ah-00 for ; Thu, 02 Oct 2003 16:34:00 +1000 Original-To: emacs-devel@gnu.org Content-Disposition: inline In-Reply-To: X-GPG: 1024D/A0B3E88B: AFAC578F 1841EE6B FD95E143 3C63CA3F A0B3E88B User-Agent: Mutt/1.5.4i X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:16853 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:16853 On 1 Oct 2003, Richard Stallman wrote: > 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 we should have both interfaces. It is good to look in the > termcap entry, but xterm is important and we can't expect its termcap > entry to be fixed soon. So we should create a mechanism that > lisp/term/xterm.el can use to supply the correct information. > > Can you do that? Here's a new patch. I have set tty-frame-use-title on by default, because it won't do anything unless we're on a terminal where it can work. This works well in xterms and under GNU screen. It's quite nice to see the title update as you flip between buffers or screens. Before this can be committed we need a term/screen.el as well. I think the only remaining problem is that this has changed the way select-buffer-by-name works. For multi-frame text terminals the names used to be F%d, but now they're "full" names, probably including the name of the buffer. This is inconsistent with how it was documented to work in the 21.3 manual, but on the other hand it is consistent with how this function works on windowing system frames. I'm not sure how to resolve this. To avoid messing up the modeline I have disabled the %F character when tty-frame-use-title is set. This is perhaps a bit ugly but I think a proper resolution would require something like adding a 'short name' for the frame as distinct from its title. diff -dru emacs-21.3/lisp/cus-start.el emacs-21.3-title/lisp/cus-start.el --- emacs-21.3/lisp/cus-start.el 2001-10-29 03:24:54.000000000 +1100 +++ emacs-21.3-title/lisp/cus-start.el 2003-10-02 16:16:15.000000000 +1000 @@ -244,6 +244,9 @@ (choice integer (const :tag "No limit" nil))) (highlight-nonselected-windows display boolean) + (tty-frame-use-title display boolean) + (tty-frame-title-start display string) + (tty-frame-title-end display end) (message-log-max debug (choice (const :tag "Disable" nil) (integer :menu-tag "lines" :format "%v") diff -dru emacs-21.3/lisp/term/xterm.el emacs-21.3-title/lisp/term/xterm.el --- emacs-21.3/lisp/term/xterm.el 2001-07-16 21:39:42.000000000 +1000 +++ emacs-21.3-title/lisp/term/xterm.el 2003-10-02 16:24:37.000000000 +1000 @@ -48,4 +48,7 @@ (define-key function-key-map "\e[24~" [f12]) (define-key function-key-map "\e[29~" [print]) +(set-variable 'tty-frame-title-start "\e]2;") +(set-variable 'tty-frame-title-end "\007") + ;;; xterm.el ends here diff -dru 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-10-02 16:02:18.000000000 +1000 @@ -2224,6 +2224,9 @@ extern int current_mode_line_height, current_header_line_height; extern int cursor_in_non_selected_windows; +extern int tty_frame_use_title; +extern Lisp_Object Vtty_frame_title_start, Vtty_frame_title_end; + /* Defined in sysdep.c */ void get_frame_size P_ ((int *, int *)); @@ -2365,6 +2368,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 -dru 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-10-02 11:56:47.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,30 @@ } void +terminal_set_frame_title (line, len) + char *line; + int len; +{ + /* XXX: Are there any terminals where we need to explicitly clear + the status line after jumping to it? */ + + if (!NILP (Vtty_frame_title_start) + && !NILP (Vtty_frame_title_end)) + { + fputs (XSTRING (Vtty_frame_title_start)->data, stdout); + fwrite (line, 1, len, stdout); + fputs (XSTRING (Vtty_frame_title_end)->data, stdout); + } + else if (TF_status && TS_to_status && TS_from_status) + { + /* defined by termcap */ + 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 +2365,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 -dru 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-10-02 16:24:52.000000000 +1000 @@ -1,5 +1,5 @@ /* Display generation from window structure and buffer text. - Copyright (C) 1985, 86, 87, 88, 93, 94, 95, 97, 98, 99, 2000, 2001, 2002 + Copyright (C) 1985, 86, 87, 88, 93, 94, 95, 97, 98, 99, 2000, 01, 02, 03 Free Software Foundation, Inc. This file is part of GNU Emacs. @@ -296,6 +296,13 @@ static int message_log_need_newline; +/* 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. */ +int tty_frame_use_title; + +Lisp_Object Vtty_frame_title_start, Vtty_frame_title_end; + /* The buffer position of the first character appearing entirely or partially on the line of the selected window which contains the @@ -688,7 +695,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 +7149,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 +7217,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) && tty_frame_use_title) || FRAME_MINIBUF_ONLY_P (f) || f->explicit_name) { @@ -7260,24 +7268,41 @@ frame_title_ptr = NULL; set_buffer_internal (obuf); +#ifdef HAVE_WINDOW_SYSTEM + /* Even if we're compiled with a window system, we might not be + using it for this frame... */ + /* Set the title only if it's changed. This avoids consing in the common case where it hasn't. (If it turns out that we've already wasted too much time by walking through the list with 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); - } -} + if (FRAME_WINDOW_P (f)) + if (! STRINGP (f->name) + || STRING_BYTES (XSTRING (f->name)) != len + || bcmp (frame_title_buf, XSTRING (f->name)->data, len) != 0) + { + /* TODO: There is some common logic across all terminal + types that could be factored out of + x_implicitly_set_name() */ + x_implicitly_set_name (f, make_string (frame_title_buf, len), Qnil); + } +#endif -#else /* not HAVE_WINDOW_SYSTEM */ + /* For termcap windows, we always reset the title when we + reconsider it, because this may not have been the + previously-visible frame. */ + if (FRAME_TERMCAP_P (f) && f == SELECTED_FRAME ()) + { + terminal_set_frame_title (frame_title_buf, len); + f->name = make_string (frame_title_buf, len); + } -#define frame_title_ptr ((char *)0) -#define store_frame_title(str, mincol, maxcol) 0 + /* There are other possibilities, e.g. a nongraphical window + on Windows NT. We don't handle that at the moment. */ + } +} -#endif /* not HAVE_WINDOW_SYSTEM */ @@ -7307,7 +7332,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 +7341,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. */ @@ -14068,6 +14091,8 @@ /* %F displays the frame name. */ if (!NILP (f->title)) return (char *) XSTRING (f->title)->data; + if (FRAME_TERMCAP_P (f) && tty_frame_use_title) + return ""; if (f->explicit_name || ! FRAME_WINDOW_P (f)) return (char *) XSTRING (f->name)->data; return "Emacs"; @@ -14955,6 +14980,27 @@ Qnil)))), Qnil))); + DEFVAR_BOOL ("tty-frame-use-title", &tty_frame_use_title, +"*Show frame titles in the title or status line of text terminals.\n\ +The title is set if this variable is non-nil and if either \n\ +`tty-frame-title-start' and `tty-frame-title-end' are set, or if the \n\ +terminal has the `ts' and `fs' termcap capabilities."); + tty_frame_use_title = 1; + + DEFVAR_LISP ("tty-frame-title-start", &Vtty_frame_title_start, +"Start of the escape sequence to set a text terminal's title bar.\n\ +This value is only used if `tty-frame-use-title' is non-nil.\n\ +The default value is suitable for xterms, GNU Screen, and many other\n\ +modern terminal emulators."); + Vtty_frame_title_start = Qnil; + + DEFVAR_LISP ("tty-frame-title-end", &Vtty_frame_title_end, +"End of the escape sequence to set a text terminal's title bar.\n\ +This value is only used if `tty-frame-use-title' is non-nil.\n\ +The default value is suitable for xterms, GNU Screen, and many other\n\ +modern terminal emulators."); + Vtty_frame_title_end = Qnil; + 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 +15166,6 @@ default_invis_vector[i] = make_number ('.'); } -#ifdef HAVE_WINDOW_SYSTEM { /* Allocate the buffer for frame titles. */ int size = 100; @@ -15128,7 +15173,6 @@ frame_title_buf_end = frame_title_buf + size; frame_title_ptr = NULL; } -#endif /* HAVE_WINDOW_SYSTEM */ help_echo_showing_p = 0; } -- Martin