;; - Olin Shivers (shivers@cs.cmu.edu)
;; - Simon Marshall (simon@gnu.org)
-;; This file defines a a shell-in-a-buffer package (shell mode) built
-;; on top of comint mode. This is actually cmushell with things
-;; renamed to replace its counterpart in Emacs 18. cmushell is more
+;; This file defines a shell-in-a-buffer package (shell mode) built on
+;; top of comint mode. This is actually cmushell with things renamed
+;; to replace its counterpart in Emacs 18. cmushell is more
;; featureful, robust, and uniform than the Emacs 18 version.
;; Since this mode is built on top of the general command-interpreter-in-
:type '(repeat (string :tag "Argument"))
:group 'shell)
+(defcustom explicit-bash-args
+ ;; Tell bash not to use readline.
+ '("--noediting" "-i")
+ "*Args passed to inferior shell by M-x shell, if the shell is bash.
+Value is a list of strings, which may be nil."
+ :type '(repeat (string :tag "Argument"))
+ :group 'shell)
+
(defcustom shell-input-autoexpand 'history
"*If non-nil, expand input command history references on completion.
This mirrors the optional behavior of tcsh (its autoexpand and histlit).
(setq shell-mode-map (nconc (make-sparse-keymap) comint-mode-map))
(define-key shell-mode-map "\C-c\C-f" 'shell-forward-command)
(define-key shell-mode-map "\C-c\C-b" 'shell-backward-command)
- (define-key shell-mode-map "\t" 'shell-pcomplete)
- (define-key shell-mode-map "\M-\t" 'shell-pcomplete-reverse)
+ (define-key shell-mode-map "\t" 'comint-dynamic-complete)
(define-key shell-mode-map "\M-?"
'comint-dynamic-list-filename-completions)
(define-key shell-mode-map [menu-bar completion]
- (copy-keymap (lookup-key comint-mode-map [menu-bar completion])))
+ (cons "Complete"
+ (copy-keymap (lookup-key comint-mode-map [menu-bar completion]))))
(define-key-after (lookup-key shell-mode-map [menu-bar completion])
[complete-env-variable] '("Complete Env. Variable Name" .
shell-dynamic-complete-environment-variable)
(setq comint-delimiter-argument-list shell-delimiter-argument-list)
(setq comint-file-name-chars shell-file-name-chars)
(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)
(make-local-variable 'font-lock-defaults)
(make-local-variable 'list-buffers-directory)
(setq list-buffers-directory (expand-file-name default-directory))
;; shell-dependent assignments.
- (let ((shell (file-name-nondirectory (car
- (process-command (get-buffer-process (current-buffer)))))))
- (setq comint-input-ring-file-name
- (or (getenv "HISTFILE")
- (cond ((string-equal shell "bash") "~/.bash_history")
- ((string-equal shell "ksh") "~/.sh_history")
- (t "~/.history"))))
- (if (or (equal comint-input-ring-file-name "")
- (equal (file-truename comint-input-ring-file-name)
- (file-truename "/dev/null")))
- (setq comint-input-ring-file-name nil))
- ;; Arrange to write out the input ring on exit, if the shell doesn't
- ;; do this itself.
- (if (and comint-input-ring-file-name
- (string-match shell-dumb-shell-regexp shell))
- (set-process-sentinel (get-buffer-process (current-buffer))
- #'shell-write-history-on-exit))
- (setq shell-dirstack-query
- (cond ((string-equal shell "sh") "pwd")
- ((string-equal shell "ksh") "echo $PWD ~-")
- (t "dirs"))))
- (comint-read-input-ring t))
+ (when (ring-empty-p comint-input-ring)
+ (let ((shell (file-name-nondirectory (car
+ (process-command (get-buffer-process (current-buffer)))))))
+ (setq comint-input-ring-file-name
+ (or (getenv "HISTFILE")
+ (cond ((string-equal shell "bash") "~/.bash_history")
+ ((string-equal shell "ksh") "~/.sh_history")
+ (t "~/.history"))))
+ (if (or (equal comint-input-ring-file-name "")
+ (equal (file-truename comint-input-ring-file-name)
+ (file-truename "/dev/null")))
+ (setq comint-input-ring-file-name nil))
+ ;; Arrange to write out the input ring on exit, if the shell doesn't
+ ;; do this itself.
+ (if (and comint-input-ring-file-name
+ (string-match shell-dumb-shell-regexp shell))
+ (set-process-sentinel (get-buffer-process (current-buffer))
+ #'shell-write-history-on-exit))
+ (setq shell-dirstack-query
+ (cond ((string-equal shell "sh") "pwd")
+ ((string-equal shell "ksh") "echo $PWD ~-")
+ (t "dirs"))))
+ (comint-read-input-ring t)))
(defun shell-write-history-on-exit (process event)
"Called when the shell process is stopped.
(progn (goto-char (match-beginning 1))
(skip-chars-forward ";&|")))))
-(defun shell-pcomplete ()
- "Cycle forwards through completions at point, using `pcomplete'.
-This function merely invokes `pcomplete', after ensuring this buffer
-is set up for it."
- (interactive)
- (unless (prog1 shell-pcomplete-setup-p
- (setq shell-pcomplete-setup-p t))
- (pcomplete-comint-setup 'shell-dynamic-complete-functions))
- ;; Convince pcomplete we are calling it directly
- (setq this-command 'pcomplete)
- (call-interactively #'pcomplete))
-
-(defun shell-pcomplete-reverse ()
- "Cycle backwards through completions at point, using `pcomplete'.
-This function merely invokes `pcomplete-reverse', after ensuring this
-buffer is set up for it."
- (interactive)
- (unless (prog1 shell-pcomplete-setup-p
- (setq shell-pcomplete-setup-p t))
- (pcomplete-comint-setup 'shell-dynamic-complete-functions))
- ;; Convince pcomplete we are calling it directly
- (setq this-command 'pcomplete-reverse)
- (call-interactively #'pcomplete-reverse))
-
(defun shell-dynamic-complete-command ()
"Dynamically complete the command at point.
This function is similar to `comint-dynamic-complete-filename', except that it
(let ((stack (cons default-directory shell-dirstack))
(index (cond ((looking-at "=-/?")
(length shell-dirstack))
- ((looking-at "=\\([0-9]+\\)")
+ ((looking-at "=\\([0-9]+\\)/?")
(string-to-number
(buffer-substring
(match-beginning 1) (match-end 1)))))))