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