Klimi's new dotfiles with stow.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

169 rader
6.4 KiB

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