Commit af08a38b authored by Duncan Bayne's avatar Duncan Bayne

Improve terminal handling

parent 0701b7f9
......@@ -373,4 +373,4 @@
(load "~/.emacs.d/personal.el"))
;; quickly spawn new terms
(global-set-key (kbd "C-x c") 'duncans_emacs:create-terminal)
(global-set-key (kbd "C-x c") 'duncans_emacs:create-or-switch-to-terminal)
......@@ -34,14 +34,14 @@
(term-send-raw-string (concat "cd " new-directory "\n"))))))
(buffer-list)))
(defun duncans_emacs:create-terminal (terminal-name)
"Creates a named terminal."
(interactive (list (read-string "Name: ")))
(defun duncans_emacs:create-or-switch-to-terminal (terminal-name)
"Creates or switches to a named terminal, earmuffing the name if it isn't already."
(interactive (list (ido-completing-read "Buffer name: " (duncans_emacs:term-buffer-names))))
(if (string= "" terminal-name)
(message "Refusing to create buffer with empty name")
(let ((new-buffer-name (concat "*" terminal-name "*")))
(let ((new-buffer-name (duncans_emacs:earmuff-name terminal-name)))
(if (get-buffer new-buffer-name)
(message "Refusing to create buffer with duplicate name")
(switch-to-buffer new-buffer-name)
(progn
(require 'multi-term)
(setq multi-term-program "/usr/bin/zsh")
......@@ -55,9 +55,18 @@
(setq multi-term-program "/usr/bin/zsh")
(mapcar
(lambda (desired-name)
(duncans_emacs:create-terminal desired-name))
(duncans_emacs:create-or-switch-to-terminal desired-name))
terminal-names))
(defun duncans_emacs:earmuff-name (name)
"Surrounds name with earmuffs, if it isn't already."
(let ((new-name name))
(if (not (string-prefix-p "*" new-name))
(setq new-name (concat "*" new-name)))
(if (not (string-suffix-p "*" new-name))
(setq new-name (concat new-name "*")))
new-name))
(defun duncans_emacs:kill-unmodified-buffers ()
"Kill any unmodifier buffers that are inspecting files."
(interactive)
......@@ -76,4 +85,20 @@
(cons (cons filename-pattern mode) auto-mode-alist)))
filename-pattern-list))
(defun duncans_emacs:term-buffers ()
"Returns all buffers that are terminals."
(remove-if-not
#'nil
(mapcar
(lambda (buffer) (if (duncans_emacs:term-p buffer) buffer nil))
(buffer-list))))
(defun duncans_emacs:term-buffer-names ()
"Returns the names of all buffers that are terminals."
(mapcar #'buffer-name (duncans_emacs:term-buffers)))
(defun duncans_emacs:term-p (buffer)
"Returns t if buffer is a terminal, nil otherwise."
(equal 'term-mode (buffer-local-value 'major-mode buffer)))
(provide 'duncans_emacs)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment