This repository has been archived by the owner on Oct 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
terminal-toggle.el
84 lines (64 loc) · 2.41 KB
/
terminal-toggle.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
82
83
;;; terminal-toggle.el --- simple pop-up terminal -*- lexical-binding: t; -*-
;; Copright (C) 2019 Mehmet Tekman <[email protected]>
;; Author: Mehmet Tekman
;; URL: https://github.com/mtekman/terminal-toggle.el
;; Keywords: outlines
;; Package-Requires: ((emacs "24") (popwin "1.0.0"))
;; Version: 0.1
;;; Commentary:
;; A simple terminal that pops-up (bottom/top/left/right) and then removes
;; itself when it loses focus without killing the buffer. Essentially it is
;; a simple hide/show for a terminal.
;;; Code:
(require 'popwin)
(defgroup terminal-toggle nil
"Group for setting terminal options"
:prefix "terminal-toggle-"
:group 'emacs)
(defcustom terminal-toggle--term-title "myterm"
"Name of buffer to hide/show."
:type 'string
:group 'terminal-toggle)
(defcustom terminal-toggle--term-command "ansi-term"
"Terminal command to launch."
:type 'string
:group 'terminal-toggle)
(defcustom terminal-toggle--term-shell "/usr/bin/zsh"
"Terminal shell to launch."
:type 'string
:group 'terminal-toggle)
(defconst terminal-toggle--term-name
(if (and (string= (substring terminal-toggle--term-title 0 1) "*")
(string= (substring terminal-toggle--term-title -1) "*"))
terminal-toggle--term-title
(concat "*" terminal-toggle--term-title "*"))
"Internal buffer name with asterisks.")
(defun terminal-toggle-is-open ()
"Terminal exists."
(get-buffer terminal-toggle--term-name))
(defun terminal-toggle-is-showing ()
"Terminal state (whether is visible)."
(get-buffer-window terminal-toggle--term-name))
(defun terminal-toggle-launch ()
"Launch ansi terminal."
(funcall (intern terminal-toggle--term-command) terminal-toggle--term-shell
(substring terminal-toggle--term-name 1 -1))
(switch-to-buffer (other-buffer (current-buffer) 1)))
(defun terminal-toggle-set-visible ()
"Show an already opened terminal."
(popwin:popup-buffer terminal-toggle--term-name))
(defun terminal-toggle-set-hidden ()
"Hide the terminal."
(delete-window (get-buffer-window terminal-toggle--term-name)))
;;;###autoload
(defun terminal-toggle ()
"Show/launch or hide terminal."
(interactive)
(if (terminal-toggle-is-open)
(if (terminal-toggle-is-showing)
(terminal-toggle-set-hidden)
(terminal-toggle-set-visible))
(progn (terminal-toggle-launch)
(terminal-toggle-set-visible))))
(provide 'terminal-toggle)
;;; terminal-toggle.el ends here