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

From: Eli Zaretskii <[email-masked]>
Date: Sun, 27 Oct 2019 07:22:20 +0200

> From: Carlos Pita <[email-masked]>
> Date: Sat, 26 Oct 2019 17:27:02 -0300
> Cc: Juanma Barranquero <[email-masked]>, [email-masked]
> 
> Only if minibuffer-auto-rise is also nil:
> 
> (let* ((minibuffer-auto-raise (or server-raise-frame minibuffer-auto-raise))

Yes, but minibuffer-auto-raise is nil by default.

> Anyway, I want the frame to be raised when it's switched to, just not
> another frame and specially not because of barely relevant messages.

I understand.

So here's an idea.  Does the following change work for you in your
original scenario?

diff --git a/lisp/server.el b/lisp/server.el
index 45fa55a..b23fdc4 100644
--- a/lisp/server.el
+++ b/lisp/server.el
@@ -1405,7 +1405,9 @@ server-visit-files
 	  (if (null obuf)
 	      (progn
 		(run-hooks 'pre-command-hook)
-		(set-buffer (find-file-noselect filen)))
+		(set-buffer
+                 (let (minibuffer-auto-raise)
+                   (find-file-noselect filen))))
             (set-buffer obuf)
 	    ;; separately for each file, in sync with post-command hooks,
 	    ;; with the new buffer current:

If this works, then can you test this in several situations different
from yours, including:

  . invoking emacsclient without -t when there's a GUI client frame
    that is iconified
  . an existing client frame is visible (not iconified)
  . visiting a file that is already visited

and maybe others, and see if the message displayed by
shell-script-mode appears as expected, and causes the right frame to
be raised (if needed)?  (It might be that in some of these situations
we need to avoid binding minibuffer-auto-raise to nil, in which case
server-visit-files will need some additional logic or an additional
argument to discern between them.)

Thanks.