annotate lisp/ilisp/comint-v18.el @ 2:ac2d302a0011 r19-15b2

Import from CVS: tag r19-15b2
author cvs
date Mon, 13 Aug 2007 08:46:35 +0200
parents 376386a54a3c
children b82b59fe008d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; -*-Emacs-Lisp-*- General command interpreter in a window stuff
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;;; Copyright Olin Shivers (1988).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;;; Please imagine a long, tedious, legalistic 5-page gnu-style copyright
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;;; notice appearing here to the effect that you may use this code any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;;; way you like, as long as you don't charge money for it, remove this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;;; notice, or hold me liable for its results.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;;; This hopefully generalises shell mode, lisp mode, tea mode, soar mode,...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;;; Hacked from tea.el and shell.el by Olin Shivers (shivers@cs.cmu.edu). 8/88
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;;; This file defines a general command-interpreter-in-a-buffer package
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;;; (comint mode). The idea is that you can build specific process-in-a-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;;; modes on top of comint mode -- e.g., lisp, shell, scheme, T, soar, ....
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;;; This way, all these specific packages share a common base functionality,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;;; and a common set of bindings, which makes them easier to use (and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;;; saves code, implementation time, etc., etc.).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;;; Several packages are already defined using comint mode:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;;; - The file cmushell.el defines cmushell and cmulisp mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;;; Cmushell and cmulisp mode are similar to, and intended to replace,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;;; their counterparts in the standard gnu emacs release (in shell.el).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;;; These replacements are more featureful, robust, and uniform than the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;;; released versions. The key bindings in lisp mode are also more compatible
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;; with the bindings of Hemlock and Zwei (the Lisp Machine emacs).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;; - The file cmuscheme.el defines inferior-scheme mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;;; - The file tea.el tunes scheme and inferior-scheme modes for T.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;;; - The file soar.el tunes lisp and inferior-lisp modes for Soar.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;;; For documentation on the functionality provided by comint mode, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;; the hooks available for customising it, see the comments below.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;;; For further information on the standard derived modes (shell,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;; inferior-lisp, inferior-scheme, ...), see the relevant source files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;;; Please send me bug reports, bug fixes, and extensions, so that I can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;;; merge them into the master source.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;;; For hints on converting existing process modes (e.g., tex-mode,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;;; background, dbx, gdb, kermit, prolog, telnet) to use comint-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;;; instead of shell-mode, see the notes at the end of this file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (provide 'comint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;;; Brief Command Documentation:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;;;============================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;;; Comint Mode Commands: (common to all derived modes, like cmushell & cmulisp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;;; mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;;; m-p comint-previous-input Cycle backwards in input history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;;; m-n comint-next-input Cycle forwards
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;;; c-c r comint-previous-input-matching Search backwards in input history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;;; return comint-send-input
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;;; c-a comint-bol Beginning of line; skip prompt.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;;; c-d comint-delchar-or-maybe-eof Delete char unless at end of buff.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;;; c-c c-u comint-kill-input ^u
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;;; c-c c-w backward-kill-word ^w
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;;; c-c c-c comint-interrupt-subjob ^c
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;;; c-c c-z comint-stop-subjob ^z
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 ;;; c-c c-\ comint-quit-subjob ^\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;;; c-c c-o comint-kill-output Delete last batch of process output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ;;; c-c c-r comint-show-output Show last batch of process output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ;;; Not bound by default in comint-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 ;;; send-invisible Read a line w/o echo, and send to proc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ;;; (These are bound in shell-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 ;;; comint-dynamic-complete Complete filename at point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 ;;; comint-dynamic-list-completions List completions in help buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 ;;; comint-replace-by-expanded-filename Expand and complete filename at point;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ;;; replace with expanded/completed name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ;;; comint-kill-subjob No mercy.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 ;;; comint-continue-subjob Send CONT signal to buffer's process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ;;; group. Useful if you accidentally
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 ;;; suspend your process (with C-c C-z).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 ;;; Bound for RMS -- I prefer the input history stuff, but you might like 'em.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 ;;; m-P comint-msearch-input Search backwards for prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 ;;; m-N comint-psearch-input Search forwards for prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 ;;; C-cR comint-msearch-input-matching Search backwards for prompt & string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ;;; comint-mode-hook is the comint mode hook. Basically for your keybindings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 ;;; comint-load-hook is run after loading in this package.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ;;; Buffer Local Variables:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 ;;;============================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 ;;; Comint mode buffer local variables:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 ;;; comint-prompt-regexp - string comint-bol uses to match prompt.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 ;;; comint-last-input-end - marker For comint-kill-output command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 ;;; input-ring-size - integer For the input history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 ;;; input-ring - ring mechanism
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 ;;; input-ring-index - marker ...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 ;;; comint-last-input-match - string ...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 ;;; comint-get-old-input - function Hooks for specific
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 ;;; comint-input-sentinel - function process-in-a-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 ;;; comint-input-filter - function modes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (defvar comint-prompt-regexp "^"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 "Regexp to recognise prompts in the inferior process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 Defaults to \"^\", the null string at BOL.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 Good choices:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 Canonical Lisp: \"^[^> ]*>+:? *\" (Lucid, franz, kcl, T, cscheme, oaklisp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 Lucid Common Lisp: \"^\\(>\\|\\(->\\)+\\) *\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 franz: \"^\\(->\\|<[0-9]*>:\\) *\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 kcl: \"^>+ *\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 shell: \"^[^#$%>]*[#$%>] *\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 T: \"^>+ *\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 This is a good thing to set in mode hooks.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (defvar input-ring-size 30
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 "Size of input history ring.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 ;;; Here are the per-interpreter hooks.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (defvar comint-get-old-input (function comint-get-old-input-default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 "Function that submits old text in comint mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 This function is called when return is typed while the point is in old text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 It returns the text to be submitted as process input. The default is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 comint-get-old-input-default, which grabs the current line, and strips off
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 leading text matching comint-prompt-regexp")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (defvar comint-input-sentinel (function ignore)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 "Called on each input submitted to comint mode process by comint-send-input.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 Thus it can, for instance, track cd/pushd/popd commands issued to the csh.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (defvar comint-input-filter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (function (lambda (str) (not (string-match "\\`\\s *\\'" str))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 "Predicate for filtering additions to input history.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 Only inputs answering true to this function are saved on the input
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 history list. Default is to save anything that isn't all whitespace")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (defvar comint-mode-hook '()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 "Called upon entry into comint-mode")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (defvar comint-mode-map nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 ;; Added for ILISP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (defvar comint-input-chunk-size 512)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (defun comint-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 "Major mode for interacting with an inferior interpreter.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 Interpreter name is same as buffer name, sans the asterisks.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 Return at end of buffer sends line as input.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 Return not at end copies rest of line to end and sends it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 This mode is typically customised to create inferior-lisp-mode,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 shell-mode, etc.. This can be done by setting the hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 comint-input-sentinel, comint-input-filter, and comint-get-old-input to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 appropriate functions, and the variable comint-prompt-regexp to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 the appropriate regular expression.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 An input history is maintained of size input-ring-size, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 can be accessed with the commands comint-next-input [\\[comint-next-input]] and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 comint-previous-input [\\[comint-previous-input]]. Commands not keybound by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 default are send-invisible, comint-dynamic-complete, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 comint-list-dynamic-completions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 \\{comint-mode-map}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 If you accidentally suspend your process, use \\[comint-continue-subjob]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 to continue it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 Entry to this mode runs the hooks on comint-mode-hook"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (let ((old-ring (and (assq 'input-ring (buffer-local-variables))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (boundp 'input-ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 input-ring)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (kill-all-local-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (setq major-mode 'comint-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (setq mode-name "Comint")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (setq mode-line-process '(": %s"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (use-local-map comint-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (make-local-variable 'comint-last-input-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (setq comint-last-input-end (make-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (make-local-variable 'comint-last-input-match)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (setq comint-last-input-match "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (make-variable-buffer-local 'comint-prompt-regexp) ; Don't set; default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (make-variable-buffer-local 'input-ring-size) ; ...to global val.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (make-local-variable 'input-ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (make-local-variable 'input-ring-index)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (setq input-ring-index 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (make-variable-buffer-local 'comint-get-old-input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (make-variable-buffer-local 'comint-input-sentinel)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (make-variable-buffer-local 'comint-input-filter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (run-hooks 'comint-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 ;Do this after the hook so the user can mung INPUT-RING-SIZE w/his hook.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 ;The test is so we don't lose history if we run comint-mode twice in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 ;a buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (setq input-ring (if (ring-p old-ring) old-ring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (make-ring input-ring-size)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (if comint-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (setq comint-mode-map (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (define-key comint-mode-map "\ep" 'comint-previous-input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (define-key comint-mode-map "\en" 'comint-next-input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (define-key comint-mode-map "\C-m" 'comint-send-input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (define-key comint-mode-map "\C-d" 'comint-delchar-or-maybe-eof)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (define-key comint-mode-map "\C-a" 'comint-bol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (define-key comint-mode-map "\C-c\C-u" 'comint-kill-input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (define-key comint-mode-map "\C-c\C-w" 'backward-kill-word)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (define-key comint-mode-map "\C-c\C-c" 'comint-interrupt-subjob)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (define-key comint-mode-map "\C-c\C-z" 'comint-stop-subjob)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (define-key comint-mode-map "\C-c\C-\\" 'comint-quit-subjob)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (define-key comint-mode-map "\C-c\C-o" 'comint-kill-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (define-key comint-mode-map "\C-cr" 'comint-previous-input-matching)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (define-key comint-mode-map "\C-c\C-r" 'comint-show-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 ;;; Here's the prompt-search stuff I installed for RMS to try...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (define-key comint-mode-map "\eP" 'comint-msearch-input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (define-key comint-mode-map "\eN" 'comint-psearch-input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (define-key comint-mode-map "\C-cR" 'comint-msearch-input-matching))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 ;;; This function is used to make a full copy of the comint mode map,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 ;;; so that client modes won't interfere with each other. This function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 ;;; isn't necessary in emacs 18.5x, but we keep it around for 18.4x versions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (defun full-copy-sparse-keymap (km)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 "Recursively copy the sparse keymap KM"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (cond ((consp km)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (cons (full-copy-sparse-keymap (car km))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (full-copy-sparse-keymap (cdr km))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (t km)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (defun comint-check-proc (buffer-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 "True if there is a process associated w/buffer BUFFER-NAME, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 it is alive (status RUN or STOP)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (let ((proc (get-buffer-process buffer-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (and proc (memq (process-status proc) '(run stop)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 ;;; Note that this guy, unlike shell.el's make-shell, barfs if you pass it ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 ;;; for the second argument (program).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (defun make-comint (name program &optional startfile &rest switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (let* ((buffer (get-buffer-create (concat "*" name "*")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (proc (get-buffer-process buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 ;; If no process, or nuked process, crank up a new one and put buffer in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 ;; comint mode. Otherwise, leave buffer and existing process alone.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (cond ((or (not proc) (not (memq (process-status proc) '(run stop))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (comint-exec buffer name program startfile switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (comint-mode)))) ; Install local vars, mode, keymap, ...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (defun comint-exec (buffer name command startfile switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 "Fires up a process in buffer for comint modes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 Blasts any old process running in the buffer. Doesn't set the buffer mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 You can use this to cheaply run a series of processes in the same comint
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (let ((proc (get-buffer-process buffer))) ; Blast any old process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (if proc (delete-process proc)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 ;; Crank up a new process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (let ((proc (apply 'start-process name buffer (concat exec-directory "env")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (format "TERMCAP=emacs:co#%d:tc=unknown:"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (screen-width))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 "TERM=emacs" "EMACS=t" "-" command switches)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 ;; Feed it the startfile.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (cond (startfile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 ;;This is guaranteed to wait long enough
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 ;;but has bad results if the comint does not prompt at all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 ;; (while (= size (buffer-size))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 ;; (sleep-for 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 ;;I hope 1 second is enough!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (sleep-for 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (insert-file-contents startfile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (setq startfile (buffer-substring (point) (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (delete-region (point) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (process-send-string proc startfile)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 ;; Jump to the end, and set the process mark.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (set-marker (process-mark proc) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 ;;; Ring Code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 ;;;============================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 ;;; This code defines a ring data structure. A ring is a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 ;;; (hd-index tl-index . vector)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 ;;; list. You can insert to, remove from, and rotate a ring. When the ring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 ;;; fills up, insertions cause the oldest elts to be quietly dropped.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 ;;; HEAD = index of the newest item on the ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 ;;; TAIL = index of the oldest item on the ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 ;;; These functions are used by the input history mechanism, but they can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 ;;; be used for other purposes as well.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (defun ring-p (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 "T if X is a ring; NIL otherwise."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (and (consp x) (integerp (car x))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (consp (cdr x)) (integerp (car (cdr x)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (vectorp (cdr (cdr x)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (defun make-ring (size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 "Make a ring that can contain SIZE elts"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (cons 1 (cons 0 (make-vector (+ size 1) nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (defun ring-plus1 (index veclen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 "INDEX+1, with wraparound"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (let ((new-index (+ index 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (if (= new-index veclen) 0 new-index)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (defun ring-minus1 (index veclen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 "INDEX-1, with wraparound"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (- (if (= 0 index) veclen index) 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (defun ring-length (ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (let ((hd (car ring)) (tl (car (cdr ring))) (siz (length (cdr (cdr ring)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (let ((len (if (<= hd tl) (+ 1 (- tl hd)) (+ 1 tl (- siz hd)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (if (= len siz) 0 len))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (defun ring-empty-p (ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (= 0 (ring-length ring)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (defun ring-insert (ring item)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 "Insert a new item onto the ring. If the ring is full, dump the oldest
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 item to make room."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (let* ((vec (cdr (cdr ring))) (len (length vec))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (new-hd (ring-minus1 (car ring) len)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (setcar ring new-hd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (aset vec new-hd item)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (if (ring-empty-p ring) ;overflow -- dump one off the tail.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (setcar (cdr ring) (ring-minus1 (car (cdr ring)) len)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (defun ring-remove (ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 "Remove the oldest item retained on the ring."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (if (ring-empty-p ring) (error "Ring empty")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (let ((tl (car (cdr ring))) (vec (cdr (cdr ring))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (set-car (cdr ring) (ring-minus1 tl (length vec)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (aref vec tl))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 ;;; This isn't actually used in this package. I just threw it in in case
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 ;;; someone else wanted it. If you want rotating-ring behavior on your history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 ;;; retrieval (analagous to kill ring behavior), this function is what you
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 ;;; need. I should write the yank-input and yank-pop-input-or-kill to go with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 ;;; this, and not bind it to a key by default, so it would be available to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 ;;; people who want to bind it to a key. But who would want it? Blech.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (defun ring-rotate (ring n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (if (not (= n 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (if (ring-empty-p ring) ;Is this the right error check?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (error "ring empty")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (let ((hd (car ring)) (tl (car (cdr ring))) (vec (cdr (cdr ring))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (let ((len (length vec)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (while (> n 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (setq tl (ring-plus1 tl len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (aset ring tl (aref ring hd))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (setq hd (ring-plus1 hd len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (setq n (- n 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 (while (< n 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 (setq hd (ring-minus1 hd len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (aset vec hd (aref vec tl))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (setq tl (ring-minus1 tl len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 (setq n (- n 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (set-car ring hd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (set-car (cdr ring) tl)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (defun comint-mod (n m)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 "Returns N mod M. M is positive. Answer is guaranteed to be non-negative,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 and less than m."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 (let ((n (% n m)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (if (>= n 0) n
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 (+ n
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (if (>= m 0) m (- m)))))) ; (abs m)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 (defun ring-ref (ring index)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 (let ((numelts (ring-length ring)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 (if (= numelts 0) (error "indexed empty ring")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 (let* ((hd (car ring)) (tl (car (cdr ring))) (vec (cdr (cdr ring)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 (index (comint-mod index numelts))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 (vec-index (comint-mod (+ index hd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (length vec))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (aref vec vec-index)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 ;;; Input history retrieval commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 ;;; M-p -- previous input M-n -- next input
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 ;;; C-c r -- previous input matching
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 ;;; ===========================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 (defun comint-previous-input (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 "Cycle backwards through input history."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 (interactive "*p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 (let ((len (ring-length input-ring)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 (cond ((<= len 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 (message "Empty input ring")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (ding))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 ((not (comint-after-pmark-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 (message "Not after process mark")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 (ding))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 (cond ((eq last-command 'comint-previous-input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (delete-region (mark) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 (set-mark (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 (setq input-ring-index
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 (if (> arg 0) -1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 (if (< arg 0) 1 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 (push-mark (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 (setq input-ring-index (comint-mod (+ input-ring-index arg) len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 (message "%d" (1+ input-ring-index))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (insert (ring-ref input-ring input-ring-index))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (setq this-command 'comint-previous-input))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (t (ding)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 (defun comint-next-input (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 "Cycle forwards through input history."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (interactive "*p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 (comint-previous-input (- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (defvar comint-last-input-match ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 "Last string searched for by comint input history search, for defaulting.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 Buffer local variable.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (defun comint-previous-input-matching (str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 "Searches backwards through input history for substring match"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 (interactive (let ((s (read-from-minibuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (format "Command substring (default %s): "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 comint-last-input-match))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (list (if (string= s "") comint-last-input-match s))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 ; (interactive "sCommand substring: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (setq comint-last-input-match str) ; update default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 (let ((str (regexp-quote str))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (len (ring-length input-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (n 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (while (and (<= n len) (not (string-match str (ring-ref input-ring n))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 (setq n (+ n 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (cond ((<= n len) (comint-previous-input (+ n 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 (t (error "Not found.")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 ;;; These next three commands are alternatives to the input history commands --
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 ;;; comint-next-input, comint-previous-input and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 ;;; comint-previous-input-matching. They search through the process buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 ;;; text looking for occurrences of the prompt. RMS likes them better;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 ;;; I don't. Bound to M-P, M-N, and C-c R (uppercase P, N, and R) for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 ;;; now. Try'em out. Go with what you like...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 ;;; comint-msearch-input-matching prompts for a string, not a regexp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 ;;; This could be considered to be the wrong thing. I decided to keep it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 ;;; simple, and not make the user worry about regexps. This, of course,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 ;;; limits functionality.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 (defun comint-psearch-input ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 "Search forwards for next occurrence of prompt and skip to end of line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 \(prompt is anything matching regexp comint-prompt-regexp)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (if (re-search-forward comint-prompt-regexp (point-max) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (error "No occurrence of prompt found")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 (defun comint-msearch-input ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 "Search backwards for previous occurrence of prompt and skip to end of line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 Search starts from beginning of current line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 (let ((p (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (cond ((re-search-backward comint-prompt-regexp (point-min) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (t nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 (if p (goto-char p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 (error "No occurrence of prompt found"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 (defun comint-msearch-input-matching (str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 "Search backwards for occurrence of prompt followed by STRING.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 STRING is prompted for, and is NOT a regular expression."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 (interactive (let ((s (read-from-minibuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (format "Command (default %s): "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 comint-last-input-match))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 (list (if (string= s "") comint-last-input-match s))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 ; (interactive "sCommand: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 (setq comint-last-input-match str) ; update default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (let* ((r (concat comint-prompt-regexp (regexp-quote str)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (p (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 (cond ((re-search-backward r (point-min) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 (t nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 (if p (goto-char p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 (error "No match"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 (defun comint-send-input ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 "Send input to process. After the process output mark, sends all text
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 from the process mark to point as input to the process. Before the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 process output mark, calls value of variable comint-get-old-input to retrieve
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 old input, copies it to the end of the buffer, and sends it. A terminal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 newline is also inserted into the buffer and sent to the process. In either
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 case, value of variable comint-input-sentinel is called on the input before
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 sending it. The input is entered into the input history ring, if value of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 variable comint-input-filter returns T when called on the input.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 comint-get-old-input, comint-input-sentinel, and comint-input-filter are chosen
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 according to the command interpreter running in the buffer. E.g.,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 If the interpreter is the csh,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 comint-get-old-input is the default: take the current line, discard any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 initial string matching regexp comint-prompt-regexp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 comint-input-sentinel monitors input for \"cd\", \"pushd\", and \"popd\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 commands. When it sees one, it cd's the buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 comint-input-filter is the default: returns T if the input isn't all white
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 space.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 If the comint is Lucid Common Lisp,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 comint-get-old-input snarfs the sexp ending at point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 comint-input-sentinel does nothing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 comint-input-filter returns NIL if the input matches input-filter-regexp,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 which matches (1) all whitespace (2) :a, :c, etc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 Similarly for Soar, Scheme, etc.."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 ;; Note that the input string does not include its terminal newline.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 (let ((proc (get-buffer-process (current-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 (if (not proc) (error "Current buffer has no process")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 (let* ((pmark (process-mark proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 (pmark-val (marker-position pmark))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (input (if (>= (point) pmark-val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 (buffer-substring pmark (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 (let ((copy (funcall comint-get-old-input)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 (goto-char pmark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 (insert copy)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 copy))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 (insert ?\n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (if (funcall comint-input-filter input) (ring-insert input-ring input))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 (funcall comint-input-sentinel input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 (process-send-string proc input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 (process-send-string proc "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 (set-marker (process-mark proc) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 (set-marker comint-last-input-end (point))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 (defun comint-get-old-input-default ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 "Default for comint-get-old-input: take the current line, and discard
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 any initial text matching comint-prompt-regexp."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 (comint-skip-prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 (let ((beg (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 (buffer-substring beg (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 (defun comint-skip-prompt ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 "Skip past the text matching regexp comint-prompt-regexp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 If this takes us past the end of the current line, don't skip at all."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 (let ((eol (save-excursion (end-of-line) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 (if (and (looking-at comint-prompt-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 (<= (match-end 0) eol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 (goto-char (match-end 0)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 (defun comint-after-pmark-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 "Is point after the process output marker?"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 ;; Since output could come into the buffer after we looked at the point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 ;; but before we looked at the process marker's value, we explicitly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 ;; serialise. This is just because I don't know whether or not emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 ;; services input during execution of lisp commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 (let ((proc-pos (marker-position
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 (process-mark (get-buffer-process (current-buffer))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 (<= proc-pos (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 (defun comint-bol (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 "Goes to the beginning of line, then skips past the prompt, if any.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 If a prefix argument is given (\\[universal-argument]), then no prompt skip
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 -- go straight to column 0.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 The prompt skip is done by skipping text matching the regular expression
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 comint-prompt-regexp, a buffer local variable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 If you don't like this command, reset c-a to beginning-of-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 in your hook, comint-mode-hook."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 (if (null arg) (comint-skip-prompt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 ;;; These two functions are for entering text you don't want echoed or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 ;;; saved -- typically passwords to ftp, telnet, or somesuch.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 ;;; Just enter m-x send-invisible and type in your line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 (defun comint-read-noecho (prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 "Prompt the user with argument PROMPT. Read a single line of text
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 without echoing, and return it. Note that the keystrokes comprising
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 the text can still be recovered (temporarily) with \\[view-lossage]. This
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 may be a security bug for some applications."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 (let ((echo-keystrokes 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 (answ "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 tem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 (if (and (stringp prompt) (not (string= (message prompt) "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 (message prompt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 (while (not(or (= (setq tem (read-char)) ?\^m)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 (= tem ?\n)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 (setq answ (concat answ (char-to-string tem))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 (message "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 answ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 (defun send-invisible (str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 "Read a string without echoing, and send it to the process running
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 in the current buffer. A new-line is additionally sent. String is not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 saved on comint input history list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 Security bug: your string can still be temporarily recovered with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 \\[view-lossage]."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 ; (interactive (list (comint-read-noecho "Enter non-echoed text")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 (interactive "P") ; Defeat snooping via C-x esc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 (let ((proc (get-buffer-process (current-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 (if (not proc) (error "Current buffer has no process")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 (process-send-string proc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 (if (stringp str) str
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 (comint-read-noecho "Enter non-echoed text")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 (process-send-string proc "\n"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 ;;; Random input hackage
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 (defun comint-kill-output ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 "Kill all output from interpreter since last input."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 (let ((pmark (process-mark (get-buffer-process (current-buffer)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 (kill-region comint-last-input-end pmark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 (goto-char pmark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 (insert "*** output flushed ***\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 (set-marker pmark (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 (defun comint-show-output ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 "Display start of this batch of interpreter output at top of window.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 Also put cursor there."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 (goto-char comint-last-input-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 (backward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 (set-window-start (selected-window) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 (end-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 (defun comint-interrupt-subjob ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 "Interrupt the current subjob."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 (interrupt-process nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 (defun comint-kill-subjob ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 "Send kill signal to the current subjob."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 (kill-process nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 (defun comint-quit-subjob ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 "Send quit signal to the current subjob."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 (quit-process nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 (defun comint-stop-subjob ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 "Stop the current subjob.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 WARNING: if there is no current subjob, you can end up suspending
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 the top-level process running in the buffer. If you accidentally do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 this, use \\[comint-continue-subjob] to resume the process. (This
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 is not a problem with most shells, since they ignore this signal.)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 (stop-process nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 (defun comint-continue-subjob ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 "Send CONT signal to process buffer's process group.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 Useful if you accidentally suspend the top-level process."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 (continue-process nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 (defun comint-kill-input ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 "Kill all text from last stuff output by interpreter to point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 (let* ((pmark (process-mark (get-buffer-process (current-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 (p-pos (marker-position pmark)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 (if (> (point) p-pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 (kill-region pmark (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 (defun comint-delchar-or-maybe-eof (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 "Delete ARG characters forward, or send an EOF to lisp if at end of buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 (if (eobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 (process-send-eof)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 (delete-char arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 ;;; Support for source-file processing commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 ;;;============================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 ;;; Many command-interpreters (e.g., Lisp, Scheme, Soar) have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 ;;; commands that process files of source text (e.g. loading or compiling
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 ;;; files). So the corresponding process-in-a-buffer modes have commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 ;;; for doing this (e.g., lisp-load-file). The functions below are useful
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 ;;; for defining these commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 ;;; Alas, these guys don't do exactly the right thing for Lisp, Scheme
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 ;;; and Soar, in that they don't know anything about file extensions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 ;;; So the compile/load interface gets the wrong default occasionally.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 ;;; The load-file/compile-file default mechanism could be smarter -- it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 ;;; doesn't know about the relationship between filename extensions and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 ;;; whether the file is source or executable. If you compile foo.lisp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 ;;; with compile-file, then the next load-file should use foo.bin for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 ;;; the default, not foo.lisp. This is tricky to do right, particularly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 ;;; because the extension for executable files varies so much (.o, .bin,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 ;;; .lbin, .mo, .vo, .ao, ...).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 ;;; COMINT-SOURCE-DEFAULT -- determines defaults for source-file processing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 ;;; commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 ;;; COMINT-CHECK-SOURCE -- if FNAME is in a modified buffer, asks you if you
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 ;;; want to save the buffer before issuing any process requests to the command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 ;;; interpreter.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 ;;; COMINT-GET-SOURCE -- used by the source-file processing commands to prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 ;;; for the file to process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 ;;; (COMINT-SOURCE-DEFAULT previous-dir/file source-modes)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 ;;;============================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 ;;; This function computes the defaults for the load-file and compile-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 ;;; commands for tea, soar, cmulisp, and cmuscheme modes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 ;;; - PREVIOUS-DIR/FILE is a pair (directory . filename) from the last
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 ;;; source-file processing command. NIL if there hasn't been one yet.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 ;;; - SOURCE-MODES is a list used to determine what buffers contain source
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 ;;; files: if the major mode of the buffer is in SOURCE-MODES, it's source.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 ;;; Typically, (lisp-mode) or (scheme-mode).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 ;;; If the command is given in a file buffer whose major modes is in
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
721 ;;; SOURCE-MODES, then the filename is the default file, and the
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 ;;; file's directory is the default directory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 ;;; If the buffer isn't a source file buffer (e.g., it's the process buffer),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 ;;; then the default directory & file are what was used in the last source-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 ;;; processing command (i.e., PREVIOUS-DIR/FILE). If this is the first time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 ;;; the command has been run (PREVIOUS-DIR/FILE is nil), the default directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 ;;; is the cwd, with no default file. (\"no default file\" = nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 ;;; SOURCE-REGEXP is typically going to be something like (tea-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 ;;; for T programs, (lisp-mode) for Lisp programs, (soar-mode lisp-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 ;;; for Soar programs, etc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 ;;; The function returns a pair: (default-directory . default-file).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 (defun comint-source-default (previous-dir/file source-modes)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 (cond ((and buffer-file-name (memq major-mode source-modes))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 (cons (file-name-directory buffer-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 (file-name-nondirectory buffer-file-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 (previous-dir/file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 (cons default-directory nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 ;;; (COMINT-CHECK-SOURCE fname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 ;;;============================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 ;;; Prior to loading or compiling (or otherwise processing) a file (in the CMU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 ;;; process-in-a-buffer modes), this function can be called on the filename.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 ;;; If the file is loaded into a buffer, and the buffer is modified, the user
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 ;;; is queried to see if he wants to save the buffer before proceeding with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 ;;; the load or compile.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 (defun comint-check-source (fname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 (let ((buff (get-file-buffer fname)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 (if (and buff
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 (buffer-modified-p buff)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 (y-or-n-p (format "Save buffer %s first? "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 (buffer-name buff))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 ;; save BUFF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 (let ((old-buffer (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 (set-buffer buff)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 (save-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 (set-buffer old-buffer)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 ;;; (COMINT-GET-SOURCE prompt prev-dir/file source-modes mustmatch-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 ;;;============================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 ;;; COMINT-GET-SOURCE is used to prompt for filenames in command-interpreter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 ;;; commands that process source files (like loading or compiling a file).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 ;;; It prompts for the filename, provides a default, if there is one,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 ;;; and returns the result filename.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 ;;; See COMINT-SOURCE-DEFAULT for more on determining defaults.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 ;;; PROMPT is the prompt string. PREV-DIR/FILE is the (directory . file) pair
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 ;;; from the last source processing command. SOURCE-MODES is a list of major
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 ;;; modes used to determine what file buffers contain source files. (These
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 ;;; two arguments are used for determining defaults). If MUSTMATCH-P is true,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 ;;; then the filename reader will only accept a file that exists.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 ;;; A typical use:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 ;;; (interactive (comint-get-source "Compile file: " prev-lisp-dir/file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 ;;; "\\.lisp\\'" t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 (defun comint-get-source (prompt prev-dir/file source-regexp mustmatch-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 (let* ((def (comint-source-default prev-dir/file source-regexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 (defdir (car def))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 (deffile (cdr def))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 (ans (read-file-name (if deffile (format "%s(default %s) "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 prompt deffile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 defdir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 (concat defdir deffile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 mustmatch-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 (list (expand-file-name (substitute-in-file-name ans)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 ;;; Filename completion in a buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 ;;; ===========================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 ;;; Useful completion functions, courtesy of the Ergo group.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 ;;; M-<Tab> will complete the filename at the cursor as much as possible
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 ;;; M-? will display a list of completions in the help buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 ;;; Three commands:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 ;;; comint-dynamic-complete Complete filename at point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 ;;; comint-dynamic-list-completions List completions in help buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 ;;; comint-replace-by-expanded-filename Expand and complete filename at point;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 ;;; replace with expanded/completed name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 ;;; These are not installed in the comint-mode keymap. But they are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 ;;; available for people who want them. Shell-mode installs them:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 ;;; (define-key cmushell-mode-map "\M-\t" 'comint-dynamic-complete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 ;;; (define-key cmushell-mode-map "\M-?" 'comint-dynamic-list-completions)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 ;;; Commands like this are fine things to put in load hooks if you
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 ;;; want them present in specific modes. Example:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 ;;; (setq cmushell-load-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 ;;; '((lambda () (define-key lisp-mode-map "\M-\t"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 ;;; 'comint-replace-by-expanded-filename))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 (defun comint-match-partial-pathname ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 "Returns the string of an existing filename or causes and error."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 (if (save-excursion (backward-char 1) (looking-at "\\s ")) ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 (re-search-backward "[^~/A-Za-z0-9---_.$#,]+")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 (re-search-forward "[~/A-Za-z0-9---_.$#,]+")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 (substitute-in-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 (buffer-substring (match-beginning 0) (match-end 0))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 (defun comint-replace-by-expanded-filename ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 "Replace filename at point with expanded, completed name"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 (let* ((pathname (comint-match-partial-pathname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 (pathdir (file-name-directory pathname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 (pathnondir (file-name-nondirectory pathname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 (completion (file-name-completion pathnondir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 (or pathdir default-directory))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 (cond ((null completion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 (message "No completions of %s." pathname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 (ding))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 ((eql completion t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 (message "Unique completion."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 (t ; this means a string was returned.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 (delete-region (match-beginning 0) (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 (insert pathdir completion)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 (defun comint-dynamic-complete ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 "Dynamically complete the filename at point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 (let* ((pathname (comint-match-partial-pathname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 (pathdir (file-name-directory pathname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 (pathnondir (file-name-nondirectory pathname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 (completion (file-name-completion pathnondir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 (or pathdir default-directory))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 (cond ((null completion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 (message "No completions of %s." pathname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 (ding))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 ((eql completion t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 (message "Unique completion."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 (t ; this means a string was returned.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 (insert (substring completion (length pathnondir)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 (defun comint-dynamic-list-completions ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 "List in help buffer all possible completions of the filename at point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 (let* ((pathname (comint-match-partial-pathname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 (pathdir (file-name-directory pathname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 (pathnondir (file-name-nondirectory pathname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 (completions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 (file-name-all-completions pathnondir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 (or pathdir default-directory))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 (cond ((null completions)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 (message "No completions of %s." pathname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 (ding))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 (t (with-output-to-temp-buffer "*Help*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 (display-completion-list completions))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 ; Ergo bindings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 ; (global-set-key "\M-\t" 'comint-replace-by-expanded-filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 ; (global-set-key "\M-?" 'comint-dynamic-list-completions)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 ; (define-key shell-mode-map "\M-\t" 'comint-dynamic-complete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 ;;; Log the user, so I know who's using the package during the beta test
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 ;;; period. This just inserts the user's name and current time into a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 ;;; central file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 (defun comint-log-user ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 (if (file-writable-p "/afs/cs/user/shivers/lib/emacs/logdir/comint.log")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 (let ((u (getenv "USER"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 (old-buff (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 (message "logging user in beta test database...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 (find-file "/afs/cs/user/shivers/lib/emacs/logdir/comint.log")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 (cond ((search-forward u nil 'to-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 (search-forward "| ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 (kill-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 (t (insert (format "%s\t%s\t| " u (current-time-string)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 (insert (format "%s\n" (current-time-string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 (let ((make-backup-files nil)) (save-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 (kill-buffer (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 (set-buffer old-buff))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 (comint-log-user)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 ;;; Converting process modes to use comint mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 ;;; ===========================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 ;;; Several gnu packages (tex-mode, background, dbx, gdb, kermit, prolog,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 ;;; telnet are some) use the shell package as clients. Most of them would
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 ;;; be better off using the comint package, but they predate it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 ;;; Altering these packages to use comint mode should greatly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 ;;; improve their functionality, and is fairly easy.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 ;;; Renaming variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 ;;; Most of the work is renaming variables and functions. These are the common
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 ;;; ones:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 ;;; Local variables:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 ;;; last-input-end comint-last-input-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 ;;; last-input-start <unnecessary>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 ;;; shell-prompt-pattern comint-prompt-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922 ;;; shell-set-directory-error-hook <no equivalent>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923 ;;; Miscellaneous:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 ;;; shell-set-directory <unnecessary>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 ;;; shell-mode-map comint-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 ;;; Commands:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 ;;; shell-send-input comint-send-input
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 ;;; shell-send-eof comint-delchar-or-maybe-eof
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 ;;; kill-shell-input comint-kill-input
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930 ;;; interrupt-shell-subjob comint-interrupt-subjob
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 ;;; stop-shell-subjob comint-stop-subjob
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 ;;; quit-shell-subjob comint-quit-subjob
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 ;;; kill-shell-subjob comint-kill-subjob
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 ;;; kill-output-from-shell comint-kill-output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 ;;; show-output-from-shell comint-show-output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 ;;; copy-last-shell-input Use comint-previous-input/comint-next-input
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 ;;; LAST-INPUT-START is no longer necessary because inputs are stored on the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 ;;; input history ring. SHELL-SET-DIRECTORY is gone, its functionality taken
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 ;;; over by SHELL-DIRECTORY-TRACKER, the shell mode's comint-input-sentinel.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941 ;;; Comint mode does not provide functionality equivalent to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942 ;;; shell-set-directory-error-hook; it is gone.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 ;;; If you are implementing some process-in-a-buffer mode, called foo-mode, do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 ;;; *not* create the comint-mode local variables in your foo-mode function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946 ;;; This is not modular. Instead, call comint-mode, and let *it* create the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947 ;;; necessary comint-specific local variables. Then create the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948 ;;; foo-mode-specific local variables in foo-mode. Set the buffer's keymap to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949 ;;; be foo-mode-map, and it's mode to be foo-mode. Set the comint-mode hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950 ;;; (comint-prompt-regexp, comint-input-filter, comint-input-sentinel,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 ;;; comint-get-old-input) that need to be different from the defaults. Call
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 ;;; foo-mode-hook, and you're done. Don't run the comint-mode hook yourself;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953 ;;; comint-mode will take care of it. The following example, from cmushell.el,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954 ;;; is typical:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 ;;; (defun shell-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957 ;;; (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958 ;;; (comint-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959 ;;; (setq comint-prompt-regexp shell-prompt-pattern)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960 ;;; (setq major-mode 'shell-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961 ;;; (setq mode-name "Shell")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962 ;;; (cond ((not shell-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963 ;;; (setq shell-mode-map (full-copy-sparse-keymap comint-mode-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964 ;;; (define-key shell-mode-map "\M-\t" 'comint-dynamic-complete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 ;;; (define-key shell-mode-map "\M-?"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966 ;;; 'comint-dynamic-list-completions)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967 ;;; (use-local-map shell-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968 ;;; (make-local-variable 'shell-directory-stack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 ;;; (setq shell-directory-stack nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 ;;; (setq comint-input-sentinel 'shell-directory-tracker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971 ;;; (run-hooks 'shell-mode-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974 ;;; Note that make-comint is different from make-shell in that it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975 ;;; doesn't have a default program argument. If you give make-shell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 ;;; a program name of NIL, it cleverly chooses one of explicit-shell-name,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977 ;;; $ESHELL, $SHELL, or /bin/sh. If you give make-comint a program argument
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 ;;; of NIL, it barfs. Adjust your code accordingly...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981 ;;; Do the user's customisation...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983 (defvar comint-load-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984 "This hook is run when comint is loaded in.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985 This is a good place to put keybindings.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987 (run-hooks 'comint-load-hook)