tools/eshell: fix parameters being set on the wrong window

This would cause find-file commands to ignore certain windows, as well
as eshell buffers closing the incorrect window when they are quit.

Addresses #593
This commit is contained in:
Henrik Lissner 2018-05-18 01:22:49 +02:00
parent 80adb9c1f6
commit 8807471846
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -36,7 +36,8 @@
(defun +eshell--remove-buffer (buf) (defun +eshell--remove-buffer (buf)
(when-let* ((idx (ring-member +eshell-buffers buf))) (when-let* ((idx (ring-member +eshell-buffers buf)))
(ring-remove +eshell-buffers idx))) (ring-remove +eshell-buffers idx)
t))
(defun +eshell--current-git-branch () (defun +eshell--current-git-branch ()
(let ((branch (car (cl-loop for match in (split-string (shell-command-to-string "git branch") "\n") (let ((branch (car (cl-loop for match in (split-string (shell-command-to-string "git branch") "\n")
@ -54,6 +55,11 @@
return buf)) return buf))
(generate-new-buffer +eshell-buffer-name))) (generate-new-buffer +eshell-buffer-name)))
(defun +eshell--set-window (window &optional flag)
(when window
(set-window-parameter window 'no-other-window flag)
(set-window-parameter window 'visible flag)))
;;;###autoload ;;;###autoload
(defun +eshell-prompt () (defun +eshell-prompt ()
"Generate the prompt string for eshell. Use for `eshell-prompt-function'." "Generate the prompt string for eshell. Use for `eshell-prompt-function'."
@ -72,6 +78,7 @@
(interactive) (interactive)
(let ((buf (+eshell--buffer (eq major-mode 'eshell-mode)))) (let ((buf (+eshell--buffer (eq major-mode 'eshell-mode))))
(switch-to-buffer buf) (switch-to-buffer buf)
(+eshell--set-window (get-buffer-window buf) t)
(with-current-buffer buf (with-current-buffer buf
(unless (eq major-mode 'eshell-mode) (eshell-mode))) (unless (eq major-mode 'eshell-mode) (eshell-mode)))
(when command (when command
@ -85,6 +92,7 @@
(with-current-buffer buf (with-current-buffer buf
(unless (eq major-mode 'eshell-mode) (eshell-mode))) (unless (eq major-mode 'eshell-mode) (eshell-mode)))
(pop-to-buffer buf) (pop-to-buffer buf)
(+eshell--set-window (get-buffer-window buf) t)
(when command (when command
(+eshell-run-command command)))) (+eshell-run-command command))))
@ -104,6 +112,7 @@ module to be loaded."
(+eshell/open)) (+eshell/open))
(when command (when command
(+eshell-run-command command)) (+eshell-run-command command))
(+eshell--set-window (selected-window) t)
(doom/workspace-display)) (doom/workspace-display))
(defun +eshell-run-command (command) (defun +eshell-run-command (command)
@ -129,29 +138,23 @@ module to be loaded."
(dolist (buf (ring-elements +eshell-buffers)) (dolist (buf (ring-elements +eshell-buffers))
(unless (buffer-live-p buf) (unless (buffer-live-p buf)
(+eshell--remove-buffer buf))) (+eshell--remove-buffer buf)))
(let ((window (selected-window)))
(set-window-parameter window 'no-other-window t)
(set-window-parameter window 'visible t)
(set-window-dedicated-p window t))
(+eshell--add-buffer buf) (+eshell--add-buffer buf)
(setq +eshell-last-buffer buf))) (setq +eshell-last-buffer buf)))
;;;###autoload ;;;###autoload
(defun +eshell|cleanup () (defun +eshell|cleanup ()
"Close window (or workspace) on quit." "Close window (or workspace) on quit."
(let ((window (selected-window))) (let ((buf (current-buffer)))
(set-window-parameter window 'no-other-window nil) (when (+eshell--remove-buffer buf)
(set-window-parameter window 'visible t) (+eshell--set-window (get-buffer-window buf) nil)
(set-window-dedicated-p window nil))
(+eshell--remove-buffer (current-buffer))
(cond ((and (featurep! :feature workspaces) (cond ((and (featurep! :feature workspaces)
(string= "eshell" (+workspace-current-name))) (string= "eshell" (+workspace-current-name)))
(+workspace/delete "eshell")) (+workspace/delete "eshell"))
((one-window-p) ((one-window-p)
(unless (doom-real-buffer-p (progn (previous-buffer) (current-buffer))) (unless (doom-real-buffer-p (progn (previous-buffer) (current-buffer)))
(switch-to-buffer (doom-fallback-buffer)))) (switch-to-buffer (doom-fallback-buffer))))
((delete (current-buffer) (get-buffer-window-list)) ((and (fboundp '+popup-window-p) (+popup-window-p))
(delete-window)))) (delete-window))))))
;; ;;