Function: shell-bookmark-jump

shell-bookmark-jump is an autoloaded and byte-compiled function defined in shell.el.gz.

Signature

(shell-bookmark-jump BOOKMARK)

Documentation

Default BOOKMARK handler for shell buffers.

Create a shell buffer with its default-directory, shell process, and buffer name from the bookmark. If there is an existing shell buffer of the same name, default shell-mode behavior is to reuse that buffer.

For a remote shell default-directory will be the remote file name. Remote shell buffers reuse existing connections that match the remote file name, or may prompt you to create a new connection. For ad-hoc multi-hop remote connections, see Info node (tramp)Ad-hoc multi-hops.

If called with a single C-u (universal-argument) prefix, a new shell buffer will be created if there is an existing buffer with the same name. The new buffer name is made unique using rename-uniquely, which see.

If called with a double C-u (universal-argument) prefix, new remote connections are inhibited, though an existing connection will be reused. You can make a remote connection manually by reloading the buffer using C-x C-v (find-alternate-file) or create a new shell using M-x shell (shell).

If called with a triple C-u (universal-argument) prefix, a new buffer will be created if necessary, and new remote connections are inhibited.

Source Code

;; Defined in /usr/src/emacs/lisp/shell.el.gz
;;;###autoload
(defun shell-bookmark-jump (bookmark)
  "Default BOOKMARK handler for shell buffers.
Create a shell buffer with its `default-directory', shell process, and
buffer name from the bookmark.  If there is an existing shell buffer of
the same name, default `shell-mode' behavior is to reuse that buffer.

For a remote shell `default-directory' will be the remote file name.
Remote shell buffers reuse existing connections that match the remote
file name, or may prompt you to create a new connection.  For ad-hoc
multi-hop remote connections, see Info node `(tramp)Ad-hoc multi-hops'.

If called with a single \\[universal-argument] prefix, a new shell
buffer will be created if there is an existing buffer with the same
name.  The new buffer name is made unique using `rename-uniquely', which
see.

If called with a double \\[universal-argument] prefix, new remote
connections are inhibited, though an existing connection will be reused.
You can make a remote connection manually by reloading the buffer using
\\[find-alternate-file] or create a new shell using \\[shell].

If called with a triple \\[universal-argument] prefix, a new buffer will
be created if necessary, and new remote connections are inhibited."
  (let* ((bookmark-default-directory (bookmark-prop-get bookmark 'location))
         (default-directory bookmark-default-directory)
         (explicit-shell-file-name (bookmark-prop-get bookmark 'shell-file-name))
         (prefix-arg (prefix-numeric-value current-prefix-arg))
         (maybe-new-shell (or (= 4 prefix-arg) (= 64 prefix-arg)))
         (non-essential (or shell-bookmark-jump-non-essential
                            (= 16 prefix-arg) (= 64 prefix-arg)))
         (shell-buffer-name (car bookmark))
         (shell-buffer-name (if (and maybe-new-shell
                                     (comint-check-proc shell-buffer-name))
                                (generate-new-buffer-name shell-buffer-name)
                              shell-buffer-name)))
    ;; Handle a local shell, a remote shell with an existing
    ;; connection, or a remote shell needing a connection and new
    ;; connections not inhibited.
    (if (or (not (file-remote-p default-directory))
            (file-remote-p default-directory nil 'connected)
            (and (not non-essential)
                 (not (file-remote-p default-directory nil 'connected))))
        (shell shell-buffer-name)
      ;; Handle a remote shell with no matching active connection and if
      ;; new connections are inhibited.
      (let* ((file-name-handler-alist nil)
             ;; Ignore file-name-handler-alist to guard
             ;; abbreviate-file-name, et.al., which are remote aware.
             ;; The macro without-remote-files is insufficient for this
             ;; case.
             (shell-buffer
              (shell shell-buffer-name)))
        (with-current-buffer shell-buffer
          ;; Allow reloading or M-x shell to attempt a remote connection.
          (setq default-directory bookmark-default-directory)
          (setq list-buffers-directory bookmark-default-directory)
          ;; Inhibit features that may cause remote connection attempts.
          ;; These settings revert when the user reloads the buffer.
          (dirtrack-mode -1)
          (shell-dirtrack-mode -1)
          (delq (assoc "7" ansi-osc-handlers) ; ansi-osc-directory-tracker
                ansi-osc-handlers))))))