2019-05-21 02:24:36 +02:00
|
|
|
;;; evil-collection-vterm.el --- Bindings for `vterm'. -*- lexical-binding: t -*-
|
|
|
|
|
|
|
|
;; Copyright (C) 2019 James Nguyen
|
|
|
|
|
|
|
|
;; Author: James Nguyen <james@jojojames.com>
|
|
|
|
;; Maintainer: James Nguyen <james@jojojames.com>
|
|
|
|
;; Pierre Neidhardt <mail@ambrevar.xyz>
|
|
|
|
;; URL: https://github.com/emacs-evil/evil-collection
|
|
|
|
;; Version: 0.0.1
|
|
|
|
;; Package-Requires: ((emacs "25.1"))
|
|
|
|
;; Keywords: evil, vterm, tools
|
|
|
|
|
|
|
|
;; This program is free software; you can redistribute it and/or modify
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
|
|
;; This program is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
;;; Bindings for `vterm'.
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
(require 'evil-collection)
|
|
|
|
(require 'vterm nil t)
|
|
|
|
|
|
|
|
(defconst evil-collection-vterm-maps '(vterm-mode-map))
|
|
|
|
|
|
|
|
(defun evil-collection-vterm-escape-stay ()
|
|
|
|
"Go back to normal state but don't move cursor backwards.
|
|
|
|
Moving cursor backwards is the default vim behavior but
|
|
|
|
it is not appropriate in some cases like terminals."
|
|
|
|
(setq-local evil-move-cursor-back nil))
|
|
|
|
|
2019-05-21 02:35:04 +02:00
|
|
|
(defun evil-collection-vterm-exit-function (buffer)
|
|
|
|
"Automatically kill `vterm' buffer on exit."
|
|
|
|
(when buffer
|
|
|
|
(kill-buffer buffer)))
|
|
|
|
|
2019-05-22 03:34:38 +02:00
|
|
|
(defun evil-collection-vterm-send-return ()
|
|
|
|
"Sends C-m to the libvterm.
|
|
|
|
|
|
|
|
Credits: https://github.com/akermu/emacs-libvterm/pull/70"
|
|
|
|
(interactive)
|
|
|
|
(process-send-string vterm--process "\C-m"))
|
|
|
|
|
2019-05-21 02:24:36 +02:00
|
|
|
;;;###autoload
|
|
|
|
(defun evil-collection-vterm-setup ()
|
|
|
|
"Set up `evil' bindings for `vterm'."
|
|
|
|
(evil-set-initial-state 'vterm-mode 'insert)
|
|
|
|
|
|
|
|
(add-hook 'vterm-mode-hook #'evil-collection-vterm-escape-stay)
|
2019-05-21 02:35:04 +02:00
|
|
|
(add-hook 'vterm-exit-functions #'evil-collection-vterm-exit-function)
|
2019-05-21 02:24:36 +02:00
|
|
|
|
2019-05-22 03:34:38 +02:00
|
|
|
;; FIXME: Remove this once https://github.com/akermu/emacs-libvterm/pull/70
|
|
|
|
;; is in.
|
|
|
|
(evil-collection-define-key 'insert 'vterm-mode-map [return] #'evil-collection-vterm-send-return)
|
|
|
|
|
2019-05-21 02:24:36 +02:00
|
|
|
;; Evil has some "C-" bindings in insert state that shadow regular terminal
|
|
|
|
;; bindings. Don't raw-send "C-c" (prefix key) nor "C-h" (help prefix).
|
|
|
|
(evil-collection-define-key 'insert 'vterm-mode-map
|
|
|
|
(kbd "C-a") 'vterm--self-insert
|
2019-05-21 02:35:22 +02:00
|
|
|
(kbd "C-b") 'vterm--self-insert ; Should not be necessary.
|
2019-05-21 02:24:36 +02:00
|
|
|
(kbd "C-d") 'vterm--self-insert
|
|
|
|
(kbd "C-e") 'vterm--self-insert
|
2019-05-21 02:35:22 +02:00
|
|
|
(kbd "C-f") 'vterm--self-insert ; Should not be necessary.
|
2019-05-21 02:24:36 +02:00
|
|
|
(kbd "C-k") 'vterm--self-insert
|
2019-05-21 02:35:22 +02:00
|
|
|
(kbd "C-l") 'vterm--self-insert ; Should not be necessary.
|
2019-05-21 02:24:36 +02:00
|
|
|
(kbd "C-n") 'vterm--self-insert
|
|
|
|
(kbd "C-o") 'vterm--self-insert
|
|
|
|
(kbd "C-p") 'vterm--self-insert
|
2019-05-21 02:35:22 +02:00
|
|
|
(kbd "C-q") 'vterm--self-insert ; Should not be necessary.
|
2019-05-21 02:24:36 +02:00
|
|
|
(kbd "C-r") 'vterm--self-insert
|
2019-05-21 02:35:22 +02:00
|
|
|
(kbd "C-s") 'vterm--self-insert ; Should not be necessary.
|
2019-05-21 02:24:36 +02:00
|
|
|
(kbd "C-t") 'vterm--self-insert
|
2019-05-21 02:35:22 +02:00
|
|
|
(kbd "C-u") 'vterm--self-insert ; Should not be necessary.
|
|
|
|
(kbd "C-v") 'vterm--self-insert ; Should not be necessary.
|
2019-05-21 02:24:36 +02:00
|
|
|
(kbd "C-w") 'vterm--self-insert
|
|
|
|
(kbd "C-y") 'vterm--self-insert
|
|
|
|
(kbd "C-z") 'vterm--self-insert)
|
|
|
|
|
|
|
|
(evil-collection-define-key 'normal 'vterm-mode-map
|
|
|
|
"p" 'vterm-yank
|
|
|
|
"u" 'vterm-undo))
|
|
|
|
|
|
|
|
(provide 'evil-collection-vterm)
|
|
|
|
;;; evil-collection-vterm.el ends here
|