From 47f33e6cb0498f2405957539efcb8bd174c602ff Mon Sep 17 00:00:00 2001 From: Eliza Velasquez Date: Tue, 10 Nov 2020 22:14:03 -0500 Subject: [PATCH] * lisp/server.el: Fix frame creation on dumb terminals (bug#25547) (server-create-dumb-terminal-frame): New function. (server-process-filter): Use it. (server-delete-client): Don't delete tty terminal when it's not exclusive to this client. --- lisp/server.el | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/lisp/server.el b/lisp/server.el index a660deab8e8..734fb8a34ac 100644 --- a/lisp/server.el +++ b/lisp/server.el @@ -354,9 +354,11 @@ Updates `server-clients'." (setq server-clients (delq proc server-clients)) - ;; Delete the client's tty, except on Windows (both GUI and console), - ;; where there's only one terminal and does not make sense to delete it. - (unless (eq system-type 'windows-nt) + ;; Delete the client's tty, except on Windows (both GUI and + ;; console), where there's only one terminal and does not make + ;; sense to delete it, or if we are explicitly told not. + (unless (or (eq system-type 'windows-nt) + (process-get proc 'no-delete-terminal)) (let ((terminal (process-get proc 'terminal))) ;; Only delete the terminal if it is non-nil. (when (and terminal (eq (terminal-live-p terminal) t)) @@ -918,6 +920,19 @@ This handles splitting the command if it would be bigger than (server-send-string proc "-window-system-unsupported \n") nil)))) +(defun server-create-dumb-terminal-frame (nowait proc &optional parameters) + (add-to-list 'frame-inherited-parameters 'client) + (let ((frame (make-frame `((client . ,(if nowait 'nowait proc)) + ;; This is a leftover, see above. + (environment . ,(process-get proc 'env)) + ,@parameters)))) + (server-log (format "%s created" frame) proc) + (select-frame frame) + (process-put proc 'frame frame) + (process-put proc 'terminal (frame-terminal frame)) + (process-put proc 'no-delete-terminal t) + frame)) + (defun server-goto-toplevel (proc) (condition-case nil ;; If we're running isearch, we must abort it to allow Emacs to @@ -1264,6 +1279,14 @@ The following commands are accepted by the client: terminal-frame))))) (setq tty-name nil tty-type nil) (if display (server-select-display display))) + ((equal tty-type "dumb") + ;; Emacsclient is likely running inside something + ;; like an Emacs shell buffer. We can't run an + ;; Emacs frame in a tty like this, so instead, use + ;; whichever terminal is currently + ;; selected. (bug#25547) + (server-create-dumb-terminal-frame nowait proc + frame-parameters)) ((or (and (eq system-type 'windows-nt) (daemonp) (setq display "w32")) -- 2.39.2