(undigestify-rmail-message): Better error messages.
[bpt/emacs.git] / lisp / shell.el
index ba87a0f..abb580b 100644 (file)
 ;;; comint-mode-hook is the comint mode hook.
 
 ;;; Shell Mode Commands:
-;;;         shell                          Fires up the shell process
-;;; tab     comint-dynamic-complete        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
-;;;        dirs                            Resync the buffer's dir stack
-;;;        dirtrack-toggle                 Turn dir tracking on/off
-;;;         shell-strip-ctrl-m              Remove trailing ^Ms from output
+;;;         shell                      Fires up the shell process
+;;; tab     comint-dynamic-complete    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
+;;;        dirs                        Resync the buffer's dir stack
+;;;        dirtrack-toggle             Turn dir tracking on/off
+;;;         comint-strip-ctrl-m                Remove trailing ^Ms from output
 ;;;
 ;;; The shell mode hook is shell-mode-hook
 ;;; comint-prompt-regexp is initialised to shell-prompt-pattern, for backwards
@@ -134,6 +135,15 @@ shell buffer.  The default is (?\\| ?& ?< ?> ?\\( ?\\) ?\\;).
 
 This is a fine thing to set in your `.emacs' file.")
 
+(defvar shell-file-name-quote-list
+  (append shell-delimiter-argument-list '(?\  ?\* ?\! ?\" ?\' ?\`))
+  "List of characters to quote when in a file name.
+This variable is used to initialize `comint-file-name-quote-list' in the
+shell buffer.  The default is (?\  ?\* ?\! ?\" ?\' ?\`) plus characters
+in `shell-delimiter-argument-list'.
+
+This is a fine thing to set in your `.emacs' file.")
+
 (defvar shell-dynamic-complete-functions
   '(comint-replace-by-expanded-history
     shell-dynamic-complete-environment-variable
@@ -239,7 +249,7 @@ Thus, this does not include the shell's current directory.")
 (defvar shell-font-lock-keywords
   (list (cons shell-prompt-pattern 'font-lock-keyword-face)
        '("[ \t]\\([+-][^ \t\n]+\\)" 1 font-lock-comment-face)
-       '("^[^ \t\n]+:.*$" . font-lock-string-face)
+       '("^[^ \t\n]+:.*" . font-lock-string-face)
        '("^\\[[1-9][0-9]*\\]" . font-lock-string-face))
   "Additional expressions to highlight in Shell mode.")
 \f
@@ -307,6 +317,7 @@ buffer."
   (setq comint-prompt-regexp shell-prompt-pattern)
   (setq comint-completion-fignore shell-completion-fignore)
   (setq comint-delimiter-argument-list shell-delimiter-argument-list)
+  (setq comint-file-name-quote-list shell-file-name-quote-list)
   (setq comint-dynamic-complete-functions shell-dynamic-complete-functions)
   (make-local-variable 'paragraph-start)
   (setq paragraph-start comint-prompt-regexp)
@@ -317,7 +328,7 @@ buffer."
   (setq shell-last-dir nil)
   (make-local-variable 'shell-dirtrackp)
   (setq shell-dirtrackp t)
-  (add-hook 'comint-input-filter-functions 'shell-directory-tracker)
+  (add-hook 'comint-input-filter-functions 'shell-directory-tracker nil t)
   (setq comint-input-autoexpand shell-input-autoexpand)
   (make-local-variable 'list-buffers-directory)
   (setq list-buffers-directory (expand-file-name default-directory))
@@ -329,7 +340,8 @@ buffer."
              (cond ((string-equal shell "bash") "~/.bash_history")
                    ((string-equal shell "ksh") "~/.sh_history")
                    (t "~/.history"))))
-    (if (equal (file-truename comint-input-ring-file-name) "/dev/null")
+    (if (or (equal comint-input-ring-file-name "")
+           (equal (file-truename comint-input-ring-file-name) "/dev/null"))
        (setq comint-input-ring-file-name nil))
     (setq shell-dirstack-query
          (if (string-match "^k?sh$" shell) "pwd" "dirs")))
@@ -365,15 +377,21 @@ Otherwise, one argument `-i' is passed to the shell.
                       "/bin/sh"))                   
             (name (file-name-nondirectory prog))
             (startfile (concat "~/.emacs_" name))
-            (xargs-name (intern-soft (concat "explicit-" name "-args"))))
-       (set-buffer (apply 'make-comint "shell" prog
-                          (if (file-exists-p startfile) startfile)
-                          (if (and xargs-name (boundp xargs-name))
-                              (symbol-value xargs-name)
-                            '("-i"))))
-       (shell-mode)
-       (switch-to-buffer (current-buffer)))
-    (switch-to-buffer "*shell*")))
+            (xargs-name (intern-soft (concat "explicit-" name "-args")))
+            shell-buffer)
+       (save-excursion
+         (set-buffer (apply 'make-comint "shell" prog
+                            (if (file-exists-p startfile) startfile)
+                            (if (and xargs-name (boundp xargs-name))
+                                (symbol-value xargs-name)
+                              '("-i"))))
+         (setq shell-buffer (current-buffer))
+         (shell-mode))
+       (pop-to-buffer shell-buffer))
+    (pop-to-buffer "*shell*")))
+
+;;; Don't do this when shell.el is loaded, only while dumping.
+;;;###autoload (add-hook 'same-window-buffer-names "*shell*")
 \f
 ;;; Directory tracking
 ;;; ===========================================================================
@@ -432,20 +450,26 @@ 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.
       (condition-case chdir-failure
-         (let ((start (progn (string-match "^[;\\s ]*" str) ; skip whitespace
+         (let ((start (progn (string-match "^[; \t]*" str) ; skip whitespace
                              (match-end 0)))
                end cmd arg1)
            (while (string-match shell-command-regexp str start)
              (setq end (match-end 0)
                    cmd (comint-arguments (substring str start end) 0 0)
                    arg1 (comint-arguments (substring str start end) 1 1))
-             (cond ((eq (string-match shell-popd-regexp cmd) 0)
+             (cond ((string-match (concat "\\`\\(" shell-popd-regexp
+                                          "\\)\\($\\|[ \t]\\)")
+                                  cmd)
                     (shell-process-popd (substitute-in-file-name arg1)))
-                   ((eq (string-match shell-pushd-regexp cmd) 0)
+                   ((string-match (concat "\\`\\(" shell-pushd-regexp
+                                          "\\)\\($\\|[ \t]\\)")
+                                  cmd)
                     (shell-process-pushd (substitute-in-file-name arg1)))
-                   ((eq (string-match shell-cd-regexp cmd) 0)
+                   ((string-match (concat "\\`\\(" shell-cd-regexp
+                                          "\\)\\($\\|[ \t]\\)")
+                                  cmd)
                     (shell-process-cd (substitute-in-file-name arg1))))
-             (setq start (progn (string-match "[;\\s ]*" str end) ; skip again
+             (setq start (progn (string-match "[; \t]*" str end) ; skip again
                                 (match-end 0)))))
        (error "Couldn't cd"))))
 
@@ -549,7 +573,9 @@ Environment variables are expanded, see function `substitute-in-file-name'."
 
 (defun shell-cd (dir)
   "Do normal `cd' to DIR, and set `list-buffers-directory'."
-  (if shell-dirtrackp (setq list-buffers-directory (expand-file-name dir)))
+  (if shell-dirtrackp
+      (setq list-buffers-directory (file-name-as-directory
+                                   (expand-file-name dir))))
   (cd dir))
 
 (defun shell-resync-dirs ()