Subject: bug#25521: 26.0.50; After (make-frame '((name . "foo"))) (select-frame-by-name "foo") doesn't see the frame

From: [email-masked]
Date: Fri, 01 Sep 2017 09:41:12 -0400

martin rudalics <[email-masked]> writes:

> I'm not very convinced.  First, the present bug should not motivate this
> change.  ‘select-frame-by-name’ is a pretty obscure function.  It fails
> in the OP's case because the display info for the new frame has not been
> yet set up.  In the interactive call, suggesting a default frame on the
> current terminal makes sense; so consulting that info is useful.  But
> the info is useless in a non-interactive call: Nothing should prevent
> that function from selecting a frame with a given name on any display.

Ah, so we could just do something like this? (untested)

>From c31a39c300e32af1f9b810e92065208eb1b5c2f3 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <[email-masked]>
Date: Fri, 1 Sep 2017 09:38:55 -0400
Subject: [PATCH v2] Let select-frame-by-name choose any frame when called from
 lisp (Bug#25521)

* lisp/frame.el (select-frame-by-name): Choose from the whole list of
frames in the non-interactive part.
---
 lisp/frame.el | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/lisp/frame.el b/lisp/frame.el
index 2a14302e9f..e8b7c82cbb 100644
--- a/lisp/frame.el
+++ b/lisp/frame.el
@@ -905,11 +905,12 @@ select-frame-by-name
      (if (= (length input) 0)
 	 (list default)
        (list input))))
-  (let* ((frame-names-alist (make-frame-names-alist))
-	 (frame (cdr (assoc name frame-names-alist))))
-    (if frame
-	(select-frame-set-input-focus frame)
-      (error "There is no frame named `%s'" name))))
+  (catch 'done
+    (dolist (frame (frame-list))
+      (when (equal (frame-parameter frame 'name) name)
+        (select-frame-set-input-focus frame)
+        (throw 'done t)))
+    (error "There is no frame named `%s'" name)))
 
 
 ;;;; Background mode.
-- 
2.14.1