-EmacsUtils
-==========
+multishell.el
+=============
-Handy Emacs utilities
+Facilitate interaction with multiple local and remote Emacs shell buffers.
-I've been using Gnu Emacs since it was publicly available (1985?), and have contributed some packages which are included with Emacs, notably the [Allout outliner](http://myriadicity.net/software-and-systems/craft/emacs-allout), [icomplete mode](http://www.emacswiki.org/emacs/IcompleteMode), and python-mode's [pdbtrack functionality](http://myriadicity.net/software-and-systems/craft/crafty-hacks#section-1). Like many long-time Emacs users, I have a bunch of custom code, some that's crucial. Here are some that others might find useful. I hope to include more, as time allows.
+I use the emacs shell a *lot*. On top of emacs' powerful shell and tramp
+facilities, multishell.el turns emacs into a versatile tool for conducting
+operations and development across numerous hosts.
-* **[multishell.el](./multishell.el)**
+Using the include customization binding, you can use a keystroke to:
- I use the emacs shell a *lot*. I bind this to Meta-space to make it easy to:
+* Get to the input point from wherever you are in a shell buffer,
+* ... or to one of your shell buffers if you're not currently in one.
+* Use universal arguments to launch and choose among alternate shell buffers,
+* ... and select which is default.
+* Append a path to a new shell name to launch a shell in that directory,
+* ... and use a path with Emacs tramp syntax to launch a remote shell.
- * Get to a shell buffer with a keystroke,
- * ... or to the input point for the current shell buffer.
- * Use universal arguments to launch and choose between alternate shell
- buffers and to select which is default.
- * Prepend a path to a new shell name to launch a shell in that directory,
- * and use Emacs tramp path syntax to launch a remote shell.
+ For example:
- On top of emacs' powerful shell and tramp facilities, this turns emacs
- into a versatile tool for conducting operations and development across
- numerous hosts.
+ * '/ssh:example.net:/' for a shell buffer in / on
+ example.net; the buffer will be named "*example.net*".
-* **[xsel.el](./xsel.el)**
+ * '#ex/ssh:example.net|sudo:root@example.net:/etc' for a root shell
+ starting in /etc on example.net named "*#ex*".
- X copy and paste emacs region from emacs tty sessions, using a shell command.
+(NOTE that there is a problem with specifying a remote homedir using
+tramp syntax, eg '/ssh:example.net:'. That sometimes fails on an obscure
+bug - particularly for remote+sudo with homedir syntax. Until fixed, you
+may need to start remote+sudo shells with an explicit path, then cd ~.)
- If xsel or linux or cygwin equivalent is installed, and DISPLAY is
- working, use `klm:xsel-copy` to copy the region to the X clipboard and
- `klm:xsel-paste` to paste the contents of the clipboard at point.
+Customize-group `multishell` to select and activate a keybinding and set
+various behaviors. Customize-group `savehist` to preserve buffer
+names/paths across emacs sessions.
- One benefit is that `klm:xsel-paste` pastes are single units, rather than
- a sequence of individual keystrokes that constitute regular X pastes to a
- terminal. This avoids layers of parsing, indenting, auto-paren insertion,
- and so forth. (You can always do a regular X paste on occasions when you
- want that processing.)
-
- NOTE well - ssh has has a little known, severe default X11 forwarding
- timeout that leads to unexpected failures after ten minutes - yikes! To
- mitigate it, set ForwardX11Timeout to something larger - up to the
- unexpected max of 596h, slightly beyond which the number is ignored. See
- http://b.kl3in.com/2012/01/x11-display-forwarding-fails-after-some-time/
- for details.
-
-* **[pdbtrack.el](./pdbtrack.el)**
-
- [I've moved my standalone version of pdbtrack aside. I hadn't realized
- that the version that I derived this code from lacks my source-buffer
- fallback provisions. It looks like I'm going to have to do some
- unraveling to reconstruct the best basis.]
-
- Add sensitivity to comint shells so the source file lines are automatically
- presented in a separate window when the Python PDB debugger steps to them.
-
- This is derived from the pdb tracking code, which I originally wrote, and
- which has been included in (various) official Emacs Python modes. I wanted
- a version that I could more easily tweak and maintain, independently of
- the python-mode code.
-
- It would be nice to eventually generalize this code, to work for things
- like the node.js debugger. We'll see if I (or anyone) ever gets around to
- that.
+See the `multishell-pop-to-shell` docstring for details.
+++ /dev/null
-;; From https://gist.github.com/offby1/1240799
-
-;; There's something similar (but fancier) in vc-git.el: vc-git-grep
-
-;; -I means don't search through binary files
-
-;; --no-color, oddly enough, is required to allow emacs to colorize the output
-
-(defcustom git-grep-switches
- "git --no-pager grep --extended-regexp -I -n --ignore-case --no-color"
- "Switches to pass to `git grep'."
- :type 'string)
-
-(defcustom git-grep-default-work-tree (expand-file-name "~/work/adtrack")
- "Top of your favorite git working tree. \\[git-grep] will search from here if it cannot figure out where else to look."
- :type 'directory
- )
-
-(when (require 'vc-git nil t)
-
- ;; Uncomment this to try out the built-in-to-Emacs function.
- ;;(defalias 'git-grep 'vc-git-grep)
-
- (defun git-grep (command-args)
- (interactive
- (let ((root (vc-git-root default-directory)))
- (when (not root)
- (setq root git-grep-default-work-tree)
- (message "git-grep: %s doesn't look like a git working tree; searching from %s instead" default-directory root))
- (list (read-shell-command
- "Run git-grep (like this): "
- (format (concat
- "cd %s && "
- "%s -e %s")
- root
- git-grep-switches
- (let ((thing (and
- ;; Don't snarf stuff from the buffer if
- ;; we're not looking at a file.
- ;; Perhaps we should also check to see
- ;; if the file is part of a git repo.
- buffer-file-name
- (thing-at-point
- 'symbol))))
- (or (and thing (progn
- (set-text-properties 0
- (length thing)
- nil thing)
- (shell-quote-argument
- (regexp-quote thing))))
- "")))
- 'git-grep-history))))
- (let ((grep-use-null-device nil))
- (grep command-args))))
-
-(provide 'gist-git-grep)
\ No newline at end of file
+++ /dev/null
-;; xsel.el -- X copy and paste emacs region from emacs tty sessions, using xsel
-
-;; TODO: Check alternative: http://emacs.stackexchange.com/a/819/9668
-
-;; Copyright (C) 2015 Free Software Foundation, Inc. and Ken Manheimer
-
-;; Author: Ken Manheimer <ken dot manheimer at gmail...>
-;; Maintainer: Ken Manheimer <ken dot manheimer at gmail...>
-;; Created: 1999 -- first public release
-;; Keywords: copy, paste, X11
-;; Website: https://github.com/kenmanheimer/EmacsUtils
-
-;;; Commentary:
-;;
-;; If xsel is installed and DISPLAY is working, use `klm:xsel-copy' to copy
-;; the region to the X clipboard and `klm:xsel-paste' to paste the contents
-;; of the clipboard at point. (The advantage of the latter over regular X
-;; mouse paste is `klm:xsel-paste' looks unitary, to emacs, rather than
-;; the mouse paste's continuous, parsed/indented/auto-parenned/etc input.)
-
-
-(defun klm:xsel-check-get-DISPLAY (&optional arg)
- "Ensure X DISPLAY is set, and prompt for it if not.
-
-With universal argument, always prompt to set it, regardless.
-
-Returns the resulting value for DISPLAY."
- (interactive "P")
- (when (or arg (not (getenv "DISPLAY")))
- (setenv "DISPLAY"
- (read-from-minibuffer "DISPLAY: "
- (or (getenv "DISPLAY") ":10.0"))))
- (getenv "DISPLAY")
- )
-
-(defun klm:xsel-copy (from to)
- "Place contents of region in X copy/paste buffer, using shell command.
-
-With universal argument, prompt to set DISPLAY."
-
- (interactive "r")
- (when (klm:xsel-check-get-DISPLAY current-prefix-arg)
- (let ((command (cond ((eq system-type 'darwin) "pbcopy")
- ((eq system-type 'cygwin) "putclip")
- ;; Linux &c:
- (t "xsel --input --clipboard"))))
- (shell-command-on-region from to command)
- (deactivate-mark)
- )))
-
-(defun klm:xsel-paste ()
- "Place contents of region in X copy/paste buffer, using shell command."
- (interactive "")
- (when (klm:xsel-check-get-DISPLAY current-prefix-arg)
- (let ((command (cond ((eq system-type 'darwin) "pbpaste")
- ((eq system-type 'cygwin) "getclip")
- ;; Linux &c:
- (t "xsel --output --clipboard"))))
- (shell-command command 1)
- (exchange-point-and-mark)
- )))