diff options
| -rw-r--r-- | init.el | 3 | ||||
| -rw-r--r-- | modules/cj-window-geometry.el | 2 | ||||
| -rw-r--r-- | modules/cj-window-toggle.el | 2 | ||||
| -rw-r--r-- | modules/eshell-config.el | 174 | ||||
| -rw-r--r-- | modules/vterm-config.el (renamed from modules/eshell-vterm-config.el) | 184 | ||||
| -rw-r--r-- | tests/test-vterm-tmux-history.el | 2 | ||||
| -rw-r--r-- | tests/test-vterm-toggle--buffer-filter.el | 2 | ||||
| -rw-r--r-- | tests/test-vterm-toggle--dispatch.el | 2 | ||||
| -rw-r--r-- | tests/test-vterm-toggle--display.el | 2 |
9 files changed, 187 insertions, 186 deletions
@@ -71,7 +71,8 @@ (require 'diff-config) ;; diff and merge functionality w/in Emacs (require 'erc-config) ;; seamless IRC client (require 'slack-config) ;; slack client via emacs-slack -(require 'eshell-vterm-config) ;; shell and terminal configuration +(require 'eshell-config) ;; emacs shell configuration +(require 'vterm-config) ;; vterm + F12 toggle + tmux history copy (require 'ai-vterm) ;; in-Emacs Claude launcher (vertical-split vterm) (require 'help-utils) ;; search: arch-wiki, devdoc, tldr, wikipedia (require 'help-config) ;; info, man, help config diff --git a/modules/cj-window-geometry.el b/modules/cj-window-geometry.el index 88fa83d4..53c1ea77 100644 --- a/modules/cj-window-geometry.el +++ b/modules/cj-window-geometry.el @@ -6,7 +6,7 @@ ;; Pure helpers for classifying a window's position in its frame and ;; computing body sizes. Shared between `ai-vterm.el' (F9 dispatch) -;; and `eshell-vterm-config.el' (F12 dispatch); the geometry- +;; and `vterm-config.el' (F12 dispatch); the geometry- ;; preservation pattern in both modules captures direction + body ;; size at toggle-off and replays them on the next toggle-on. ;; diff --git a/modules/cj-window-toggle.el b/modules/cj-window-toggle.el index 016b1967..2aa66ac9 100644 --- a/modules/cj-window-toggle.el +++ b/modules/cj-window-toggle.el @@ -5,7 +5,7 @@ ;;; Commentary: ;; Parameterized helpers used by ai-vterm.el (F9) and -;; eshell-vterm-config.el (F12) to capture a window's geometry at +;; vterm-config.el (F12) to capture a window's geometry at ;; toggle-off and replay it on the next toggle-on. Each consumer ;; holds its own pair of state variables (last-direction symbol + ;; last-size integer/float) and passes the variable symbols to the diff --git a/modules/eshell-config.el b/modules/eshell-config.el new file mode 100644 index 00000000..62b3a7ab --- /dev/null +++ b/modules/eshell-config.el @@ -0,0 +1,174 @@ +;;; eshell-config.el --- Settings for the Emacs Shell -*- lexical-binding: t; coding: utf-8; -*- +;; author Craig Jennings <c@cjennings.net> + +;;; Commentary: + +;; ESHELL +;; - Eshell is useful as a REPL +;; - Redirect to the kill ring : ls > /dev/kill +;; - Redirect to the clioboard : ls > /dev/clip +;; - Redirect to a buffer : ls > #<ls-output> +;; - Use elisp functions : write your own "detox" command in elisp +;; : then use it in eshell +;; - cd to remote directories : cd /sshx:c@cjennings.net:/home/cjennings +;; : and take all the elisp functionality remotely +;; : including Dired or Magit on a remote server + +;;; Code: + +(require 'system-utils) + +(use-package eshell + :ensure nil ;; built-in + :commands (eshell) + :config + (setq eshell-banner-message "") + (setq eshell-scroll-to-bottom-on-input 'all) + (setq eshell-error-if-no-glob t) + (setq eshell-hist-ignoredups t) + (setq eshell-save-history-on-exit t) + (setq eshell-prefer-lisp-functions nil) + (setq eshell-destroy-buffer-when-process-dies t) + + ;; no pagers required + (setenv "PAGER" "cat") + + (setq eshell-prompt-function + (lambda () + (concat + (propertize (format-time-string "[%d-%m-%y %T]") 'face '(:foreground "gray")) + " " + (propertize (user-login-name) 'face '(:foreground "gray")) + " " + (propertize (system-name) 'face '(:foreground "gray")) + ":" + (propertize (abbreviate-file-name (eshell/pwd)) 'face '(:foreground "gray")) + "\n" + (propertize "%" 'face '(:foreground "white")) + " "))) + + (add-hook + 'eshell-mode-hook + (lambda () + (setq pcomplete-cycle-completions nil))) + (setq eshell-cmpl-cycle-completions nil) + + (add-to-list 'eshell-modules-list 'eshell-tramp) + + (add-hook 'eshell-hist-mode-hook + (lambda () + (keymap-set eshell-hist-mode-map "<up>" #'previous-line) + (keymap-set eshell-hist-mode-map "<down>" #'next-line))) + + (add-hook 'eshell-mode-hook + (lambda () + (add-to-list 'eshell-visual-commands '("lf" "ranger" "tail" "htop" "gotop" "mc" "ncdu" "top")) + (add-to-list 'eshell-visual-subcommands '("git" "log" "diff" "show")) + (add-to-list 'eshell-visual-options '("git" "--help" "--paginate")) + + ;; aliases + (eshell/alias "e" "find-file $1") + (eshell/alias "em" "find-file $1") + (eshell/alias "emacs" "find-file $1") + (eshell/alias "open" "cj/xdg-open $1") + (eshell/alias "gocj" "cd /sshx:cjennings@cjennings.net:/var/cjennings/") + (eshell/alias "gosb" "cd /sshx:cjennings@wolf.usbx.me:/home/cjennings/") + (eshell/alias "gowolf" "cd /sshx:cjennings@wolf.usbx.me:/home/cjennings/") + (eshell/alias "v" "eshell-exec-visual $*") + (eshell/alias "ff" "find-file-other-window $1") + (eshell/alias "f" "find-using-dired $1") + (eshell/alias "r" "ranger") + (eshell/alias "ll" "ls -laF")))) + +(defun eshell/find-file-other-window (&rest files) + "Open FILE(s) in other window from eshell." + (if (= 1 (length files)) + ;; Single file - just use it directly + (find-file-other-window (car files)) + ;; Multiple files - open each in other window + (dolist (file files) + (find-file-other-window file)))) + +(defun eshell/find-file (&rest files) + "Open FILE(s) from eshell." + (if (= 1 (length files)) + ;; Single file + (find-file (car files)) + ;; Multiple files + (dolist (file files) + (find-file file)))) + +(defun eshell/clear () + "Clear the eshell buffer." + (let ((inhibit-read-only t)) + (erase-buffer) + (eshell-send-input))) + +(defun eshell/find-using-dired (file-pattern) + "Find a file matching FILE-PATTERN using `find-name-dired'." + (let ((escaped-pattern (regexp-quote file-pattern))) + (find-name-dired default-directory escaped-pattern))) + +(defun cj/eshell-delete-window-on-exit () + "Close the eshell window when exiting." + (when (not (one-window-p)) + (delete-window))) +(advice-add 'eshell-life-is-too-much :after 'cj/eshell-delete-window-on-exit) + +(use-package eshell-toggle + :custom + (eshell-toggle-size-fraction 2) + (eshell-toggle-run-command nil) + (eshell-toggle-init-function #'eshell-toggle-init-eshell) + :bind + ("C-<f12>" . eshell-toggle)) + +(use-package xterm-color + :after eshell + :hook + (eshell-before-prompt-hook . (lambda () + (setq xterm-color-preserve-properties t))) + :config + (setenv "TERM" "xterm-256color")) + +(use-package eshell-syntax-highlighting + :after esh-mode + :config + (eshell-syntax-highlighting-global-mode +1)) + +(use-package eshell-up + :after eshell + :config + (defalias 'eshell/up 'eshell-up) + (defalias 'eshell/up-peek 'eshell-up-peek)) + +;; Enhance history searching +(defun cj/eshell-history-search () + "Search eshell history with completion." + (interactive) + (insert + (completing-read "Eshell history: " + (delete-dups + (ring-elements eshell-history-ring))))) + +(add-hook 'eshell-mode-hook + (lambda () + (keymap-set eshell-mode-map "C-r" #'cj/eshell-history-search))) + +;; Better completion for eshell +(use-package pcmpl-args + :after eshell) + +;; Company mode integration for eshell +(use-package company-shell + :after (eshell company) + :config + (add-to-list 'company-backends 'company-shell) + (add-hook 'eshell-mode-hook + (lambda () + (setq-local company-minimum-prefix-length 2) + (setq-local company-idle-delay 2) + (company-mode 1)))) + +(provide 'eshell-config) +;;; eshell-config.el ends here. diff --git a/modules/eshell-vterm-config.el b/modules/vterm-config.el index 165e0437..8442c65f 100644 --- a/modules/eshell-vterm-config.el +++ b/modules/vterm-config.el @@ -1,19 +1,8 @@ -;;; eshell-vterm-config --- Settings for the Emacs Shell -*- lexical-binding: t; coding: utf-8; -*- +;;; vterm-config.el --- Settings for vterm and the F12 toggle -*- lexical-binding: t; coding: utf-8; -*- ;; author Craig Jennings <c@cjennings.net> ;;; Commentary: -;; ESHELL -;; - Eshell is useful as a REPL -;; - Redirect to the kill ring : ls > /dev/kill -;; - Redirect to the clioboard : ls > /dev/clip -;; - Redirect to a buffer : ls > #<ls-output> -;; - Use elisp functions : write your own "detox" command in elisp -;; : then use it in eshell -;; - cd to remote directories : cd /sshx:c@cjennings.net:/home/cjennings -;; : and take all the elisp functionality remotely -;; : including Dired or Magit on a remote server - ;; VTERM ;; At the moment, vterm behaves like a real terminal. For most keys, vterm will ;; just send them to the process that is currently running. So, C-a may be @@ -32,169 +21,11 @@ ;;; Code: -(require 'system-utils) (require 'keybindings) (require 'seq) (require 'subr-x) - -;; ------------------------------ Eshell ----------------------------- -;; the Emacs shell. - -(use-package eshell - :ensure nil ;; built-in - :commands (eshell) - :config - (setq eshell-banner-message "") - (setq eshell-scroll-to-bottom-on-input 'all) - (setq eshell-error-if-no-glob t) - (setq eshell-hist-ignoredups t) - (setq eshell-save-history-on-exit t) - (setq eshell-prefer-lisp-functions nil) - (setq eshell-destroy-buffer-when-process-dies t) - - ;; no pagers required - (setenv "PAGER" "cat") - - (setq eshell-prompt-function - (lambda () - (concat - (propertize (format-time-string "[%d-%m-%y %T]") 'face '(:foreground "gray")) - " " - (propertize (user-login-name) 'face '(:foreground "gray")) - " " - (propertize (system-name) 'face '(:foreground "gray")) - ":" - (propertize (abbreviate-file-name (eshell/pwd)) 'face '(:foreground "gray")) - "\n" - (propertize "%" 'face '(:foreground "white")) - " "))) - - (add-hook - 'eshell-mode-hook - (lambda () - (setq pcomplete-cycle-completions nil))) - (setq eshell-cmpl-cycle-completions nil) - - (add-to-list 'eshell-modules-list 'eshell-tramp) - - (add-hook 'eshell-hist-mode-hook - (lambda () - (keymap-set eshell-hist-mode-map "<up>" #'previous-line) - (keymap-set eshell-hist-mode-map "<down>" #'next-line))) - - (add-hook 'eshell-mode-hook - (lambda () - (add-to-list 'eshell-visual-commands '("lf" "ranger" "tail" "htop" "gotop" "mc" "ncdu" "top")) - (add-to-list 'eshell-visual-subcommands '("git" "log" "diff" "show")) - (add-to-list 'eshell-visual-options '("git" "--help" "--paginate")) - - ;; aliases - (eshell/alias "e" "find-file $1") - (eshell/alias "em" "find-file $1") - (eshell/alias "emacs" "find-file $1") - (eshell/alias "open" "cj/xdg-open $1") - (eshell/alias "gocj" "cd /sshx:cjennings@cjennings.net:/var/cjennings/") - (eshell/alias "gosb" "cd /sshx:cjennings@wolf.usbx.me:/home/cjennings/") - (eshell/alias "gowolf" "cd /sshx:cjennings@wolf.usbx.me:/home/cjennings/") - (eshell/alias "v" "eshell-exec-visual $*") - (eshell/alias "ff" "find-file-other-window $1") - (eshell/alias "f" "find-using-dired $1") - (eshell/alias "r" "ranger") - (eshell/alias "ll" "ls -laF")))) - -(defun eshell/find-file-other-window (&rest files) - "Open FILE(s) in other window from eshell." - (if (= 1 (length files)) - ;; Single file - just use it directly - (find-file-other-window (car files)) - ;; Multiple files - open each in other window - (dolist (file files) - (find-file-other-window file)))) - -(defun eshell/find-file (&rest files) - "Open FILE(s) from eshell." - (if (= 1 (length files)) - ;; Single file - (find-file (car files)) - ;; Multiple files - (dolist (file files) - (find-file file)))) - -(defun eshell/clear () - "Clear the eshell buffer." - (let ((inhibit-read-only t)) - (erase-buffer) - (eshell-send-input))) - -(defun eshell/find-using-dired (file-pattern) - "Find a file matching FILE-PATTERN using `find-name-dired'." - (let ((escaped-pattern (regexp-quote file-pattern))) - (find-name-dired default-directory escaped-pattern))) - -(defun cj/eshell-delete-window-on-exit () - "Close the eshell window when exiting." - (when (not (one-window-p)) - (delete-window))) -(advice-add 'eshell-life-is-too-much :after 'cj/eshell-delete-window-on-exit) - -(use-package eshell-toggle - :custom - (eshell-toggle-size-fraction 2) - (eshell-toggle-run-command nil) - (eshell-toggle-init-function #'eshell-toggle-init-eshell) - :bind - ("C-<f12>" . eshell-toggle)) - -(use-package xterm-color - :after eshell - :hook - (eshell-before-prompt-hook . (lambda () - (setq xterm-color-preserve-properties t))) - :config - (setenv "TERM" "xterm-256color")) - -(use-package eshell-syntax-highlighting - :after esh-mode - :config - (eshell-syntax-highlighting-global-mode +1)) - -(use-package eshell-up - :after eshell - :config - (defalias 'eshell/up 'eshell-up) - (defalias 'eshell/up-peek 'eshell-up-peek)) - -;; Enhance history searching -(defun cj/eshell-history-search () - "Search eshell history with completion." - (interactive) - (insert - (completing-read "Eshell history: " - (delete-dups - (ring-elements eshell-history-ring))))) - -(add-hook 'eshell-mode-hook - (lambda () - (keymap-set eshell-mode-map "C-r" #'cj/eshell-history-search))) - -;; Better completion for eshell -(use-package pcmpl-args - :after eshell) - -;; Company mode integration for eshell -(use-package company-shell - :after (eshell company) - :config - (add-to-list 'company-backends 'company-shell) - (add-hook 'eshell-mode-hook - (lambda () - (setq-local company-minimum-prefix-length 2) - (setq-local company-idle-delay 2) - (company-mode 1)))) - - -;; ------------------------------ Vterm ------------------------------ -;; faster and highly dependable, but not extensible +(require 'cj-window-geometry) +(require 'cj-window-toggle) (defvar-keymap cj/vterm-map :doc "Personal vterm command map.") @@ -393,11 +224,6 @@ ai-vterm.el is loaded." ;; frame-edge directions and `(body-columns . N)' / `(body-lines . N)' ;; so the result is divider-independent and layout-stable. -(require 'cl-lib) -(require 'seq) -(require 'cj-window-geometry) -(require 'cj-window-toggle) - (defcustom cj/vterm-toggle-window-height 0.7 "Default fraction of frame height for the F12 vterm window. Used as the size fallback when `cj/--vterm-toggle-last-size' is nil @@ -569,5 +395,5 @@ C-F9 / M-F9 dispatch via `cj/ai-vterm'." "C-; V r" "reset vterm cursor point" "C-; V t" "toggle vterm")) -(provide 'eshell-vterm-config) -;;; eshell-vterm-config.el ends here. +(provide 'vterm-config) +;;; vterm-config.el ends here. diff --git a/tests/test-vterm-tmux-history.el b/tests/test-vterm-tmux-history.el index 33fa1330..754ddc9c 100644 --- a/tests/test-vterm-tmux-history.el +++ b/tests/test-vterm-tmux-history.el @@ -15,7 +15,7 @@ (defvar vterm-mode-map (make-sparse-keymap)) (defvar vterm-copy-mode-map (make-sparse-keymap)) (keymap-set vterm-mode-map "C-c C-t" #'ignore) -(require 'eshell-vterm-config) +(require 'vterm-config) (require 'testutil-vterm-buffers) (defmacro test-vterm-tmux-history--with-tmux-mock (responses &rest body) diff --git a/tests/test-vterm-toggle--buffer-filter.el b/tests/test-vterm-toggle--buffer-filter.el index 96681461..82afe756 100644 --- a/tests/test-vterm-toggle--buffer-filter.el +++ b/tests/test-vterm-toggle--buffer-filter.el @@ -13,7 +13,7 @@ (add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) (add-to-list 'load-path (expand-file-name "tests" user-emacs-directory)) -(require 'eshell-vterm-config) +(require 'vterm-config) (require 'testutil-vterm-buffers) (defun test-vterm-toggle--cleanup () diff --git a/tests/test-vterm-toggle--dispatch.el b/tests/test-vterm-toggle--dispatch.el index 93c06467..7e87f2b1 100644 --- a/tests/test-vterm-toggle--dispatch.el +++ b/tests/test-vterm-toggle--dispatch.el @@ -14,7 +14,7 @@ (add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) (add-to-list 'load-path (expand-file-name "tests" user-emacs-directory)) -(require 'eshell-vterm-config) +(require 'vterm-config) (require 'testutil-vterm-buffers) (ert-deftest test-vterm-toggle--dispatch-window-displayed-returns-toggle-off () diff --git a/tests/test-vterm-toggle--display.el b/tests/test-vterm-toggle--display.el index ed7cd858..69bf2360 100644 --- a/tests/test-vterm-toggle--display.el +++ b/tests/test-vterm-toggle--display.el @@ -14,7 +14,7 @@ (require 'cl-lib) (add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) -(require 'eshell-vterm-config) +(require 'vterm-config) (ert-deftest test-vterm-toggle--capture-state-records-direction-and-size () "Normal: capture-state writes direction and integer body size." |
