summary refs log tree commit diff
diff options
context:
space:
mode:
authorFranck Cuny <franck.cuny@gmail.com>2016-10-26 15:47:03 -0700
committerFranck Cuny <franck.cuny@gmail.com>2016-10-26 15:47:03 -0700
commit18c95780c50b5a4a756dda9663167d5a793c19f3 (patch)
treea85e91e9272b9c0745ab5b52895955d2101ee1f9
parent[emacs] Some changes to the UI. (diff)
downloademacs.d-18c95780c50b5a4a756dda9663167d5a793c19f3.tar.gz
[emacs] Add configuration to manage terminals.
Manage my terminals in emacs. A few functions to quickly create new
buffers and one to switch between them.
-rw-r--r--emacs.d/init.el36
1 files changed, 36 insertions, 0 deletions
diff --git a/emacs.d/init.el b/emacs.d/init.el
index fdddbc1..0052749 100644
--- a/emacs.d/init.el
+++ b/emacs.d/init.el
@@ -236,6 +236,42 @@
 ;;     (dolist (var '("GEM_HOME" "MY_RUBY_HOME"))
 ;;       (unless (getenv var)
 ;;         (exec-path-from-shell-copy-env var))))
+(use-package term
+  :bind (("C-x t" . fc/open-term)
+         ("C-x m" . fc/switch-to-term-buffer))
+  :config
+  (progn
+    (defun fc/make-term (new-buffer-name cmd &rest switches)
+      (setq term-ansi-buffer-name (concat "<" new-buffer-name ">"))
+      (setq term-ansi-buffer-name (generate-new-buffer-name term-ansi-buffer-name))
+      (setq term-ansi-buffer-name (apply 'make-term term-ansi-buffer-name cmd nil switches))
+      (set-buffer term-ansi-buffer-name)
+      (term-mode)
+      (term-char-mode)
+      (term-set-escape-char ?\C-x)
+      (switch-to-buffer term-ansi-buffer-name))
+
+    (defun fc/open-term (name)
+      (interactive "sName: ")
+      (fc/make-term name "bash"))
+
+    (defun fc/list-term-buffers ()
+      "Returns a list of term buffers"
+      (delq nil
+            (mapcar (lambda(x)
+                      (set-buffer x)
+                      (when (string= major-mode "term-mode")
+                        (buffer-name)))
+                    (buffer-list))))
+
+    (defun fc/switch-to-term-buffer ()
+      "Switch to a term buffer."
+      (interactive)
+      (let ((collection (fc/list-term-buffers)))
+        (ivy-read "term buffers:" collection
+                  :action (lambda (x) (switch-to-buffer x))
+                  :caller 'fc/find-term-buffers)))))
+
 
 ;; some bindings
 (global-set-key (kbd "M-j") 'join-line)