;;; shell.el --- specialized comint.el for running the shell -*- lexical-binding: t -*-
-;; Copyright (C) 1988, 1993-1997, 2000-2013 Free Software Foundation, Inc.
+;; Copyright (C) 1988, 1993-1997, 2000-2016 Free Software Foundation,
+;; Inc.
;; Author: Olin Shivers <shivers@cs.cmu.edu>
;; Simon Marshall <simon@gnu.org>
-;; Maintainer: FSF <emacs-devel@gnu.org>
+;; Maintainer: emacs-devel@gnu.org
;; Keywords: processes
;; This file is part of GNU Emacs.
;; tab completion-at-point Complete filename/command/history
;; m-? comint-dynamic-list-filename-completions
;; List completions in help buffer
-;; m-c-f shell-forward-command Forward a shell command
-;; m-c-b shell-backward-command Backward a shell command
+;; c-c c-f shell-forward-command Forward a shell command
+;; c-c c-b shell-backward-command Backward a shell command
;; dirs Resync the buffer's dir stack
;; shell-dirtrack-mode Turn dir tracking on/off
;; comint-strip-ctrl-m Remove trailing ^Ms from output
(setq shell-dirstack-query
(cond ((string-equal shell "sh") "pwd")
((string-equal shell "ksh") "echo $PWD ~-")
+ ;; Bypass any aliases. TODO all shells could use this.
+ ((string-equal shell "bash") "command dirs")
(t "dirs")))
;; Bypass a bug in certain versions of bash.
(when (string-equal shell "bash")
;; The buffer's window must be correctly set when we call comint (so
;; that comint sets the COLUMNS env var properly).
- (pop-to-buffer-same-window buffer)
+ (pop-to-buffer buffer)
(unless (comint-check-proc buffer)
(let* ((prog (or explicit-shell-file-name
(getenv "ESHELL") shell-file-name))
Environment variables are expanded, see function `substitute-in-file-name'."
(if shell-dirtrackp
;; We fail gracefully if we think the command will fail in the shell.
- (with-demoted-errors "Couldn't cd: %s"
- (let ((start (progn (string-match
+;;; (with-demoted-errors "Directory tracker failure: %s"
+ ;; This fails so often that it seems better to just ignore errors (?).
+ ;; Eg even: foo=/tmp; cd $foo is beyond us (bug#17159).
+ (ignore-errors
+ (let ((start (progn (string-match
(concat "^" shell-command-separator-regexp)
str) ; skip whitespace
(match-end 0)))
"Move forward across ARG shell command(s). Does not cross lines.
See `shell-command-regexp'."
(interactive "p")
- (let ((limit (line-end-position)))
- (if (re-search-forward (concat shell-command-regexp "\\([;&|][\t ]*\\)+")
- limit 'move arg)
- (skip-syntax-backward " "))))
+ (let ((limit (line-end-position))
+ (pt (point)))
+ (re-search-forward (concat shell-command-regexp "\\([;&|][\t ]*\\)+")
+ limit 'move arg)
+ (and (/= pt (point))
+ (skip-syntax-backward " " pt))))
(defun shell-backward-command (&optional arg)
(when (> limit (point))
(setq limit (line-beginning-position)))
(skip-syntax-backward " " limit)
- (if (re-search-backward
- (format "[;&|]+[\t ]*\\(%s\\)" shell-command-regexp) limit 'move arg)
- (progn (goto-char (match-beginning 1))
- (skip-chars-forward ";&|")))))
+ (let ((pt (point)))
+ (if (re-search-backward
+ (format "[;&|]+[\t ]*\\(%s\\)" shell-command-regexp) limit 'move arg)
+ (progn (goto-char (match-beginning 1))
+ (skip-chars-forward ";&|")))
+ (and (/= pt (point))
+ (skip-syntax-forward " " pt)))))
(defun shell-dynamic-complete-command ()
"Dynamically complete the command at point.