unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#11033: emacsclient: create a new frame only if one doesn't exist
@ 2012-03-16 23:18 Eddie Hillenbrand
  2021-06-08 13:36 ` bug#11033: (no subject) Peter Oliver
  2021-06-08 13:43 ` Peter Oliver
  0 siblings, 2 replies; 6+ messages in thread
From: Eddie Hillenbrand @ 2012-03-16 23:18 UTC (permalink / raw)
  To: 11033

I'm using emacsclient with emacs --daemon, but I find myself wanting a
different behavior than the standard options provide.

It would be nice if emacsclient could create a window system frame
only when one doesn't exist and if one does exist simply reuse that
frame.

I know I can get this behavior by initially invoking emacsclient with
-c and then subsequently invoking it without the -c, however I'd
prefer not to think about whether I need to include the -c when
opening files.

server-window was suggested as a possible way to get this
behavior. After inspection of lisp/server.el and trying a few test
cases I found that the server-window variable is not inspected until
after frames are created, thus the best I could do with server-window
is destroy the newly created frame which would be clunky IMHO.

Additionally, lisp/server.el is now lexically scoped (it wasn't in
Emacs 23) so server-window can't access tty-name to check if the
client is requesting a window system frame or a tty frame. The
variable is also not inspected when a file argument is not
provided. But I digress.

As an example:

$ Emacs.app/Contents/MacOS/Emacs -Q --daemon
$ Emacs.app/Contents/MacOS/bin/emacsclient -c -n
Insert and evaluate the following in the scratch buffer:
(setq server-window
      (lambda (next-buffer)
      	(message "SERVER-WINDOW")))
$ Emacs.app/Contents/MacOS/bin/emacsclient -c -n ~/a.txt
Prints the following in *Messages*:
When done with this frame, type C-x 5 0
SERVER-WINDOW

That demonstrates that the frame is created before server-window is
called. So server-window can't be made to provide the desired
behavior.

It is possible to use emacsclient's --eval option to provide this
behavior, but it is extremely ugly. Plus it occurred to me that this
behavior may be general enough to include in emacsclient as a standard
option and would be much cleaner.

I'm proposing adding a -C option to emacsclient that would "create a
new frame if one doesn't exist otherwise use the current Emacs frame."
I'd be happy to make the required changes and submit a patch.

Thanks,

Eddie


In GNU Emacs 24.0.94.1 (x86_64-apple-darwin11.3.0, NS apple-appkit-1138.32)
 of 2012-03-16 on lore.local
Windowing system distributor `Apple', version 10.3.1138
Configured using:
 `configure '--with-ns''






^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#11033: (no subject)
  2012-03-16 23:18 bug#11033: emacsclient: create a new frame only if one doesn't exist Eddie Hillenbrand
@ 2021-06-08 13:36 ` Peter Oliver
  2021-06-08 13:43 ` Peter Oliver
  1 sibling, 0 replies; 6+ messages in thread
From: Peter Oliver @ 2021-06-08 13:36 UTC (permalink / raw)
  To: 11033

The reporter suggests adding a new option to emacsclient to achieve their preferred behaviour.  However, the current behaviour, when emacs is run as a daemon, has no current frames, and emacsclient is not run on a TTY, is for the file to be opened in the daemon but not displayed to the user.  I find it hard to see why anyone would want that, so think that the suggested behaviour should be the default in that case.

