From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Mark Oteiza Newsgroups: gmane.emacs.bugs Subject: bug#28340: 26.0.50; xterm frame titles Date: Wed, 20 Sep 2017 08:23:51 -0400 Message-ID: <20170920122351.wx43g7m72xyxc37w@logos.localdomain> References: <87h8wjo44r.fsf@holos> <83mv6b2j4l.fsf@gnu.org> <20170912012122.GA11282@holos.localdomain> <83poalg6b5.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1505916842 14500 195.159.176.226 (20 Sep 2017 14:14:02 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 20 Sep 2017 14:14:02 +0000 (UTC) User-Agent: NeoMutt/20170912-13-728bb5 Cc: 28340@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Sep 20 16:13:51 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dufl8-0003CG-Im for geb-bug-gnu-emacs@m.gmane.org; Wed, 20 Sep 2017 16:13:51 +0200 Original-Received: from localhost ([::1]:48350 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1duflF-0002BD-OA for geb-bug-gnu-emacs@m.gmane.org; Wed, 20 Sep 2017 10:13:57 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38293) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1duf4a-0005Mu-9f for bug-gnu-emacs@gnu.org; Wed, 20 Sep 2017 09:29:55 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1duf4R-0005qZ-9P for bug-gnu-emacs@gnu.org; Wed, 20 Sep 2017 09:29:49 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:40493) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1duf4R-0005q9-4t for bug-gnu-emacs@gnu.org; Wed, 20 Sep 2017 09:29:43 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1due2r-0008DJ-K3 for bug-gnu-emacs@gnu.org; Wed, 20 Sep 2017 08:24:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Mark Oteiza Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 20 Sep 2017 12:24:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 28340 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 28340-submit@debbugs.gnu.org id=B28340.150591024031566 (code B ref 28340); Wed, 20 Sep 2017 12:24:01 +0000 Original-Received: (at 28340) by debbugs.gnu.org; 20 Sep 2017 12:24:00 +0000 Original-Received: from localhost ([127.0.0.1]:49139 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1due2q-0008D4-Gs for submit@debbugs.gnu.org; Wed, 20 Sep 2017 08:24:00 -0400 Original-Received: from mail-qk0-f182.google.com ([209.85.220.182]:56464) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1due2o-0008Cr-Sd for 28340@debbugs.gnu.org; Wed, 20 Sep 2017 08:23:59 -0400 Original-Received: by mail-qk0-f182.google.com with SMTP id u7so2450004qku.13 for <28340@debbugs.gnu.org>; Wed, 20 Sep 2017 05:23:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=udel-edu.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=j5vlZjddvTiICFw8x3UfpSe5srghT07N5+/VqUItumU=; b=OSbSpGK0pVWXzHilEX6wkcVy1mBCegJElELZ5z9uSg7ExbQ4ocFFSoPO4frN4V/Scb esDvpVEn7A9brpz4cPO9qVR8Gg5APwtgS7aINgzqlRqQeT9bTW2J1mwrEGTz14WM0XiK 6VB+kbLYbRkN2Pq++SMrVIgHaTMcTr2GqVQ8sVgjhHm6zvxveEqBFPNjb+TZr9lIX2eF DsllQ0szV3nnnGPDPW0y8nCpYLrYNasFafsQj2OgChKbOzzZ4FDXMOT5Ur6OsVFfREEd AYD6n/8oW4scAWqbMwE4fwOd9zF74rVOm4x/Rwx/7bBAfPE0bGGZS2iNZjsjmcdloszg gE4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=j5vlZjddvTiICFw8x3UfpSe5srghT07N5+/VqUItumU=; b=Yb4Z9X57Q/96FTLzLY0XS11jysaBdl1M0Pof9+bGYzd6X0h4NTN8JxxCIBAUJchYjG DVucnth2mUYLl3/VRbM6C7oHI3gTZJSD7+hA/YJIrOQd+5V4xHwaUASTCYKO1CWd9oNc YsStnUIT2YscZXwj1q30qUDzKossg/ppLdh3j8w3kbRWX9GePrrZ2NyD5O0zYrGVUxx7 QeR1ZhH28aHBss6Dw3vHm2BAySyrTYX3FSa4Qi/KjmMrZ3lfurtIanUfKZCwipAJLBsx f7XPKNgJttboGBQEHJa6p3DLiKafXDm//wXQ2FWYaAYid7vTu3NRp6VyNW1HzrOJl4IS mhlg== X-Gm-Message-State: AHPjjUjZMveX2Sub5ikTdSDpy+nE+X4OiyMOR9g+1B1QdI7w6bswO1RG jhl83JOoDYKeC3OIgZmqx8Wt/Q== X-Google-Smtp-Source: AOwi7QBbWHeTuN8956iiNwgcah6coYSVIXq/5+ejtTepCo9IFe3bj6s38E1eGUkCeLqynbYO18jNpg== X-Received: by 10.55.79.85 with SMTP id d82mr6478542qkb.5.1505910233217; Wed, 20 Sep 2017 05:23:53 -0700 (PDT) Original-Received: from logos.localdomain (pool-173-67-36-61.bltmmd.fios.verizon.net. [173.67.36.61]) by smtp.gmail.com with ESMTPSA id e18sm1227528qtc.59.2017.09.20.05.23.51 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Sep 2017 05:23:51 -0700 (PDT) Content-Disposition: inline In-Reply-To: <83poalg6b5.fsf@gnu.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:137166 Archived-At: On 20/09/17 at 07:47am, Eli Zaretskii wrote: > > Date: Mon, 11 Sep 2017 21:21:22 -0400 > > From: Mark Oteiza > > Cc: 28340@debbugs.gnu.org > > > > > Maybe one of the hooks provided by server.el would fit the bill? > > > > Nope, none of those appear relevant, and hooking into them does nothing > > apparent. Even doing the following, I get the title as the selected > > buffer in the previously selected frame. > > > > Messaging (frame-list) in xterm-test shows that the car of the list is > > always the new frame, but still the frame title is incorrect--a new > > frame created by emacsclient -t ends up on the scratch buffer. I say > > "ends up" because sometimes I see another buffer flash before I see the > > scratch buffer. This all seems a little buggy to me, but I know > > Bug#18137 and its ancestors were tough. > > What about window-configuration-change-hook, does that help? You > could set some flag in after-make-frame-functions, and then test and > reset that flag in window-configuration-change-hook, when you see that > a buffer is switched in the frame. Would that work? This appears to work, thank you. Please see attached. diff --git a/lisp/term/xterm.el b/lisp/term/xterm.el index 4f79703833..a11acbc4db 100644 --- a/lisp/term/xterm.el +++ b/lisp/term/xterm.el @@ -68,6 +68,11 @@ xterm-max-cut-length :version "25.1" :type 'integer) +(defcustom xterm-set-window-title t + "Whether Emacs should set window titles to an Emacs frame in an XTerm." + :version "27.1" + :type 'boolean) + (defconst xterm-paste-ending-sequence "\e[201~" "Characters send by the terminal to end a bracketed paste.") @@ -802,6 +807,8 @@ terminal-init-xterm (when (memq 'setSelection xterm-extra-capabilities) (xterm--init-activate-set-selection))) + (when xterm-set-window-title + (xterm--init-frame-title)) ;; Unconditionally enable bracketed paste mode: terminals that don't ;; support it just ignore the sequence. (xterm--init-bracketed-paste-mode) @@ -828,6 +835,31 @@ xterm--init-activate-set-selection "Terminal initialization for `gui-set-selection'." (set-terminal-parameter nil 'xterm--set-selection t)) +(defun xterm--init-frame-title () + "Terminal initialization for `gui-set-selection'." + (xterm-set-window-title) + (add-hook 'after-make-frame-functions 'xterm-set-window-title-flag) + (add-hook 'window-configuration-change-hook 'xterm-unset-window-title-flag) + (add-hook 'post-command-hook 'xterm-set-window-title) + (add-hook 'minibuffer-exit-hook 'xterm-set-window-title)) + +(defvar xterm-window-title-flag nil + "Whether the a new frame has been created, calling for a title update.") + +(defun xterm-set-window-title-flag (_frame) + (setq xterm-window-title-flag t)) + +(defun xterm-unset-window-title-flag () + (when xterm-window-title-flag + (setq xterm-window-title-flag nil) + (xterm-set-window-title))) + +(defun xterm-set-window-title (&optional terminal) + "Set the window title of the Xterm with the current Emacs frame." + (send-string-to-terminal + (format "\e]2;%s\a" (format-mode-line frame-title-format)) + terminal)) + (defun xterm--selection-char (type) (pcase type ('PRIMARY "p")