2019-07-21 00:37:46 +02:00
|
|
|
;;; terminal.el --- Module file for terminal configuration.
|
2017-08-30 01:14:25 +01:00
|
|
|
;;
|
2019-07-21 00:37:46 +02:00
|
|
|
;; Copyright (C) 2017-2019 Wojciech Kozlowski
|
2017-08-30 01:14:25 +01:00
|
|
|
;;
|
2018-02-04 17:18:18 +00:00
|
|
|
;; Author: Wojciech Kozlowski <wk@wojciechkozlowski.eu>
|
2019-07-21 00:37:46 +02:00
|
|
|
;; Created: 2017-08-28
|
2017-08-30 01:14:25 +01:00
|
|
|
;;
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
;;
|
|
|
|
;;; Commentary:
|
|
|
|
;;
|
|
|
|
;; This module sets up packages and configuration for working with a terminal
|
|
|
|
;; in Emacs.
|
|
|
|
;;
|
|
|
|
;;; License: GPLv3
|
|
|
|
|
|
|
|
;;; Required packages:
|
|
|
|
|
2018-07-07 21:34:00 +01:00
|
|
|
;;; Code:
|
2017-08-30 01:14:25 +01:00
|
|
|
|
2019-07-21 00:37:46 +02:00
|
|
|
(defvar emodule/terminal-packages
|
2017-08-30 01:14:25 +01:00
|
|
|
|
2019-08-07 12:10:37 +02:00
|
|
|
'(vterm)
|
2018-07-07 21:34:00 +01:00
|
|
|
|
|
|
|
)
|
2017-08-30 01:14:25 +01:00
|
|
|
|
|
|
|
;; Configuration:
|
|
|
|
|
2019-07-21 00:37:46 +02:00
|
|
|
(defun emodule/terminal-init ()
|
|
|
|
"Initialise the `terminal' module."
|
2017-08-30 01:14:25 +01:00
|
|
|
|
2018-02-08 06:55:21 +00:00
|
|
|
;; --------------------------------------------------------------------------
|
2019-07-21 00:37:46 +02:00
|
|
|
;; `eshell'
|
2018-02-08 06:55:21 +00:00
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
|
2018-02-09 19:25:25 +00:00
|
|
|
(use-package eshell
|
2018-02-11 21:01:12 +00:00
|
|
|
:config
|
|
|
|
(defun eshell-pop (name)
|
|
|
|
"Launch terminal in (preferably) other window."
|
|
|
|
(let ((esh-buf nil)
|
|
|
|
(cur-buf (current-buffer)))
|
|
|
|
(setq esh-buf (eshell name))
|
|
|
|
(switch-to-buffer cur-buf)
|
|
|
|
(switch-to-buffer-other-window esh-buf)))
|
|
|
|
|
2018-02-09 19:25:25 +00:00
|
|
|
(defun eshell-here ()
|
|
|
|
(interactive)
|
2018-02-11 21:01:12 +00:00
|
|
|
(let* ((parent default-directory)
|
2018-02-09 19:25:25 +00:00
|
|
|
(name (car
|
|
|
|
(last
|
2018-02-11 21:01:12 +00:00
|
|
|
(split-string parent "/" t))))
|
|
|
|
(esh-buf-name (concat "*eshell: " name "*"))
|
|
|
|
(is-esh (string= "eshell-mode" major-mode))
|
|
|
|
(esh-buf (first-matching-buffer esh-buf-name)))
|
|
|
|
|
|
|
|
(unless is-esh
|
|
|
|
(if esh-buf
|
|
|
|
(switch-to-buffer-other-window esh-buf)
|
|
|
|
(progn
|
|
|
|
(eshell-pop "new")
|
|
|
|
(rename-buffer esh-buf-name))))
|
2018-02-09 19:25:25 +00:00
|
|
|
|
|
|
|
(insert (concat "ls"))
|
|
|
|
(eshell-send-input)))
|
|
|
|
|
|
|
|
(defun delete-single-window (&optional window)
|
|
|
|
"Remove WINDOW from the display. Default is `selected-window'.
|
|
|
|
If WINDOW is the only one in its frame, then `delete-frame' too."
|
|
|
|
(interactive)
|
|
|
|
(save-current-buffer
|
|
|
|
(setq window (or window (selected-window)))
|
|
|
|
(select-window window)
|
|
|
|
(kill-buffer)
|
|
|
|
(if (one-window-p t)
|
|
|
|
(delete-frame)
|
|
|
|
(delete-window (selected-window)))))
|
|
|
|
|
|
|
|
(defun eshell/x (&rest args)
|
|
|
|
(delete-single-window))
|
|
|
|
|
|
|
|
(defun eshell-setup ()
|
|
|
|
(interactive)
|
|
|
|
(define-key eshell-mode-map (kbd "C-0") 'delete-window))
|
|
|
|
|
|
|
|
(add-hook 'eshell-mode-hook 'eshell-setup t)
|
|
|
|
|
2018-02-11 21:01:12 +00:00
|
|
|
(global-set-key (kbd "C-x /") 'eshell-here))
|
2018-02-11 18:06:17 +00:00
|
|
|
|
|
|
|
(use-package em-smart
|
|
|
|
:config
|
|
|
|
(setq eshell-where-to-jump 'begin)
|
|
|
|
(setq eshell-review-quick-commands nil)
|
|
|
|
(setq eshell-smart-space-goes-to-end t))
|
|
|
|
|
|
|
|
(use-package em-term
|
|
|
|
:config
|
|
|
|
(setq eshell-visual-commands (nconc eshell-visual-commands '("htop"
|
|
|
|
"tmux"))))
|
|
|
|
|
2019-07-21 22:08:29 +02:00
|
|
|
;; --------------------------------------------------------------------------
|
2019-08-07 12:10:37 +02:00
|
|
|
;; `vterm'
|
2019-07-21 22:08:29 +02:00
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
|
2019-08-07 12:10:37 +02:00
|
|
|
(use-package vterm
|
|
|
|
:init
|
|
|
|
(setq vterm-shell "/bin/zsh"
|
|
|
|
vterm-max-scrollback 10000)
|
|
|
|
|
|
|
|
(defun x-vterm-setup ()
|
|
|
|
(define-key vterm-mode-map
|
2019-12-15 16:03:52 +01:00
|
|
|
[remap whole-line-or-region-yank] 'vterm-yank)
|
2019-12-15 16:54:55 +01:00
|
|
|
(define-key vterm-mode-map (kbd "C-S-v") 'vterm-yank)
|
|
|
|
|
|
|
|
(define-key vterm-mode-map
|
|
|
|
[remap scroll-up-command] 'vterm--self-insert)
|
|
|
|
(define-key vterm-mode-map
|
|
|
|
[remap scroll-down-command] 'vterm--self-insert))
|
2019-08-07 12:10:37 +02:00
|
|
|
|
|
|
|
(defun x-vterm-recycle ()
|
|
|
|
"Kill current buffer and start a vterm in it."
|
|
|
|
(let ((working-directory default-directory))
|
|
|
|
(kill-buffer (current-buffer))
|
|
|
|
(let ((default-directory working-directory))
|
|
|
|
(vterm))))
|
|
|
|
|
2019-12-15 16:03:52 +01:00
|
|
|
(defun x-vterm-other-window ()
|
|
|
|
"Start vterm in other window unless in initial buffer."
|
|
|
|
(interactive)
|
|
|
|
(if (equal major-mode 'init-buffer-mode)
|
|
|
|
(vterm)
|
|
|
|
(vterm-other-window)))
|
|
|
|
|
2019-08-07 12:10:37 +02:00
|
|
|
(defun visit-vterm ()
|
|
|
|
"Open or switch to active vterm.
|
|
|
|
If current buffer is a vterm:
|
|
|
|
If it is running
|
|
|
|
Open a new vterm in a new window
|
|
|
|
If it is not running
|
|
|
|
Recycle (kill buffer, restart vterm)
|
|
|
|
If current buffer is not a vterm:
|
|
|
|
If a buffer in vterm-mode exists
|
|
|
|
Switch to that buffer in other window
|
|
|
|
Recycle if necessary
|
|
|
|
If it does not exist
|
|
|
|
Open a new vterm in a new window"
|
|
|
|
(interactive)
|
|
|
|
(if (string= "vterm-mode" major-mode)
|
|
|
|
(if (term-check-proc (buffer-name))
|
|
|
|
(vterm-other-window)
|
|
|
|
(x-vterm-recycle))
|
|
|
|
(let ((anon-term (seq-find (lambda (buffer)
|
|
|
|
(with-current-buffer buffer
|
|
|
|
(string= "vterm-mode" major-mode)))
|
|
|
|
(buffer-list))))
|
|
|
|
(if anon-term
|
|
|
|
(progn
|
2019-12-15 16:03:52 +01:00
|
|
|
(if (equal major-mode 'init-buffer-mode)
|
|
|
|
(switch-to-buffer anon-term)
|
|
|
|
(switch-to-buffer-other-window anon-term))
|
2019-08-07 12:10:37 +02:00
|
|
|
(unless (term-check-proc (buffer-name))
|
|
|
|
(x-vterm-recycle)))
|
2019-12-15 16:03:52 +01:00
|
|
|
(x-vterm-other-window)))))
|
2019-08-07 12:10:37 +02:00
|
|
|
|
|
|
|
:hook
|
|
|
|
(vterm-mode . x-vterm-setup)
|
|
|
|
:bind
|
|
|
|
(("C-x '" . visit-vterm)))
|
2019-07-21 22:08:29 +02:00
|
|
|
|
2017-08-30 01:14:25 +01:00
|
|
|
)
|
2018-07-07 21:34:00 +01:00
|
|
|
|
2019-07-21 00:37:46 +02:00
|
|
|
(provide 'emodule/terminal)
|
|
|
|
;;; terminal.el ends here
|