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