diff options
| author | Aaron Jensen | 2018-02-16 17:43:04 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2018-02-16 17:43:04 +0200 |
| commit | 49fc040077b33bd1e78ee425575e76329b772a41 (patch) | |
| tree | f8d057c1820f9bd87265452bd90bcc169a097bb5 | |
| parent | aead21d83ed073f179df856a93228202ff9baee0 (diff) | |
| download | emacs-49fc040077b33bd1e78ee425575e76329b772a41.tar.gz emacs-49fc040077b33bd1e78ee425575e76329b772a41.zip | |
Don't flash previous buffer when connecting with emacsclient
* lisp/server.el (server-execute): Accept lambda for creating
frame rather than frame. Ensure newly created tty frame
initially shows the correct buffer.
(server-process-filter): Pass a lambda to server-execute to create
a frame. (Bug#24218)
| -rw-r--r-- | lisp/server.el | 88 |
1 files changed, 49 insertions, 39 deletions
diff --git a/lisp/server.el b/lisp/server.el index d3933883cf7..a892203c24a 100644 --- a/lisp/server.el +++ b/lisp/server.el | |||
| @@ -1092,7 +1092,8 @@ The following commands are accepted by the client: | |||
| 1092 | tty-type ; string. | 1092 | tty-type ; string. |
| 1093 | files | 1093 | files |
| 1094 | filepos | 1094 | filepos |
| 1095 | args-left) | 1095 | args-left |
| 1096 | create-frame-func) | ||
| 1096 | ;; Remove this line from STRING. | 1097 | ;; Remove this line from STRING. |
| 1097 | (setq string (substring string (match-end 0))) | 1098 | (setq string (substring string (match-end 0))) |
| 1098 | (setq args-left | 1099 | (setq args-left |
| @@ -1244,28 +1245,29 @@ The following commands are accepted by the client: | |||
| 1244 | (or files commands) | 1245 | (or files commands) |
| 1245 | (setq use-current-frame t)) | 1246 | (setq use-current-frame t)) |
| 1246 | 1247 | ||
| 1247 | (setq frame | 1248 | (setq create-frame-func |
| 1248 | (cond | 1249 | (lambda () |
| 1249 | ((and use-current-frame | 1250 | (cond |
| 1250 | (or (eq use-current-frame 'always) | 1251 | ((and use-current-frame |
| 1251 | ;; We can't use the Emacs daemon's | 1252 | (or (eq use-current-frame 'always) |
| 1252 | ;; terminal frame. | 1253 | ;; We can't use the Emacs daemon's |
| 1253 | (not (and (daemonp) | 1254 | ;; terminal frame. |
| 1254 | (null (cdr (frame-list))) | 1255 | (not (and (daemonp) |
| 1255 | (eq (selected-frame) | 1256 | (null (cdr (frame-list))) |
| 1256 | terminal-frame))))) | 1257 | (eq (selected-frame) |
| 1257 | (setq tty-name nil tty-type nil) | 1258 | terminal-frame))))) |
| 1258 | (if display (server-select-display display))) | 1259 | (setq tty-name nil tty-type nil) |
| 1259 | ((or (and (eq system-type 'windows-nt) | 1260 | (if display (server-select-display display))) |
| 1260 | (daemonp) | 1261 | ((or (and (eq system-type 'windows-nt) |
| 1261 | (setq display "w32")) | 1262 | (daemonp) |
| 1262 | (eq tty-name 'window-system)) | 1263 | (setq display "w32")) |
| 1263 | (server-create-window-system-frame display nowait proc | 1264 | (eq tty-name 'window-system)) |
| 1264 | parent-id | 1265 | (server-create-window-system-frame display nowait proc |
| 1265 | frame-parameters)) | 1266 | parent-id |
| 1266 | ;; When resuming on a tty, tty-name is nil. | 1267 | frame-parameters)) |
| 1267 | (tty-name | 1268 | ;; When resuming on a tty, tty-name is nil. |
| 1268 | (server-create-tty-frame tty-name tty-type proc)))) | 1269 | (tty-name |
| 1270 | (server-create-tty-frame tty-name tty-type proc))))) | ||
| 1269 | 1271 | ||
| 1270 | (process-put | 1272 | (process-put |
| 1271 | proc 'continuation | 1273 | proc 'continuation |
| @@ -1277,7 +1279,7 @@ The following commands are accepted by the client: | |||
| 1277 | (if (and dir (file-directory-p dir)) | 1279 | (if (and dir (file-directory-p dir)) |
| 1278 | dir default-directory))) | 1280 | dir default-directory))) |
| 1279 | (server-execute proc files nowait commands | 1281 | (server-execute proc files nowait commands |
| 1280 | dontkill frame tty-name))))) | 1282 | dontkill create-frame-func tty-name))))) |
| 1281 | 1283 | ||
| 1282 | (when (or frame files) | 1284 | (when (or frame files) |
| 1283 | (server-goto-toplevel proc)) | 1285 | (server-goto-toplevel proc)) |
| @@ -1286,7 +1288,7 @@ The following commands are accepted by the client: | |||
| 1286 | ;; condition-case | 1288 | ;; condition-case |
| 1287 | (error (server-return-error proc err)))) | 1289 | (error (server-return-error proc err)))) |
| 1288 | 1290 | ||
| 1289 | (defun server-execute (proc files nowait commands dontkill frame tty-name) | 1291 | (defun server-execute (proc files nowait commands dontkill create-frame-func tty-name) |
| 1290 | ;; This is run from timers and process-filters, i.e. "asynchronously". | 1292 | ;; This is run from timers and process-filters, i.e. "asynchronously". |
| 1291 | ;; But w.r.t the user, this is not really asynchronous since the timer | 1293 | ;; But w.r.t the user, this is not really asynchronous since the timer |
| 1292 | ;; is run after 0s and the process-filter is run in response to the | 1294 | ;; is run after 0s and the process-filter is run in response to the |
| @@ -1296,21 +1298,29 @@ The following commands are accepted by the client: | |||
| 1296 | ;; including code that needs to wait. | 1298 | ;; including code that needs to wait. |
| 1297 | (with-local-quit | 1299 | (with-local-quit |
| 1298 | (condition-case err | 1300 | (condition-case err |
| 1299 | (let ((buffers (server-visit-files files proc nowait))) | 1301 | (let* ((buffers (server-visit-files files proc nowait)) |
| 1300 | (mapc 'funcall (nreverse commands)) | 1302 | ;; If we were told only to open a new client, obey |
| 1303 | ;; `initial-buffer-choice' if it specifies a file | ||
| 1304 | ;; or a function. | ||
| 1305 | (initial-buffer (unless (or files commands) | ||
| 1306 | (let ((buf | ||
| 1307 | (cond ((stringp initial-buffer-choice) | ||
| 1308 | (find-file-noselect initial-buffer-choice)) | ||
| 1309 | ((functionp initial-buffer-choice) | ||
| 1310 | (funcall initial-buffer-choice))))) | ||
| 1311 | (if (buffer-live-p buf) buf (get-buffer-create "*scratch*"))))) | ||
| 1312 | ;; Set current buffer so that newly created tty frames | ||
| 1313 | ;; show the correct buffer initially. | ||
| 1314 | (frame (with-current-buffer (or (car buffers) | ||
| 1315 | initial-buffer | ||
| 1316 | (current-buffer)) | ||
| 1317 | (prog1 | ||
| 1318 | (funcall create-frame-func) | ||
| 1319 | ;; Switch to initial buffer in case the frame was reused. | ||
| 1320 | (when initial-buffer | ||
| 1321 | (switch-to-buffer initial-buffer 'norecord)))))) | ||
| 1301 | 1322 | ||
| 1302 | ;; If we were told only to open a new client, obey | 1323 | (mapc 'funcall (nreverse commands)) |
| 1303 | ;; `initial-buffer-choice' if it specifies a file | ||
| 1304 | ;; or a function. | ||
| 1305 | (unless (or files commands) | ||
| 1306 | (let ((buf | ||
| 1307 | (cond ((stringp initial-buffer-choice) | ||
| 1308 | (find-file-noselect initial-buffer-choice)) | ||
| 1309 | ((functionp initial-buffer-choice) | ||
| 1310 | (funcall initial-buffer-choice))))) | ||
| 1311 | (switch-to-buffer | ||
| 1312 | (if (buffer-live-p buf) buf (get-buffer-create "*scratch*")) | ||
| 1313 | 'norecord))) | ||
| 1314 | 1324 | ||
| 1315 | ;; Delete the client if necessary. | 1325 | ;; Delete the client if necessary. |
| 1316 | (cond | 1326 | (cond |