Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
####### # # E-scripts on eat ("emulate a terminal") # # Note 1: use the eev command (defined in eev.el) and the # ee alias (in my .zshrc) to execute parts of this file. # Executing this file as a whole makes no sense. # An introduction to eev can be found here: # # (find-eev-quick-intro) # http://anggtwu.net/eev-intros/find-eev-quick-intro.html # # Note 2: be VERY careful and make sure you understand what # you're doing. # # Note 3: If you use a shell other than zsh things like |& # and the for loops may not work. # # Note 4: I always run as root. # # Note 5: some parts are too old and don't work anymore. Some # never worked. # # Note 6: the definitions for the find-xxxfile commands are on my # .emacs. # # Note 7: if you see a strange command check my .zshrc -- it may # be defined there as a function or an alias. # # Note 8: the sections without dates are always older than the # sections with dates. # # This file is at <http://anggtwu.net/e/eat.e> # or at <http://anggtwu.net/e/eat.e.html>. # See also <http://anggtwu.net/emacs.html>, # <http://anggtwu.net/.emacs[.html]>, # <http://anggtwu.net/.zshrc[.html]>, # <http://anggtwu.net/escripts.html>, # and <http://anggtwu.net/>. # ####### # «.2022» (to "2022") # «.2024» (to "2024") # «.eat-args» (to "eat-args") # «.keymaps» (to "keymaps") # «.sixel» (to "sixel") # «.kill-if-needed» (to "kill-if-needed") # (find-es "emacs" "eat") ##### # # Notes from 2022 # 2023dec03 # ##### # «2022» (to ".2022") # (find-epackage-links 'eat "eat" t) # (find-epackages 'eat) # (find-epackage 'eat) # (code-c-d "eat" "~/.emacs.d/elpa/eat-0.9.4/" "eat") # (find-eatfile "") # (find-eatnode "") # (find-eatnode "Colors") # (find-eatnode "Hello Terminal") # (find-efunction 'eat) # (find-efunction 'eat--1) (eat--1 program arg display-buffer-fn) (eat--1 "lua5.1" nil '+) (eat--1 "lua5.1" 1 '+) # (find-efunction 'eat-semi-char-mode) # (find-evardescr 'eat--mouse-click-mode-map) # (find-evardescr 'eat--mouse-modifier-click-mode-map) # (find-evardescr 'eat--mouse-movement-mode-map) # (find-evardescr 'eat-char-mode-map) # (find-evardescr 'eat-eshell-char-mode-map) # (find-evardescr 'eat-eshell-emacs-mode-map) # (find-evardescr 'eat-eshell-semi-char-mode-map) # (find-evardescr 'eat-line-mode-map) # (find-evardescr 'eat-mode-map) # (find-evardescr 'eat-semi-char-mode-map) # (find-evardescr 'eat-trace-replay-mode-map) # (find-efunction 'eat-self-input) # (find-ekeymapdescr eat--mouse-click-mode-map) # https://codeberg.org/akib/emacs-eat/ # https://akib.codeberg.page/blog/introducing-eat.html # https://www.reddit.com/r/planetemacs/comments/z52uwf/introducing_eat_a_new_terminal_emulator_for_emacs/ # https://codeberg.org/akib/emacs-eat/issues/17 # https://emacsconf.org/2023/talks/eat/ (defun find-eatprocess0 (name program-and-args) (let* ((bufname (format "*%s*" name)) (buffer (switch-to-buffer bufname))) (unless (eq major-mode #'eat-mode) (eat-mode)) (unless eat--process (eat-exec buffer "eat" "/usr/bin/env" nil program-and-args)) (eat-emacs-mode))) (defun find-eatprocess (program-and-args &optional n) (find-eatprocess0 (format "eat: %s%s" (ee-unsplit program-and-args) (if n (format " (%s)" n) "")) (ee-split program-and-args))) (defun eepitch-line-eat (line) "Send LINE to the eat buffer and run the key binding for RET there." (eepitch-eval-at-target-window `(progn (eat-semi-char-mode) (process-send-string eat--process ,(concat line "\n")))) (eat-emacs-mode)) (defun eepitch-eat (program-and-args &optional n) (interactive) (prog1 (eepitch `(find-eatprocess ,program-and-args ,n)) (setq eepitch-line 'eepitch-line-eat))) ##### # # 2024 # 2024mar24 # ##### # «2024» (to ".2024") # (find-eatfile "eat.el" "(defun eat--1 ") # (find-angg "elisp/eev-eat.el") # (find-eaproposf "eat.*live") # (find-eaproposf "eat.*position") # (find-eaproposf "eat.*insert") (defun eat--0 (program buffer) (with-current-buffer buffer (unless (eq major-mode #'eat-mode) (eat-mode)) (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)) (find-ebuffer (eat--0 "lua5.1" "foo")) (defun eat--1-buffer (arg) (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)))) # (find-eapropos "^eat--") (generate-new-buffer "foo") (with-current-buffer "foo" 42) (defun eat--1 (program0 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 (eat--1-program program0)) (buffer (eat--1-program arg)) (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))) ;; This is similar to: ;; (find-eev "eepitch.el" "other-terms") ;; but with fewer features... the arguments of `program-and-args' are ;; discarded - only the program name is kept - and we have little ;; control over the name of the buffer - n can only be a number or ;; nil. ;; (defun find-eatprocess (&optional program-and-args n) (let ((prog (if program-and-args (car (ee-split program-and-args)) (or explicit-shell-file-name (getenv "ESHELL") shell-file-name)))) (eat--1 prog n 'switch-to-buffer))) (defun eepitch-eat (&optional program-and-args n) (interactive) (prog1 (eepitch `(find-eatprocess ,program-and-args ,n)) (setq eepitch-line 'eepitch-line-eat))) ;; (find-efunction 'eepitch) ;; (find-efunction 'eepitch-prepare) ;; (find-efunction 'eepitch-buffer-create) (defun eepitch-buffer-create2 () (save-window-excursion (eval eepitch-code) (setq eepitch-buffer-name (buffer-name (current-buffer))))) (defun eepitch-prepare2 () (if (not (eepitch-buffer-exists)) (eepitch-buffer-create2)) (if (eq (current-buffer) (eepitch-target-buffer)) (error "Can't pitch to the current buffer")) (if (not (eepitch-window-exists)) (eval eepitch-window-show))) (defun eepitch2 (code) (setq eepitch-code code) (setq eepitch-buffer-name "") ; so that `eepitch-buffer-exists' will fail (setq eepitch-window-show ; set the way to set up windows to the '(eepitch-window-show)) ; default two-window setting (setq eepitch-kill ; set the behavior of `eepitch-kill' '(eepitch-kill-buffer)) ; to just kill the target buffer (setq eepitch-line nil) ; use the default `eepitch-line' (eepitch-prepare2) (list 'Target: eepitch-buffer-name)) ; feedback (for <f8> and `M-e') * (eepitch-eat "lua5.1") * (eepitch-kill) * (eepitch-eat "lua5.1") * (eepitch2 '(find-eatprocess)) * (eepitch-shell) * (eepitch-kill) * (eepitch-shell) (find-2a nil '(find-eatprocess "lua5.1")) ) (find-ansitermprocess "lua5.1") (find-eatprocess) (find-eatprocess nil 42) (find-eatprocess "lua5.1") (find-eatprocess "lua5.1" 42) # (find-eaproposf "find.*comint") (ee-split nil) (ee-split "a b c") (ee-split '("a" "b c")) (require 'eat) (find-2a nil '(find-eatprocess "lua5.1")) (eat-term-send-string TERMINAL STRING) * (eepitch-eat "lua5.1") * (eepitch-kill) * (eepitch-eat "lua5.1") print(1+2) ##### # # eat-args # 2024mar24 # ##### # «eat-args» (to ".eat-args") # (find-efunction 'eat) # (find-efunction 'eat--1) (eat) (eat "lua5.1") (eat "lua5.1" 42) (eat--1 nil nil #'pop-to-buffer-same-window) (eat--1 nil 42 #'pop-to-buffer-same-window) (eat--1 "lua5.1" nil #'pop-to-buffer-same-window) (eat--1 "lua5.1" 42 #'pop-to-buffer-same-window) (eat--1 "lua5.1" 42 'switch-to-buffer) (eat--1 program arg #'pop-to-buffer-same-window) ##### # # keymaps # 2024mar24 # ##### # «keymaps» (to ".keymaps") # (find-eatnode "Keyboard") # (find-eatnode "Input Modes") # (find-eatnode "Input Modes" "7.1 Semi-char Mode") # (find-eatnode "Input Modes" "7.2 Char Mode") # (find-eatnode "Input Modes" "7.3 Emacs Mode") # (find-eatnode "Input Modes" "7.4 Line Mode") # (find-eapropos "^eat.*map") # (find-eaproposv "^eat.*-mode-map") # (find-evariable 'eat--mouse-click-mode-map) # (find-ekeymapdescr eat--mouse-click-mode-map) # (find-evariable 'eat--mouse-modifier-click-mode-map) # (find-ekeymapdescr eat--mouse-modifier-click-mode-map) # (find-evariable 'eat--mouse-movement-mode-map) # (find-ekeymapdescr eat--mouse-movement-mode-map) # (find-evariable 'eat-char-mode-map) # (find-ekeymapdescr eat-char-mode-map) # (find-evariable 'eat-eshell-char-mode-map) # (find-ekeymapdescr eat-eshell-char-mode-map) # (find-evariable 'eat-eshell-emacs-mode-map) # (find-ekeymapdescr eat-eshell-emacs-mode-map) # (find-evariable 'eat-eshell-semi-char-mode-map) # (find-ekeymapdescr eat-eshell-semi-char-mode-map) # (find-evariable 'eat-line-mode-map) # (find-ekeymapdescr eat-line-mode-map) # (find-evariable 'eat-mode-map) # (find-ekeymapdescr eat-mode-map) # (find-evariable 'eat-semi-char-mode-map) # (find-ekeymapdescr eat-semi-char-mode-map) # (find-evariable 'eat-trace-replay-mode-map) # (find-ekeymapdescr eat-trace-replay-mode-map) # (find-elocus-links "C-c C-e" 'eat-semi-char-mode-map) # (define-key eat-mode-map (kbd "M-k") 'ee-kill-this-buffer) # (define-key eat-mode-map (kbd "M-k") 'ee-kill-this-buffer) # (define-key eat-semi-char-mode-map (kbd "M-K") 'bury-buffer) # (define-key eat-semi-char-mode-map (kbd "M-K") 'bury-buffer) ##### # # sixel # 2024mar24 # ##### # «sixel» (to ".sixel") # (find-eatnode "Sixel") # (find-es "sixel" "sixel-experiments") ##### # # kill-if-needed # 2024mar25 # ##### # «kill-if-needed» (to ".kill-if-needed") (defun ee-eat-kill-buffer-if-needed (bufname) (if (and (get-buffer bufname) (with-current-buffer bufname (or (not (eq major-mode 'eat-mode)) (not eat-terminal) (not (eat-term-live-p eat-terminal))))) (ee-kill-buffer buffer))) (defun ee-eat-buffer-kill-needed (bufname) (and (get-buffer bufname) (with-current-buffer bufname (or (not (eq major-mode 'eat-mode)) (not eat-terminal) (not (eat-term-live-p eat-terminal)))))) (find-efunction 'eat--t-ensure-live-term) (find-efunction 'eat-term-live-p) # Local Variables: # coding: utf-8-unix # modes: (fundamental-mode emacs-lisp-mode) # End: