From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Carlos Pita Newsgroups: gmane.emacs.bugs Subject: bug#37826: Very annoying autoraise client/server behavior with -t option Date: Mon, 21 Oct 2019 15:40:13 -0300 Message-ID: References: <83tv84540m.fsf@gnu.org> <83v9si2y9u.fsf@gnu.org> <83a79u2oih.fsf@gnu.org> <83y2xe12ut.fsf@gnu.org> <83r23610oc.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="173222"; mail-complaints-to="usenet@blaine.gmane.org" Cc: Juanma Barranquero , 37826@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Oct 21 20:41:11 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iMccA-000ivD-RR for geb-bug-gnu-emacs@m.gmane.org; Mon, 21 Oct 2019 20:41:10 +0200 Original-Received: from localhost ([::1]:46766 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iMcc9-00057c-M3 for geb-bug-gnu-emacs@m.gmane.org; Mon, 21 Oct 2019 14:41:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55210) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iMcc3-00057U-V5 for bug-gnu-emacs@gnu.org; Mon, 21 Oct 2019 14:41:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iMcc2-0007cy-Rd for bug-gnu-emacs@gnu.org; Mon, 21 Oct 2019 14:41:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:49011) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iMcc2-0007ct-Of for bug-gnu-emacs@gnu.org; Mon, 21 Oct 2019 14:41:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iMcc1-0001qT-Qr for bug-gnu-emacs@gnu.org; Mon, 21 Oct 2019 14:41:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Carlos Pita Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 21 Oct 2019 18:41:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 37826 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 37826-submit@debbugs.gnu.org id=B37826.15716832327040 (code B ref 37826); Mon, 21 Oct 2019 18:41:01 +0000 Original-Received: (at 37826) by debbugs.gnu.org; 21 Oct 2019 18:40:32 +0000 Original-Received: from localhost ([127.0.0.1]:57831 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iMcbY-0001pT-7q for submit@debbugs.gnu.org; Mon, 21 Oct 2019 14:40:32 -0400 Original-Received: from mail-yw1-f46.google.com ([209.85.161.46]:35027) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iMcbW-0001pF-Ta for 37826@debbugs.gnu.org; Mon, 21 Oct 2019 14:40:31 -0400 Original-Received: by mail-yw1-f46.google.com with SMTP id r134so5274471ywg.2 for <37826@debbugs.gnu.org>; Mon, 21 Oct 2019 11:40:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=m0+yIqfw6VTmOIFpnEs8otB8SKGXJ70Y2iUXWRdJvlY=; b=W7W7CHoWddi1r6Jspzni/LSuDi+0x59SEpFRdmnDglP3Y3UZMOJl/HLb9ZmZH3dB03 oxx1pWYNuy0lh0oinSSIjVivp8QLRTVSFsIHPzm0s/OZUCb+EkTNpu4uIvrErNcqQNIW i+ddzeIYK3Ea9hneQo9EplReaW53rEQ8kGv19286BxGdpYQg79+8YRXcbh032AkHvJCb hB6RcsJfLtusoO9n8OPQvkIi/26vCv9N1HrxbA3CTSIb+kD5jNt1j5Rhz6VBrvKklTEY ryDxp8bp56Vl4drpQWB7RG0TdmdmXFWpTs5ViLkQMEIDABbgVQItkVK/toi++7T5m7mF adaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=m0+yIqfw6VTmOIFpnEs8otB8SKGXJ70Y2iUXWRdJvlY=; b=s6//TE4BlD0kn1VdpPhe+qYexfgEjs5xUE5OPDNf8f932IRSLoqEjVXA5b60nVcOn9 6ANXJ285SE+8nOmvQUELMar1BEI2bkWQuj6B1Wv8aHYFwFR1WRR1C/Pu0Qfi67TQ7X5Y X6LHRH8V5bfvGGbnEJ1+wflO36YI3egUhbIkZy0OZOviRreZxz9d4ONxpkRyg10mGrXG GCqac9LUwtPn4s7RoClW5ULalDJa7OAX+BcD8ZllPIAaSAa+bO6/zUKbK2veKs/GTHGh HjVolB+NfO6Qcchjiz6VZjWdl72BeqI+iVt/CgRCvudm+RX01i/yAn4C+XBojZXhie1v FTjg== X-Gm-Message-State: APjAAAUe3mCHuVUfc7lTOUwOpxObA0t3PXVE8ist3ODvuF+KUUf5+n7E IsooIS97Iw+atORFBcdT4jJtyLyA8HUwX72QESU= X-Google-Smtp-Source: APXvYqxO846vyinWlX+3LALzRaphOV8UwyhsTCCXWbiI9Z3YzJUL8Yvz1n3YPdQMZVG92Rq1woZjQS+npwXhuzFEyjU= X-Received: by 2002:a81:9a16:: with SMTP id r22mr197837ywg.277.1571683225168; Mon, 21 Oct 2019 11:40:25 -0700 (PDT) In-Reply-To: <83r23610oc.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: 209.51.188.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:169939 Archived-At: Here is some preliminary work. The patch suppresses messages from server-visit-files. Some remarks: 1. Perhaps I'd have preferred to advice only around find-file-noselect, but this would probably require using a global variable to pass delayed messages from server-visit-files to server-execute. Thus I wrapped the entire server-visit-files call and keep the messages local to server-execute. 2. Also I'd have liked that the mock message function returned the formatted message (since it's part of the interface) but there are some corner cases (nil, non-string, empty first parameter) that force me to replicate much of the actual implementation (Fmessage), which I dislike. 3. I'm dumping the delayed messages in an environment with `(or frame (selected-frame))` selected frame. The last `((not (null buffers))` guard in the case statement that comes after my change suggests that indeed `frame` might be nil, so I'm being careful and fallbacking to the selected frame in that case. Now, there might be no frame at all, but then I fail to see what else can be done. I'm rather open to change any of the above points. diff --git a/lisp/server.el b/lisp/server.el index 45fa55ad6b..5943a9ddca 100644 --- a/lisp/server.el +++ b/lisp/server.el @@ -1304,7 +1304,14 @@ server-execute ;; including code that needs to wait. (with-local-quit (condition-case err - (let* ((buffers (server-visit-files files proc nowait)) + (let* (;; Delay messages to avoid auto raising frame (Bug#37826). + (messages nil) + (delay (lambda (fun &rest args) (push args messages))) + (buffers (unwind-protect + (progn + (advice-add #'message :around delay) + (server-visit-files files proc nowait)) + (advice-remove #'message delay))) ;; If we were told only to open a new client, obey ;; `initial-buffer-choice' if it specifies a file ;; or a function. @@ -1325,6 +1332,10 @@ server-execute ;; Switch to initial buffer in case the frame was reused. (when initial-buffer (switch-to-buffer initial-buffer 'norecord)))))) + ;; Show all delayed messages in the new frame (if any). + (with-selected-frame (or frame (selected-frame)) + (dolist (args (nreverse messages)) + (apply #'message args))) (mapc #'funcall (nreverse commands))