(defvar term-toggle-goto-eob t
"*If non-nil `term-toggle' will move point to the end of the shell-buffer
whenever the `term-toggle' switched to the shell-buffer.
When `term-toggle-cd' is called the point is allways moved to the end of the
(defvar term-toggle-automatic-cd t
"*If non-nil `term-toggle-cd' will send the \"cd\" command to the shell.
If nil `term-toggle-cd' will only insert the \"cd\" command in the
shell-buffer. Leaving it to the user to press RET to send the command to
(defun term-toggle-cd ()
"Calls `term-toggle' with a prefix argument. Se command `term-toggle'"
(defun term-toggle (make-cd)
"Toggles between the *terminal* buffer and whatever buffer you are editing.
With a prefix ARG also insert a \"cd DIR\" command into the shell, where DIR is
the directory of the current buffer.
Call twice in a row to get a full screen window for the *terminal* buffer.
When called in the *terminal* buffer returns you to the buffer you were editing
before caling the first time.
(if (eq major-mode 'term-mode)
(if (and (or (eq last-command 'term-toggle)
(eq last-command 'term-toggle-cd))
(not (eq (count-windows) 1)))
(defvar term-toggle-pre-shell-win-conf nil
"Contains the window configuration before the *terminal* buffer was selected")
(defun term-toggle-buffer-return-from-shell ()
"Restores the window configuration used before switching the *terminal* buffer.
If no configuration has been stored, just burry the *terminal* buffer."
(if (window-configuration-p term-toggle-pre-shell-win-conf)
(setq term-toggle-pre-shell-win-conf nil)
(bury-buffer (get-buffer "*terminal*")))
(defun term-toggle-buffer-goto-shell (make-cd)
"Switches other window to the *terminal* buffer. If no *terminal* buffer exists
start a new shell and switch to it in other window. If argument MAKE-CD is
non-nil, insert a \"cd DIR\" command into the shell, where DIR is the directory
of the current buffer.
Stores the window cofiguration before creating and/or switching window."
(setq term-toggle-pre-shell-win-conf (current-window-configuration))
(let ((shell-buffer (get-buffer "*terminal*"))
(or (and make-cd
(concat "cd " (file-name-directory (buffer-file-name))))
(concat "cd " list-buffers-directory)))))
(term (getenv "SHELL"))
(error (switch-to-buffer "*terminal*"))))
(if (or cd-command term-toggle-goto-eob)
(if (and cd-command term-toggle-automatic-cd)
(term-send-raw-string (concat cd-command "\n"))
(defun term-toggle-buffer-switch-to-other-window ()
"Switches to other window. If the current window is the only window in the
current frame, create a new window and switch to it.
\(This is less intrusive to the current window configuration then
(let ((this-window (selected-window)))
(if (eq this-window (selected-window))