-
Notifications
You must be signed in to change notification settings - Fork 3
/
idee-vterm.el
81 lines (67 loc) · 3.18 KB
/
idee-vterm.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
;; idee-vterm.el --- Vterm integration -*- lexical-binding: t -*-
;; Copyright (C) 2018 Ioannis Canellos
;; Licensed under the Apache License, Version 2.0 (the "License");
;; you may not use this file except in compliance with the License.
;; You may obtain a copy of the License at
;; http://www.apache.org/licenses/LICENSE-2.0
;;Unless required by applicable law or agreed to in writing, software
;;distributed under the License is distributed on an "AS IS" BASIS,
;;WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;;See the License for the specific language governing permissions and
;;limitations under the License.
;; Author: Ioannis Canellos
;;; Commentary:
;;; Code:
(require 'projectile)
;;;###autoload
(defun idee/vterm-open-in-project ()
"Open vterm in project root."
(interactive)
(require 'vterm)
(let* ((name (format "*vterm %s*" (projectile-project-name)))
(buf (get-buffer name))
(window (if buf (get-buffer-window buf) nil))
(default-directory (projectile-project-root)))
(cond (window (progn
(select-window window)))
(buf (progn
(idee/split-and-follow-vertically)
(set-window-buffer (get-buffer-window) buf)))
(t (progn
(vterm)
(rename-buffer name))))))
;;;###autoload
(defun idee/vterm-command-execute-in-project (command &optional new-shell)
"Run a single COMMAND in the current project shell.
When NEW-SHELL is specified the old eshell project buffer is killed."
(require 'vterm)
(let* ((name (format "*vterm %s*" (projectile-project-name)))
(buf (get-buffer name))
(comint-scroll-to-bottom-on-output t))
(when (and buf new-shell)
;; Let's didsable the process-kill-buffer-query-function before we kill the buffer
;; or we are going to get a very annoyng message.
(let ((kill-buffer-query-functions (delq 'process-kill-buffer-query-function kill-buffer-query-functions)))
(kill-buffer buf)))
(idee/vterm-open-in-project)
(when (not (idee/string-blank command))
(vterm-insert command))
(vterm-send-return)))
;;;###autoload
(defun idee/vterm-visible-window ()
"Return the visible vterm window."
(car (idee/windows-visible-get (lambda (b) (string-prefix-p "*vterm" (buffer-name b))))))
;;;###autoload
(defun idee/vterm-enable ()
"Enable vterm."
(interactive)
;;Clear existing associations
(setq idee/function-alist (delq (assoc 'idee/shell-command-execute-in-project-function idee/function-alist) idee/function-alist))
(setq idee/function-alist (delq (assoc 'idee/shell-visible-window-function idee/function-alist) idee/function-alist))
(setq idee/function-alist (delq (assoc 'idee/shell-open-in-project-function idee/function-alist) idee/function-alist))
;; Register vterm functions
(add-to-list 'idee/function-alist '(idee/shell-command-execute-in-project-function . idee/vterm-command-execute-in-project))
(add-to-list 'idee/function-alist '(idee/shell-visible-window-function . idee/vterm-visible-window))
(add-to-list 'idee/function-alist '(idee/shell-open-in-project-function . idee/vterm-open-in-project)))
(provide 'idee-vterm)
;;; idee-vterm.el ends here