-- 
Peter Oliver





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#11033: (no subject)
  2012-03-16 23:18 bug#11033: emacsclient: create a new frame only if one doesn't exist Eddie Hillenbrand
  2021-06-08 13:36 ` bug#11033: (no subject) Peter Oliver
@ 2021-06-08 13:43 ` Peter Oliver
  2021-06-09  9:32   ` bug#11033: emacsclient: create a new frame only if one doesn't exist Lars Ingebrigtsen
  1 sibling, 1 reply; 6+ messages in thread
From: Peter Oliver @ 2021-06-08 13:43 UTC (permalink / raw)
  To: 11033

[-- Attachment #1: Type: text/plain, Size: 478 bytes --]

Attached is a patch which causes emacs to try to create a new GUI frame if there are no existing frames and the current TTY is unusable.

This only works if emacsclient tells us which display to use, and currently it only does that if --display=… is specified.  This is fine for my purposes, but we might want to look at having it pass along $DISPLAY in more situations.

I have submitted copyright assignment paperwork but am currently waiting to hear back.

-- 
Peter Oliver

[-- Attachment #2: Type: text/plain, Size: 1418 bytes --]

From 9b13571d0da02344a6fbb0a875ff0f88b9c65b18 Mon Sep 17 00:00:00 2001
From: Peter Oliver <git@mavit.org.uk>
Date: Tue, 8 Jun 2021 14:31:00 +0100
Subject: [PATCH] =?UTF-8?q?If=20the=20daemon=E2=80=99s=20TTY=20is=20our=20?=
 =?UTF-8?q?only=20frame,=20create=20a=20new=20frame?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* server.el (server-process-filter): If there won't be a current frame
to use, fall back to trying to create a new one.
---
 lisp/server.el | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/lisp/server.el b/lisp/server.el
index 3205ba182e..ac5db197f3 100644
--- a/lisp/server.el
+++ b/lisp/server.el
@@ -1308,7 +1308,17 @@ server-process-filter
 						       frame-parameters))
 		   ;; When resuming on a tty, tty-name is nil.
 		   (tty-name
-		    (server-create-tty-frame tty-name tty-type proc))))
+		    (server-create-tty-frame tty-name tty-type proc))
+
+                   ;; If there won't be a current frame to use, fall
+                   ;; back to trying to create a new one.
+		   ((and use-current-frame
+			 (daemonp)
+			 (null (cdr (frame-list)))
+			 (eq (selected-frame) terminal-frame)
+			 display)
+		    (setq tty-name nil tty-type nil)
+		    (server-select-display display))))
 
             (process-put
              proc 'continuation
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* bug#11033: emacsclient: create a new frame only if one doesn't exist
  2021-06-08 13:43 ` Peter Oliver
@ 2021-06-09  9:32   ` Lars Ingebrigtsen
  2021-06-22 10:51     ` Peter Oliver
  0 siblings, 1 reply; 6+ messages in thread
From: Lars Ingebrigtsen @ 2021-06-09  9:32 UTC (permalink / raw)
  To: Peter Oliver; +Cc: 11033

Peter Oliver <p.d.oliver@mavit.org.uk> writes:

> Attached is a patch which causes emacs to try to create a new GUI
> frame if there are no existing frames and the current TTY is unusable.

Makes sense to me.

> I have submitted copyright assignment paperwork but am currently
> waiting to hear back.

Let us know when the paperwork's final (in case we miss it), and we'll
get the patch applied.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#11033: emacsclient: create a new frame only if one doesn't exist
  2021-06-09  9:32   ` bug#11033: emacsclient: create a new frame only if one doesn't exist Lars Ingebrigtsen
@ 2021-06-22 10:51     ` Peter Oliver
  2021-06-22 13:21       ` Lars Ingebrigtsen
  0 siblings, 1 reply; 6+ messages in thread
From: Peter Oliver @ 2021-06-22 10:51 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 11033

On Wed, 9 Jun 2021, Lars Ingebrigtsen wrote:

> Peter Oliver <p.d.oliver@mavit.org.uk> writes:
>
>> I have submitted copyright assignment paperwork but am currently
>> waiting to hear back.
>
> Let us know when the paperwork's final (in case we miss it), and we'll
> get the patch applied.

The paperwork is now complete.  Thanks.

-- 
Peter Oliver





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#11033: emacsclient: create a new frame only if one doesn't exist
  2021-06-22 10:51     ` Peter Oliver
@ 2021-06-22 13:21       ` Lars Ingebrigtsen
  0 siblings, 0 replies; 6+ messages in thread
From: Lars Ingebrigtsen @ 2021-06-22 13:21 UTC (permalink / raw)
  To: Peter Oliver; +Cc: 11033

Peter Oliver <p.d.oliver@mavit.org.uk> writes:

> The paperwork is now complete.  Thanks.

And I've now pushed your patch to Emacs 28.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-06-22 13:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-16 23:18 bug#11033: emacsclient: create a new frame only if one doesn't exist Eddie Hillenbrand
2021-06-08 13:36 ` bug#11033: (no subject) Peter Oliver
2021-06-08 13:43 ` Peter Oliver
2021-06-09  9:32   ` bug#11033: emacsclient: create a new frame only if one doesn't exist Lars Ingebrigtsen
2021-06-22 10:51     ` Peter Oliver
2021-06-22 13:21       ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).