Add command 'eat-other-window'

* eat.el (eat--1, eat-other-window): New function.
* eat.el (eat): Move all logic to 'eat--1' and call it.
This commit is contained in:
Akib Azmain Turja 2023-08-31 19:04:23 +06:00
parent 79a5c2dc94
commit 8da6684841
No known key found for this signature in database
GPG key ID: 5535FCF54D88616B

72
eat.el
View file

@ -6248,6 +6248,32 @@ PROGRAM."
(eat-exec buffer name program startfile switches)) (eat-exec buffer name program startfile switches))
buffer)) buffer))
(defun eat--1 (program arg display-buffer-fn)
"Start a new Eat terminal emulator in a buffer.
PROGRAM and ARG is same as in `eat' and `eat-other-window'.
DISPLAY-BUFFER-FN is the function to display the buffer."
(let ((program (or program (or explicit-shell-file-name
(getenv "ESHELL")
shell-file-name)))
(buffer
(cond
((numberp arg)
(get-buffer-create (format "%s<%d>" eat-buffer-name arg)))
(arg
(generate-new-buffer eat-buffer-name))
(t
(get-buffer-create eat-buffer-name)))))
(with-current-buffer buffer
(unless (eq major-mode #'eat-mode)
(eat-mode))
(funcall display-buffer-fn buffer)
(unless (and eat--terminal
(eat-term-parameter eat--terminal 'eat--process))
(eat-exec buffer (buffer-name) "/usr/bin/env" nil
(list "sh" "-c" program)))
buffer)))
;;;###autoload ;;;###autoload
(defun eat (&optional program arg) (defun eat (&optional program arg)
"Start a new Eat terminal emulator in a buffer. "Start a new Eat terminal emulator in a buffer.
@ -6272,26 +6298,32 @@ PROGRAM can be a shell command."
(getenv "ESHELL") (getenv "ESHELL")
shell-file-name))) shell-file-name)))
current-prefix-arg)) current-prefix-arg))
(let ((program (or program (or explicit-shell-file-name (eat--1 program arg #'pop-to-buffer-same-window))
(getenv "ESHELL")
shell-file-name))) ;;;###autoload
(buffer (defun eat-other-window (&optional program arg)
(cond "Start a new Eat terminal emulator in a buffer in another window.
((numberp arg)
(get-buffer-create (format "%s<%d>" eat-buffer-name arg))) Start a new Eat session, or switch to an already active session.
(arg Return the buffer selected (or created).
(generate-new-buffer eat-buffer-name))
(t With a non-numeric prefix ARG, create a new session.
(get-buffer-create eat-buffer-name)))))
(with-current-buffer buffer With a numeric prefix ARG switch to the session with that number, or
(unless (eq major-mode #'eat-mode) create it if it doesn't already exist.
(eat-mode))
(pop-to-buffer-same-window buffer) With double prefix argument ARG, ask for the program to run and run it
(unless (and eat--terminal in a newly created session.
(eat-term-parameter eat--terminal 'eat--process))
(eat-exec buffer (buffer-name) "/usr/bin/env" nil PROGRAM can be a shell command."
(list "sh" "-c" program))) (interactive
buffer))) (list (when (equal current-prefix-arg '(16))
(read-shell-command "Run program: "
(or explicit-shell-file-name
(getenv "ESHELL")
shell-file-name)))
current-prefix-arg))
(eat--1 program arg #'pop-to-buffer))
;;;; Eshell integration. ;;;; Eshell integration.