setting ess-style now works from *customized* ess-default-style
[ess.git] / lisp / msdos.el
blob8b57f10ef238fa5a36686eb2edb2795e4d3f5c24
1 ;;; msdos.el --- Run an MS-DOS shell in an NTemacs buffer with bash as the shell
3 ;; Copyright (C) 1999 Richard M. Heiberger <rmh@fisher.stat.temple.edu>
4 ;; Copyright (C) 2000--2004 A.J. Rossini, Rich M. Heiberger, Martin
5 ;; Maechler, Kurt Hornik, Rodney Sparapani, and Stephen Eglen.
7 ;; Original Author: Richard M. Heiberger <rmh@fisher.stat.temple.edu>
8 ;; Created: February 1999
9 ;; Maintainers: ESS-core <ESS-core@stat.math.ethz.ch>
11 ;; Keywords: processes
13 ;; This file is part of ESS.
15 ;; This file is free software; you can redistribute it and/or modify
16 ;; it under the terms of the GNU General Public License as published by
17 ;; the Free Software Foundation; either version 2, or (at your option)
18 ;; any later version.
20 ;; This file is distributed in the hope that it will be useful,
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 ;; GNU General Public License for more details.
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with GNU Emacs; see the file COPYING. If not, write to
27 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
29 ;;; Comments on file:
31 ;; The file msdos.el in the next mail message opens an *msdos* buffer
32 ;; in shell-mode and msdos-minor-mode. When cmdproxy.exe/command.com
33 ;; is the emacs shell, then this gets various setting right that M-x
34 ;; shell currently misses. The function M-x msdos-minor-mode could be
35 ;; automatically run by emacs in shell-mode in that case.
37 ;; When bash is the emacs shell, msdos.el still opens a
38 ;; cmdproxy.exe/command.com shell in the buffer *msdos*. There are
39 ;; occasions when it is necessary to run DOS character-based programs
40 ;; in an emacs window.
42 ;; I followed the suggestion by AndrewI to look at M-x shell and modify
43 ;; it. It turns out not to have been trivial.
45 ;; I've listed it as part of ESS (emacs speaks statistics) for now. I
46 ;; will be happy to sign it over to FSF and have it become part of the
47 ;; standard distribution for windows machines.
49 ;;; Code:
51 (require 'shell)
53 ;;; Customization and Buffer Variables
55 (defcustom explicit-msdos-shell-file-name "cmdproxy.exe"
56 "*If non-nil, is file name to use for explicitly requested msdos
57 inferior shell."
58 :type '(choice (const :tag "None" nil) file)
59 :group 'shell)
61 (defcustom explicit-msdos-comspec-file-name
62 (if (w32-using-nt)
63 "cmd.exe"
64 "command.com")
65 "*If non-nil, is file name to use for explicitly requested COMSPEC
66 environment variable."
67 :type '(choice (const :tag "None" nil) file)
68 :group 'shell)
70 (make-variable-buffer-local 'msdos-minor-mode)
71 (defvar msdos-minor-mode nil
72 "Non-nil if using msdos-minor mode as a minor mode of some other mode.")
74 (defun msdos ()
75 "Run an inferior msdos shell, with I/O through buffer *msdos*.
76 This function is intended to be used in an Ntemacs session in which
77 bash is the primary shell. But sometimes an MSDOS window, within emacs,
78 is also needed.
80 If buffer exists but shell process is not running, make new shell.
81 If buffer exists and shell process is running, just switch to buffer `*msdos*'.
82 Program used comes from variable `explicit-msdos-shell-file-name'.
83 If a file `~/.emacs_SHELLNAME' exists, it is given as initial input
84 (Note that this may lose due to a timing error if the shell
85 discards input when it starts up.)
86 The buffer is put in Shell mode, giving commands for sending input
87 and controlling the subjobs of the shell. See `shell-mode'.
88 See also the variable `shell-prompt-pattern'.
90 The buffer is put into \\[msdos-minor-mode]. See `msdos-minor-mode'.
92 The COMSPEC environment variable in the inferior shell, but not in the emacs
93 process, is set to `explicit-msdos-comspec-file-name'.
94 The SHELL environment variable in the inferior shell, but not in the emacs
95 process, is set to `explicit-msdos-shell-file-name'.
97 The shell file name (sans directories) is used to make a symbol name
98 such as `explicit-csh-args'. If that symbol is a variable,
99 its value is used as a list of arguments when invoking the shell.
101 \(Type \\[describe-mode] in the shell buffer for a list of commands.)"
102 (interactive)
103 (if (not (comint-check-proc "*msdos*"))
104 (let* ((prog explicit-msdos-shell-file-name)
105 (name (file-name-nondirectory prog))
106 (startfile (concat "~/.emacs_" name))
107 (xargs-name (intern-soft (concat "explicit-" name "-args")))
108 shell-buffer
109 (comspec (getenv "COMSPEC"))
110 (shell (getenv "SHELL"))
112 (save-excursion
113 (setenv "COMSPEC" explicit-msdos-comspec-file-name)
114 (setenv "SHELL" explicit-msdos-shell-file-name)
115 (set-buffer (apply 'make-comint "msdos" prog
116 (if (and xargs-name (boundp xargs-name))
117 (symbol-value xargs-name))
118 (if (file-exists-p startfile)
119 (concat "/k " startfile))))
120 (setenv "COMSPEC" comspec)
121 (setenv "SHELL" shell)
122 (setq shell-buffer (current-buffer))
123 (shell-mode)
124 (msdos-minor-mode)
125 (sleep-for 4) ; need to wait, else working too fast!
126 ;;; The `exit' warning should precede the "c:\" prompt.
127 ;;; If not, then increase the sleep-for time!
128 (goto-char (point-min))
129 (insert
130 "Remember to exit this buffer with `exit'. If you kill the
131 buffer without exiting, you may not be able to shut down Windows cleanly.")
132 (goto-char (point-max)))
133 (pop-to-buffer shell-buffer))
134 (pop-to-buffer "*msdos*")))
137 (defun msdos-minor-mode ()
138 "Minor mode for running msdos in a shell-mode buffer:
139 a. Uses \\[set-buffer-process-coding-system] to set the coding system
140 to `'raw-text-dos'. The DOS C-m C-l end-of-line is critical. The
141 shell freezes without it.
143 b. The variable `comint-completion-addsuffix' is set to `\\' for directories.
145 c. Prevents echoing of commands.
147 d. strips ctrl-m from output.
149 (interactive)
150 (setq msdos-minor-mode t)
151 (make-variable-buffer-local 'comint-completion-addsuffix)
152 (setq comint-completion-addsuffix '("\\" . " "))
153 (setq comint-process-echoes t)
154 (add-hook 'comint-output-filter-functions 'shell-strip-ctrl-m nil t)
155 (set-buffer-process-coding-system 'raw-text-dos 'raw-text-dos)
156 ;; buffer-process-coding-system is critical.
159 ;; Install ourselves:
162 (put 'msdos-minor-mode 'permanent-local t)
163 (or (assq 'msdos-minor-mode minor-mode-alist)
164 (setq minor-mode-alist
165 (append minor-mode-alist
166 (list '(msdos-minor-mode " msdos")))))
168 ;; Provide ourselves:
170 (provide 'msdos)
172 ;;; msdos.el ends here