|
| 1 | +;;; eee-eat.el --- Eat support for eee.el -*- lexical-binding: t -*- |
| 2 | + |
| 3 | +;;; Commentary: |
| 4 | + |
| 5 | +;; To use Eat with EEE, eval the following code: |
| 6 | + |
| 7 | +;; (setq ee-start-terminal-function #'ee-eat-start-terminal) |
| 8 | + |
| 9 | +;;; Code: |
| 10 | + |
| 11 | +(require 'eat) |
| 12 | + |
| 13 | +;; Define a derived mode of eat-mode to make it easy |
| 14 | +;; to customize `display-buffer-alist'. |
| 15 | +(define-derived-mode ee-eat-mode eat-mode "Eat[EEE]" ) |
| 16 | + |
| 17 | +(defun ee-eat--setup-buffer () |
| 18 | + (let ((inhibit-read-only t)) |
| 19 | + (erase-buffer)) |
| 20 | + (unless (eq major-mode #'ee-eat-mode) |
| 21 | + (ee-eat-mode)) |
| 22 | + (pop-to-buffer (current-buffer) |
| 23 | + '((display-buffer-pop-up-frame))) |
| 24 | + ;; Enable `eat-char-mode' so that all keyboard events are sent to Eat. |
| 25 | + ;; `eat-char-mode' can only be enabled after the process starts. |
| 26 | + (add-hook 'eat-exec-hook (lambda (_) (eat-char-mode)) nil t) |
| 27 | + |
| 28 | + ;; Delete the popped-up frame after the process exits. Use a higher |
| 29 | + ;; priority to make sure this function executes before the callback function |
| 30 | + (add-hook 'eat-exit-hook (lambda (p) |
| 31 | + (when (zerop (process-exit-status p)) |
| 32 | + (quit-restore-window (selected-window) 'kill))) |
| 33 | + -90 t)) |
| 34 | + |
| 35 | +;;;###autoload |
| 36 | +(defun ee-eat-start-terminal (name command callback) |
| 37 | + "Run COMMAND in an Eat buffer and display that buffer in a new frame. |
| 38 | +
|
| 39 | +The buffer name is made by surrounding NAME with `*'s. |
| 40 | +
|
| 41 | +The buffer is killed if the process exits normally. |
| 42 | +CALLBACK is called after the process exits. |
| 43 | +
|
| 44 | +See `ee-start-terminal-function' and |
| 45 | +`ee-start-process-shell-command-in-terminal'." |
| 46 | + (let ((dir default-directory)) |
| 47 | + (with-current-buffer (get-buffer-create (concat "*" name "*")) |
| 48 | + (setq default-directory dir) |
| 49 | + (ee-eat--setup-buffer) |
| 50 | + (add-hook 'eat-exit-hook callback 50 t) |
| 51 | + (eat-exec (current-buffer) name "bash" nil (list "-c" command))))) |
| 52 | + |
| 53 | +(provide 'eee-eat) |
| 54 | +;;; eee-eat.el ends here |
0 commit comments