Subject: bug#37826: Very annoying autoraise client/server behavior with -t option

From: Carlos Pita <[email-masked]>
Date: Mon, 21 Oct 2019 05:58:13 -0300

> We prefer to avoid both unpleasant effects.  But if there's no way to
> solve both, I think we prefer the former, because visiting a file in a
> way that causes an echo-area message is relatively rare.

Here is a patch that narrows the scope of minibuffer-auto-raise to
write/revert actions that require user intervention.

Short of a more selective auto-raise mechanism, I believe this is
preferable to raising and focusing a frame when creating a new one
just because of random uninteresting messages.

Moreover, if the user has explicitly set minibuffer-auto-raise, the
scope won't be narrowed at all. So I think it's safe to reduce its
scope a bit when the user has not even signalled interest by toggling
minibuffer-auto-raise to t.
From 0a80b3c71ac52829bc89036f070f1fb5632ea889 Mon Sep 17 00:00:00 2001
From: memeplex <[email-masked]>
Date: Mon, 21 Oct 2019 05:12:48 -0300
Subject: [PATCH] Avoid autoraising frame when tty client is run (Bug#37826)

* lisp/server.el (server-visit-files): Narrow scope of minibuffer-auto-rise.
---
 lisp/server.el | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/lisp/server.el b/lisp/server.el
index 45fa55ad6b..46c76895e9 100644
--- a/lisp/server.el
+++ b/lisp/server.el
@@ -1397,9 +1397,7 @@ server-visit-files
 	;; If there is an existing buffer modified or the file is
 	;; modified, revert it.  If there is an existing buffer with
 	;; deleted file, offer to write it.
-	(let* ((minibuffer-auto-raise (or server-raise-frame
-					  minibuffer-auto-raise))
-	       (filen (car file))
+	(let* ((filen (car file))
 	       (obuf (get-file-buffer filen)))
 	  (add-to-history 'file-name-history filen)
 	  (if (null obuf)
@@ -1410,14 +1408,16 @@ server-visit-files
 	    ;; separately for each file, in sync with post-command hooks,
 	    ;; with the new buffer current:
 	    (run-hooks 'pre-command-hook)
-            (cond ((file-exists-p filen)
-                   (when (not (verify-visited-file-modtime obuf))
-                     (revert-buffer t nil)))
-                  (t
-                   (when (y-or-n-p
-                          (concat "File no longer exists: " filen
-                                  ", write buffer to file? "))
-                     (write-file filen))))
+	    (let ((minibuffer-auto-raise (or server-raise-frame
+					     minibuffer-auto-raise)))
+              (cond ((file-exists-p filen)
+                     (when (not (verify-visited-file-modtime obuf))
+                       (revert-buffer t nil)))
+                    (t
+                     (when (y-or-n-p
+                            (concat "File no longer exists: " filen
+                                    ", write buffer to file? "))
+                       (write-file filen)))))
             (unless server-buffer-clients
               (setq server-existing-buffer t)))
           (server-goto-line-column (cdr file))
-- 
2.20.1