0
|
1 ;;; comint.el --- general command interpreter in a window stuff
|
|
2
|
|
3 ;; Copyright (C) 1988, 90, 92, 93, 94, 95 Free Software Foundation, Inc.
|
|
4
|
|
5 ;; Author: Olin Shivers <shivers@cs.cmu.edu>
|
|
6 ;; Adapted-by: Simon Marshall <simon@gnu.ai.mit.edu>
|
|
7 ;; Keywords: processes
|
|
8
|
|
9 ;; This file is part of XEmacs.
|
|
10
|
|
11 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
12 ;; under the terms of the GNU General Public License as published by
|
|
13 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
14 ;; any later version.
|
|
15
|
|
16 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
19 ;; General Public License for more details.
|
|
20
|
|
21 ;; You should have received a copy of the GNU General Public License
|
16
|
22 ;; along with XEmacs; see the file COPYING. If not, write to the
|
|
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
24 ;; Boston, MA 02111-1307, USA.
|
0
|
25
|
|
26 ;;; Synched up with: FSF 19.30.
|
|
27
|
|
28 ;;; Commentary:
|
|
29
|
|
30 ;;; Please send me bug reports, bug fixes, and extensions, so that I can
|
|
31 ;;; merge them into the master source.
|
|
32 ;;; - Olin Shivers (shivers@cs.cmu.edu)
|
|
33 ;;; - Simon Marshall (simon@gnu.ai.mit.edu)
|
|
34
|
|
35 ;;; This file defines a general command-interpreter-in-a-buffer package
|
|
36 ;;; (comint mode). The idea is that you can build specific process-in-a-buffer
|
|
37 ;;; modes on top of comint mode -- e.g., lisp, shell, scheme, T, soar, ....
|
|
38 ;;; This way, all these specific packages share a common base functionality,
|
|
39 ;;; and a common set of bindings, which makes them easier to use (and
|
|
40 ;;; saves code, implementation time, etc., etc.).
|
|
41
|
|
42 ;;; Several packages are already defined using comint mode:
|
|
43 ;;; - shell.el defines a shell-in-a-buffer mode.
|
|
44 ;;; - cmulisp.el defines a simple lisp-in-a-buffer mode.
|
|
45 ;;;
|
|
46 ;;; - The file cmuscheme.el defines a scheme-in-a-buffer mode.
|
|
47 ;;; - The file tea.el tunes scheme and inferior-scheme modes for T.
|
|
48 ;;; - The file soar.el tunes lisp and inferior-lisp modes for Soar.
|
|
49 ;;; - cmutex.el defines tex and latex modes that invoke tex, latex, bibtex,
|
|
50 ;;; previewers, and printers from within emacs.
|
|
51 ;;; - background.el allows csh-like job control inside emacs.
|
|
52 ;;; It is pretty easy to make new derived modes for other processes.
|
|
53
|
|
54 ;;; For documentation on the functionality provided by comint mode, and
|
|
55 ;;; the hooks available for customising it, see the comments below.
|
|
56 ;;; For further information on the standard derived modes (shell,
|
|
57 ;;; inferior-lisp, inferior-scheme, ...), see the relevant source files.
|
|
58
|
|
59 ;;; For hints on converting existing process modes (e.g., tex-mode,
|
|
60 ;;; background, dbx, gdb, kermit, prolog, telnet) to use comint-mode
|
|
61 ;;; instead of shell-mode, see the notes at the end of this file.
|
|
62
|
|
63
|
|
64 ;;; Brief Command Documentation:
|
|
65 ;;;============================================================================
|
|
66 ;;; Comint Mode Commands: (common to all derived modes, like shell & cmulisp
|
|
67 ;;; mode)
|
|
68 ;;;
|
|
69 ;;; XEmacs - FSF19 binds M-p/M-n to comint-{previous,next}-input instead of
|
|
70 ;;; comint-{previous,next}-matching-input-from-input.
|
|
71 ;;; XEmacs is mo' better.
|
|
72 ;;;
|
|
73 ;;;
|
|
74 ;;; m-p comint-previous-matching-input-from-input Cycle backwards in input history
|
|
75 ;;; m-n comint-next-matching-input-from-input Cycle forwards
|
|
76 ;;; m-r comint-previous-matching-input Previous input matching a regexp
|
|
77 ;;; m-s comint-next-matching-input Next input that matches
|
|
78 ;;; XEmacs - remove evil binding of M-C-l. It's already bound to C-c C-r.
|
|
79 ;;; NOT: m-c-l comint-show-output Show last batch of process output
|
|
80 ;;; m-c-r comint-previous-input-matching Search backwards in input history
|
|
81 ;;; return comint-send-input
|
|
82 ;;; XEmacs - fsf nuked the binding for ^A, and we nuked the binding for ^D
|
|
83 ;;; c-a comint-bol Beginning of line; skip prompt
|
|
84 ;;; NOT: c-d comint-delchar-or-maybe-eof Delete char unless at end of buff
|
|
85 ;;; c-c c-a comint-bol Beginning of line; skip prompt
|
|
86 ;;; c-c c-d comint-send-eof ^d
|
|
87 ;;; c-c c-u comint-kill-input ^u
|
|
88 ;;; c-c c-w backward-kill-word ^w
|
|
89 ;;; c-c c-c comint-interrupt-subjob ^c
|
|
90 ;;; c-c c-z comint-stop-subjob ^z
|
|
91 ;;; c-c c-\ comint-quit-subjob ^\
|
|
92 ;;; c-c c-o comint-kill-output Delete last batch of process output
|
|
93 ;;; c-c c-r comint-show-output Show last batch of process output
|
|
94 ;;; c-c c-l comint-dynamic-list-input-ring List input history
|
|
95 ;;;
|
|
96 ;;; Not bound by default in comint-mode (some are in shell mode)
|
|
97 ;;; comint-run Run a program under comint-mode
|
|
98 ;;; send-invisible Read a line w/o echo, and send to proc
|
|
99 ;;; comint-dynamic-complete-filename Complete filename at point.
|
|
100 ;;; comint-dynamic-complete-variable Complete variable name at point.
|
|
101 ;;; comint-dynamic-list-filename-completions List completions in help buffer.
|
|
102 ;;; comint-replace-by-expanded-filename Expand and complete filename at point;
|
|
103 ;;; replace with expanded/completed name.
|
|
104 ;;; comint-replace-by-expanded-history Expand history at point;
|
|
105 ;;; replace with expanded name.
|
|
106 ;;; comint-magic-space Expand history and add (a) space(s).
|
|
107 ;;; comint-kill-subjob No mercy.
|
|
108 ;;; comint-show-maximum-output Show as much output as possible.
|
|
109 ;;; comint-continue-subjob Send CONT signal to buffer's process
|
|
110 ;;; group. Useful if you accidentally
|
|
111 ;;; suspend your process (with C-c C-z).
|
|
112
|
|
113 ;;; comint-mode-hook is the comint mode hook. Basically for your keybindings.
|
|
114
|
|
115 ;;; Code:
|
|
116
|
|
117 (require 'ring)
|
|
118
|
|
119 ;;; Buffer Local Variables:
|
|
120 ;;;============================================================================
|
|
121 ;;; Comint mode buffer local variables:
|
|
122 ;;; comint-prompt-regexp - string comint-bol uses to match prompt
|
|
123 ;;; comint-delimiter-argument-list - list For delimiters and arguments
|
|
124 ;;; comint-last-input-start - marker Handy if inferior always echoes
|
|
125 ;;; comint-last-input-end - marker For comint-kill-output command
|
|
126 ;;; comint-input-ring-size - integer For the input history
|
|
127 ;;; comint-input-ring - ring mechanism
|
|
128 ;;; comint-input-ring-index - number ...
|
|
129 ;;; comint-input-autoexpand - symbol ...
|
|
130 ;;; comint-input-ignoredups - boolean ...
|
|
131 ;;; comint-last-input-match - string ...
|
|
132 ;;; comint-dynamic-complete-functions - hook For the completion mechanism
|
|
133 ;;; comint-completion-fignore - list ...
|
|
134 ;;; comint-file-name-quote-list - list ...
|
|
135 ;;; comint-get-old-input - function Hooks for specific
|
|
136 ;;; comint-input-filter-functions - hook process-in-a-buffer
|
|
137 ;;; comint-output-filter-functions - hook function modes.
|
|
138 ;;; comint-input-filter - function ...
|
|
139 ;;; comint-input-sender - function ...
|
|
140 ;;; comint-eol-on-send - boolean ...
|
|
141 ;;; comint-process-echoes - boolean ...
|
|
142 ;;; comint-scroll-to-bottom-on-input - symbol For scroll behavior
|
|
143 ;;; comint-scroll-to-bottom-on-output - symbol ...
|
|
144 ;;; comint-scroll-show-maximum-output - boolean...
|
|
145 ;;;
|
|
146 ;;; Comint mode non-buffer local variables:
|
|
147 ;;; comint-completion-addsuffix - boolean/cons For file name completion
|
|
148 ;;; comint-completion-autolist - boolean behavior
|
|
149 ;;; comint-completion-recexact - boolean ...
|
|
150
|
|
151 (defvar comint-prompt-regexp "^"
|
|
152 "Regexp to recognise prompts in the inferior process.
|
|
153 Defaults to \"^\", the null string at BOL.
|
|
154
|
|
155 Good choices:
|
|
156 Canonical Lisp: \"^[^> \\n]*>+:? *\" (Lucid, franz, kcl, T, cscheme, oaklisp)
|
|
157 Lucid Common Lisp: \"^\\\\(>\\\\|\\\\(->\\\\)+\\\\) *\"
|
|
158 franz: \"^\\\\(->\\\\|<[0-9]*>:\\\\) *\"
|
|
159 kcl: \"^>+ *\"
|
|
160 shell: \"^[^#$%>\\n]*[#$%>] *\"
|
|
161 T: \"^>+ *\"
|
|
162
|
|
163 The pattern should begin with \"^\". It can match text on more than one line.
|
|
164 This pattern gets handed to re-search-backward, not looking-at.
|
|
165
|
|
166 This is a good thing to set in mode hooks.")
|
|
167
|
|
168 (defvar comint-delimiter-argument-list ()
|
|
169 "List of characters to recognise as separate arguments in input.
|
|
170 Strings comprising a character in this list will separate the arguments
|
|
171 surrounding them, and also be regarded as arguments in their own right (unlike
|
|
172 whitespace). See `comint-arguments'.
|
|
173 Defaults to the empty list.
|
|
174
|
|
175 For shells, a good value is (?\\| ?& ?< ?> ?\\( ?\\) ?;).
|
|
176
|
|
177 This is a good thing to set in mode hooks.")
|
|
178
|
|
179 ;; #### BUG: this loser mangles history; when one types
|
|
180 ;; find /tmp \( -name foo \) -print
|
|
181 ;; one gets find /tmp \ ( -name foo \ ) -print
|
|
182 ;;
|
|
183 ;; XEmacs - So turn this off by default. -- jwz
|
|
184 ;;
|
|
185 (defvar comint-input-autoexpand nil
|
|
186 "*If non-nil, expand input command history references on completion.
|
|
187 This mirrors the optional behavior of tcsh (its autoexpand and histlit).
|
|
188
|
|
189 If the value is `input', then the expansion is seen on input.
|
|
190 If the value is `history', then the expansion is only when inserting
|
|
191 into the buffer's input ring. See also `comint-magic-space' and
|
|
192 `comint-dynamic-complete'.
|
|
193
|
|
194 This variable is buffer-local.")
|
|
195
|
|
196 ;; XEmacs - this should default to t for consistency with minibuffer history. -jwz
|
|
197 (defvar comint-input-ignoredups t
|
|
198 "*If non-nil, don't add input matching the last on the input ring.
|
|
199 This mirrors the optional behavior of bash.
|
|
200
|
|
201 This variable is buffer-local.")
|
|
202
|
|
203 (defvar comint-input-ring-file-name nil
|
|
204 "*If non-nil, name of the file to read/write input history.
|
|
205 See also `comint-read-input-ring' and `comint-write-input-ring'.
|
|
206
|
|
207 This variable is buffer-local, and is a good thing to set in mode hooks.")
|
|
208
|
|
209 (defvar comint-scroll-to-bottom-on-input nil
|
|
210 "*Controls whether input to interpreter causes window to scroll.
|
|
211 If nil, then do not scroll. If t or `all', scroll all windows showing buffer.
|
|
212 If `this', scroll only the selected window.
|
|
213
|
|
214 The default is nil.
|
|
215
|
|
216 See `comint-preinput-scroll-to-bottom'. This variable is buffer-local.")
|
|
217
|
|
218 (defvar comint-scroll-to-bottom-on-output nil
|
|
219 "*Controls whether interpreter output causes window to scroll.
|
|
220 If nil, then do not scroll. If t or `all', scroll all windows showing buffer.
|
|
221 If `this', scroll only the selected window.
|
|
222 If `others', scroll only those that are not the selected window.
|
|
223
|
|
224 The default is nil.
|
|
225
|
|
226 See variable `comint-scroll-show-maximum-output' and function
|
|
227 `comint-postoutput-scroll-to-bottom'. This variable is buffer-local.")
|
|
228
|
|
229 ;; XEmacs - Default this to nil: this is just horrible
|
|
230 (defvar comint-scroll-show-maximum-output nil
|
|
231 "*Controls how interpreter output causes window to scroll.
|
|
232 If non-nil, then show the maximum output when the window is scrolled.
|
|
233
|
|
234 See variable `comint-scroll-to-bottom-on-output' and function
|
|
235 `comint-postoutput-scroll-to-bottom'. This variable is buffer-local.")
|
|
236
|
|
237 (defvar comint-buffer-maximum-size 1024
|
|
238 "*The maximum size in lines for comint buffers.
|
|
239 Comint buffers are truncated from the top to be no greater than this number, if
|
|
240 the function `comint-truncate-buffer' is on `comint-output-filter-functions'.")
|
|
241
|
|
242 (defvar comint-input-ring-size 32
|
|
243 "Size of input history ring.")
|
|
244
|
|
245 (defvar comint-process-echoes nil
|
|
246 "*If non-nil, assume that the subprocess echoes any input.
|
|
247 If so, delete one copy of the input so that only one copy eventually
|
|
248 appears in the buffer.
|
|
249
|
|
250 This variable is buffer-local.")
|
|
251
|
|
252 ;; AIX puts the name of the person being su'd to in from of the prompt.
|
|
253 (defvar comint-password-prompt-regexp
|
|
254 (if (eq system-type 'aix-v3)
|
|
255 "\\(\\([Oo]ld \\|[Nn]ew \\|^\\|^..*s\\)[Pp]assword\\|pass phrase\\):\\s *\\'"
|
|
256 "\\(\\([Oo]ld \\|[Nn]ew \\|^\\)[Pp]assword\\|pass phrase\\):\\s *\\'")
|
|
257 "*Regexp matching prompts for passwords in the inferior process.
|
|
258 This is used by `comint-watch-for-password-prompt'.")
|
|
259
|
|
260 ;;; Here are the per-interpreter hooks.
|
|
261 (defvar comint-get-old-input (function comint-get-old-input-default)
|
|
262 "Function that returns old text in comint mode.
|
|
263 This function is called when return is typed while the point is in old text.
|
|
264 It returns the text to be submitted as process input. The default is
|
|
265 `comint-get-old-input-default', which grabs the current line, and strips off
|
|
266 leading text matching `comint-prompt-regexp'.")
|
|
267
|
|
268 ;; XEmacs - fsf doesn't have this, and I think it ought to default to 't'
|
|
269 ;; because it's good idiot-proof interface. --stig
|
|
270 (defvar comint-append-old-input t
|
|
271 "*If nil, old text selected by \\[comint-send-input] is re-sent immediately.
|
|
272 If non-nil, the old text is appended to the end of the buffer,
|
|
273 and a prompting message is printed.
|
|
274
|
|
275 This flag does not affect the behavior of \\[comint-send-input]
|
|
276 after the process output mark.")
|
|
277
|
|
278 (defvar comint-dynamic-complete-functions
|
|
279 '(comint-replace-by-expanded-history comint-dynamic-complete-filename)
|
|
280 "List of functions called to perform completion.
|
|
281 Functions should return non-nil if completion was performed.
|
|
282 See also `comint-dynamic-complete'.
|
|
283
|
|
284 This is a good thing to set in mode hooks.")
|
|
285
|
|
286 (defvar comint-input-filter
|
|
287 #'(lambda (str)
|
|
288 (and (not (string-match "\\`\\s *\\'" str))
|
|
289 ;; XEmacs - ignore '!!' and kin
|
|
290 (> (length str) 2)))
|
|
291 "Predicate for filtering additions to input history.
|
|
292 Takes one argument, the input. If non-nil, the input may be saved on the input
|
|
293 history list. Default is to save anything longer than two characters
|
|
294 that isn't all whitespace.")
|
|
295
|
|
296 (defvar comint-input-filter-functions '()
|
|
297 "Functions to call before input is sent to the process.
|
|
298 These functions get one argument, a string containing the text to send.
|
|
299
|
|
300 This variable is buffer-local.")
|
|
301
|
|
302 (defvar comint-output-filter-functions '(comint-postoutput-scroll-to-bottom
|
|
303 ;; XEmacs - not here by default for FSF
|
|
304 comint-watch-for-password-prompt)
|
|
305 "Functions to call after output is inserted into the buffer.
|
|
306 One possible function is `comint-postoutput-scroll-to-bottom'.
|
|
307 These functions get one argument, a string containing the text just inserted.
|
|
308
|
|
309 This variable is buffer-local.")
|
|
310
|
|
311 (defvar comint-input-sender (function comint-simple-send)
|
|
312 "Function to actually send to PROCESS the STRING submitted by user.
|
|
313 Usually this is just `comint-simple-send', but if your mode needs to
|
|
314 massage the input string, put a different function here.
|
|
315 `comint-simple-send' just sends the string plus a newline.
|
|
316 This is called from the user command `comint-send-input'.")
|
|
317
|
|
318 (defvar comint-eol-on-send t
|
|
319 "*Non-nil means go to the end of the line before sending input.
|
|
320 See `comint-send-input'.")
|
|
321
|
|
322 (defvar comint-mode-hook '()
|
|
323 "Called upon entry into comint-mode
|
|
324 This is run before the process is cranked up.")
|
|
325
|
|
326 (defvar comint-exec-hook '()
|
|
327 "Called each time a process is exec'd by `comint-exec'.
|
|
328 This is called after the process is cranked up. It is useful for things that
|
|
329 must be done each time a process is executed in a comint mode buffer (e.g.,
|
|
330 `(process-kill-without-query)'). In contrast, the `comint-mode-hook' is only
|
|
331 executed once when the buffer is created.")
|
|
332
|
|
333 (defvar comint-mode-map nil)
|
|
334
|
|
335 (defvar comint-ptyp t
|
|
336 "Non-nil if communications via pty; false if by pipe. Buffer local.
|
|
337 This is to work around a bug in Emacs process signalling.")
|
|
338
|
|
339 (defvar comint-input-ring nil)
|
|
340 (defvar comint-last-input-start)
|
|
341 (defvar comint-last-input-end)
|
|
342 (defvar comint-last-output-start)
|
|
343 (defvar comint-input-ring-index nil
|
|
344 "Index of last matched history element.")
|
|
345 (defvar comint-matching-input-from-input-string ""
|
|
346 "Input previously used to match input history.")
|
|
347
|
|
348 (put 'comint-input-ring 'permanent-local t)
|
|
349 (put 'comint-input-ring-index 'permanent-local t)
|
|
350 (put 'comint-input-autoexpand 'permanent-local t)
|
|
351 (put 'comint-input-filter-functions 'permanent-local t)
|
|
352 (put 'comint-output-filter-functions 'permanent-local t)
|
|
353 (put 'comint-scroll-to-bottom-on-input 'permanent-local t)
|
|
354 (put 'comint-scroll-to-bottom-on-output 'permanent-local t)
|
|
355 (put 'comint-scroll-show-maximum-output 'permanent-local t)
|
|
356 (put 'comint-ptyp 'permanent-local t)
|
|
357
|
|
358 (defun comint-mode ()
|
|
359 "Major mode for interacting with an inferior interpreter.
|
|
360 Interpreter name is same as buffer name, sans the asterisks.
|
|
361 Return at end of buffer sends line as input.
|
|
362 Return not at end copies rest of line to end and sends it.
|
|
363 Setting variable `comint-eol-on-send' means jump to the end of the line
|
|
364 before submitting new input.
|
|
365
|
|
366 This mode is customised to create major modes such as Inferior Lisp
|
|
367 mode, Shell mode, etc. This can be done by setting the hooks
|
|
368 `comint-input-filter-functions', `comint-input-filter', `comint-input-sender'
|
|
369 and `comint-get-old-input' to appropriate functions, and the variable
|
|
370 `comint-prompt-regexp' to the appropriate regular expression.
|
|
371
|
|
372 An input history is maintained of size `comint-input-ring-size', and
|
|
373 can be accessed with the commands \\[comint-next-input], \\[comint-previous-input], and \\[comint-dynamic-list-input-ring].
|
|
374 Input ring history expansion can be achieved with the commands
|
|
375 \\[comint-replace-by-expanded-history] or \\[comint-magic-space].
|
|
376 Input ring expansion is controlled by the variable `comint-input-autoexpand',
|
|
377 and addition is controlled by the variable `comint-input-ignoredups'.
|
|
378
|
|
379 Commands with no default key bindings include `send-invisible',
|
|
380 `comint-dynamic-complete', `comint-dynamic-list-filename-completions', and
|
|
381 `comint-magic-space'.
|
|
382
|
|
383 Input to, and output from, the subprocess can cause the window to scroll to
|
|
384 the end of the buffer. See variables `comint-output-filter-functions',
|
|
385 `comint-scroll-to-bottom-on-input', and `comint-scroll-to-bottom-on-output'.
|
|
386
|
|
387 If you accidentally suspend your process, use \\[comint-continue-subjob]
|
|
388 to continue it.
|
|
389
|
|
390 \\{comint-mode-map}
|
|
391
|
|
392 Entry to this mode runs the hooks on `comint-mode-hook'."
|
|
393 (interactive)
|
|
394 ;; Do not remove this. All major modes must do this.
|
|
395 (kill-all-local-variables)
|
|
396 (setq major-mode 'comint-mode)
|
|
397 (setq mode-name "Comint")
|
|
398 (setq mode-line-process '(": %s")) ; XEmacs
|
|
399 (use-local-map comint-mode-map)
|
|
400 (make-local-variable 'comint-last-input-start)
|
|
401 (setq comint-last-input-start (make-marker))
|
|
402 (set-marker comint-last-input-start (point-min))
|
|
403 (make-local-variable 'comint-last-input-end)
|
|
404 (setq comint-last-input-end (make-marker))
|
|
405 (set-marker comint-last-input-end (point-min))
|
|
406 (make-local-variable 'comint-last-output-start)
|
|
407 (setq comint-last-output-start (make-marker))
|
|
408 (make-local-variable 'comint-prompt-regexp) ; Don't set; default
|
|
409 (make-local-variable 'comint-input-ring-size) ; ...to global val.
|
|
410 (make-local-variable 'comint-input-ring)
|
|
411 (make-local-variable 'comint-input-ring-file-name)
|
|
412 (or (and (boundp 'comint-input-ring) comint-input-ring)
|
|
413 (setq comint-input-ring (make-ring comint-input-ring-size)))
|
|
414 (make-local-variable 'comint-input-ring-index)
|
|
415 (or (and (boundp 'comint-input-ring-index) comint-input-ring-index)
|
|
416 (setq comint-input-ring-index nil))
|
|
417 (make-local-variable 'comint-matching-input-from-input-string)
|
|
418 (make-local-variable 'comint-input-autoexpand)
|
|
419 (make-local-variable 'comint-input-ignoredups)
|
|
420 (make-local-variable 'comint-delimiter-argument-list)
|
|
421 (make-local-hook 'comint-dynamic-complete-functions)
|
|
422 (make-local-variable 'comint-completion-fignore)
|
|
423 (make-local-variable 'comint-get-old-input)
|
|
424 (make-local-hook 'comint-input-filter-functions)
|
|
425 (make-local-variable 'comint-input-filter)
|
|
426 (make-local-variable 'comint-input-sender)
|
|
427 (make-local-variable 'comint-eol-on-send)
|
|
428 (make-local-variable 'comint-scroll-to-bottom-on-input)
|
|
429 (make-local-variable 'comint-scroll-to-bottom-on-output)
|
|
430 (make-local-variable 'comint-scroll-show-maximum-output)
|
|
431 (make-local-hook 'pre-command-hook)
|
|
432 (add-hook 'pre-command-hook 'comint-preinput-scroll-to-bottom nil t)
|
|
433 (make-local-hook 'comint-output-filter-functions)
|
|
434 (make-local-variable 'comint-ptyp)
|
|
435 (make-local-hook 'comint-exec-hook)
|
|
436 (make-local-variable 'comint-process-echoes)
|
|
437 (make-local-variable 'comint-file-name-quote-list)
|
|
438 (if (featurep 'menubar)
|
|
439 (progn
|
|
440 ;; make a local copy of the menubar, so our modes don't
|
|
441 ;; change the global menubar
|
|
442 (set-buffer-menubar current-menubar)
|
|
443 (add-submenu nil comint-1-menubar-menu)
|
|
444 (add-submenu nil comint-2-menubar-menu)
|
|
445 (add-submenu nil comint-history-menubar-menu)))
|
|
446 (run-hooks 'comint-mode-hook))
|
|
447
|
|
448 (if comint-mode-map
|
|
449 nil
|
|
450 ;; Keys:
|
|
451 (setq comint-mode-map (make-sparse-keymap))
|
|
452 (set-keymap-name comint-mode-map 'comint-mode-map) ; XEmacs
|
|
453
|
|
454 ;; XEmacs - The FSF19 party line
|
|
455 ;;(define-key comint-mode-map "\ep" 'comint-previous-input)
|
|
456 ;;(define-key comint-mode-map "\en" 'comint-next-input)
|
|
457
|
|
458 ;; The Lucid party line
|
|
459 (define-key comint-mode-map "\ep" 'comint-previous-matching-input-from-input)
|
|
460 (define-key comint-mode-map "\en" 'comint-next-matching-input-from-input)
|
|
461 (define-key comint-mode-map '(control up)
|
|
462 'comint-previous-matching-input-from-input)
|
|
463 (define-key comint-mode-map '(control down)
|
|
464 'comint-next-matching-input-from-input)
|
|
465
|
|
466 (define-key comint-mode-map "\er" 'comint-previous-matching-input)
|
|
467 (define-key comint-mode-map "\es" 'comint-next-matching-input)
|
|
468 ;; XEmacs - alt-meta-anything is a horrible binding. Some keyboards don't have
|
|
469 ;; meta keys, so we use alt as meta. Consequently, alt-meta will not exist on
|
|
470 ;; all keyboards. Just blow this. These functions are on M-n and M-p. --stig
|
|
471 ;;(define-key comint-mode-map [?\A-\M-r] 'comint-previous-matching-input-from-input)
|
|
472 ;;(define-key comint-mode-map [?\A-\M-s] 'comint-next-matching-input-from-input)
|
|
473 ;; XEmacs: Yuck yuck. C-M-l has a perfectly good normal binding.
|
|
474 ;;(define-key comint-mode-map "\e\C-l" 'comint-show-output)
|
|
475 (define-key comint-mode-map "\C-m" 'comint-send-input)
|
|
476 ;; XEmacs - Use ^C^D instead of ^D. Jamie & Stig think this is too un-emacs.
|
|
477 ;;(define-key comint-mode-map "\C-d" 'comint-delchar-or-maybe-eof)
|
|
478 ;; XEmacs - FSF nuked this, but we're gonna keep it....
|
|
479 (define-key comint-mode-map "\C-a" 'comint-bol)
|
|
480 ;; yuck, this is evil.
|
|
481 ;;(define-key comint-mode-map "\C-u" 'comint-universal-argument) ; XEmacs
|
|
482 (define-key comint-mode-map "\C-c\C-a" 'comint-bol)
|
|
483 (define-key comint-mode-map "\C-c\C-u" 'comint-kill-input)
|
|
484 (define-key comint-mode-map "\C-c\C-w" 'backward-kill-word)
|
|
485 (define-key comint-mode-map "\C-c\C-c" 'comint-interrupt-subjob)
|
|
486 (define-key comint-mode-map "\C-c\C-z" 'comint-stop-subjob)
|
|
487 (define-key comint-mode-map "\C-c\C-\\" 'comint-quit-subjob)
|
|
488 (define-key comint-mode-map "\C-c\C-m" 'comint-copy-old-input)
|
|
489 (define-key comint-mode-map "\C-c\C-o" 'comint-kill-output)
|
|
490 (define-key comint-mode-map "\C-c\C-r" 'comint-show-output)
|
|
491 (define-key comint-mode-map "\C-c\C-e" 'comint-show-maximum-output)
|
|
492 (define-key comint-mode-map "\C-c\C-l" 'comint-dynamic-list-input-ring)
|
|
493 (define-key comint-mode-map "\C-c\C-d" 'comint-send-eof)
|
|
494
|
|
495 (define-key comint-mode-map "\C-c\C-n" 'comint-next-prompt)
|
|
496 (define-key comint-mode-map "\C-c\C-p" 'comint-previous-prompt)
|
|
497 ;; John Rose's suggestion
|
|
498 (define-key comint-mode-map "\e}" 'comint-next-prompt)
|
|
499 (define-key comint-mode-map "\e{" 'comint-previous-prompt)
|
|
500
|
|
501 (define-key comint-mode-map 'button3 'comint-popup-menu)
|
|
502 )
|
|
503
|
|
504 (defconst comint-1-menubar-menu
|
|
505 (purecopy
|
|
506 '("Comint1"
|
|
507 ["Previous Matching Current Input"
|
|
508 comint-previous-matching-input-from-input t]
|
|
509 ["Next Matching Current Input" comint-next-matching-input-from-input t]
|
|
510 ["Previous Input" comint-previous-input t]
|
|
511 ["Next Input" comint-next-input t]
|
|
512 ["Previous Input Matching Regexp..." comint-previous-matching-input t]
|
|
513 ["Next Input Matching Regexp..." comint-next-matching-input t]
|
|
514 ["Backward Matching Input..." comint-backward-matching-input t]
|
|
515 ["Forward Matching Input..." comint-forward-matching-input t]
|
|
516 "---"
|
|
517 ["Copy Old Input" comint-copy-old-input t]
|
|
518 ["Kill Current Input" comint-kill-input t]
|
|
519 ["Show Current Output Group" comint-show-output t]
|
|
520 ["Show Maximum Output" comint-show-maximum-output t]
|
|
521 ["Goto Previous Prompt" comint-previous-prompt t]
|
|
522 ["Goto Next Prompt" comint-next-prompt t]
|
|
523 ["Kill Command Output" comint-kill-output t]
|
|
524 )))
|
|
525
|
|
526 (defconst comint-2-menubar-menu
|
|
527 (purecopy
|
|
528 '("Comint2"
|
|
529 ["Complete Before Point" comint-dynamic-complete t]
|
|
530 ["Complete File Name" comint-dynamic-complete-filename t]
|
|
531 ["File Completion Listing" comint-dynamic-list-filename-completions t]
|
|
532 ["Expand File Name" comint-replace-by-expanded-filename t]
|
|
533 ;; this is cheesy but the easiest way to get this.
|
|
534 ["Complete Env. Variable Name" shell-dynamic-complete-environment-variable
|
|
535 :active t :included (eq 'shell-mode major-mode)]
|
|
536 ["Expand Directory Reference" shell-replace-by-expanded-directory
|
|
537 :active t :included (eq 'shell-mode major-mode)]
|
|
538 "---"
|
70
|
539 ["Send INT" comint-interrupt-subjob t]
|
0
|
540 ["Send STOP" comint-stop-subjob t]
|
|
541 ["Send CONT" comint-continue-subjob t]
|
|
542 ["Send QUIT" comint-quit-subjob t]
|
|
543 ["Send KILL" comint-kill-subjob t]
|
|
544 ["Send EOF" comint-send-eof t]
|
|
545 )))
|
|
546
|
|
547 (defconst comint-history-menubar-menu
|
|
548 (purecopy
|
|
549 '("History"
|
|
550 :filter comint-history-menu-filter
|
|
551 ["Expand History Before Point" comint-replace-by-expanded-history
|
|
552 comint-input-autoexpand]
|
|
553 ["List Input History" comint-dynamic-list-input-ring t]
|
|
554 "---"
|
|
555 )))
|
|
556
|
|
557 (defconst comint-popup-menu
|
|
558 '("Command Interpreter Commands"
|
|
559 ["Kill Command Output" comint-kill-output t]
|
|
560 ["Goto Next Prompt" comint-next-prompt t]
|
|
561 ["Goto Previous Prompt" comint-previous-prompt t]
|
|
562 ["Kill Input" comint-kill-input t]
|
|
563 "----"
|
|
564 ["Previous Input" comint-previous-matching-input-from-input t]
|
|
565 ["Next Input" comint-next-matching-input-from-input t]
|
|
566 ["Previous Input matching Regexp..." 'comint-previous-matching-input t]
|
|
567 ["Next Input matching Regexp..." 'comint-next-matching-input t]
|
|
568 ["List Command History" comint-dynamic-list-input-ring t]
|
|
569 "----"
|
70
|
570 ["Send INT" comint-interrupt-subjob t]
|
0
|
571 ["Send STOP" comint-stop-subjob t]
|
|
572 ["Send CONT" comint-continue-subjob t]
|
|
573 ["Send QUIT" comint-quit-subjob t]
|
|
574 ["Send KILL" comint-kill-subjob t]
|
|
575 ["Send EOF" comint-send-eof t]
|
|
576 ))
|
|
577
|
|
578 (defun comint-popup-menu (event)
|
|
579 "Display the comint-mode menu."
|
|
580 (interactive "@e")
|
|
581 (let ((history (comint-make-history-menu)))
|
|
582 (popup-menu (if history
|
|
583 (append comint-popup-menu
|
|
584 (list "---" (cons "Command History" history)))
|
2
|
585 comint-popup-menu))))
|
0
|
586
|
|
587 (defvar comint-history-menu-max 40
|
|
588 "*Maximum number of entries to display on the Comint command-history menu.")
|
|
589
|
|
590 (defun comint-history-menu-filter (menu)
|
70
|
591 (append menu (comint-make-history-menu)))
|
0
|
592
|
|
593 (defun comint-make-history-menu ()
|
|
594 (if (or (not (ring-p comint-input-ring))
|
|
595 (ring-empty-p comint-input-ring))
|
|
596 nil
|
|
597 (let ((menu nil)
|
|
598 hist
|
|
599 (index (1- (ring-length comint-input-ring)))
|
|
600 (count 0))
|
|
601 ;; We have to build up a list ourselves from the ring vector.
|
70
|
602 ;; We don't want the entries to get translated in a Mule
|
|
603 ;; environment, so we use the `suffix' field of the menu entries.
|
0
|
604 (while (and (>= index 0)
|
|
605 (and comint-history-menu-max
|
|
606 (< count comint-history-menu-max)))
|
|
607 (setq hist (ring-ref comint-input-ring index)
|
70
|
608 menu (cons (vector "" (list 'comint-menu-history hist) t hist)
|
0
|
609 menu)
|
|
610 count (1+ count)
|
|
611 index (1- index)))
|
|
612 menu)))
|
|
613
|
|
614 (defun comint-menu-history (string)
|
|
615 (goto-char (point-max))
|
|
616 (delete-region (process-mark (get-buffer-process (current-buffer))) (point))
|
|
617 (insert string))
|
|
618
|
|
619 (defun comint-check-proc (buffer)
|
|
620 "Return t if there is a living process associated w/buffer BUFFER.
|
|
621 Living means the status is `open', `run', or `stop'.
|
|
622 BUFFER can be either a buffer or the name of one."
|
|
623 (let ((proc (get-buffer-process buffer)))
|
|
624 (and proc (memq (process-status proc) '(open run stop)))))
|
|
625
|
|
626 ;;; Note that this guy, unlike shell.el's make-shell, barfs if you pass it ()
|
|
627 ;;; for the second argument (program).
|
|
628 ;;;###autoload
|
|
629 (defun make-comint (name program &optional startfile &rest switches)
|
|
630 "Make a comint process NAME in a buffer, running PROGRAM.
|
|
631 The name of the buffer is made by surrounding NAME with `*'s.
|
|
632 PROGRAM should be either a string denoting an executable program to create
|
|
633 via `start-process', or a cons pair of the form (HOST . SERVICE) denoting a TCP
|
|
634 connection to be opened via `open-network-stream'. If there is already a
|
|
635 running process in that buffer, it is not restarted. Optional third arg
|
|
636 STARTFILE is the name of a file to send the contents of to the process.
|
|
637
|
|
638 If PROGRAM is a string, any more args are arguments to PROGRAM."
|
|
639 (or (fboundp 'start-process)
|
2
|
640 (error "Multiple processes are not supported for this system"))
|
0
|
641 (let ((buffer (get-buffer-create (concat "*" name "*"))))
|
|
642 ;; If no process, or nuked process, crank up a new one and put buffer in
|
|
643 ;; comint mode. Otherwise, leave buffer and existing process alone.
|
|
644 (cond ((not (comint-check-proc buffer))
|
|
645 (save-excursion
|
|
646 (set-buffer buffer)
|
|
647 (comint-mode)) ; Install local vars, mode, keymap, ...
|
|
648 (comint-exec buffer name program startfile switches)))
|
|
649 buffer))
|
|
650
|
|
651 ;;;###autoload
|
|
652 (defun comint-run (program)
|
|
653 "Run PROGRAM in a comint buffer and switch to it.
|
|
654 The buffer name is made by surrounding the file name of PROGRAM with `*'s.
|
|
655 The file name is used to make a symbol name, such as `comint-sh-hook', and any
|
|
656 hooks on this symbol are run in the buffer.
|
|
657 See `make-comint' and `comint-exec'."
|
|
658 (interactive "sRun program: ")
|
|
659 (let ((name (file-name-nondirectory program)))
|
|
660 (switch-to-buffer (make-comint name program))
|
|
661 (run-hooks (intern-soft (concat "comint-" name "-hook")))))
|
|
662
|
|
663 (defun comint-exec (buffer name command startfile switches)
|
|
664 "Start up a process in buffer BUFFER for comint modes.
|
|
665 Blasts any old process running in the buffer. Doesn't set the buffer mode.
|
|
666 You can use this to cheaply run a series of processes in the same comint
|
|
667 buffer. The hook `comint-exec-hook' is run after each exec."
|
|
668 (save-excursion
|
|
669 (set-buffer buffer)
|
|
670 (let ((proc (get-buffer-process buffer))) ; Blast any old process.
|
|
671 (if proc (delete-process proc)))
|
|
672 ;; Crank up a new process
|
|
673 (let ((proc
|
|
674 (if (consp command)
|
|
675 (open-network-stream name buffer (car command) (cdr command))
|
|
676 (comint-exec-1 name buffer command switches))))
|
|
677 (set-process-filter proc 'comint-output-filter)
|
|
678 (make-local-variable 'comint-ptyp)
|
|
679 (setq comint-ptyp process-connection-type) ; T if pty, NIL if pipe.
|
|
680 ;; Jump to the end, and set the process mark.
|
|
681 (goto-char (point-max))
|
|
682 (set-marker (process-mark proc) (point))
|
|
683 ;; Feed it the startfile.
|
|
684 (cond (startfile
|
|
685 ;;This is guaranteed to wait long enough
|
|
686 ;;but has bad results if the comint does not prompt at all
|
|
687 ;; (while (= size (buffer-size))
|
|
688 ;; (sleep-for 1))
|
|
689 ;;I hope 1 second is enough!
|
|
690 (sleep-for 1)
|
|
691 (goto-char (point-max))
|
|
692 (insert-file-contents startfile)
|
|
693 (setq startfile (buffer-substring (point) (point-max)))
|
|
694 (delete-region (point) (point-max))
|
|
695 (comint-send-string proc startfile)))
|
|
696 (run-hooks 'comint-exec-hook)
|
|
697 buffer)))
|
|
698
|
|
699 ;;; This auxiliary function cranks up the process for comint-exec in
|
|
700 ;;; the appropriate environment.
|
|
701
|
|
702 (defun comint-exec-1 (name buffer command switches)
|
|
703 (let ((process-environment
|
|
704 (nconc
|
|
705 ;; If using termcap, we specify `emacs' as the terminal type
|
|
706 ;; because that lets us specify a width.
|
|
707 ;; If using terminfo, we specify `unknown' because that is
|
|
708 ;; a defined terminal type. `emacs' is not a defined terminal type
|
|
709 ;; and there is no way for us to define it here.
|
|
710 ;; Some programs that use terminfo get very confused
|
|
711 ;; if TERM is not a valid terminal type.
|
|
712 (if (and (boundp 'system-uses-terminfo) system-uses-terminfo)
|
|
713 (list "TERM=unknown"
|
|
714 (format "COLUMNS=%d" (frame-width)))
|
|
715 (list "TERM=emacs"
|
|
716 (format "TERMCAP=emacs:co#%d:tc=unknown:" (frame-width))))
|
|
717 (if (getenv "EMACS") nil (list "EMACS=t"))
|
|
718 process-environment))
|
|
719 (default-directory
|
|
720 (if (file-directory-p default-directory)
|
|
721 default-directory
|
|
722 "/")))
|
|
723 (apply 'start-process name buffer command switches)))
|
|
724
|
|
725 ;;; Input history processing in a buffer
|
|
726 ;;; ===========================================================================
|
|
727 ;;; Useful input history functions, courtesy of the Ergo group.
|
|
728
|
|
729 ;;; Eleven commands:
|
|
730 ;;; comint-dynamic-list-input-ring List history in help buffer.
|
|
731 ;;; comint-previous-input Previous input...
|
|
732 ;;; comint-previous-matching-input ...matching a string.
|
|
733 ;;; comint-previous-matching-input-from-input ... matching the current input.
|
|
734 ;;; comint-next-input Next input...
|
|
735 ;;; comint-next-matching-input ...matching a string.
|
|
736 ;;; comint-next-matching-input-from-input ... matching the current input.
|
|
737 ;;; comint-backward-matching-input Backwards input...
|
|
738 ;;; comint-forward-matching-input ...matching a string.
|
|
739 ;;; comint-replace-by-expanded-history Expand history at point;
|
|
740 ;;; replace with expanded history.
|
|
741 ;;; comint-magic-space Expand history and insert space.
|
|
742 ;;;
|
|
743 ;;; Three functions:
|
|
744 ;;; comint-read-input-ring Read into comint-input-ring...
|
|
745 ;;; comint-write-input-ring Write to comint-input-ring-file-name.
|
|
746 ;;; comint-replace-by-expanded-history-before-point Workhorse function.
|
|
747
|
|
748 (defun comint-read-input-ring (&optional silent)
|
|
749 "Sets the buffer's `comint-input-ring' from a history file.
|
|
750 The name of the file is given by the variable `comint-input-ring-file-name'.
|
|
751 The history ring is of size `comint-input-ring-size', regardless of file size.
|
|
752 If `comint-input-ring-file-name' is nil this function does nothing.
|
|
753
|
|
754 If the optional argument SILENT is non-nil, we say nothing about a
|
|
755 failure to read the history file.
|
|
756
|
|
757 This function is useful for major mode commands and mode hooks.
|
|
758
|
|
759 The structure of the history file should be one input command per line,
|
|
760 with the most recent command last.
|
|
761 See also `comint-input-ignoredups' and `comint-write-input-ring'."
|
|
762 (cond ((or (null comint-input-ring-file-name)
|
|
763 (equal comint-input-ring-file-name ""))
|
|
764 nil)
|
|
765 ((not (file-readable-p comint-input-ring-file-name))
|
|
766 (or silent
|
|
767 (message "Cannot read history file %s"
|
|
768 comint-input-ring-file-name)))
|
|
769 (t
|
|
770 (let ((history-buf (get-buffer-create " *comint-history*"))
|
|
771 (file comint-input-ring-file-name)
|
|
772 (count 0)
|
|
773 (ring (make-ring comint-input-ring-size)))
|
|
774 (unwind-protect
|
|
775 (save-excursion
|
|
776 (set-buffer history-buf)
|
|
777 (widen)
|
|
778 (erase-buffer)
|
|
779 (insert-file-contents file)
|
|
780 ;; Save restriction in case file is already visited...
|
|
781 ;; Watch for those date stamps in history files!
|
|
782 (goto-char (point-max))
|
|
783 (while (and (< count comint-input-ring-size)
|
|
784 (re-search-backward "^[ \t]*\\([^#\n].*\\)[ \t]*$"
|
|
785 nil t))
|
|
786 (let ((history (buffer-substring (match-beginning 1)
|
|
787 (match-end 1))))
|
|
788 (if (or (null comint-input-ignoredups)
|
|
789 (ring-empty-p ring)
|
|
790 (not (string-equal (ring-ref ring 0) history)))
|
|
791 (ring-insert-at-beginning ring history)))
|
|
792 (setq count (1+ count))))
|
|
793 (kill-buffer history-buf))
|
|
794 (setq comint-input-ring ring
|
|
795 comint-input-ring-index nil)))))
|
|
796
|
|
797 (defun comint-write-input-ring ()
|
|
798 "Writes the buffer's `comint-input-ring' to a history file.
|
|
799 The name of the file is given by the variable `comint-input-ring-file-name'.
|
|
800 The original contents of the file are lost if `comint-input-ring' is not empty.
|
|
801 If `comint-input-ring-file-name' is nil this function does nothing.
|
|
802
|
|
803 Useful within process sentinels.
|
|
804
|
|
805 See also `comint-read-input-ring'."
|
|
806 (cond ((or (null comint-input-ring-file-name)
|
|
807 (equal comint-input-ring-file-name "")
|
|
808 (null comint-input-ring) (ring-empty-p comint-input-ring))
|
|
809 nil)
|
|
810 ((not (file-writable-p comint-input-ring-file-name))
|
|
811 (message "Cannot write history file %s" comint-input-ring-file-name))
|
|
812 (t
|
|
813 (let* ((history-buf (get-buffer-create " *Temp Input History*"))
|
|
814 (ring comint-input-ring)
|
|
815 (file comint-input-ring-file-name)
|
|
816 (index (ring-length ring)))
|
|
817 ;; Write it all out into a buffer first. Much faster, but messier,
|
|
818 ;; than writing it one line at a time.
|
|
819 (save-excursion
|
|
820 (set-buffer history-buf)
|
|
821 (erase-buffer)
|
|
822 (while (> index 0)
|
|
823 (setq index (1- index))
|
|
824 (insert (ring-ref ring index) ?\n))
|
|
825 (write-region (buffer-string) nil file nil 'no-message)
|
|
826 (kill-buffer nil))))))
|
|
827
|
|
828 ;; XEmacs - FSF doesn't have this.
|
|
829 (defun comint-restore-window-config (conf &optional message)
|
|
830 ;; Don't obscure buffer being edited
|
|
831 (or (eq (selected-window) (minibuffer-window))
|
|
832 (message "%s" (or message "Press space to flush")))
|
|
833 (sit-for 0)
|
|
834 (if (if (fboundp 'next-command-event)
|
|
835 ;; lemacs
|
|
836 (let ((ch (next-command-event)))
|
|
837 (if (eq (event-to-character ch) ?\ )
|
|
838 t
|
|
839 (progn (setq unread-command-event ch)
|
|
840 nil)))
|
|
841 ;; v19 FSFmacs
|
|
842 (let ((ch (read-event)))
|
|
843 (if (eq ch ?\ )
|
|
844 t
|
|
845 (progn (setq unread-command-events (list ch))
|
|
846 nil))))
|
|
847 (set-window-configuration conf)))
|
|
848
|
|
849
|
|
850 (defun comint-dynamic-list-input-ring ()
|
|
851 "List in help buffer the buffer's input history."
|
|
852 (interactive)
|
|
853 (if (or (not (ring-p comint-input-ring))
|
|
854 (ring-empty-p comint-input-ring))
|
|
855 (message "No history")
|
|
856 (let ((history nil)
|
|
857 (history-buffer " *Input History*")
|
|
858 (index (1- (ring-length comint-input-ring)))
|
|
859 (conf (current-window-configuration)))
|
|
860 ;; We have to build up a list ourselves from the ring vector.
|
|
861 (while (>= index 0)
|
|
862 (setq history (cons (ring-ref comint-input-ring index) history)
|
|
863 index (1- index)))
|
|
864 ;; Change "completion" to "history reference"
|
|
865 ;; to make the display accurate.
|
|
866 (with-output-to-temp-buffer history-buffer
|
|
867 (display-completion-list history)
|
|
868 (set-buffer history-buffer)
|
|
869 (forward-line 3)
|
|
870 (let ((buffer-read-only nil))
|
|
871 (while (search-backward "completion" nil 'move)
|
|
872 (replace-match "history reference"))))
|
|
873 (comint-restore-window-config conf))))
|
|
874
|
|
875 (defun comint-regexp-arg (prompt)
|
|
876 ;; Return list of regexp and prefix arg using PROMPT.
|
|
877 (let* ((minibuffer-history-sexp-flag nil)
|
|
878 ;; Don't clobber this.
|
|
879 (last-command last-command)
|
|
880 (regexp (read-from-minibuffer prompt nil nil nil
|
|
881 'minibuffer-history-search-history)))
|
|
882 (list (if (string-equal regexp "")
|
|
883 (setcar minibuffer-history-search-history
|
|
884 (nth 1 minibuffer-history-search-history))
|
|
885 regexp)
|
|
886 (prefix-numeric-value current-prefix-arg))))
|
|
887
|
|
888 (defun comint-search-arg (arg)
|
|
889 ;; First make sure there is a ring and that we are after the process mark
|
|
890 (cond ((not (comint-after-pmark-p))
|
|
891 (error "Not at command line"))
|
|
892 ((or (null comint-input-ring)
|
|
893 (ring-empty-p comint-input-ring))
|
|
894 (error "Empty input ring"))
|
|
895 ((zerop arg)
|
|
896 ;; arg of zero resets search from beginning, and uses arg of 1
|
|
897 (setq comint-input-ring-index nil)
|
|
898 1)
|
|
899 (t
|
|
900 arg)))
|
|
901
|
|
902 (defun comint-search-start (arg)
|
|
903 ;; Index to start a directional search, starting at comint-input-ring-index
|
|
904 (if comint-input-ring-index
|
|
905 ;; If a search is running, offset by 1 in direction of arg
|
|
906 (mod (+ comint-input-ring-index (if (> arg 0) 1 -1))
|
|
907 (ring-length comint-input-ring))
|
|
908 ;; For a new search, start from beginning or end, as appropriate
|
|
909 (if (>= arg 0)
|
|
910 0 ; First elt for forward search
|
|
911 (1- (ring-length comint-input-ring))))) ; Last elt for backward search
|
|
912
|
|
913 (defun comint-previous-input-string (arg)
|
|
914 "Return the string ARG places along the input ring.
|
|
915 Moves relative to `comint-input-ring-index'."
|
|
916 (ring-ref comint-input-ring (if comint-input-ring-index
|
|
917 (mod (+ arg comint-input-ring-index)
|
|
918 (ring-length comint-input-ring))
|
|
919 arg)))
|
|
920
|
|
921 (defun comint-previous-input (arg)
|
|
922 "Cycle backwards through input history."
|
|
923 (interactive "*p")
|
|
924 (comint-previous-matching-input "." arg))
|
|
925
|
|
926 (defun comint-next-input (arg)
|
|
927 "Cycle forwards through input history."
|
|
928 (interactive "*p")
|
|
929 (comint-previous-input (- arg)))
|
|
930
|
|
931 (defun comint-previous-matching-input-string (regexp arg)
|
|
932 "Return the string matching REGEXP ARG places along the input ring.
|
|
933 Moves relative to `comint-input-ring-index'."
|
|
934 (let* ((pos (comint-previous-matching-input-string-position regexp arg)))
|
|
935 (if pos (ring-ref comint-input-ring pos))))
|
|
936
|
|
937 (defun comint-previous-matching-input-string-position (regexp arg &optional start)
|
|
938 "Return the index matching REGEXP ARG places along the input ring.
|
|
939 Moves relative to START, or `comint-input-ring-index'."
|
|
940 (if (or (not (ring-p comint-input-ring))
|
|
941 (ring-empty-p comint-input-ring))
|
|
942 (error "No history"))
|
|
943 (let* ((len (ring-length comint-input-ring))
|
|
944 (motion (if (> arg 0) 1 -1))
|
|
945 (n (mod (- (or start (comint-search-start arg)) motion) len))
|
|
946 (tried-each-ring-item nil)
|
|
947 (prev nil))
|
|
948 ;; Do the whole search as many times as the argument says.
|
|
949 (while (and (/= arg 0) (not tried-each-ring-item))
|
|
950 ;; Step once.
|
|
951 (setq prev n
|
|
952 n (mod (+ n motion) len))
|
|
953 ;; If we haven't reached a match, step some more.
|
|
954 (while (and (< n len) (not tried-each-ring-item)
|
|
955 (not (string-match regexp (ring-ref comint-input-ring n))))
|
|
956 (setq n (mod (+ n motion) len)
|
|
957 ;; If we have gone all the way around in this search.
|
|
958 tried-each-ring-item (= n prev)))
|
|
959 (setq arg (if (> arg 0) (1- arg) (1+ arg))))
|
|
960 ;; Now that we know which ring element to use, if we found it, return that.
|
|
961 (if (string-match regexp (ring-ref comint-input-ring n))
|
|
962 n)))
|
|
963
|
|
964 (defun comint-previous-matching-input (regexp arg)
|
|
965 "Search backwards through input history for match for REGEXP.
|
|
966 \(Previous history elements are earlier commands.)
|
|
967 With prefix argument N, search for Nth previous match.
|
|
968 If N is negative, find the next or Nth next match."
|
|
969 (interactive (comint-regexp-arg "Previous input matching (regexp): "))
|
|
970 (setq arg (comint-search-arg arg))
|
|
971 (let ((pos (comint-previous-matching-input-string-position regexp arg)))
|
|
972 ;; Has a match been found?
|
|
973 (if (null pos)
|
|
974 (error "Not found")
|
|
975 (setq comint-input-ring-index pos)
|
|
976 (message "History item: %d" (1+ pos))
|
|
977 (delete-region
|
|
978 ;; Can't use kill-region as it sets this-command
|
|
979 (process-mark (get-buffer-process (current-buffer))) (point))
|
|
980 (insert (ring-ref comint-input-ring pos)))))
|
|
981
|
|
982 (defun comint-next-matching-input (regexp arg)
|
|
983 "Search forwards through input history for match for REGEXP.
|
|
984 \(Later history elements are more recent commands.)
|
|
985 With prefix argument N, search for Nth following match.
|
|
986 If N is negative, find the previous or Nth previous match."
|
|
987 (interactive (comint-regexp-arg "Next input matching (regexp): "))
|
|
988 (comint-previous-matching-input regexp (- arg)))
|
|
989
|
|
990 (defun comint-previous-matching-input-from-input (arg)
|
|
991 "Search backwards through input history for match for current input.
|
|
992 \(Previous history elements are earlier commands.)
|
|
993 With prefix argument N, search for Nth previous match.
|
|
994 If N is negative, search forwards for the -Nth following match."
|
|
995 (interactive "p")
|
|
996 (if (not (memq last-command '(comint-previous-matching-input-from-input
|
|
997 comint-next-matching-input-from-input)))
|
|
998 ;; Starting a new search
|
|
999 (setq comint-matching-input-from-input-string
|
|
1000 (buffer-substring
|
|
1001 (process-mark (get-buffer-process (current-buffer)))
|
|
1002 (point))
|
|
1003 comint-input-ring-index nil))
|
|
1004 (comint-previous-matching-input
|
|
1005 (concat "^" (regexp-quote comint-matching-input-from-input-string))
|
|
1006 arg))
|
|
1007
|
|
1008 (defun comint-next-matching-input-from-input (arg)
|
|
1009 "Search forwards through input history for match for current input.
|
|
1010 \(Following history elements are more recent commands.)
|
|
1011 With prefix argument N, search for Nth following match.
|
|
1012 If N is negative, search backwards for the -Nth previous match."
|
|
1013 (interactive "p")
|
|
1014 (comint-previous-matching-input-from-input (- arg)))
|
|
1015
|
|
1016
|
|
1017 (defun comint-replace-by-expanded-history (&optional silent)
|
|
1018 "Expand input command history references before point.
|
|
1019 Expansion is dependent on the value of `comint-input-autoexpand'.
|
|
1020
|
|
1021 This function depends on the buffer's idea of the input history, which may not
|
|
1022 match the command interpreter's idea, assuming it has one.
|
|
1023
|
|
1024 Assumes history syntax is like typical Un*x shells'. However, since emacs
|
|
1025 cannot know the interpreter's idea of input line numbers, assuming it has one,
|
|
1026 it cannot expand absolute input line number references.
|
|
1027
|
|
1028 If the optional argument SILENT is non-nil, never complain
|
|
1029 even if history reference seems erroneous.
|
|
1030
|
|
1031 See `comint-magic-space' and `comint-replace-by-expanded-history-before-point'.
|
|
1032
|
|
1033 Returns t if successful."
|
|
1034 (interactive)
|
|
1035 (if (and comint-input-autoexpand
|
70
|
1036 (string-match "[!^]" (funcall comint-get-old-input))
|
0
|
1037 (save-excursion (beginning-of-line)
|
|
1038 (looking-at comint-prompt-regexp)))
|
|
1039 ;; Looks like there might be history references in the command.
|
|
1040 (let ((previous-modified-tick (buffer-modified-tick)))
|
|
1041 (message "Expanding history references...")
|
|
1042 (comint-replace-by-expanded-history-before-point silent)
|
|
1043 (/= previous-modified-tick (buffer-modified-tick)))))
|
|
1044
|
|
1045
|
|
1046 (defun comint-replace-by-expanded-history-before-point (silent)
|
|
1047 "Expand directory stack reference before point.
|
|
1048 See `comint-replace-by-expanded-history'. Returns t if successful."
|
|
1049 (save-excursion
|
|
1050 (let ((toend (- (save-excursion (end-of-line nil) (point)) (point)))
|
|
1051 (start (progn (comint-bol nil) (point))))
|
|
1052 ;; XEmacs - fsf has something weird and complex here that does the same thing.
|
|
1053 (while (re-search-forward
|
|
1054 "[!^]" (save-excursion (end-of-line nil) (- (point) toend)) t)
|
|
1055 ;; This seems a bit complex. We look for references such as !!, !-num,
|
|
1056 ;; !foo, !?foo, !{bar}, !?{bar}, ^oh, ^my^, ^god^it, ^never^ends^.
|
|
1057 ;; If that wasn't enough, the plings can be suffixed with argument
|
|
1058 ;; range specifiers.
|
|
1059 ;; Argument ranges are complex too, so we hive off the input line,
|
|
1060 ;; referenced with plings, with the range string to `comint-args'.
|
|
1061 (setq comint-input-ring-index nil)
|
|
1062 (goto-char (match-beginning 0)) ; XEmacs
|
|
1063 (cond ((or (= (preceding-char) ?\\)
|
|
1064 (comint-within-quotes start (point)))
|
|
1065 ;; The history is quoted, or we're in quotes.
|
|
1066 (goto-char (match-end 0))) ; XEmacs
|
|
1067 ((looking-at "![0-9]+\\($\\|[^-]\\)")
|
|
1068 ;; We cannot know the interpreter's idea of input line numbers.
|
|
1069 (goto-char (match-end 0))
|
|
1070 (message "Absolute reference cannot be expanded"))
|
|
1071 ((looking-at "!-\\([0-9]+\\)\\(:?[0-9^$*-]+\\)?")
|
|
1072 ;; Just a number of args from `number' lines backward.
|
|
1073 (let ((number (1- (string-to-number
|
|
1074 (buffer-substring (match-beginning 1)
|
|
1075 (match-end 1))))))
|
|
1076 (if (<= number (ring-length comint-input-ring))
|
|
1077 (progn
|
|
1078 (replace-match
|
|
1079 (comint-args (comint-previous-input-string number)
|
|
1080 (match-beginning 2) (match-end 2))
|
|
1081 t t)
|
|
1082 (setq comint-input-ring-index number)
|
|
1083 (message "History item: %d" (1+ number)))
|
|
1084 (goto-char (match-end 0))
|
|
1085 (message "Relative reference exceeds input history size"))))
|
|
1086 ((or (looking-at "!!?:?\\([0-9^$*-]+\\)") (looking-at "!!"))
|
|
1087 ;; Just a number of args from the previous input line.
|
|
1088 (replace-match
|
|
1089 (comint-args (comint-previous-input-string 0)
|
|
1090 (match-beginning 1) (match-end 1)) t t)
|
|
1091 (message "History item: previous"))
|
|
1092 ((looking-at
|
|
1093 "!\\??\\({\\(.+\\)}\\|\\(\\sw+\\)\\)\\(:?[0-9^$*-]+\\)?")
|
|
1094 ;; Most recent input starting with or containing (possibly
|
|
1095 ;; protected) string, maybe just a number of args. Phew.
|
|
1096 (let* ((mb1 (match-beginning 1)) (me1 (match-end 1))
|
|
1097 (mb2 (match-beginning 2)) (me2 (match-end 2))
|
|
1098 (exp (buffer-substring (or mb2 mb1) (or me2 me1)))
|
|
1099 (pref (if (save-match-data (looking-at "!\\?")) "" "^"))
|
|
1100 (pos (save-match-data
|
|
1101 (comint-previous-matching-input-string-position
|
|
1102 (concat pref (regexp-quote exp)) 1))))
|
|
1103 (if (null pos)
|
|
1104 (progn
|
|
1105 (goto-char (match-end 0))
|
|
1106 (or silent
|
|
1107 (progn (message "Not found")
|
|
1108 (ding))))
|
|
1109 (setq comint-input-ring-index pos)
|
|
1110 (replace-match
|
|
1111 (comint-args (ring-ref comint-input-ring pos)
|
|
1112 (match-beginning 4) (match-end 4))
|
|
1113 t t)
|
|
1114 (message "History item: %d" (1+ pos)))))
|
|
1115 ((looking-at "\\^\\([^^]+\\)\\^?\\([^^]*\\)\\^?")
|
|
1116 ;; Quick substitution on the previous input line.
|
|
1117 (let ((old (buffer-substring (match-beginning 1) (match-end 1)))
|
|
1118 (new (buffer-substring (match-beginning 2) (match-end 2)))
|
|
1119 (pos nil))
|
|
1120 (replace-match (comint-previous-input-string 0) t t)
|
|
1121 (setq pos (point))
|
|
1122 (goto-char (match-beginning 0))
|
|
1123 (if (not (search-forward old pos t))
|
|
1124 (or silent
|
|
1125 (error "Not found"))
|
|
1126 (replace-match new t t)
|
|
1127 (message "History item: substituted"))))
|
|
1128 (t
|
|
1129 (goto-char (match-end 0))))))))
|
|
1130
|
|
1131
|
|
1132 (defun comint-magic-space (arg)
|
|
1133 "Expand input history references before point and insert ARG spaces.
|
|
1134 A useful command to bind to SPC. See `comint-replace-by-expanded-history'."
|
|
1135 (interactive "p")
|
|
1136 (comint-replace-by-expanded-history)
|
|
1137 (self-insert-command arg))
|
|
1138
|
|
1139 (defun comint-within-quotes (beg end)
|
|
1140 "Return t if the number of quotes between BEG and END is odd.
|
|
1141 Quotes are single and double."
|
|
1142 (let ((countsq (comint-how-many-region "\\(^\\|[^\\\\]\\)\'" beg end))
|
|
1143 (countdq (comint-how-many-region "\\(^\\|[^\\\\]\\)\"" beg end)))
|
|
1144 (or (= (mod countsq 2) 1) (= (mod countdq 2) 1))))
|
|
1145
|
|
1146 (defun comint-how-many-region (regexp beg end)
|
|
1147 "Return number of matches for REGEXP from BEG to END."
|
|
1148 (let ((count 0))
|
|
1149 (save-excursion
|
|
1150 (save-match-data
|
|
1151 (goto-char beg)
|
|
1152 (while (re-search-forward regexp end t)
|
|
1153 (setq count (1+ count)))))
|
|
1154 count))
|
|
1155
|
|
1156 (defun comint-args (string begin end)
|
|
1157 ;; From STRING, return the args depending on the range specified in the text
|
|
1158 ;; from BEGIN to END. If BEGIN is nil, assume all args. Ignore leading `:'.
|
|
1159 ;; Range can be x-y, x-, -y, where x/y can be [0-9], *, ^, $.
|
|
1160 (save-match-data
|
|
1161 (if (null begin)
|
|
1162 (comint-arguments string 0 nil)
|
|
1163 (let* ((range (buffer-substring
|
|
1164 (if (eq (char-after begin) ?:) (1+ begin) begin) end))
|
|
1165 (nth (cond ((string-match "^[*^]" range) 1)
|
|
1166 ((string-match "^-" range) 0)
|
|
1167 ((string-equal range "$") nil)
|
|
1168 (t (string-to-number range))))
|
|
1169 (mth (cond ((string-match "[-*$]$" range) nil)
|
|
1170 ((string-match "-" range)
|
|
1171 (string-to-number (substring range (match-end 0))))
|
|
1172 (t nth))))
|
|
1173 (comint-arguments string nth mth)))))
|
|
1174
|
|
1175 ;; Return a list of arguments from ARG. Break it up at the
|
|
1176 ;; delimiters in comint-delimiter-argument-list. Returned list is backwards.
|
|
1177 (defun comint-delim-arg (arg)
|
|
1178 (if (null comint-delimiter-argument-list)
|
|
1179 (list arg)
|
|
1180 (let ((args nil)
|
|
1181 (pos 0)
|
|
1182 (len (length arg)))
|
|
1183 (while (< pos len)
|
|
1184 (let ((char (aref arg pos))
|
|
1185 (start pos))
|
|
1186 (if (memq char comint-delimiter-argument-list)
|
|
1187 (while (and (< pos len) (eq (aref arg pos) char))
|
|
1188 (setq pos (1+ pos)))
|
|
1189 (while (and (< pos len)
|
|
1190 (not (memq (aref arg pos)
|
|
1191 comint-delimiter-argument-list)))
|
|
1192 (setq pos (1+ pos))))
|
|
1193 (setq args (cons (substring arg start pos) args))))
|
|
1194 args)))
|
|
1195
|
|
1196 (defun comint-arguments (string nth mth)
|
|
1197 "Return from STRING the NTH to MTH arguments.
|
|
1198 NTH and/or MTH can be nil, which means the last argument.
|
|
1199 Returned arguments are separated by single spaces.
|
|
1200 We assume whitespace separates arguments, except within quotes.
|
|
1201 Also, a run of one or more of a single character
|
|
1202 in `comint-delimiter-argument-list' is a separate argument.
|
|
1203 Argument 0 is the command name."
|
|
1204 (let ((argpart "[^ \n\t\"'`]+\\|\\(\"[^\"]*\"\\|'[^']*'\\|`[^`]*`\\)")
|
|
1205 (args ()) (pos 0)
|
|
1206 (count 0)
|
|
1207 beg str value quotes)
|
|
1208 ;; Build a list of all the args until we have as many as we want.
|
|
1209 (while (and (or (null mth) (<= count mth))
|
|
1210 (string-match argpart string pos))
|
|
1211 (if (and beg (= pos (match-beginning 0)))
|
|
1212 ;; It's contiguous, part of the same arg.
|
|
1213 (setq pos (match-end 0)
|
|
1214 quotes (or quotes (match-beginning 1)))
|
|
1215 ;; It's a new separate arg.
|
|
1216 (if beg
|
|
1217 ;; Put the previous arg, if there was one, onto ARGS.
|
|
1218 (setq str (substring string beg pos)
|
|
1219 args (if quotes (cons str args)
|
|
1220 (nconc (comint-delim-arg str) args))
|
|
1221 count (1+ count)))
|
|
1222 (setq quotes (match-beginning 1))
|
|
1223 (setq beg (match-beginning 0))
|
|
1224 (setq pos (match-end 0))))
|
|
1225 (if beg
|
|
1226 (setq str (substring string beg pos)
|
|
1227 args (if quotes (cons str args)
|
|
1228 (nconc (comint-delim-arg str) args))
|
|
1229 count (1+ count)))
|
|
1230 (let ((n (or nth (1- count)))
|
|
1231 (m (if mth (1- (- count mth)) 0)))
|
|
1232 (mapconcat
|
|
1233 (function (lambda (a) a)) (nthcdr n (nreverse (nthcdr m args))) " "))))
|
|
1234
|
|
1235 ;;;
|
|
1236 ;;; Input processing stuff
|
|
1237 ;;;
|
|
1238
|
|
1239 (defun comint-send-input ()
|
|
1240 "Send input to process.
|
|
1241 After the process output mark, sends all text from the process mark to
|
|
1242 point as input to the process. Before the process output mark, calls value
|
|
1243 of variable `comint-get-old-input' to retrieve old input, copies it to the
|
|
1244 process mark, and sends it. If variable `comint-process-echoes' is nil,
|
|
1245 a terminal newline is also inserted into the buffer and sent to the process
|
|
1246 \(if it is non-nil, all text from the process mark to point is deleted,
|
|
1247 since it is assumed the remote process will re-echo it).
|
|
1248
|
|
1249 Any history reference may be expanded depending on the value of the variable
|
|
1250 `comint-input-autoexpand'. The list of function names contained in the value
|
|
1251 of `comint-input-filter-functions' is called on the input before sending it.
|
|
1252 The input is entered into the input history ring, if the value of variable
|
|
1253 `comint-input-filter' returns non-nil when called on the input.
|
|
1254
|
|
1255 If variable `comint-eol-on-send' is non-nil, then point is moved to the
|
|
1256 end of line before sending the input.
|
|
1257
|
|
1258 If variable `comint-append-old-input' is non-nil, then the results of
|
|
1259 calling `comint-get-old-input' are appended to the end of the buffer.
|
|
1260 The new input will combine with any partially-typed text already present
|
|
1261 after the process output mark. Point is moved just before the newly
|
|
1262 appended input, and a message is displayed prompting the user to type
|
|
1263 \\[comint-send-input] again.
|
|
1264
|
|
1265 The values of `comint-get-old-input', `comint-input-filter-functions' and
|
|
1266 `comint-input-filter' are chosen according to the command interpreter running
|
|
1267 in the buffer. E.g.,
|
|
1268
|
|
1269 If the interpreter is the csh,
|
|
1270 comint-get-old-input is the default: take the current line, discard any
|
|
1271 initial string matching regexp comint-prompt-regexp.
|
|
1272 comint-input-filter-functions monitors input for \"cd\", \"pushd\", and
|
|
1273 \"popd\" commands. When it sees one, it cd's the buffer.
|
|
1274 comint-input-filter is the default: returns t if the input isn't all white
|
|
1275 space.
|
|
1276
|
|
1277 If the comint is Lucid Common Lisp,
|
|
1278 comint-get-old-input snarfs the sexp ending at point.
|
|
1279 comint-input-filter-functions does nothing.
|
|
1280 comint-input-filter returns nil if the input matches input-filter-regexp,
|
|
1281 which matches (1) all whitespace (2) :a, :c, etc.
|
|
1282
|
|
1283 Similarly for Soar, Scheme, etc."
|
|
1284 (interactive)
|
|
1285 ;; Note that the input string does not include its terminal newline.
|
|
1286 (let ((proc (get-buffer-process (current-buffer))))
|
|
1287 (if (not proc) (error "Current buffer has no process")
|
|
1288 (let* ((pmark (process-mark proc))
|
|
1289 (pmark-val (marker-position pmark))
|
|
1290 ;; XEmacs - change by John Rose: confirm before sending input if
|
|
1291 ;; not after process mark.
|
|
1292 (append-here nil)
|
|
1293 (intxt (if (>= (point) pmark-val)
|
|
1294 (progn (if comint-eol-on-send (end-of-line))
|
|
1295 (buffer-substring pmark (point)))
|
|
1296 (let ((copy (funcall comint-get-old-input)))
|
|
1297 (push-mark)
|
|
1298 (if (not comint-append-old-input)
|
|
1299 (goto-char pmark-val)
|
|
1300 (setq append-here (point-max))
|
|
1301 (goto-char append-here))
|
|
1302 (insert copy)
|
|
1303 copy)))
|
|
1304 (input (if (not (eq comint-input-autoexpand 'input))
|
|
1305 ;; Just whatever's already there
|
|
1306 intxt
|
|
1307 ;; Expand and leave it visible in buffer
|
|
1308 (comint-replace-by-expanded-history t)
|
|
1309 (buffer-substring pmark (point))))
|
|
1310 (history (if (not (eq comint-input-autoexpand 'history))
|
|
1311 (if (eq comint-input-autoexpand nil)
|
|
1312 ;; XEmacs - nil means leave it alone!
|
|
1313 input
|
|
1314 (comint-arguments input 0 nil))
|
|
1315 ;; This is messy 'cos ultimately the original
|
|
1316 ;; functions used do insertion, rather than return
|
|
1317 ;; strings. We have to expand, then insert back.
|
|
1318 (comint-replace-by-expanded-history t)
|
|
1319 (let ((copy (buffer-substring pmark (point))))
|
|
1320 (delete-region pmark (point))
|
|
1321 (insert input)
|
|
1322 (comint-arguments copy 0 nil)))))
|
|
1323 (if append-here
|
|
1324 (progn
|
|
1325 (goto-char append-here)
|
|
1326 (message
|
|
1327 (substitute-command-keys
|
|
1328 "(\\[comint-send-input] to confirm)")))
|
|
1329 (if comint-process-echoes
|
|
1330 (delete-region pmark (point))
|
|
1331 (insert ?\n))
|
|
1332 (if (and (funcall comint-input-filter history)
|
|
1333 (or (null comint-input-ignoredups)
|
|
1334 (not (ring-p comint-input-ring))
|
|
1335 (ring-empty-p comint-input-ring)
|
|
1336 (not (string-equal (ring-ref comint-input-ring 0)
|
|
1337 history))))
|
|
1338 (ring-insert comint-input-ring history))
|
|
1339 ;; XEmacs - run the input filters on the history instead
|
|
1340 ;; of the input, so that the input sentinel is called on the
|
|
1341 ;; history-expanded text and sees "cd foo" instead of "cd !$".
|
|
1342 (run-hook-with-args 'comint-input-filter-functions
|
|
1343 (concat history "\n"))
|
|
1344 (setq comint-input-ring-index nil)
|
|
1345 ;; Update the markers before we send the input
|
|
1346 ;; in case we get output amidst sending the input.
|
|
1347 (set-marker comint-last-input-start pmark)
|
|
1348 (set-marker comint-last-input-end (point))
|
|
1349 (set-marker (process-mark proc) (point))
|
|
1350 (funcall comint-input-sender proc input)
|
|
1351 ;; XEmacs - A kludge to prevent the delay between insert and
|
|
1352 ;; process output affecting the display. A case for a
|
|
1353 ;; comint-send-input-hook?
|
|
1354 (run-hook-with-args 'comint-output-filter-functions
|
|
1355 (concat input "\n"))
|
|
1356 (comint-output-filter proc "")
|
|
1357 )))))
|
|
1358
|
|
1359 ;; The purpose of using this filter for comint processes
|
|
1360 ;; is to keep comint-last-input-end from moving forward
|
|
1361 ;; when output is inserted.
|
|
1362 (defun comint-output-filter (process string)
|
|
1363 ;; First check for killed buffer
|
|
1364 (let ((oprocbuf (process-buffer process)))
|
|
1365 (if (and oprocbuf (buffer-name oprocbuf))
|
|
1366 (let ((obuf (current-buffer))
|
|
1367 (opoint nil) (obeg nil) (oend nil))
|
|
1368 (set-buffer oprocbuf)
|
|
1369 (setq string (replace-in-string string "\^M" "")
|
|
1370 opoint (point)
|
|
1371 obeg (point-min)
|
|
1372 oend (point-max))
|
|
1373 (let ((buffer-read-only nil)
|
|
1374 (nchars (length string))
|
|
1375 (ostart nil))
|
|
1376 (widen)
|
|
1377 (goto-char (process-mark process))
|
|
1378 (setq ostart (point))
|
|
1379 (if (<= (point) opoint)
|
|
1380 (setq opoint (+ opoint nchars)))
|
|
1381 ;; Insert after old_begv, but before old_zv.
|
|
1382 (if (< (point) obeg)
|
|
1383 (setq obeg (+ obeg nchars)))
|
|
1384 (if (<= (point) oend)
|
|
1385 (setq oend (+ oend nchars)))
|
|
1386 (insert-before-markers string)
|
|
1387 ;; Don't insert initial prompt outside the top of the window.
|
|
1388 (if (= (window-start (selected-window)) (point))
|
|
1389 (set-window-start (selected-window) (- (point) (length string))))
|
|
1390 (if (and comint-last-input-end
|
|
1391 (marker-buffer comint-last-input-end)
|
|
1392 (= (point) comint-last-input-end))
|
|
1393 (set-marker comint-last-input-end (- comint-last-input-end nchars)))
|
|
1394 (set-marker comint-last-output-start ostart)
|
|
1395 (set-marker (process-mark process) (point))
|
|
1396 (redraw-modeline))
|
|
1397
|
|
1398 (narrow-to-region obeg oend)
|
|
1399 (goto-char opoint)
|
|
1400 (run-hook-with-args 'comint-output-filter-functions string)
|
|
1401 (set-buffer obuf)))))
|
|
1402
|
|
1403 ;; XEmacs - Use a variable for this so that new commands can be added easily.
|
|
1404 (defvar comint-scroll-to-bottom-on-input-commands
|
|
1405 '(self-insert-command
|
|
1406 mouse-yank
|
|
1407 mouse-yank-at-click
|
|
1408 x-insert-selection
|
|
1409 comint-previous-input
|
|
1410 comint-next-input
|
|
1411 comint-previous-matching-input
|
|
1412 comint-next-matching-input
|
|
1413 comint-previous-matching-input-from-input
|
|
1414 comint-next-matching-input-from-input
|
|
1415 )
|
|
1416 "List of functions which will cause the point to move to the end of comint buffers.")
|
|
1417
|
|
1418 (defun comint-preinput-scroll-to-bottom ()
|
|
1419 "Go to the end of buffer in all windows showing it.
|
|
1420 Movement occurs if point in the selected window is not after the process mark,
|
|
1421 and `this-command' is an insertion command. Insertion commands recognised
|
|
1422 are those in `comint-scroll-to-bottom-on-input-commands'.
|
|
1423 Depends on the value of `comint-scroll-to-bottom-on-input'.
|
|
1424
|
|
1425 This function should be a pre-command hook."
|
|
1426 (if (and comint-scroll-to-bottom-on-input
|
|
1427 (memq this-command comint-scroll-to-bottom-on-input-commands))
|
|
1428 (let* ((selected (selected-window))
|
|
1429 (current (current-buffer))
|
|
1430 (process (get-buffer-process current))
|
|
1431 (scroll comint-scroll-to-bottom-on-input))
|
|
1432 (if (and process (< (point) (process-mark process))
|
|
1433 scroll (not (window-minibuffer-p selected)))
|
|
1434 (if (eq scroll 'this)
|
|
1435 (goto-char (point-max))
|
|
1436 (walk-windows
|
|
1437 (function (lambda (window)
|
|
1438 (if (and (eq (window-buffer window) current)
|
|
1439 (or (eq scroll t) (eq scroll 'all)))
|
|
1440 ;; XEmacs - fsf does this the hard way.
|
|
1441 (set-window-point window (point-max))
|
|
1442 )))
|
|
1443 'not-minibuf t))))))
|
|
1444
|
|
1445 (defun comint-postoutput-scroll-to-bottom (string)
|
|
1446 "Go to the end of buffer in all windows showing it.
|
|
1447 Does not scroll if the current line is the last line in the buffer.
|
|
1448 Depends on the value of `comint-scroll-to-bottom-on-output' and
|
|
1449 `comint-scroll-show-maximum-output'.
|
|
1450
|
|
1451 This function should be in the list `comint-output-filter-functions'."
|
|
1452 (let* ((selected (selected-window))
|
|
1453 (current (current-buffer))
|
|
1454 (process (get-buffer-process current))
|
|
1455 (scroll comint-scroll-to-bottom-on-output))
|
|
1456 ;; XEmacs - don't select windows as they're walked.
|
|
1457 (if process
|
|
1458 (walk-windows
|
|
1459 (function (lambda (window)
|
|
1460 (if (eq (window-buffer window) current)
|
|
1461 (progn
|
|
1462 (if (and (< (window-point window)
|
|
1463 (process-mark process))
|
|
1464 (or (eq scroll t) (eq scroll 'all)
|
|
1465 ;; Maybe user wants point to jump to the end.
|
|
1466 (and (eq scroll 'this)
|
|
1467 (eq selected window))
|
|
1468 (and (eq scroll 'others)
|
|
1469 (not (eq selected window)))
|
|
1470 ;; If point was at the end, keep it at the end.
|
|
1471 (>= (window-point window)
|
|
1472 (- (process-mark process) (length string)))))
|
|
1473 (set-window-point window (process-mark process)))
|
|
1474 ;; Optionally scroll so that the text
|
|
1475 ;; ends at the bottom of the window.
|
|
1476 (if (and comint-scroll-show-maximum-output
|
|
1477 (>= (window-point window)
|
|
1478 (process-mark process))
|
|
1479 ;; XEmacs - lemacs addition
|
|
1480 (not (pos-visible-in-window-p (point-max) window)))
|
|
1481 (save-excursion
|
|
1482 (set-window-point window (point-max))
|
|
1483 (recenter
|
|
1484 ;; XEmacs - lemacs addition
|
|
1485 ;; (cond ((integerp comint-scroll-show-maximum-output)
|
|
1486 ;; comint-scroll-show-maximum-output)
|
|
1487 ;; ((floatp comint-scroll-show-maximum-output)
|
|
1488 ;; (floor (* (window-height window)
|
|
1489 ;; comint-scroll-show-maximum-output)
|
|
1490 ;; 1))
|
|
1491 ;; (t
|
|
1492 ;; -1))
|
|
1493 )))
|
|
1494 ))))
|
|
1495 nil t))))
|
|
1496
|
|
1497 (defun comint-truncate-buffer (&optional string)
|
|
1498 "Truncate the buffer to `comint-buffer-maximum-size'.
|
|
1499 This function could be on `comint-output-filter-functions' or bound to a key."
|
|
1500 (interactive)
|
|
1501 (save-excursion
|
|
1502 (goto-char (point-max))
|
|
1503 (forward-line (- comint-buffer-maximum-size))
|
|
1504 (beginning-of-line)
|
|
1505 (delete-region (point-min) (point))))
|
|
1506
|
|
1507 (defun comint-strip-ctrl-m (&optional string)
|
|
1508 "Strip trailing `^M' characters from the current output group.
|
|
1509 This function could be on `comint-output-filter-functions' or bound to a key."
|
|
1510 (interactive)
|
|
1511 (let ((pmark (process-mark (get-buffer-process (current-buffer)))))
|
|
1512 (save-excursion
|
|
1513 (goto-char
|
|
1514 (if (interactive-p) comint-last-input-end comint-last-output-start))
|
|
1515 (while (re-search-forward "\r+$" pmark t)
|
|
1516 (replace-match "" t t)))))
|
|
1517 (defalias 'shell-strip-ctrl-m 'comint-strip-ctrl-m)
|
|
1518
|
|
1519 (defun comint-show-maximum-output ()
|
|
1520 "Put the end of the buffer at the bottom of the window."
|
|
1521 (interactive)
|
|
1522 (goto-char (point-max))
|
|
1523 (recenter -1))
|
|
1524
|
|
1525 (defun comint-get-old-input-default ()
|
|
1526 "Default for `comint-get-old-input'.
|
|
1527 Take the current line, and discard any initial text matching
|
|
1528 `comint-prompt-regexp'."
|
|
1529 (save-excursion
|
|
1530 (beginning-of-line)
|
|
1531 (comint-skip-prompt)
|
|
1532 (let ((beg (point)))
|
|
1533 (end-of-line)
|
|
1534 (buffer-substring beg (point)))))
|
|
1535
|
|
1536 (defun comint-copy-old-input ()
|
|
1537 "Insert after prompt old input at point as new input to be edited.
|
|
1538 Calls `comint-get-old-input' to get old input."
|
|
1539 (interactive)
|
|
1540 (let ((input (funcall comint-get-old-input))
|
|
1541 (process (get-buffer-process (current-buffer))))
|
|
1542 (if (not process)
|
|
1543 (error "Current buffer has no process")
|
|
1544 (goto-char (process-mark process))
|
|
1545 (insert input))))
|
|
1546
|
|
1547 (defun comint-skip-prompt ()
|
|
1548 "Skip past the text matching regexp `comint-prompt-regexp'.
|
|
1549 If this takes us past the end of the current line, don't skip at all."
|
|
1550 (let ((eol (save-excursion (end-of-line) (point)))
|
|
1551 ;; XEmacs - Arbitrary limit: prompt can be up to 10 lines long.
|
|
1552 (search-limit (save-excursion (forward-line -10) (point))))
|
|
1553 (if (and (save-excursion
|
|
1554 (goto-char eol)
|
|
1555 (re-search-backward comint-prompt-regexp search-limit t))
|
|
1556 (<= (match-beginning 0) (point))
|
|
1557 (> (match-end 0) (point))
|
|
1558 (<= (match-end 0) eol))
|
|
1559 (goto-char (match-end 0)))))
|
|
1560
|
|
1561 (defun comint-after-pmark-p ()
|
|
1562 "Return t if point is after the process output marker."
|
|
1563 (let ((pmark (process-mark (get-buffer-process (current-buffer)))))
|
|
1564 (<= (marker-position pmark) (point))))
|
|
1565
|
|
1566 (defun comint-simple-send (proc string)
|
|
1567 "Default function for sending to PROC input STRING.
|
|
1568 This just sends STRING plus a newline. To override this,
|
|
1569 set the hook `comint-input-sender'."
|
|
1570 (comint-send-string proc string)
|
|
1571 (comint-send-string proc "\n"))
|
|
1572
|
|
1573 ;; XEmacs - fsf doesn't bind this to ^A, but we do. There is some merit to
|
|
1574 ;; their change, so we change the behavior of the function to act the same
|
|
1575 ;; as normal ^A unless we're after the process mark. For the old behavior,
|
|
1576 ;; use ^C^A as in FSF. --Stig
|
|
1577 (defun comint-bol (arg)
|
|
1578 "Goes to the beginning of line, then skips past the prompt, if any.
|
|
1579 If prefix argument is given (\\[universal-argument]) the prompt is not skipped.
|
|
1580
|
|
1581 The prompt skip is done by skipping text matching the regular expression
|
|
1582 `comint-prompt-regexp', a buffer local variable."
|
|
1583 (interactive "_P")
|
|
1584 (let ((skip (and (null arg)
|
|
1585 (or (not (eq (lookup-key global-map (this-command-keys))
|
|
1586 'beginning-of-line))
|
|
1587 ;; If the buffer's process has gone bye-bye
|
|
1588 ;; revert to being just beginning-of-line.
|
|
1589 (not (get-buffer-process (current-buffer)))
|
|
1590 (comint-after-pmark-p)))))
|
|
1591 (beginning-of-line)
|
|
1592 (if skip (comint-skip-prompt))))
|
|
1593
|
|
1594 ;; XEmacs - more like an xterm interaction model...
|
|
1595 (defun comint-universal-argument ()
|
|
1596 "Erase the current line of input, or begin a numeric argument.
|
|
1597
|
|
1598 In buffers with interactive subprocesses, this modified version of
|
|
1599 `universal-argument' erases the current line of user input just as ^U erases a
|
|
1600 line of text at the UNIX command prompt.
|
|
1601
|
|
1602 Otherwise, begin a numeric argument for the following command.
|
|
1603 Digits or minus sign following \\[universal-argument] make up the numeric argument.
|
|
1604 \\[universal-argument] following the digits or minus sign ends the argument.
|
|
1605 \\[universal-argument] without digits or minus sign provides 4 as argument.
|
|
1606 Repeating \\[universal-argument] without digits or minus sign
|
|
1607 multiplies the argument by 4 each time."
|
|
1608 (interactive)
|
|
1609 (let ((proc (get-buffer-process (current-buffer))))
|
|
1610 (if (and proc (> (point) (process-mark proc)))
|
|
1611 (progn (comint-bol nil)
|
|
1612 (kill-region (point) (save-excursion (end-of-line) (point))))
|
|
1613 (let (key)
|
|
1614 (setq key (read-key-sequence nil t))
|
|
1615 (while (equal (key-binding key) 'universal-argument)
|
|
1616 (setq key (read-key-sequence nil t)))))))
|
|
1617
|
|
1618 ;;; These three functions are for entering text you don't want echoed or
|
|
1619 ;;; saved -- typically passwords to ftp, telnet, or somesuch.
|
|
1620 ;;; Just enter m-x send-invisible and type in your line, or add
|
|
1621 ;;; `comint-watch-for-password-prompt' to `comint-output-filter-functions'.
|
|
1622
|
|
1623 ;; XEmacs has a standard function for this.
|
|
1624 (defun comint-read-noecho (prompt &optional stars)
|
|
1625 "Read a password from the user.
|
|
1626 See documentation of `read-passwd' for more info."
|
|
1627 (read-passwd prompt))
|
|
1628
|
|
1629 (defun send-invisible (str)
|
|
1630 "Read a string without echoing.
|
|
1631 Then send it to the process running in the current buffer. A new-line
|
|
1632 is additionally sent. String is not saved on comint input history list.
|
|
1633 Security bug: your string can still be temporarily recovered with
|
|
1634 \\[view-lossage]."
|
|
1635 (interactive "P") ; Defeat snooping via C-x esc
|
|
1636 (let ((proc (get-buffer-process (current-buffer))))
|
|
1637 (if (not proc)
|
|
1638 (error "Current buffer has no process")
|
|
1639 (comint-send-string
|
|
1640 proc (if (stringp str) str (comint-read-noecho "Non-echoed text: " t)))
|
|
1641 (comint-send-string proc "\n"))))
|
|
1642
|
|
1643 (defun comint-watch-for-password-prompt (string)
|
|
1644 "Prompt in the minibuffer for password and send without echoing.
|
|
1645 This function uses `send-invisible' to read and send a password to the buffer's
|
|
1646 process if STRING contains a password prompt defined by
|
|
1647 `comint-password-prompt-regexp'.
|
|
1648
|
|
1649 This function could be in the list `comint-output-filter-functions'."
|
|
1650 (if (string-match comint-password-prompt-regexp string)
|
|
1651 (send-invisible nil)))
|
|
1652
|
|
1653 ;;; Low-level process communication
|
|
1654
|
|
1655 (defalias 'comint-send-string 'process-send-string)
|
|
1656 (defalias 'comint-send-region 'process-send-region)
|
|
1657
|
|
1658 ;;; Random input hackage
|
|
1659
|
|
1660 (defun comint-kill-output ()
|
|
1661 "Kill all output from interpreter since last input.
|
|
1662 Does not delete the prompt."
|
|
1663 (interactive)
|
|
1664 (let ((proc (get-buffer-process (current-buffer)))
|
|
1665 (replacement nil))
|
|
1666 (save-excursion
|
|
1667 (let ((pmark (progn (goto-char (process-mark proc))
|
|
1668 (beginning-of-line nil)
|
|
1669 (point-marker))))
|
|
1670 ;; XEmacs - kill in case we want it back...
|
|
1671 (kill-region comint-last-input-end pmark)
|
|
1672 (goto-char (process-mark proc))
|
|
1673 (setq replacement (concat "*** output flushed ***\n"
|
|
1674 (buffer-substring pmark (point))))
|
|
1675 (delete-region pmark (point))))
|
|
1676 ;; Output message and put back prompt
|
|
1677 (comint-output-filter proc replacement)))
|
|
1678
|
|
1679 ;; XEmacs - don't move cursor unless necessary...
|
|
1680 (defun comint-show-output ()
|
|
1681 "Display start of this batch of interpreter output at top of window.
|
|
1682 Also put cursor there if the current position is not visible.
|
|
1683 If the cursor is moved, then a mark is set at its old location."
|
|
1684 (interactive)
|
|
1685 (let ((pos (point)))
|
|
1686 (goto-char (or (marker-position comint-last-input-end) (point-max)))
|
|
1687 (beginning-of-line 0)
|
|
1688 (set-window-start (selected-window) (point))
|
|
1689 (if (pos-visible-in-window-p pos)
|
|
1690 (goto-char pos)
|
|
1691 (save-excursion
|
|
1692 (goto-char pos)
|
|
1693 (push-mark))
|
|
1694 (comint-skip-prompt))))
|
|
1695
|
|
1696 (defun comint-interrupt-subjob ()
|
|
1697 "Interrupt the current subjob."
|
|
1698 (interactive)
|
|
1699 (interrupt-process nil comint-ptyp))
|
|
1700
|
|
1701 (defun comint-kill-subjob ()
|
|
1702 "Send kill signal to the current subjob."
|
|
1703 (interactive)
|
|
1704 (kill-process nil comint-ptyp))
|
|
1705
|
|
1706 (defun comint-quit-subjob ()
|
|
1707 "Send quit signal to the current subjob."
|
|
1708 (interactive)
|
|
1709 (quit-process nil comint-ptyp))
|
|
1710
|
|
1711 (defun comint-stop-subjob ()
|
|
1712 "Stop the current subjob.
|
|
1713 WARNING: if there is no current subjob, you can end up suspending
|
|
1714 the top-level process running in the buffer. If you accidentally do
|
|
1715 this, use \\[comint-continue-subjob] to resume the process. (This
|
|
1716 is not a problem with most shells, since they ignore this signal.)"
|
|
1717 (interactive)
|
|
1718 (stop-process nil comint-ptyp))
|
|
1719
|
|
1720 (defun comint-continue-subjob ()
|
|
1721 "Send CONT signal to process buffer's process group.
|
|
1722 Useful if you accidentally suspend the top-level process."
|
|
1723 (interactive)
|
|
1724 (continue-process nil comint-ptyp))
|
|
1725
|
|
1726 (defun comint-kill-input ()
|
|
1727 "Kill all text from last stuff output by interpreter to point."
|
|
1728 (interactive)
|
|
1729 (let ((pmark (process-mark (get-buffer-process (current-buffer)))))
|
|
1730 (if (> (point) (marker-position pmark))
|
|
1731 (kill-region pmark (point)))))
|
|
1732
|
|
1733 (defun comint-delchar-or-maybe-eof (arg)
|
|
1734 "Delete ARG characters forward, or (if at eob) send an EOF to subprocess."
|
|
1735 (interactive "p")
|
|
1736 (if (eobp)
|
|
1737 (process-send-eof)
|
|
1738 (delete-char arg)))
|
|
1739
|
|
1740 (defun comint-send-eof ()
|
|
1741 "Send an EOF to the current buffer's process."
|
|
1742 (interactive)
|
|
1743 (process-send-eof))
|
|
1744
|
|
1745
|
|
1746 (defun comint-backward-matching-input (regexp arg)
|
|
1747 "Search backward through buffer for match for REGEXP.
|
|
1748 Matches are searched for on lines that match `comint-prompt-regexp'.
|
|
1749 With prefix argument N, search for Nth previous match.
|
|
1750 If N is negative, find the next or Nth next match."
|
|
1751 (interactive (comint-regexp-arg "Backward input matching (regexp): "))
|
|
1752 (let* ((re (concat comint-prompt-regexp ".*" regexp))
|
|
1753 (pos (save-excursion (end-of-line (if (> arg 0) 0 1))
|
|
1754 (if (re-search-backward re nil t arg)
|
|
1755 (point)))))
|
|
1756 (if (null pos)
|
|
1757 (progn (message "Not found")
|
|
1758 (ding))
|
|
1759 (goto-char pos)
|
|
1760 (comint-bol nil))))
|
|
1761
|
|
1762 (defun comint-forward-matching-input (regexp arg)
|
|
1763 "Search forward through buffer for match for REGEXP.
|
|
1764 Matches are searched for on lines that match `comint-prompt-regexp'.
|
|
1765 With prefix argument N, search for Nth following match.
|
|
1766 If N is negative, find the previous or Nth previous match."
|
|
1767 (interactive (comint-regexp-arg "Forward input matching (regexp): "))
|
|
1768 (comint-backward-matching-input regexp (- arg)))
|
|
1769
|
|
1770
|
|
1771 (defun comint-next-prompt (n)
|
|
1772 "Move to end of Nth next prompt in the buffer.
|
|
1773 See `comint-prompt-regexp'."
|
|
1774 (interactive "_p") ; XEmacs - zmacs-regions
|
|
1775 (let ((paragraph-start comint-prompt-regexp))
|
|
1776 (end-of-line (if (> n 0) 1 0))
|
|
1777 (forward-paragraph n)
|
|
1778 (comint-skip-prompt)))
|
|
1779
|
|
1780 (defun comint-previous-prompt (n)
|
|
1781 "Move to end of Nth previous prompt in the buffer.
|
|
1782 See `comint-prompt-regexp'."
|
|
1783 (interactive "_p") ; XEmacs
|
|
1784 (comint-next-prompt (- n)))
|
|
1785
|
|
1786 ;;; Support for source-file processing commands.
|
|
1787 ;;;============================================================================
|
|
1788 ;;; Many command-interpreters (e.g., Lisp, Scheme, Soar) have
|
|
1789 ;;; commands that process files of source text (e.g. loading or compiling
|
|
1790 ;;; files). So the corresponding process-in-a-buffer modes have commands
|
|
1791 ;;; for doing this (e.g., lisp-load-file). The functions below are useful
|
|
1792 ;;; for defining these commands.
|
|
1793 ;;;
|
|
1794 ;;; Alas, these guys don't do exactly the right thing for Lisp, Scheme
|
|
1795 ;;; and Soar, in that they don't know anything about file extensions.
|
|
1796 ;;; So the compile/load interface gets the wrong default occasionally.
|
|
1797 ;;; The load-file/compile-file default mechanism could be smarter -- it
|
|
1798 ;;; doesn't know about the relationship between filename extensions and
|
|
1799 ;;; whether the file is source or executable. If you compile foo.lisp
|
|
1800 ;;; with compile-file, then the next load-file should use foo.bin for
|
|
1801 ;;; the default, not foo.lisp. This is tricky to do right, particularly
|
|
1802 ;;; because the extension for executable files varies so much (.o, .bin,
|
|
1803 ;;; .lbin, .mo, .vo, .ao, ...).
|
|
1804
|
|
1805
|
|
1806 ;;; COMINT-SOURCE-DEFAULT -- determines defaults for source-file processing
|
|
1807 ;;; commands.
|
|
1808 ;;;
|
|
1809 ;;; COMINT-CHECK-SOURCE -- if FNAME is in a modified buffer, asks you if you
|
|
1810 ;;; want to save the buffer before issuing any process requests to the command
|
|
1811 ;;; interpreter.
|
|
1812 ;;;
|
|
1813 ;;; COMINT-GET-SOURCE -- used by the source-file processing commands to prompt
|
|
1814 ;;; for the file to process.
|
|
1815
|
|
1816 ;;; (COMINT-SOURCE-DEFAULT previous-dir/file source-modes)
|
|
1817 ;;;============================================================================
|
|
1818 ;;; This function computes the defaults for the load-file and compile-file
|
|
1819 ;;; commands for tea, soar, cmulisp, and cmuscheme modes.
|
|
1820 ;;;
|
|
1821 ;;; - PREVIOUS-DIR/FILE is a pair (directory . filename) from the last
|
|
1822 ;;; source-file processing command. NIL if there hasn't been one yet.
|
|
1823 ;;; - SOURCE-MODES is a list used to determine what buffers contain source
|
|
1824 ;;; files: if the major mode of the buffer is in SOURCE-MODES, it's source.
|
|
1825 ;;; Typically, (lisp-mode) or (scheme-mode).
|
|
1826 ;;;
|
|
1827 ;;; If the command is given while the cursor is inside a string, *and*
|
|
1828 ;;; the string is an existing filename, *and* the filename is not a directory,
|
|
1829 ;;; then the string is taken as default. This allows you to just position
|
|
1830 ;;; your cursor over a string that's a filename and have it taken as default.
|
|
1831 ;;;
|
|
1832 ;;; If the command is given in a file buffer whose major mode is in
|
2
|
1833 ;;; SOURCE-MODES, then the filename is the default file, and the
|
0
|
1834 ;;; file's directory is the default directory.
|
|
1835 ;;;
|
|
1836 ;;; If the buffer isn't a source file buffer (e.g., it's the process buffer),
|
|
1837 ;;; then the default directory & file are what was used in the last source-file
|
|
1838 ;;; processing command (i.e., PREVIOUS-DIR/FILE). If this is the first time
|
|
1839 ;;; the command has been run (PREVIOUS-DIR/FILE is nil), the default directory
|
|
1840 ;;; is the cwd, with no default file. (\"no default file\" = nil)
|
|
1841 ;;;
|
|
1842 ;;; SOURCE-REGEXP is typically going to be something like (tea-mode)
|
|
1843 ;;; for T programs, (lisp-mode) for Lisp programs, (soar-mode lisp-mode)
|
|
1844 ;;; for Soar programs, etc.
|
|
1845 ;;;
|
|
1846 ;;; The function returns a pair: (default-directory . default-file).
|
|
1847
|
|
1848 (defun comint-source-default (previous-dir/file source-modes)
|
|
1849 (cond ((and buffer-file-name (memq major-mode source-modes))
|
|
1850 (cons (file-name-directory buffer-file-name)
|
|
1851 (file-name-nondirectory buffer-file-name)))
|
|
1852 (previous-dir/file)
|
|
1853 (t
|
|
1854 (cons default-directory nil))))
|
|
1855
|
|
1856
|
|
1857 ;;; (COMINT-CHECK-SOURCE fname)
|
|
1858 ;;;============================================================================
|
|
1859 ;;; Prior to loading or compiling (or otherwise processing) a file (in the CMU
|
|
1860 ;;; process-in-a-buffer modes), this function can be called on the filename.
|
|
1861 ;;; If the file is loaded into a buffer, and the buffer is modified, the user
|
|
1862 ;;; is queried to see if he wants to save the buffer before proceeding with
|
|
1863 ;;; the load or compile.
|
|
1864
|
|
1865 (defun comint-check-source (fname)
|
|
1866 (let ((buff (get-file-buffer fname)))
|
|
1867 (if (and buff
|
|
1868 (buffer-modified-p buff)
|
|
1869 (y-or-n-p (format "Save buffer %s first? " (buffer-name buff))))
|
|
1870 ;; save BUFF.
|
|
1871 (let ((old-buffer (current-buffer)))
|
|
1872 (set-buffer buff)
|
|
1873 (save-buffer)
|
|
1874 (set-buffer old-buffer)))))
|
|
1875
|
|
1876
|
|
1877 ;;; (COMINT-GET-SOURCE prompt prev-dir/file source-modes mustmatch-p)
|
|
1878 ;;;============================================================================
|
|
1879 ;;; COMINT-GET-SOURCE is used to prompt for filenames in command-interpreter
|
|
1880 ;;; commands that process source files (like loading or compiling a file).
|
|
1881 ;;; It prompts for the filename, provides a default, if there is one,
|
|
1882 ;;; and returns the result filename.
|
|
1883 ;;;
|
|
1884 ;;; See COMINT-SOURCE-DEFAULT for more on determining defaults.
|
|
1885 ;;;
|
|
1886 ;;; PROMPT is the prompt string. PREV-DIR/FILE is the (directory . file) pair
|
|
1887 ;;; from the last source processing command. SOURCE-MODES is a list of major
|
|
1888 ;;; modes used to determine what file buffers contain source files. (These
|
|
1889 ;;; two arguments are used for determining defaults). If MUSTMATCH-P is true,
|
|
1890 ;;; then the filename reader will only accept a file that exists.
|
|
1891 ;;;
|
|
1892 ;;; A typical use:
|
|
1893 ;;; (interactive (comint-get-source "Compile file: " prev-lisp-dir/file
|
|
1894 ;;; '(lisp-mode) t))
|
|
1895
|
|
1896 ;;; This is pretty stupid about strings. It decides we're in a string
|
|
1897 ;;; if there's a quote on both sides of point on the current line.
|
|
1898 (defun comint-extract-string ()
|
|
1899 "Return string around POINT that starts the current line, or nil."
|
|
1900 (save-excursion
|
|
1901 (let* ((point (point))
|
|
1902 (bol (progn (beginning-of-line) (point)))
|
|
1903 (eol (progn (end-of-line) (point)))
|
|
1904 (start (progn (goto-char point)
|
|
1905 (and (search-backward "\"" bol t)
|
|
1906 (1+ (point)))))
|
|
1907 (end (progn (goto-char point)
|
|
1908 (and (search-forward "\"" eol t)
|
|
1909 (1- (point))))))
|
|
1910 (and start end
|
|
1911 (buffer-substring start end)))))
|
|
1912
|
|
1913 (defun comint-get-source (prompt prev-dir/file source-modes mustmatch-p)
|
|
1914 (let* ((def (comint-source-default prev-dir/file source-modes))
|
|
1915 (stringfile (comint-extract-string))
|
|
1916 (sfile-p (and stringfile
|
|
1917 (condition-case ()
|
|
1918 (file-exists-p stringfile)
|
|
1919 (error nil))
|
|
1920 (not (file-directory-p stringfile))))
|
|
1921 (defdir (if sfile-p (file-name-directory stringfile)
|
|
1922 (car def)))
|
|
1923 (deffile (if sfile-p (file-name-nondirectory stringfile)
|
|
1924 (cdr def)))
|
|
1925 (ans (read-file-name (if deffile (format "%s(default %s) "
|
|
1926 prompt deffile)
|
|
1927 prompt)
|
|
1928 defdir
|
|
1929 (concat defdir deffile)
|
|
1930 mustmatch-p)))
|
|
1931 (list (expand-file-name (substitute-in-file-name ans)))))
|
|
1932
|
|
1933 ;;; I am somewhat divided on this string-default feature. It seems
|
|
1934 ;;; to violate the principle-of-least-astonishment, in that it makes
|
|
1935 ;;; the default harder to predict, so you actually have to look and see
|
|
1936 ;;; what the default really is before choosing it. This can trip you up.
|
|
1937 ;;; On the other hand, it can be useful, I guess. I would appreciate feedback
|
|
1938 ;;; on this.
|
|
1939 ;;; -Olin
|
|
1940
|
|
1941
|
|
1942 ;;; Simple process query facility.
|
|
1943 ;;; ===========================================================================
|
|
1944 ;;; This function is for commands that want to send a query to the process
|
|
1945 ;;; and show the response to the user. For example, a command to get the
|
|
1946 ;;; arglist for a Common Lisp function might send a "(arglist 'foo)" query
|
|
1947 ;;; to an inferior Common Lisp process.
|
|
1948 ;;;
|
|
1949 ;;; This simple facility just sends strings to the inferior process and pops
|
|
1950 ;;; up a window for the process buffer so you can see what the process
|
|
1951 ;;; responds with. We don't do anything fancy like try to intercept what the
|
|
1952 ;;; process responds with and put it in a pop-up window or on the message
|
|
1953 ;;; line. We just display the buffer. Low tech. Simple. Works good.
|
|
1954
|
|
1955 ;;; Send to the inferior process PROC the string STR. Pop-up but do not select
|
|
1956 ;;; a window for the inferior process so that its response can be seen.
|
|
1957 (defun comint-proc-query (proc str)
|
|
1958 (let* ((proc-buf (process-buffer proc))
|
|
1959 (proc-mark (process-mark proc)))
|
|
1960 (display-buffer proc-buf)
|
|
1961 (set-buffer proc-buf) ; but it's not the selected *window*
|
|
1962 (let ((proc-win (get-buffer-window proc-buf))
|
|
1963 (proc-pt (marker-position proc-mark)))
|
|
1964 (comint-send-string proc str) ; send the query
|
|
1965 (accept-process-output proc) ; wait for some output
|
|
1966 ;; Try to position the proc window so you can see the answer.
|
|
1967 ;; This is bogus code. If you delete the (sit-for 0), it breaks.
|
|
1968 ;; I don't know why. Wizards invited to improve it.
|
|
1969 (if (not (pos-visible-in-window-p proc-pt proc-win))
|
|
1970 (let ((opoint (window-point proc-win)))
|
|
1971 (set-window-point proc-win proc-mark)
|
|
1972 (sit-for 0)
|
|
1973 (if (not (pos-visible-in-window-p opoint proc-win))
|
|
1974 (push-mark opoint)
|
|
1975 (set-window-point proc-win opoint)))))))
|
|
1976
|
|
1977
|
|
1978 ;;; Filename/command/history completion in a buffer
|
|
1979 ;;; ===========================================================================
|
|
1980 ;;; Useful completion functions, courtesy of the Ergo group.
|
|
1981
|
|
1982 ;;; Six commands:
|
|
1983 ;;; comint-dynamic-complete Complete or expand command, filename,
|
|
1984 ;;; history at point.
|
|
1985 ;;; comint-dynamic-complete-filename Complete filename at point.
|
|
1986 ;;; comint-dynamic-list-filename-completions List completions in help buffer.
|
|
1987 ;;; comint-replace-by-expanded-filename Expand and complete filename at point;
|
|
1988 ;;; replace with expanded/completed name.
|
|
1989 ;;; comint-dynamic-simple-complete Complete stub given candidates.
|
|
1990
|
|
1991 ;;; These are not installed in the comint-mode keymap. But they are
|
|
1992 ;;; available for people who want them. Shell-mode installs them:
|
|
1993 ;;; (define-key shell-mode-map "\t" 'comint-dynamic-complete)
|
|
1994 ;;; (define-key shell-mode-map "\M-?"
|
|
1995 ;;; 'comint-dynamic-list-filename-completions)))
|
|
1996 ;;;
|
|
1997 ;;; Commands like this are fine things to put in load hooks if you
|
|
1998 ;;; want them present in specific modes.
|
|
1999
|
|
2000 (defvar comint-completion-autolist nil
|
70
|
2001 "*If non-nil, automatically list possiblities on partial completion.
|
0
|
2002 This mirrors the optional behavior of tcsh.")
|
|
2003
|
|
2004 (defvar comint-completion-addsuffix t
|
|
2005 "*If non-nil, add a `/' to completed directories, ` ' to file names.
|
|
2006 If a cons pair, it should be of the form (DIRSUFFIX . FILESUFFIX) where
|
|
2007 DIRSUFFIX and FILESUFFIX are strings added on unambiguous or exact completion.
|
|
2008 This mirrors the optional behavior of tcsh.")
|
|
2009
|
|
2010 (defvar comint-completion-recexact nil
|
|
2011 "*If non-nil, use shortest completion if characters cannot be added.
|
|
2012 This mirrors the optional behavior of tcsh.
|
|
2013
|
|
2014 A non-nil value is useful if `comint-completion-autolist' is non-nil too.")
|
|
2015
|
|
2016 (defvar comint-completion-fignore nil
|
|
2017 "*List of suffixes to be disregarded during file completion.
|
|
2018 This mirrors the optional behavior of bash and tcsh.
|
|
2019
|
|
2020 Note that this applies to `comint-dynamic-complete-filename' only.")
|
|
2021
|
|
2022 (defvar comint-file-name-prefix ""
|
|
2023 "Prefix prepended to absolute file names taken from process input.
|
|
2024 This is used by comint's and shell's completion functions, and by shell's
|
|
2025 directory tracking functions.")
|
|
2026
|
|
2027 (defvar comint-file-name-quote-list nil
|
|
2028 "List of characters to quote with `\' when in a file name.
|
|
2029
|
|
2030 This is a good thing to set in mode hooks.")
|
|
2031
|
|
2032
|
|
2033 (defun comint-directory (directory)
|
|
2034 ;; Return expanded DIRECTORY, with `comint-file-name-prefix' if absolute.
|
|
2035 (expand-file-name (if (file-name-absolute-p directory)
|
|
2036 (concat comint-file-name-prefix directory)
|
|
2037 directory)))
|
|
2038
|
|
2039
|
|
2040 (defun comint-word (word-chars)
|
|
2041 "Return the word of WORD-CHARS at point, or nil if non is found.
|
|
2042 Word constituents are considered to be those in WORD-CHARS, which is like the
|
|
2043 inside of a \"[...]\" (see `skip-chars-forward')."
|
|
2044 (save-excursion
|
|
2045 (let ((non-word-chars (concat "[^\\\\" word-chars "]")) (here (point)))
|
|
2046 (while (and (re-search-backward non-word-chars nil 'move)
|
|
2047 ;(memq (char-after (point)) shell-file-name-quote-list)
|
|
2048 (eq (preceding-char) ?\\))
|
|
2049 (backward-char 1))
|
|
2050 ;; Don't go forward over a word-char (this can happen if we're at bob).
|
|
2051 (if (or (not (bobp)) (looking-at non-word-chars))
|
|
2052 (forward-char 1))
|
|
2053 ;; Set match-data to match the entire string.
|
|
2054 (if (< (point) here)
|
|
2055 (progn (store-match-data (list (point) here))
|
|
2056 (match-string 0))))))
|
|
2057
|
|
2058
|
|
2059 (defun comint-match-partial-filename ()
|
|
2060 "Return the filename at point, or nil if non is found.
|
|
2061 Environment variables are substituted. See `comint-word'."
|
|
2062 (let ((filename (comint-word "~/A-Za-z0-9+@:_.$#%,={}-")))
|
|
2063 (and filename (substitute-in-file-name (comint-unquote-filename filename)))))
|
|
2064
|
|
2065
|
|
2066 (defun comint-quote-filename (filename)
|
|
2067 "Return FILENAME with magic characters quoted.
|
|
2068 Magic characters are those in `comint-file-name-quote-list'."
|
|
2069 (if (null comint-file-name-quote-list)
|
|
2070 filename
|
|
2071 (let ((regexp
|
|
2072 (format "\\(^\\|[^\\]\\)\\([%s]\\)"
|
|
2073 (mapconcat 'char-to-string comint-file-name-quote-list ""))))
|
|
2074 (save-match-data
|
|
2075 (while (string-match regexp filename)
|
|
2076 (setq filename (replace-match "\\1\\\\\\2" nil nil filename)))
|
|
2077 filename))))
|
|
2078
|
|
2079 (defun comint-unquote-filename (filename)
|
|
2080 "Return FILENAME with quoted characters unquoted."
|
|
2081 (if (null comint-file-name-quote-list)
|
|
2082 filename
|
|
2083 (save-match-data
|
|
2084 (while (string-match "\\\\\\(.\\)" filename)
|
|
2085 (setq filename (replace-match "\\1" nil nil filename)))
|
|
2086 filename)))
|
|
2087
|
|
2088
|
|
2089 ;;;###autoload
|
|
2090 (defun comint-dynamic-complete ()
|
|
2091 "Dynamically perform completion at point.
|
|
2092 Calls the functions in `comint-dynamic-complete-functions' to perform
|
|
2093 completion until a function returns non-nil, at which point completion is
|
|
2094 assumed to have occurred."
|
|
2095 (interactive)
|
|
2096 (run-hook-with-args-until-success 'comint-dynamic-complete-functions))
|
|
2097
|
|
2098
|
|
2099 (defun comint-dynamic-complete-filename ()
|
|
2100 "Dynamically complete the filename at point.
|
|
2101 Completes if after a filename. See `comint-match-partial-filename' and
|
|
2102 `comint-dynamic-complete-as-filename'.
|
|
2103 This function is similar to `comint-replace-by-expanded-filename', except that
|
|
2104 it won't change parts of the filename already entered in the buffer; it just
|
|
2105 adds completion characters to the end of the filename. A completions listing
|
|
2106 may be shown in a help buffer if completion is ambiguous.
|
|
2107
|
|
2108 Completion is dependent on the value of `comint-completion-addsuffix',
|
|
2109 `comint-completion-recexact' and `comint-completion-fignore', and the timing of
|
|
2110 completions listing is dependent on the value of `comint-completion-autolist'.
|
|
2111
|
|
2112 Returns t if successful."
|
|
2113 (interactive)
|
|
2114 (if (comint-match-partial-filename)
|
|
2115 (prog2 (or (window-minibuffer-p (selected-window))
|
|
2116 (message "Completing file name..."))
|
|
2117 (comint-dynamic-complete-as-filename))))
|
|
2118
|
|
2119
|
|
2120 (defun comint-dynamic-complete-as-filename ()
|
|
2121 "Dynamically complete at point as a filename.
|
|
2122 See `comint-dynamic-complete-filename'. Returns t if successful."
|
|
2123 (let* ((completion-ignore-case nil)
|
|
2124 (completion-ignored-extensions comint-completion-fignore)
|
|
2125 (file-name-handler-alist nil)
|
|
2126 (minibuffer-p (window-minibuffer-p (selected-window)))
|
|
2127 (success t)
|
|
2128 (dirsuffix (cond ((not comint-completion-addsuffix) "")
|
|
2129 ((not (consp comint-completion-addsuffix)) "/")
|
|
2130 (t (car comint-completion-addsuffix))))
|
|
2131 (filesuffix (cond ((not comint-completion-addsuffix) "")
|
|
2132 ((not (consp comint-completion-addsuffix)) " ")
|
|
2133 (t (cdr comint-completion-addsuffix))))
|
|
2134 (filename (or (comint-match-partial-filename) ""))
|
|
2135 (pathdir (file-name-directory filename))
|
|
2136 (pathnondir (file-name-nondirectory filename))
|
|
2137 (directory (if pathdir (comint-directory pathdir) default-directory))
|
|
2138 (completion (file-name-completion pathnondir directory)))
|
|
2139 (cond ((null completion)
|
|
2140 (if minibuffer-p (ding) (message "No completions of %s" filename))
|
|
2141 (setq success nil))
|
|
2142 ((eq completion t) ; Means already completed "file".
|
|
2143 (insert filesuffix)
|
|
2144 (or minibuffer-p (message "Sole completion")))
|
|
2145 ((string-equal completion "") ; Means completion on "directory/".
|
|
2146 (comint-dynamic-list-filename-completions))
|
|
2147 (t ; Completion string returned.
|
|
2148 (let ((file (concat (file-name-as-directory directory) completion)))
|
|
2149 (insert (comint-quote-filename
|
|
2150 (substring (directory-file-name completion)
|
|
2151 (length pathnondir))))
|
|
2152 (cond ((symbolp (file-name-completion completion directory))
|
|
2153 ;; We inserted a unique completion.
|
|
2154 (insert (if (file-directory-p file) dirsuffix filesuffix))
|
|
2155 (or minibuffer-p (message "Completed")))
|
|
2156 ((and comint-completion-recexact comint-completion-addsuffix
|
|
2157 (string-equal pathnondir completion)
|
|
2158 (file-exists-p file))
|
|
2159 ;; It's not unique, but user wants shortest match.
|
|
2160 (insert (if (file-directory-p file) dirsuffix filesuffix))
|
|
2161 (or minibuffer-p (message "Completed shortest")))
|
|
2162 ((or comint-completion-autolist
|
|
2163 (string-equal pathnondir completion))
|
|
2164 ;; It's not unique, list possible completions.
|
|
2165 (comint-dynamic-list-filename-completions))
|
|
2166 (t
|
|
2167 (or minibuffer-p (message "Partially completed")))))))
|
|
2168 success))
|
|
2169
|
|
2170
|
|
2171 (defun comint-replace-by-expanded-filename ()
|
|
2172 "Dynamically expand and complete the filename at point.
|
|
2173 Replace the filename with an expanded, canonicalised and completed replacement.
|
|
2174 \"Expanded\" means environment variables (e.g., $HOME) and `~'s are replaced
|
|
2175 with the corresponding directories. \"Canonicalised\" means `..' and `.' are
|
|
2176 removed, and the filename is made absolute instead of relative. For expansion
|
|
2177 see `expand-file-name' and `substitute-in-file-name'. For completion see
|
|
2178 `comint-dynamic-complete-filename'."
|
|
2179 (interactive)
|
|
2180 (replace-match (expand-file-name (comint-match-partial-filename)) t t)
|
|
2181 (comint-dynamic-complete-filename))
|
|
2182
|
|
2183
|
|
2184 (defun comint-dynamic-simple-complete (stub candidates)
|
|
2185 "Dynamically complete STUB from CANDIDATES list.
|
|
2186 This function inserts completion characters at point by completing STUB from
|
|
2187 the strings in CANDIDATES. A completions listing may be shown in a help buffer
|
|
2188 if completion is ambiguous.
|
|
2189
|
|
2190 Returns nil if no completion was inserted.
|
|
2191 Returns `sole' if completed with the only completion match.
|
|
2192 Returns `shortest' if completed with the shortest of the completion matches.
|
|
2193 Returns `partial' if completed as far as possible with the completion matches.
|
|
2194 Returns `listed' if a completion listing was shown.
|
|
2195
|
|
2196 See also `comint-dynamic-complete-filename'."
|
|
2197 (let* ((completion-ignore-case nil)
|
|
2198 (suffix (cond ((not comint-completion-addsuffix) "")
|
|
2199 ((not (consp comint-completion-addsuffix)) " ")
|
|
2200 (t (cdr comint-completion-addsuffix))))
|
|
2201 (candidates (mapcar (function (lambda (x) (list x))) candidates))
|
|
2202 (completions (all-completions stub candidates)))
|
|
2203 (cond ((null completions)
|
|
2204 (message "No completions of %s" stub)
|
|
2205 nil)
|
|
2206 ((= 1 (length completions)) ; Gotcha!
|
|
2207 (let ((completion (car completions)))
|
|
2208 (if (string-equal completion stub)
|
|
2209 (message "Sole completion")
|
|
2210 (insert (substring completion (length stub)))
|
|
2211 (message "Completed"))
|
|
2212 (insert suffix)
|
|
2213 'sole))
|
|
2214 (t ; There's no unique completion.
|
|
2215 (let ((completion (try-completion stub candidates)))
|
|
2216 ;; Insert the longest substring.
|
|
2217 (insert (substring completion (length stub)))
|
|
2218 (cond ((and comint-completion-recexact comint-completion-addsuffix
|
|
2219 (string-equal stub completion)
|
|
2220 (member completion completions))
|
|
2221 ;; It's not unique, but user wants shortest match.
|
|
2222 (insert suffix)
|
|
2223 (message "Completed shortest")
|
|
2224 'shortest)
|
|
2225 ((or comint-completion-autolist
|
|
2226 (string-equal stub completion))
|
|
2227 ;; It's not unique, list possible completions.
|
|
2228 (comint-dynamic-list-completions completions)
|
|
2229 'listed)
|
|
2230 (t
|
|
2231 (message "Partially completed")
|
|
2232 'partial)))))))
|
|
2233
|
|
2234
|
|
2235 (defun comint-dynamic-list-filename-completions ()
|
|
2236 "List in help buffer possible completions of the filename at point."
|
|
2237 (interactive)
|
|
2238 (let* ((completion-ignore-case nil)
|
|
2239 (file-name-handler-alist nil)
|
|
2240 (filename (or (comint-match-partial-filename) ""))
|
|
2241 (pathdir (file-name-directory filename))
|
|
2242 (pathnondir (file-name-nondirectory filename))
|
|
2243 (directory (if pathdir (comint-directory pathdir) default-directory))
|
|
2244 (completions (file-name-all-completions pathnondir directory)))
|
|
2245 (if (not completions)
|
|
2246 (message "No completions of %s" filename)
|
|
2247 (comint-dynamic-list-completions
|
|
2248 (mapcar 'comint-quote-filename completions)))))
|
|
2249
|
|
2250
|
|
2251 ;;;###autoload
|
|
2252 (defun comint-dynamic-list-completions (completions)
|
|
2253 "List in help buffer sorted COMPLETIONS.
|
|
2254 Typing SPC flushes the help buffer."
|
|
2255 (let ((conf (current-window-configuration)))
|
|
2256 (with-output-to-temp-buffer "*Completions*"
|
|
2257 (display-completion-list (sort completions 'string-lessp)))
|
|
2258 ;; XEmacs - centralize this
|
|
2259 (comint-restore-window-config conf)))
|
|
2260
|
|
2261 ;; #### - FSFmacs doesn't have this and I'm not gonna nuke it just yet, but
|
|
2262 ;; it seems awfully redundant to have this here when compile.el does pretty
|
|
2263 ;; much the same thing. --Stig
|
|
2264
|
|
2265 ;;; Filename and source location extraction from a buffer.
|
|
2266 ;;; lemacs change by John Rose
|
|
2267 ;;; ===========================================================================
|
|
2268 ;;; Functions for recognizing and extracting file names and line numbers.
|
|
2269 ;;; C-c C-f attempts to extract a location from the current line, and
|
|
2270 ;;; go to that location.
|
|
2271
|
|
2272 ;;; One command:
|
|
2273 ;;; comint-find-source-code Extract source location and follow it.
|
|
2274
|
|
2275 ;;; This should be installed globally, since file names and source locations
|
|
2276 ;;; are ubiquitous. However, don't overwrite an existing key binding.
|
|
2277 (if (not (lookup-key global-map "\C-c\C-f"))
|
|
2278 (global-set-key "\C-c\C-f" 'comint-find-source-code))
|
|
2279
|
|
2280 ;;; Utility functions:
|
|
2281 ;;; comint-extract-source-location Parse source loc. from buffer or string.
|
|
2282 ;;; comint-extract-current-pathname Extract potential pathname around point.
|
|
2283 ;;; comint-match-partial-pathname Match a potential pathname before point.
|
|
2284
|
|
2285 (defconst comint-source-location-patterns
|
|
2286 '(;; grep (and cpp): file.c: 10:
|
|
2287 ("\\(^\\|[ \t]\\)\\([^ \t\n]+\\): *\\([0-9]+\\):[ \t]*\\(.*\\)" (grep cpp) (2 3 4))
|
|
2288 ;; cpp: #line 10 "file.c"
|
|
2289 ("#\\(line\\)? *\\([0-9]+\\) *\"\\([^\"\n]+\\)\"" cpp (3 2))
|
|
2290 ;; cc: "file.c", line 10
|
|
2291 ("\"\\([^\"\n]+\\)\", line +\\([0-9]+\\)\\(:[ \t]+\\(.*\\)\\)?" cc (1 2 4))
|
|
2292 ;; f77: line 10 of file.c
|
|
2293 ("line +\\([0-9]+\\) +of +\\([^ \t\n]+\\)\\(:[ \t]+\\(.*\\)\\)?" f77 (2 1 4))
|
|
2294 ;; perl: ...at file.c line 10.
|
|
2295 ;; perl: ...at file.c line 10, near "foo"
|
|
2296 ("^\\(.*\\) at \\([^ \t\n]+\\) line +\\([0-9]+\\)\\(\\.$\\|, \\)"
|
|
2297 perl (2 3 1))
|
|
2298 ;; dbx: line 10 in "file.c"
|
|
2299 ("\\(^\\(.*\\)[ \t]+at \\)?line +\\([0-9]+\\) +[in of file]+ +\"\\([^\"\n]+\\)\""
|
|
2300 dbx (4 3 2))
|
|
2301 ;; dbx: "file.c":10
|
|
2302 ("\"\\([^\"\n]+\\)\":\\([0-9]+\\)" dbx (1 2))
|
|
2303 ;; centerline: "file.c:10"
|
|
2304 ("\"\\([^\"\n]+\\):\\([0-9]+\\)\"" centerline (1 2))
|
|
2305 ;; lint: : file.c(10)
|
|
2306 (": *\\([^ \t\n)]+\\) *(\\([0-9]+\\))" lint (1 2))
|
|
2307 ;; lint: file.c(10) :
|
|
2308 ("\\(^\\|[ \t]\\)\\([^ \t\n)]+\\) *(\\([0-9]+\\)) *:" lint (2 3))
|
|
2309 ;; lint: ( file.c(10) )
|
|
2310 ("( +\\([^ \t\n)]+\\) *(\\([0-9]+\\)) +)" lint (1 2))
|
|
2311 ;; troff: `file.c', line 10
|
|
2312 ("[\"`']\\([^\"`'\n]+\\)[\"`'], line +\\([0-9]+\\)" troff (1 2))
|
|
2313 ;; ri: "file.c" 10:
|
|
2314 ("\"\\([^\"\n]+\\)\" *\\([0-9]+\\):" ri (1 2)) ;;Never heard of ri.
|
|
2315 ;; mod: File file.c, line 10
|
|
2316 ("[Ff]ile +\\([^ \t\n]+\\), line +\\([0-9]+\\)" mod (1 2))
|
|
2317 ;; ksh: file.c[10] :
|
|
2318 ("\\(^\\|[ \t]\\)\\([^ \t\n)]+\\) *\\[\\([0-9]+\\)\\] *:[ \t]+\\(.*\\)"
|
|
2319 ksh (2 3 4))
|
|
2320 ;; shell: file.c: syntax error at line 10
|
|
2321 ("\\(^\\|[ \t]\\)\\([^ \t\n:]+\\):[ \t]+\\(.*\\)[ \t]+[, at]*line +\\([0-9]+\\)"
|
|
2322 sh (2 4 3) -1)
|
|
2323 )
|
|
2324 "Series of regexps matching file number locations.
|
|
2325 Each list entry is a 3-list of a regexp, a program name, and up to 3 numbers.
|
|
2326 The numbers name regexp fields which will hold the file, line number,
|
|
2327 and associated diagnostic message (if any).
|
|
2328 The program name is a symbol or list of symbols, and
|
|
2329 is returned unexamined from `comint-extract-source-location';
|
|
2330 it should be a guess at who produced the message, e.g., 'cc'.
|
|
2331
|
|
2332 In the case of multiple matches, `comint-extract-source-location'
|
|
2333 will return the leftmost, longest match of the highest priority.
|
|
2334 The priority of most patterns is 0, but a fourth element on
|
|
2335 the list, if present, specifies a different priority.
|
|
2336
|
|
2337 The regexps initially stored here are based on the one in compile.el
|
|
2338 \(although the pattern containing 'of' must also contain 'line').
|
|
2339 They are also drawn from the Unix filters 'error' and 'fwarn'.
|
|
2340 The patterns are known to recognize errors from the following
|
|
2341 Un*x language processors:
|
|
2342 cpp, cc, dbx, lex, f77, Centerline C, sh (Bourne), lint, mod
|
|
2343 The following language processors do not incorporate file names
|
|
2344 in every error message, and so are more difficult to accomodate:
|
|
2345 yacc, pc, csh
|
|
2346 ")
|
|
2347
|
|
2348 (defun comint-extract-source-location (&optional start end commands markers)
|
|
2349 "Return a 6-list of (file line command diagnostic mstart mend),
|
|
2350 obtained by parsing the current buffer between START and END,
|
|
2351 which default to the bounds of the current line.
|
|
2352
|
|
2353 Use the list comint-source-location-patterns to guide parsing.
|
|
2354
|
|
2355 The match returned will be on the latest line containing a match, but
|
|
2356 will be the earliest possible match on that line.
|
|
2357
|
|
2358 START can also be a string, in which case it inserted in the buffer
|
|
2359 \"*Extract File and Line*\" and parsed there.
|
|
2360
|
|
2361 COMMANDS is an optional list of pattern types, which has the effect of
|
|
2362 temporarily reducing the list comint-source-location-patterns
|
|
2363 to only those entries which apply to the given commands.
|
|
2364
|
|
2365 Return NIL if there is no recognizable source location.
|
|
2366
|
|
2367 MSTART and MEND give the limits of the matched source location.
|
|
2368
|
|
2369 If MARKERS is true, return no strings, but rather cons cells
|
|
2370 of the form (beg-marker . end-marker).
|
|
2371 "
|
|
2372 (if (not start)
|
|
2373 (progn
|
|
2374 (setq start (save-excursion (beginning-of-line) (point)))
|
|
2375 (setq end (save-excursion (end-of-line) (point)))))
|
|
2376 (if (stringp start)
|
|
2377 (save-excursion
|
|
2378 (set-buffer (get-buffer-create "*Extract File and Line*"))
|
|
2379 (erase-buffer)
|
|
2380 (insert start)
|
|
2381 (comint-extract-source-location (point-min) (point-max) commands markers))
|
|
2382 (let ((ptr (if (and (consp commands)
|
|
2383 (consp (car commands)))
|
|
2384 (prog1 commands (setq commands nil))
|
|
2385 comint-source-location-patterns))
|
|
2386 pat
|
|
2387 (found-bol (- (point-min) 1))
|
|
2388 (found-prio -999999)
|
|
2389 found-beg
|
|
2390 found-end
|
|
2391 found-pat
|
|
2392 found-data
|
|
2393 set-found-data)
|
|
2394 (setq set-found-data
|
|
2395 (function (lambda (data)
|
|
2396 (while found-data
|
|
2397 (let ((m (car found-data)))
|
|
2398 (if (markerp m) (set-marker m nil)))
|
|
2399 (setq found-data (cdr found-data)))
|
|
2400 (setq found-data data))))
|
|
2401 (if (and commands (not (listp commands)))
|
|
2402 (setq commands (list commands)))
|
|
2403 (save-excursion
|
|
2404 (save-restriction
|
|
2405 (narrow-to-region start end)
|
|
2406 (while ptr
|
|
2407 (setq pat (car ptr) ptr (cdr ptr))
|
|
2408 (goto-char (point-max))
|
|
2409 (if (and (or (null commands)
|
|
2410 (if (consp (nth 1 pat))
|
|
2411 (member (nth 1 pat) commands)
|
|
2412 ;; If (cadr pat) is a list, each list element
|
|
2413 ;; is a command that might produce this.
|
|
2414 (let ((ptr (nth 1 pat))
|
|
2415 (ismem nil))
|
|
2416 (while (and ptr (not ismem))
|
|
2417 (if (member (car ptr) commands)
|
|
2418 (setq ismem t))
|
|
2419 (setq ptr (cdr ptr)))
|
|
2420 ismem)))
|
|
2421 (re-search-backward (nth 0 pat) found-bol t))
|
|
2422 (let (beg end bol prio)
|
|
2423 (setq beg (match-beginning 0))
|
|
2424 (setq end (match-end 0))
|
|
2425 (beginning-of-line)
|
|
2426 (setq bol (point))
|
|
2427 (re-search-forward (nth 0 pat))
|
|
2428 (if (> (match-beginning 0) beg)
|
|
2429 (error "comint-extract-source-location botch"))
|
|
2430 (setq beg (match-beginning 0))
|
|
2431 (setq end (match-end 0))
|
|
2432 (setq prio (or (nth 3 pat) 0))
|
|
2433 (if (or (> bol found-bol)
|
|
2434 (and (= bol found-bol)
|
|
2435 (or (> prio found-prio)
|
|
2436 (and (= prio found-prio)
|
|
2437 (or (< beg found-beg)
|
|
2438 (and (= beg found-beg)
|
|
2439 (> end found-end)))))))
|
|
2440 (progn
|
|
2441 (setq found-bol bol)
|
|
2442 (setq found-prio prio)
|
|
2443 (setq found-beg beg)
|
|
2444 (setq found-end end)
|
|
2445 (setq found-pat pat)
|
|
2446 (funcall set-found-data (match-data)))))))))
|
|
2447 (and found-data
|
|
2448 (let* ((command (nth 1 found-pat))
|
|
2449 (fields (nth 2 found-pat))
|
|
2450 (f1 (nth 0 fields))
|
|
2451 (f2 (nth 1 fields))
|
|
2452 (f3 (nth 2 fields))
|
|
2453 (get-field
|
|
2454 (function
|
|
2455 (lambda (fn)
|
|
2456 (and fn
|
|
2457 (let ((beg (match-beginning fn))
|
|
2458 (end (match-end fn)))
|
|
2459 (and beg end (> end beg)
|
|
2460 (if markers
|
|
2461 (cons (copy-marker beg) (copy-marker end))
|
|
2462 (buffer-substring beg end)))))))))
|
|
2463 (store-match-data found-data)
|
|
2464 (funcall set-found-data nil)
|
|
2465 (let ((file (funcall get-field f1))
|
|
2466 (line (funcall get-field f2))
|
|
2467 (diagnostic (funcall get-field f3))
|
|
2468 (mstart (match-beginning 0))
|
|
2469 (mend (match-end 0)))
|
|
2470 ;; (carefully use all match-data before calling string-match)
|
|
2471 (list
|
|
2472 file
|
|
2473 (if (and (stringp line)
|
|
2474 (prog1
|
|
2475 (string-match "\\`[0-9]+\\'" line)
|
|
2476 (store-match-data found-data)))
|
|
2477 (string-to-int line)
|
|
2478 line)
|
|
2479 command
|
|
2480 diagnostic
|
|
2481 mstart
|
|
2482 mend
|
|
2483 ))))
|
|
2484 )))
|
|
2485
|
|
2486 ;;; Commands for extracting source locations:
|
|
2487
|
|
2488 (defvar comint-find-source-code-max-lines 100
|
|
2489 "*Maximum number of lines to search backward for a source location,
|
|
2490 when using \\[comint-find-source-code\\] with an interactive prefix.")
|
|
2491
|
|
2492 (defvar comint-find-source-file-hook nil
|
|
2493 "*Function to call instead of comint-default-find-source-file
|
|
2494 when comint-find-source-code parses out a file name and then wants to
|
|
2495 visit its buffer. The sole argument is the file name. The function
|
|
2496 must find the file, setting the current buffer, and return the file
|
|
2497 name. It may also adjust the file name. If you change this variable,
|
|
2498 make it buffer local.")
|
|
2499
|
|
2500 (defvar comint-goto-source-line-hook nil
|
|
2501 "*Function to call instead of comint-default-goto-source-line
|
|
2502 after comint-find-source-code finds a file and then wants to
|
|
2503 go to a line number mentioned in a source location.
|
|
2504 The sole argument is the line number. The function must
|
|
2505 return the line number, possibly adjusted. If you change
|
|
2506 this variable, make it buffer local.")
|
|
2507
|
|
2508 (defun comint-find-source-code (multi-line)
|
|
2509 "Search backward from point for a source location.
|
|
2510 If a source location is found in the current line,
|
|
2511 go to that location.
|
|
2512
|
|
2513 If MULTI-LINE is false (this is the interactive prefix flag),
|
|
2514 then only look for source locations in the current line.
|
|
2515 Otherwise, look within comint-find-source-code-max-lines
|
|
2516 before point. If a source location is found on a previous line, move
|
|
2517 point to that location, so that another use of \\[comint-find-source-code\\]
|
|
2518 will go to the indicated place.
|
|
2519
|
|
2520 If no source location is found, then try to extract a filename
|
|
2521 around the point, using comint-extract-current-pathname.
|
|
2522
|
|
2523 In any case, if the file does not exist, prompt the user for
|
|
2524 a pathname that does. Sometimes the file's directory needs
|
|
2525 hand adjustment.
|
|
2526
|
|
2527 This command uses comint-extract-source-location, which is customizable.
|
|
2528 Also, once a source file and line have been extracted, it uses
|
|
2529 comint-find-source-file-hook and comint-goto-source-line-hook
|
|
2530 to interpret them."
|
|
2531 (interactive "P")
|
|
2532 (let* ((beg (save-excursion
|
|
2533 (if multi-line
|
|
2534 (forward-line (min 0 (- comint-find-source-code-max-lines)))
|
|
2535 (beginning-of-line))
|
|
2536 (point)))
|
|
2537 (end (save-excursion (end-of-line) (point)))
|
|
2538 (res (or (comint-extract-source-location beg end)
|
|
2539 ;; #### comint-extract-current-pathname doesn't exist
|
|
2540 (let ((file (comint-extract-current-pathname)))
|
|
2541 (and file
|
|
2542 (list file nil nil nil
|
|
2543 (match-beginning 0)
|
|
2544 (match-end 0))))
|
|
2545 (error "Not sitting on a source location."))))
|
|
2546 (let ((file (nth 0 res))
|
|
2547 (line (nth 1 res))
|
|
2548 ;;(cmd (nth 2 res))
|
|
2549 (info (nth 3 res))
|
|
2550 (mbeg (nth 4 res))
|
|
2551 (mend (nth 5 res))
|
|
2552 dofind)
|
|
2553 (setq dofind
|
|
2554 (not (and multi-line
|
|
2555 mend
|
|
2556 (< mend (save-excursion (beginning-of-line) (point))))))
|
|
2557 (if (not dofind)
|
|
2558 (goto-char mbeg)
|
|
2559 (progn
|
|
2560 (setq file
|
|
2561 (funcall (or comint-find-source-file-hook
|
|
2562 'comint-default-find-source-file)
|
|
2563 file))
|
|
2564 (if line
|
|
2565 (setq line
|
|
2566 (funcall (or comint-goto-source-line-hook
|
|
2567 'comint-default-goto-source-line)
|
|
2568 line)))
|
|
2569 ))
|
|
2570 (message "%s%s of %s%s%s"
|
|
2571 (if dofind
|
|
2572 "" (substitute-command-keys
|
|
2573 "Hit \\[comint-find-source-code] for "))
|
|
2574 (cond ((null line) "current line")
|
|
2575 ((numberp line) (format "line %s" line))
|
|
2576 (t line))
|
|
2577 (file-name-nondirectory file)
|
|
2578 (if info ": " "") (or info "")))))
|
|
2579
|
|
2580
|
|
2581 (defun comint-default-find-source-file (file)
|
|
2582 "Action taken by \\[comint-find-source-code] when find-source-file-hook is nil.
|
|
2583 It calls substitute-in-file-name. If the file does not exist, it prompts
|
|
2584 for the right pathname, using a similar pathname derived from a nearby
|
|
2585 buffer as a default. It then calls find-file-other-window and returns the
|
|
2586 amended file name."
|
|
2587 (setq file (substitute-in-file-name file))
|
|
2588 (if (not (file-readable-p file))
|
|
2589 (setq file (comint-fixup-source-file-name file)))
|
|
2590 (find-file-other-window file)
|
|
2591 file)
|
|
2592
|
|
2593 (defun comint-fixup-source-file-name (file)
|
|
2594 (let (dir ptr nondir bfile res)
|
|
2595 (setq nondir (file-name-nondirectory file))
|
|
2596 (setq ptr (buffer-list))
|
|
2597 (while (and ptr (not dir))
|
|
2598 (setq bfile (buffer-file-name (car ptr)))
|
|
2599 (if (and bfile (equal (file-name-nondirectory bfile) nondir))
|
|
2600 (setq dir (file-name-directory bfile)
|
|
2601 file (file-name-nondirectory bfile)))
|
|
2602 (setq ptr (cdr ptr)))
|
|
2603 (setq res
|
|
2604 (read-file-name "Source file: " dir t nil file))
|
|
2605 (if (eq res t)
|
|
2606 (expand-file-name file dir)
|
|
2607 res)))
|
|
2608
|
|
2609 (defun comint-default-goto-source-line (line)
|
|
2610 "Action taken by \\[comint-find-source-code] when goto-source-line-hook is nil.
|
|
2611 It widens & pushes the mark, then does goto-line in the current buffer.
|
|
2612 It returns its line argument."
|
|
2613 (widen)
|
|
2614 (setq line (max line 0))
|
|
2615 (setq line (min line (+ 1 (count-lines (point-min) (point-max)))))
|
|
2616 (push-mark)
|
|
2617 (goto-line line)
|
|
2618 line)
|
|
2619
|
|
2620 ;;; Converting process modes to use comint mode
|
|
2621 ;;; ===========================================================================
|
|
2622 ;;; The code in the Emacs 19 distribution has all been modified to use comint
|
|
2623 ;;; where needed. However, there are `third-party' packages out there that
|
|
2624 ;;; still use the old shell mode. Here's a guide to conversion.
|
|
2625 ;;;
|
|
2626 ;;; Renaming variables
|
|
2627 ;;; Most of the work is renaming variables and functions. These are the common
|
|
2628 ;;; ones:
|
|
2629 ;;; Local variables:
|
|
2630 ;;; last-input-start comint-last-input-start
|
|
2631 ;;; last-input-end comint-last-input-end
|
|
2632 ;;; shell-prompt-pattern comint-prompt-regexp
|
|
2633 ;;; shell-set-directory-error-hook <no equivalent>
|
|
2634 ;;; Miscellaneous:
|
|
2635 ;;; shell-set-directory <unnecessary>
|
|
2636 ;;; shell-mode-map comint-mode-map
|
|
2637 ;;; Commands:
|
|
2638 ;;; shell-send-input comint-send-input
|
|
2639 ;;; shell-send-eof comint-delchar-or-maybe-eof
|
|
2640 ;;; kill-shell-input comint-kill-input
|
|
2641 ;;; interrupt-shell-subjob comint-interrupt-subjob
|
|
2642 ;;; stop-shell-subjob comint-stop-subjob
|
|
2643 ;;; quit-shell-subjob comint-quit-subjob
|
|
2644 ;;; kill-shell-subjob comint-kill-subjob
|
|
2645 ;;; kill-output-from-shell comint-kill-output
|
|
2646 ;;; show-output-from-shell comint-show-output
|
|
2647 ;;; copy-last-shell-input Use comint-previous-input/comint-next-input
|
|
2648 ;;;
|
|
2649 ;;; SHELL-SET-DIRECTORY is gone, its functionality taken over by
|
|
2650 ;;; SHELL-DIRECTORY-TRACKER, the shell mode's comint-input-filter-functions.
|
|
2651 ;;; Comint mode does not provide functionality equivalent to
|
|
2652 ;;; shell-set-directory-error-hook; it is gone.
|
|
2653 ;;;
|
|
2654 ;;; comint-last-input-start is provided for modes which want to munge
|
|
2655 ;;; the buffer after input is sent, perhaps because the inferior
|
|
2656 ;;; insists on echoing the input. The LAST-INPUT-START variable in
|
|
2657 ;;; the old shell package was used to implement a history mechanism,
|
|
2658 ;;; but you should think twice before using comint-last-input-start
|
|
2659 ;;; for this; the input history ring often does the job better.
|
|
2660 ;;;
|
|
2661 ;;; If you are implementing some process-in-a-buffer mode, called foo-mode, do
|
|
2662 ;;; *not* create the comint-mode local variables in your foo-mode function.
|
|
2663 ;;; This is not modular. Instead, call comint-mode, and let *it* create the
|
|
2664 ;;; necessary comint-specific local variables. Then create the
|
|
2665 ;;; foo-mode-specific local variables in foo-mode. Set the buffer's keymap to
|
|
2666 ;;; be foo-mode-map, and its mode to be foo-mode. Set the comint-mode hooks
|
|
2667 ;;; (comint-{prompt-regexp, input-filter, input-filter-functions,
|
|
2668 ;;; get-old-input) that need to be different from the defaults. Call
|
|
2669 ;;; foo-mode-hook, and you're done. Don't run the comint-mode hook yourself;
|
|
2670 ;;; comint-mode will take care of it. The following example, from shell.el,
|
|
2671 ;;; is typical:
|
|
2672 ;;;
|
|
2673 ;;; (defvar shell-mode-map '())
|
|
2674 ;;; (cond ((not shell-mode-map)
|
|
2675 ;;; (setq shell-mode-map (copy-keymap comint-mode-map))
|
|
2676 ;;; (define-key shell-mode-map "\C-c\C-f" 'shell-forward-command)
|
|
2677 ;;; (define-key shell-mode-map "\C-c\C-b" 'shell-backward-command)
|
|
2678 ;;; (define-key shell-mode-map "\t" 'comint-dynamic-complete)
|
|
2679 ;;; (define-key shell-mode-map "\M-?"
|
|
2680 ;;; 'comint-dynamic-list-filename-completions)))
|
|
2681 ;;;
|
|
2682 ;;; (defun shell-mode ()
|
|
2683 ;;; (interactive)
|
|
2684 ;;; (comint-mode)
|
|
2685 ;;; (setq comint-prompt-regexp shell-prompt-pattern)
|
|
2686 ;;; (setq major-mode 'shell-mode)
|
|
2687 ;;; (setq mode-name "Shell")
|
|
2688 ;;; (use-local-map shell-mode-map)
|
|
2689 ;;; (make-local-variable 'shell-directory-stack)
|
|
2690 ;;; (setq shell-directory-stack nil)
|
|
2691 ;;; (add-hook 'comint-input-filter-functions 'shell-directory-tracker)
|
|
2692 ;;; (run-hooks 'shell-mode-hook))
|
|
2693 ;;;
|
|
2694 ;;;
|
|
2695 ;;; Note that make-comint is different from make-shell in that it
|
|
2696 ;;; doesn't have a default program argument. If you give make-shell
|
|
2697 ;;; a program name of NIL, it cleverly chooses one of explicit-shell-name,
|
|
2698 ;;; $ESHELL, $SHELL, or /bin/sh. If you give make-comint a program argument
|
|
2699 ;;; of NIL, it barfs. Adjust your code accordingly...
|
|
2700 ;;;
|
|
2701 ;;; Completion for comint-mode users
|
|
2702 ;;;
|
|
2703 ;;; For modes that use comint-mode, comint-dynamic-complete-functions is the
|
|
2704 ;;; hook to add completion functions to. Functions on this list should return
|
|
2705 ;;; non-nil if completion occurs (i.e., further completion should not occur).
|
|
2706 ;;; You could use comint-dynamic-simple-complete to do the bulk of the
|
|
2707 ;;; completion job.
|
|
2708
|
|
2709
|
|
2710 ;;; Do the user's customisation...
|
|
2711
|
|
2712 (defvar comint-load-hook nil
|
|
2713 "This hook is run when comint is loaded in.
|
|
2714 This is a good place to put keybindings.")
|
|
2715
|
|
2716 (run-hooks 'comint-load-hook)
|
|
2717
|
|
2718
|
|
2719 (provide 'comint)
|
|
2720
|
|
2721 ;;; comint.el ends here
|