From 71feed095982f769ecb46b8c929a4deee1f445bd Mon Sep 17 00:00:00 2001 From: Stephane Zermatten Date: Wed, 4 Dec 2024 21:32:11 +0200 Subject: [PATCH] refactor: Generate new buffer name from the buffer. Before this change, buffer name generation was called before creating the buffer, from the original environment. That was surprising and required some hacks to define mistty-shell-command in that environment. This change creates a buffer with a temporary name, then run buffer name generation from that buffer. --- mistty.el | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/mistty.el b/mistty.el index e9babb0..b9c39dc 100644 --- a/mistty.el +++ b/mistty.el @@ -164,9 +164,9 @@ become \"*mistty-root*\". The functions on this list should look at the current environment, primarily, `default-directory' and `mistty-shell-command', set to the current command by -`mistty-create', to make their choice. Note that they're not -called from the mistty buffer, but rather from the environment -the buffer will be created." +`mistty-create', to make their choice. At the point this function +is called, the buffer is not a mistty buffer yet and just has a +temporary name." :type '(repeat (choice string (function-item mistty-buffer-name-shell) (function-item mistty-buffer-name-user) @@ -1148,17 +1148,21 @@ Upon success, the function returns the newly-created buffer." current-prefix-arg (mistty--read-default-directory)) default-directory)) + + (buf (generate-new-buffer " *mistty-new")) (command (or command - (with-connection-local-variables - (or - mistty-shell-command - explicit-shell-file-name - shell-file-name - (getenv "ESHELL") - (getenv "SHELL"))))) - (buf (let ((mistty-shell-command command)) - (generate-new-buffer (mistty-new-buffer-name))))) - (with-current-buffer buf (mistty-mode)) + (with-current-buffer buf + (with-connection-local-variables + (or + mistty-shell-command + explicit-shell-file-name + shell-file-name + (getenv "ESHELL") + (getenv "SHELL"))))))) + (with-current-buffer buf + (setq-local mistty-shell-command command) + (rename-buffer (generate-new-buffer-name (mistty-new-buffer-name))) + (mistty-mode)) ;; Note that it's important to attach the buffer to a window ;; before executing the command, so that the shell known the size ;; of the terminal from the very beginning.