├── LICENSE.txt ├── README.md └── sane-term.el /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014, 2015 Adam Patterson 2 | 3 | Permission to use, copy, modify, and/or distribute this software for any purpose 4 | with or without fee is hereby granted, provided that the above copyright notice 5 | and this permission notice appear in all copies. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 8 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND 9 | FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 10 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS 11 | OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 12 | TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF 13 | THIS SOFTWARE. 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### Notice 2 | This project is no longer maintained. I've switched to `vterm` and 3 | `multi-vterm` which provide the same functionality as `ansi-term` and 4 | this package, respectively. 5 | 6 | # Sane Term 7 | 8 | sane-term is ansi-term with sane options and the ability to cycle/create terms. 9 | 10 | __Overview__ 11 | 12 | * `sane-term` will cycle through term buffers, creating one if there are none. 13 | * `sane-term-create` will create a new term buffer. 14 | 15 | __Setup__ 16 | 17 | ```emacs 18 | (use-package sane-term 19 | :ensure t 20 | :bind ( 21 | ("C-x t" . sane-term) 22 | ("C-x T" . sane-term-create))) 23 | ``` 24 | 25 | __Variables__ 26 | 27 | * `sane-term-shell-command` [`$SHELL or "/bin/sh"`] - shell to use for sane-term. 28 | * `sane-term-initial-create` [`t`] - `sane-term` will create first term if none exist. 29 | * `sane-term-kill-on-exit` [`t`] - C-d or `exit` will kill the term buffer. 30 | * `sane-term-next-on-kill` [`t`] - After killing a term buffer, cycle to another. 31 | 32 | __Common Issues__ 33 | 34 | When you start a term you may find your environment variables are not set. This is the proper, yet unexpected behavior. You can read about it here https://github.com/adamrt/sane-term/issues/6 but the gist is that your `~/.profile` is not being read. Non-login shells read from `~/.bashrc` instead. Put the following in your `~/.bashrc` (create it if necessary). 35 | 36 | ``` 37 | source /etc/profile 38 | source ~/.profile 39 | ``` 40 | -------------------------------------------------------------------------------- /sane-term.el: -------------------------------------------------------------------------------- 1 | ;;; sane-term.el --- Multi Term is crazy. This is not. 2 | 3 | ;; Copyright (C) 2018 Adam Patterson 4 | 5 | ;; Author: Adam Patterson 6 | ;; URL: http://github.com/adamrt/sane-term 7 | ;; Version: 0.6 8 | ;; Package-Requires: ((emacs "24.1")) 9 | 10 | ;;; Commentary: 11 | 12 | ;; You can set it up like this: 13 | 14 | ;; (use-package sane-term 15 | ;; :ensure t 16 | ;; :bind (("C-x t" . sane-term) 17 | ;; ("C-x T" . sane-term-create))) 18 | 19 | ;;; Code: 20 | 21 | (defgroup sane-term nil 22 | "Multi Term is crazy. This is not." 23 | :group 'term) 24 | 25 | (defcustom sane-term-shell-command (or (getenv "SHELL") 26 | "/bin/sh") 27 | "Specify which shell to use." 28 | :type 'string 29 | :group 'sane-term) 30 | 31 | (defcustom sane-term-initial-create t 32 | "Creates a term if one doesn't exist." 33 | :type 'boolean 34 | :group 'sane-term) 35 | 36 | (defcustom sane-term-kill-on-exit t 37 | "Kill term buffer on exit (C-d or `exit`)." 38 | :type 'boolean 39 | :group 'sane-term) 40 | 41 | (defcustom sane-term-next-on-kill t 42 | "When killing a term buffer, go to the next one. 43 | Depends on sane-term-kill-on-exit." 44 | :type 'boolean 45 | :group 'sane-term) 46 | 47 | (defun sane-term-buffer-exists-p () 48 | "Boolean if term-mode buffers exist." 49 | (catch 'loop 50 | (dolist (buf (buffer-list)) 51 | (with-current-buffer buf 52 | (when (derived-mode-p 'term-mode) 53 | (throw 'loop t)))))) 54 | 55 | (defun sane-term-cycle (reverse) 56 | (unless reverse 57 | (when (derived-mode-p 'term-mode) 58 | (bury-buffer))) 59 | (let ((buffers (buffer-list))) 60 | (when reverse 61 | (setq buffers (nreverse buffers))) 62 | (catch 'loop 63 | (dolist (buf buffers) 64 | (when (with-current-buffer buf (derived-mode-p 'term-mode)) 65 | (switch-to-buffer buf) 66 | (throw 'loop nil)))))) 67 | 68 | (defun sane-term-prev () 69 | "Cycle through term buffers, in reverse." 70 | (interactive) 71 | (sane-term-cycle t)) 72 | 73 | (defun sane-term-next () 74 | "Cycle through term buffers." 75 | (interactive) 76 | (sane-term-cycle nil)) 77 | 78 | ;;;###autoload 79 | (defun sane-term-create () 80 | "Create new term buffer." 81 | (interactive) 82 | (ansi-term sane-term-shell-command)) 83 | 84 | ;;;###autoload 85 | (defun sane-term () 86 | "Cycle through term buffers, creating if necessary." 87 | (interactive) 88 | (when sane-term-initial-create 89 | (unless (sane-term-buffer-exists-p) 90 | (sane-term-create))) 91 | (sane-term-next)) 92 | 93 | (defun sane-term-mode-toggle () 94 | "Toggles term between line mode and char mode. Nice to have a 95 | single key so I don't have to remember separate char and line 96 | mode bindings" 97 | (interactive) 98 | (if (term-in-line-mode) 99 | (term-char-mode) 100 | (term-line-mode))) 101 | 102 | (defadvice term-handle-exit 103 | (after term-kill-buffer-on-exit activate) 104 | "Kill term buffers on exiting term (C-d or `exit`). 105 | Optionally go to next term buffer." 106 | (when sane-term-kill-on-exit 107 | (kill-buffer) 108 | (when sane-term-next-on-kill 109 | (sane-term-next)))) 110 | 111 | 112 | (provide 'sane-term) 113 | 114 | ;;; sane-term.el ends here 115 | --------------------------------------------------------------------------------