summaryrefslogtreecommitdiffhomepage
path: root/attic
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2021-11-10 23:00:57 +0000
committerjao <jao@gnu.org>2021-11-10 23:02:11 +0000
commit89e738b464a53817b5b5ab473563783dd407c8bb (patch)
treec1029148d9db1d840aa82d341c3df02f2c908b71 /attic
parentae067465ab06850da8764cd29e34884c0331cb92 (diff)
downloadelibs-89e738b464a53817b5b5ab473563783dd407c8bb.tar.gz
elibs-89e738b464a53817b5b5ab473563783dd407c8bb.tar.bz2
simpler eshell toggling and term handling
Diffstat (limited to 'attic')
-rw-r--r--attic/misc.org112
1 files changed, 71 insertions, 41 deletions
diff --git a/attic/misc.org b/attic/misc.org
index b468c7b..c3df4b7 100644
--- a/attic/misc.org
+++ b/attic/misc.org
@@ -537,55 +537,85 @@
#+end_src
* vterm
- #+begin_src emacs-lisp
+*** vterm
+ #+begin_src emacs-lisp :tangle no
+ (use-package vterm-toggle
+ :ensure t
+ :config
+ (defun jao-vterm--toggle (cd)
+ (interactive "P")
+ (if cd (vterm-toggle-cd) (vterm-toggle)))
+ :bind (("C-<f3>" . jao-vterm--toggle)))
+
(use-package vterm
:ensure t
- :init
- (setq vterm-kill-buffer-on-exit t
- vterm-copy-exclude-prompt t
- vterm-use-vterm-prompt-detection-method t
- vterm-buffer-name-string nil)
:config
- (define-key vterm-mode-map [(f1)] nil)
- :bind (:map vterm-mode-map (("C-c C-c" . vterm-send-C-c))))
-
- (defun jao-exec-in-vterm (cmd &optional name)
- (vterm)
- (when name (vterm-send-string "unset PROMPT_COMMAND\n"))
- (vterm-send-string cmd)
- (vterm-send-return)
- (when name (rename-buffer name)))
-
- (defun jao-exec-in-vterm (cmd &optional name)
- (ansi-term cmd name))
-
- (defvar-local jao-vterm--cmd nil)
-
- (defun jao-vterm--find (cmd)
- (seq-find (lambda (b)
- (and (eq (buffer-local-value 'major-mode b) 'vterm-mode)
- (string= (or (buffer-local-value 'jao-vterm--cmd b) "")
- cmd)))
- (buffer-list)))
-
- (defmacro jao-def-exec-in-vterm (name cmd &rest prelude)
- `(defun ,(intern (format "jao-vterm-%s" name)) ()
- (interactive)
- ,@prelude
- (if-let ((b (jao-vterm--find ,cmd)))
- (pop-to-buffer b)
- (jao-exec-in-vterm (format "%s; exit" ,cmd)
- ,(when name (format "%s" name)))
- (setq-local jao-vterm--cmd ,cmd))))
-
- (jao-def-exec-in-vterm aptitude "aptitude" (jao-afio--goto-scratch))
- (jao-def-exec-in-vterm htop "htop" (jao-afio--goto-scratch))
- #+end_src
+ :custom ((vterm-kill-buffer-on-exit t)))
+
+ (use-package eshell-vterm
+ :ensure t
+ :config (eshell-vterm-mode))
+
+ (defun jao-exec-in-vterm (cmd bname)
+ (if (string-blank-p (or cmd ""))
+ (vterm)
+ (let ((vterm-shell cmd)
+ (vterm-kill-buffer-on-exit t)
+ (buff (generate-new-buffer bname)))
+ (switch-to-buffer buff)
+ (vterm-mode))))
+
+ #+end_src
*** Vterm repls
#+begin_src emacs-lisp
(use-package jao-vterm-repl)
(jao-define-attached-buffer "^\\* vrepl - .+ \\*.*")
#+end_src
+* eshell here
+ #+begin_src emacs-lisp
+ (defun jao-shell-here--find-window (b)
+ (when-let (w (seq-find (lambda (w) (eq (window-buffer w) b))
+ (window-list)))
+ (select-window w)))
+
+ (defun jao-shell-frame-buffer (&optional b)
+ (let ((p 'jao-eshell-buffer))
+ (if b (set-frame-parameter nil p b) (frame-parameter nil p))))
+
+ (defun jao-shell--cd-here (dir)
+ (eshell-kill-input)
+ (eshell/cd dir)
+ (insert "\n")
+ (eshell-send-input))
+
+ (defun jao-shell-here (&optional stay)
+ (interactive)
+ (let* ((dir default-directory)
+ (b (jao-shell-frame-buffer)))
+ (jao-with-attached-buffer "^\\*eshell" 35
+ (if (buffer-live-p b)
+ (pop-to-buffer b nil t)
+ (eshell)
+ (jao-shell-frame-buffer (current-buffer))))
+ (eshell-save-some-history)
+ (unless stay (jao-shell--cd-here dir))))
+
+ (defun eshell/x ()
+ (when (derived-mode-p 'eshell-mode)
+ (when (fboundp 'eshell-autojump-save)
+ (eshell-autojump-save))
+ (eshell-save-some-history))
+ (if (> (frame-height) (window-height)) (delete-window) (bury-buffer)))
+
+ (defun jao-shell-here-toggle ()
+ (interactive)
+ (if (eq (current-buffer) (jao-shell-frame-buffer))
+ (eshell/x)
+ (jao-shell-here t)))
+
+ (global-set-key (kbd "C-!") #'jao-shell-here)
+ (global-set-key [(f1)] #'jao-shell-here-toggle)
+ #+end_src
* scrolling
#+begin_src emacs-lisp
(use-package iscroll