aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/comint.el
diff options
context:
space:
mode:
authorStefan Monnier2004-04-14 18:58:45 +0000
committerStefan Monnier2004-04-14 18:58:45 +0000
commitf4e432bbf3cd4cbf89142983e124bb2dff132595 (patch)
treeed039f8e91552562875cc594e61c6484cc72ea32 /lisp/comint.el
parent6070505443d4d95f5d376c6c4cdbedbf19a2b879 (diff)
downloademacs-f4e432bbf3cd4cbf89142983e124bb2dff132595.tar.gz
emacs-f4e432bbf3cd4cbf89142983e124bb2dff132595.zip
Doc fixes.
(comint-last-input-start, comint-last-input-end) (comint-last-output-start): Give them values. (comint-arguments): Avoid warning. (comint-skip-prompt): Use line-end-position. (comint-backward-matching-input): Rename arg to agree with doc. (comint-extract-string): Use syntax-ppss. (comint-dynamic-simple-complete): Delete useless list construction. (comint-redirect-subvert-readonly): New. (comint-redirect-preoutput-filter): Use it.
Diffstat (limited to 'lisp/comint.el')
-rw-r--r--lisp/comint.el380
1 files changed, 185 insertions, 195 deletions
diff --git a/lisp/comint.el b/lisp/comint.el
index 6bc40a01bd3..57e785dce47 100644
--- a/lisp/comint.el
+++ b/lisp/comint.el
@@ -1,6 +1,6 @@
1;;; comint.el --- general command interpreter in a window stuff 1;;; comint.el --- general command interpreter in a window stuff
2 2
3;; Copyright (C) 1988,90,92,93,94,95,96,97,98,99,2000,01,02,2003 3;; Copyright (C) 1988,90,92,93,94,95,96,97,98,99,2000,01,02,03,2004
4;; Free Software Foundation, Inc. 4;; Free Software Foundation, Inc.
5 5
6;; Author: Olin Shivers <shivers@cs.cmu.edu> 6;; Author: Olin Shivers <shivers@cs.cmu.edu>
@@ -27,14 +27,9 @@
27 27
28;;; Commentary: 28;;; Commentary:
29 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.org)
34
35;; This file defines a general command-interpreter-in-a-buffer package 30;; 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 31;; (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, .... 32;; 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, 33;; 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 34;; and a common set of bindings, which makes them easier to use (and
40;; saves code, implementation time, etc., etc.). 35;; saves code, implementation time, etc., etc.).
@@ -45,13 +40,13 @@
45;; 40;;
46;; - The file cmuscheme.el defines a scheme-in-a-buffer mode. 41;; - The file cmuscheme.el defines a scheme-in-a-buffer mode.
47;; - The file tea.el tunes scheme and inferior-scheme modes for T. 42;; - 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. 43;; - 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, 44;; - cmutex.el defines TeX and LaTeX modes that invoke TeX, LaTeX, BibTeX,
50;; previewers, and printers from within emacs. 45;; previewers, and printers from within Emacs.
51;; - background.el allows csh-like job control inside emacs. 46;; - background.el allows csh-like job control inside Emacs.
52;; It is pretty easy to make new derived modes for other processes. 47;; It is pretty easy to make new derived modes for other processes.
53 48
54;; For documentation on the functionality provided by comint mode, and 49;; For documentation on the functionality provided by Comint mode, and
55;; the hooks available for customising it, see the comments below. 50;; the hooks available for customising it, see the comments below.
56;; For further information on the standard derived modes (shell, 51;; For further information on the standard derived modes (shell,
57;; inferior-lisp, inferior-scheme, ...), see the relevant source files. 52;; inferior-lisp, inferior-scheme, ...), see the relevant source files.
@@ -66,23 +61,23 @@
66;; Comint Mode Commands: (common to all derived modes, like shell & cmulisp 61;; Comint Mode Commands: (common to all derived modes, like shell & cmulisp
67;; mode) 62;; mode)
68;; 63;;
69;; m-p comint-previous-input Cycle backwards in input history 64;; M-p comint-previous-input Cycle backwards in input history
70;; m-n comint-next-input Cycle forwards 65;; M-n comint-next-input Cycle forwards
71;; m-r comint-previous-matching-input Previous input matching a regexp 66;; M-r comint-previous-matching-input Previous input matching a regexp
72;; m-s comint-next-matching-input Next input that matches 67;; M-s comint-next-matching-input Next input that matches
73;; m-c-l comint-show-output Show last batch of process output 68;; M-C-l comint-show-output Show last batch of process output
74;; return comint-send-input 69;; RET comint-send-input
75;; c-d comint-delchar-or-maybe-eof Delete char unless at end of buff 70;; C-d comint-delchar-or-maybe-eof Delete char unless at end of buff
76;; c-c c-a comint-bol-or-process-mark First time, move point to bol; 71;; C-c C-a comint-bol-or-process-mark First time, move point to bol;
77;; second time, move to process-mark. 72;; second time, move to process-mark.
78;; c-c c-u comint-kill-input ^u 73;; C-c C-u comint-kill-input ^u
79;; c-c c-w backward-kill-word ^w 74;; C-c C-w backward-kill-word ^w
80;; c-c c-c comint-interrupt-subjob ^c 75;; C-c C-c comint-interrupt-subjob ^c
81;; c-c c-z comint-stop-subjob ^z 76;; C-c C-z comint-stop-subjob ^z
82;; c-c c-\ comint-quit-subjob ^\ 77;; C-c C-\ comint-quit-subjob ^\
83;; c-c c-o comint-delete-output Delete last batch of process output 78;; C-c C-o comint-delete-output Delete last batch of process output
84;; c-c c-r comint-show-output Show last batch of process output 79;; C-c C-r comint-show-output Show last batch of process output
85;; c-c c-l comint-dynamic-list-input-ring List input history 80;; C-c C-l comint-dynamic-list-input-ring List input history
86;; 81;;
87;; Not bound by default in comint-mode (some are in shell mode) 82;; Not bound by default in comint-mode (some are in shell mode)
88;; comint-run Run a program under comint-mode 83;; comint-run Run a program under comint-mode
@@ -97,7 +92,7 @@
97;; comint-kill-subjob No mercy. 92;; comint-kill-subjob No mercy.
98;; comint-show-maximum-output Show as much output as possible. 93;; comint-show-maximum-output Show as much output as possible.
99;; comint-continue-subjob Send CONT signal to buffer's process 94;; comint-continue-subjob Send CONT signal to buffer's process
100;; group. Useful if you accidentally 95;; group. Useful if you accidentally
101;; suspend your process (with C-c C-z). 96;; suspend your process (with C-c C-z).
102;; comint-get-next-from-history Fetch successive input history lines 97;; comint-get-next-from-history Fetch successive input history lines
103;; comint-accumulate Combine lines to send them together 98;; comint-accumulate Combine lines to send them together
@@ -105,7 +100,7 @@
105;; comint-goto-process-mark Move point to where process-mark is. 100;; comint-goto-process-mark Move point to where process-mark is.
106;; comint-set-process-mark Set process-mark to point. 101;; comint-set-process-mark Set process-mark to point.
107 102
108;; comint-mode-hook is the comint mode hook. Basically for your keybindings. 103;; comint-mode-hook is the Comint mode hook. Basically for your keybindings.
109 104
110;;; Code: 105;;; Code:
111 106
@@ -189,7 +184,7 @@ This is a good thing to set in mode hooks.")
189 184
190(defcustom comint-input-autoexpand nil 185(defcustom comint-input-autoexpand nil
191 "*If non-nil, expand input command history references on completion. 186 "*If non-nil, expand input command history references on completion.
192This mirrors the optional behavior of tcsh (its autoexpand and histlit). 187This mirrors the optional behavior of tcsh (its autoexpand and histlist).
193 188
194If the value is `input', then the expansion is seen on input. 189If the value is `input', then the expansion is seen on input.
195If the value is `history', then the expansion is only when inserting 190If the value is `history', then the expansion is only when inserting
@@ -256,7 +251,7 @@ The default is nil.
256 251
257See the variable `comint-scroll-show-maximum-output' and the function 252See the variable `comint-scroll-show-maximum-output' and the function
258`comint-postoutput-scroll-to-bottom'. 253`comint-postoutput-scroll-to-bottom'.
259This variable is buffer-local in all comint buffers." 254This variable is buffer-local in all Comint buffers."
260 :type '(choice (const :tag "off" nil) 255 :type '(choice (const :tag "off" nil)
261 (const t) 256 (const t)
262 (const all) 257 (const all)
@@ -275,16 +270,16 @@ and output from the subprocess is inserted.
275 270
276Non-nil means scroll so that the window is full of text 271Non-nil means scroll so that the window is full of text
277and point is on the last line. A value of nil 272and point is on the last line. A value of nil
278means don't do anyting special--scroll normally. 273means don't do anything special--scroll normally.
279 274
280See also the variable `comint-move-point-for-output' and the function 275See also the variable `comint-move-point-for-output' and the function
281`comint-postoutput-scroll-to-bottom'. 276`comint-postoutput-scroll-to-bottom'.
282This variable is buffer-local in all comint buffers." 277This variable is buffer-local in all Comint buffers."
283 :type 'boolean 278 :type 'boolean
284 :group 'comint) 279 :group 'comint)
285 280
286(defcustom comint-buffer-maximum-size 1024 281(defcustom comint-buffer-maximum-size 1024
287 "*The maximum size in lines for comint buffers. 282 "*The maximum size in lines for Comint buffers.
288Comint buffers are truncated from the top to be no greater than this number, if 283Comint buffers are truncated from the top to be no greater than this number, if
289the function `comint-truncate-buffer' is on `comint-output-filter-functions'." 284the function `comint-truncate-buffer' is on `comint-output-filter-functions'."
290 :type 'integer 285 :type 'integer
@@ -297,7 +292,7 @@ the function `comint-truncate-buffer' is on `comint-output-filter-functions'."
297 "Separator between commands in the history file.") 292 "Separator between commands in the history file.")
298 293
299(defvar comint-input-history-ignore "^#" 294(defvar comint-input-history-ignore "^#"
300 "Regexp for history entries that should be ignored when comint initializes.") 295 "Regexp for history entries that should be ignored when Comint initializes.")
301 296
302(defcustom comint-process-echoes nil 297(defcustom comint-process-echoes nil
303 "*If non-nil, assume that the subprocess echoes any input. 298 "*If non-nil, assume that the subprocess echoes any input.
@@ -316,7 +311,7 @@ This variable is buffer-local."
316(defcustom comint-password-prompt-regexp 311(defcustom comint-password-prompt-regexp
317 "\\(\\([Oo]ld \\|[Nn]ew \\|'s \\|login \\|\ 312 "\\(\\([Oo]ld \\|[Nn]ew \\|'s \\|login \\|\
318Kerberos \\|CVS \\|UNIX \\| SMB \\|^\\)\ 313Kerberos \\|CVS \\|UNIX \\| SMB \\|^\\)\
319[Pp]assword\\( (again)\\)?\\|\ 314\[Pp]assword\\( (again)\\)?\\|\
320pass phrase\\|\\(Enter\\|Repeat\\) passphrase\\)\ 315pass phrase\\|\\(Enter\\|Repeat\\) passphrase\\)\
321\\( for [^:]+\\)?:\\s *\\'" 316\\( for [^:]+\\)?:\\s *\\'"
322 "*Regexp matching prompts for passwords in the inferior process. 317 "*Regexp matching prompts for passwords in the inferior process.
@@ -326,7 +321,7 @@ This is used by `comint-watch-for-password-prompt'."
326 321
327;; Here are the per-interpreter hooks. 322;; Here are the per-interpreter hooks.
328(defvar comint-get-old-input (function comint-get-old-input-default) 323(defvar comint-get-old-input (function comint-get-old-input-default)
329 "Function that returns old text in comint mode. 324 "Function that returns old text in Comint mode.
330This function is called when return is typed while the point is in old 325This function is called when return is typed while the point is in old
331text. It returns the text to be submitted as process input. The 326text. It returns the text to be submitted as process input. The
332default is `comint-get-old-input-default', which either grabs the 327default is `comint-get-old-input-default', which either grabs the
@@ -398,15 +393,15 @@ field boundaries in a natural way)."
398 :group 'comint) 393 :group 'comint)
399 394
400(defcustom comint-mode-hook '(turn-on-font-lock) 395(defcustom comint-mode-hook '(turn-on-font-lock)
401 "Called upon entry into `comint-mode' 396 "Hook run upon entry to `comint-mode'.
402This is run before the process is cranked up." 397This is run before the process is cranked up."
403 :type 'hook 398 :type 'hook
404 :group 'comint) 399 :group 'comint)
405 400
406(defcustom comint-exec-hook '() 401(defcustom comint-exec-hook '()
407 "Called each time a process is exec'd by `comint-exec'. 402 "Hook run each time a process is exec'd by `comint-exec'.
408This is called after the process is cranked up. It is useful for things that 403This is called after the process is cranked up. It is useful for things that
409must be done each time a process is executed in a comint mode buffer (e.g., 404must be done each time a process is executed in a Comint mode buffer (e.g.,
410`(process-kill-without-query)'). In contrast, the `comint-mode-hook' is only 405`(process-kill-without-query)'). In contrast, the `comint-mode-hook' is only
411executed once when the buffer is created." 406executed once when the buffer is created."
412 :type 'hook 407 :type 'hook
@@ -414,14 +409,15 @@ executed once when the buffer is created."
414 409
415(defvar comint-mode-map nil) 410(defvar comint-mode-map nil)
416 411
412;; Fixme: Is this still relevant?
417(defvar comint-ptyp t 413(defvar comint-ptyp t
418 "Non-nil if communications via pty; false if by pipe. Buffer local. 414 "Non-nil if communications via pty; false if by pipe. Buffer local.
419This is to work around a bug in Emacs process signaling.") 415This is to work around a bug in Emacs process signaling.")
420 416
421(defvar comint-input-ring nil) 417(defvar comint-input-ring nil)
422(defvar comint-last-input-start) 418(defvar comint-last-input-start nil)
423(defvar comint-last-input-end) 419(defvar comint-last-input-end nil)
424(defvar comint-last-output-start) 420(defvar comint-last-output-start nil)
425(defvar comint-input-ring-index nil 421(defvar comint-input-ring-index nil
426 "Index of last matched history element.") 422 "Index of last matched history element.")
427(defvar comint-matching-input-from-input-string "" 423(defvar comint-matching-input-from-input-string ""
@@ -644,7 +640,7 @@ BUFFER can be either a buffer or the name of one."
644 640
645;;;###autoload 641;;;###autoload
646(defun make-comint-in-buffer (name buffer program &optional startfile &rest switches) 642(defun make-comint-in-buffer (name buffer program &optional startfile &rest switches)
647 "Make a comint process NAME in BUFFER, running PROGRAM. 643 "Make a Comint process NAME in BUFFER, running PROGRAM.
648If BUFFER is nil, it defaults to NAME surrounded by `*'s. 644If BUFFER is nil, it defaults to NAME surrounded by `*'s.
649PROGRAM should be either a string denoting an executable program to create 645PROGRAM should be either a string denoting an executable program to create
650via `start-process', or a cons pair of the form (HOST . SERVICE) denoting a TCP 646via `start-process', or a cons pair of the form (HOST . SERVICE) denoting a TCP
@@ -667,20 +663,20 @@ If PROGRAM is a string, any more args are arguments to PROGRAM."
667 663
668;;;###autoload 664;;;###autoload
669(defun make-comint (name program &optional startfile &rest switches) 665(defun make-comint (name program &optional startfile &rest switches)
670 "Make a comint process NAME in a buffer, running PROGRAM. 666 "Make a Comint process NAME in a buffer, running PROGRAM.
671The name of the buffer is made by surrounding NAME with `*'s. 667The name of the buffer is made by surrounding NAME with `*'s.
672PROGRAM should be either a string denoting an executable program to create 668PROGRAM should be either a string denoting an executable program to create
673via `start-process', or a cons pair of the form (HOST . SERVICE) denoting a TCP 669via `start-process', or a cons pair of the form (HOST . SERVICE) denoting a TCP
674connection to be opened via `open-network-stream'. If there is already a 670connection to be opened via `open-network-stream'. If there is already a
675running process in that buffer, it is not restarted. Optional third arg 671running process in that buffer, it is not restarted. Optional third arg
676STARTFILE is the name of a file to send the contents of to the process. 672STARTFILE is the name of a file to send the contents of the process to.
677 673
678If PROGRAM is a string, any more args are arguments to PROGRAM." 674If PROGRAM is a string, any more args are arguments to PROGRAM."
679 (apply #'make-comint-in-buffer name nil program startfile switches)) 675 (apply #'make-comint-in-buffer name nil program startfile switches))
680 676
681;;;###autoload 677;;;###autoload
682(defun comint-run (program) 678(defun comint-run (program)
683 "Run PROGRAM in a comint buffer and switch to it. 679 "Run PROGRAM in a Comint buffer and switch to it.
684The buffer name is made by surrounding the file name of PROGRAM with `*'s. 680The buffer name is made by surrounding the file name of PROGRAM with `*'s.
685The file name is used to make a symbol name, such as `comint-sh-hook', and any 681The file name is used to make a symbol name, such as `comint-sh-hook', and any
686hooks on this symbol are run in the buffer. 682hooks on this symbol are run in the buffer.
@@ -691,9 +687,10 @@ See `make-comint' and `comint-exec'."
691 (run-hooks (intern-soft (concat "comint-" name "-hook"))))) 687 (run-hooks (intern-soft (concat "comint-" name "-hook")))))
692 688
693(defun comint-exec (buffer name command startfile switches) 689(defun comint-exec (buffer name command startfile switches)
694 "Start up a process in buffer BUFFER for comint modes. 690 "Start up a process named NAME in buffer BUFFER for Comint modes.
691Runs the given COMMAND with SWITCHES with output to STARTFILE.
695Blasts any old process running in the buffer. Doesn't set the buffer mode. 692Blasts any old process running in the buffer. Doesn't set the buffer mode.
696You can use this to cheaply run a series of processes in the same comint 693You can use this to cheaply run a series of processes in the same Comint
697buffer. The hook `comint-exec-hook' is run after each exec." 694buffer. The hook `comint-exec-hook' is run after each exec."
698 (with-current-buffer buffer 695 (with-current-buffer buffer
699 (let ((proc (get-buffer-process buffer))) ; Blast any old process. 696 (let ((proc (get-buffer-process buffer))) ; Blast any old process.
@@ -778,7 +775,7 @@ buffer. The hook `comint-exec-hook' is run after each exec."
778 775
779 776
780(defun comint-insert-clicked-input (event) 777(defun comint-insert-clicked-input (event)
781 "In a comint buffer, set the current input to the clicked-on previous input." 778 "In a Comint buffer, set the current input to the clicked-on previous input."
782 (interactive "e") 779 (interactive "e")
783 (let ((pos (posn-point (event-end event)))) 780 (let ((pos (posn-point (event-end event))))
784 (if (not (eq (get-char-property pos 'field) 'input)) 781 (if (not (eq (get-char-property pos 'field) 'input))
@@ -825,7 +822,7 @@ buffer. The hook `comint-exec-hook' is run after each exec."
825;; comint-replace-by-expanded-history-before-point Workhorse function. 822;; comint-replace-by-expanded-history-before-point Workhorse function.
826 823
827(defun comint-read-input-ring (&optional silent) 824(defun comint-read-input-ring (&optional silent)
828 "Sets the buffer's `comint-input-ring' from a history file. 825 "Set the buffer's `comint-input-ring' from a history file.
829The name of the file is given by the variable `comint-input-ring-file-name'. 826The name of the file is given by the variable `comint-input-ring-file-name'.
830The history ring is of size `comint-input-ring-size', regardless of file size. 827The history ring is of size `comint-input-ring-size', regardless of file size.
831If `comint-input-ring-file-name' is nil this function does nothing. 828If `comint-input-ring-file-name' is nil this function does nothing.
@@ -970,7 +967,7 @@ See also `comint-read-input-ring'."
970 967
971 968
972(defun comint-regexp-arg (prompt) 969(defun comint-regexp-arg (prompt)
973 ;; Return list of regexp and prefix arg using PROMPT. 970 "Return list of regexp and prefix arg using PROMPT."
974 (let* (;; Don't clobber this. 971 (let* (;; Don't clobber this.
975 (last-command last-command) 972 (last-command last-command)
976 (regexp (read-from-minibuffer prompt nil nil nil 973 (regexp (read-from-minibuffer prompt nil nil nil
@@ -996,7 +993,7 @@ See also `comint-read-input-ring'."
996 arg))) 993 arg)))
997 994
998(defun comint-search-start (arg) 995(defun comint-search-start (arg)
999 ;; Index to start a directional search, starting at comint-input-ring-index 996 "Index to start a directional search, starting at `comint-input-ring-index'."
1000 (if comint-input-ring-index 997 (if comint-input-ring-index
1001 ;; If a search is running, offset by 1 in direction of arg 998 ;; If a search is running, offset by 1 in direction of arg
1002 (mod (+ comint-input-ring-index (if (> arg 0) 1 -1)) 999 (mod (+ comint-input-ring-index (if (> arg 0) 1 -1))
@@ -1120,7 +1117,7 @@ Expansion is dependent on the value of `comint-input-autoexpand'.
1120This function depends on the buffer's idea of the input history, which may not 1117This function depends on the buffer's idea of the input history, which may not
1121match the command interpreter's idea, assuming it has one. 1118match the command interpreter's idea, assuming it has one.
1122 1119
1123Assumes history syntax is like typical Un*x shells'. However, since emacs 1120Assumes history syntax is like typical Un*x shells'. However, since Emacs
1124cannot know the interpreter's idea of input line numbers, assuming it has one, 1121cannot know the interpreter's idea of input line numbers, assuming it has one,
1125it cannot expand absolute input line number references. 1122it cannot expand absolute input line number references.
1126 1123
@@ -1285,9 +1282,10 @@ Quotes are single and double."
1285 (t nth)))) 1282 (t nth))))
1286 (comint-arguments string nth mth))))) 1283 (comint-arguments string nth mth)))))
1287 1284
1288;; Return a list of arguments from ARG. Break it up at the
1289;; delimiters in comint-delimiter-argument-list. Returned list is backwards.
1290(defun comint-delim-arg (arg) 1285(defun comint-delim-arg (arg)
1286 "Return a list of arguments from ARG.
1287Break it up at the delimiters in `comint-delimiter-argument-list'.
1288Returned list is backwards."
1291 (if (null comint-delimiter-argument-list) 1289 (if (null comint-delimiter-argument-list)
1292 (list arg) 1290 (list arg)
1293 (let ((args nil) 1291 (let ((args nil)
@@ -1321,8 +1319,8 @@ Argument 0 is the command name."
1321 ;; The third matches '-quoted strings. 1319 ;; The third matches '-quoted strings.
1322 ;; The fourth matches `-quoted strings. 1320 ;; The fourth matches `-quoted strings.
1323 ;; This seems to fit the syntax of BASH 2.0. 1321 ;; This seems to fit the syntax of BASH 2.0.
1324 (let* ((first (if (and (eq system-type 'windows-nt) 1322 (let* ((first (if (if (fboundp 'w32-shell-dos-semantics)
1325 (w32-shell-dos-semantics)) 1323 (w32-shell-dos-semantics))
1326 "[^ \n\t\"'`]+\\|" 1324 "[^ \n\t\"'`]+\\|"
1327 "[^ \n\t\"'`\\]+\\|\\\\[\"'`\\ \t]+\\|")) 1325 "[^ \n\t\"'`\\]+\\|\\\\[\"'`\\ \t]+\\|"))
1328 (argpart (concat first 1326 (argpart (concat first
@@ -1331,7 +1329,7 @@ Argument 0 is the command name."
1331`[^`]*`\\)")) 1329`[^`]*`\\)"))
1332 (args ()) (pos 0) 1330 (args ()) (pos 0)
1333 (count 0) 1331 (count 0)
1334 beg str value quotes) 1332 beg str quotes)
1335 ;; Build a list of all the args until we have as many as we want. 1333 ;; Build a list of all the args until we have as many as we want.
1336 (while (and (or (null mth) (<= count mth)) 1334 (while (and (or (null mth) (<= count mth))
1337 (string-match argpart string pos)) 1335 (string-match argpart string pos))
@@ -1379,7 +1377,8 @@ After the process output mark, sends all text from the process mark to
1379point as input to the process. Before the process output mark, calls 1377point as input to the process. Before the process output mark, calls
1380value of variable `comint-get-old-input' to retrieve old input, copies 1378value of variable `comint-get-old-input' to retrieve old input, copies
1381it to the process mark, and sends it. A terminal newline is also 1379it to the process mark, and sends it. A terminal newline is also
1382inserted into the buffer and sent to the process. 1380inserted into the buffer and sent to the process unless NO-NEWLINE is
1381non-nil.
1383 1382
1384Any history reference may be expanded depending on the value of the variable 1383Any history reference may be expanded depending on the value of the variable
1385`comint-input-autoexpand'. The list of function names contained in the value 1384`comint-input-autoexpand'. The list of function names contained in the value
@@ -1391,7 +1390,7 @@ If variable `comint-eol-on-send' is non-nil, then point is moved to the
1391end of line before sending the input. 1390end of line before sending the input.
1392 1391
1393After the input has been sent, if `comint-process-echoes' is non-nil, 1392After the input has been sent, if `comint-process-echoes' is non-nil,
1394then comint-send-input waits to see if the process outputs a string 1393then `comint-send-input' waits to see if the process outputs a string
1395matching the input, and if so, deletes that part of the output. 1394matching the input, and if so, deletes that part of the output.
1396 1395
1397The values of `comint-get-old-input', `comint-input-filter-functions', and 1396The values of `comint-get-old-input', `comint-input-filter-functions', and
@@ -1399,19 +1398,19 @@ The values of `comint-get-old-input', `comint-input-filter-functions', and
1399in the buffer. E.g., 1398in the buffer. E.g.,
1400 1399
1401If the interpreter is the csh, 1400If the interpreter is the csh,
1402 comint-get-old-input is the default: 1401 `comint-get-old-input' is the default:
1403 If `comint-use-prompt-regexp-instead-of-fields' is nil, then 1402 If `comint-use-prompt-regexp-instead-of-fields' is nil, then
1404 either return the current input field, if point is on an input 1403 either return the current input field, if point is on an input
1405 field, or the current line, if point is on an output field. 1404 field, or the current line, if point is on an output field.
1406 If `comint-use-prompt-regexp-instead-of-fields' is non-nil, then 1405 If `comint-use-prompt-regexp-instead-of-fields' is non-nil, then
1407 return the current line with any initial string matching the 1406 return the current line with any initial string matching the
1408 regexp `comint-prompt-regexp' removed. 1407 regexp `comint-prompt-regexp' removed.
1409 comint-input-filter-functions monitors input for \"cd\", \"pushd\", and 1408 `comint-input-filter-functions' monitors input for \"cd\", \"pushd\", and
1410 \"popd\" commands. When it sees one, it cd's the buffer. 1409 \"popd\" commands. When it sees one, it cd's the buffer.
1411 comint-input-filter is the default: returns t if the input isn't all white 1410 comint-input-filter is the default: returns t if the input isn't all white
1412 space. 1411 space.
1413 1412
1414If the comint is Lucid Common Lisp, 1413If the Comint is Lucid Common Lisp,
1415 comint-get-old-input snarfs the sexp ending at point. 1414 comint-get-old-input snarfs the sexp ending at point.
1416 comint-input-filter-functions does nothing. 1415 comint-input-filter-functions does nothing.
1417 comint-input-filter returns nil if the input matches input-filter-regexp, 1416 comint-input-filter returns nil if the input matches input-filter-regexp,
@@ -1542,17 +1541,17 @@ You can use `add-hook' to add functions to this list
1542either globally or locally.") 1541either globally or locally.")
1543 1542
1544(defvar comint-inhibit-carriage-motion nil 1543(defvar comint-inhibit-carriage-motion nil
1545 "If nil, comint will interpret `carriage control' characters in output. 1544 "If nil, Comint will interpret `carriage control' characters in output.
1546See `comint-carriage-motion' for details.") 1545See `comint-carriage-motion' for details.")
1547 1546
1548;; When non-nil, this is an overlay over the last recognized prompt in 1547;; When non-nil, this is an overlay over the last recognized prompt in
1549;; the buffer; it is used when highlighting the prompt. 1548;; the buffer; it is used when highlighting the prompt.
1550(defvar comint-last-prompt-overlay nil) 1549(defvar comint-last-prompt-overlay nil)
1551 1550
1552;; `snapshot' any current comint-last-prompt-overlay, freezing its
1553;; attributes in place, even when more input comes a long and moves the
1554;; prompt overlay.
1555(defun comint-snapshot-last-prompt () 1551(defun comint-snapshot-last-prompt ()
1552 "`snapshot' any current `comint-last-prompt-overlay'.
1553freeze its attributes in place, even when more input comes a long
1554and moves the prompt overlay."
1556 (when comint-last-prompt-overlay 1555 (when comint-last-prompt-overlay
1557 (let ((inhibit-read-only t)) 1556 (let ((inhibit-read-only t))
1558 (add-text-properties (overlay-start comint-last-prompt-overlay) 1557 (add-text-properties (overlay-start comint-last-prompt-overlay)
@@ -1835,10 +1834,9 @@ Calls `comint-get-old-input' to get old input."
1835(defun comint-skip-prompt () 1834(defun comint-skip-prompt ()
1836 "Skip past the text matching regexp `comint-prompt-regexp'. 1835 "Skip past the text matching regexp `comint-prompt-regexp'.
1837If this takes us past the end of the current line, don't skip at all." 1836If this takes us past the end of the current line, don't skip at all."
1838 (let ((eol (save-excursion (end-of-line) (point)))) 1837 (if (and (looking-at comint-prompt-regexp)
1839 (if (and (looking-at comint-prompt-regexp) 1838 (<= (match-end 0) (line-end-position)))
1840 (<= (match-end 0) eol)) 1839 (goto-char (match-end 0))))
1841 (goto-char (match-end 0)))))
1842 1840
1843(defun comint-after-pmark-p () 1841(defun comint-after-pmark-p ()
1844 "Return t if point is after the process output marker." 1842 "Return t if point is after the process output marker."
@@ -1847,7 +1845,7 @@ If this takes us past the end of the current line, don't skip at all."
1847 1845
1848(defun comint-simple-send (proc string) 1846(defun comint-simple-send (proc string)
1849 "Default function for sending to PROC input STRING. 1847 "Default function for sending to PROC input STRING.
1850This just sends STRING plus a newline. To override this, 1848This just sends STRING plus a newline. To override this,
1851set the hook `comint-input-sender'." 1849set the hook `comint-input-sender'."
1852 (comint-send-string proc string) 1850 (comint-send-string proc string)
1853 (if comint-input-sender-no-newline 1851 (if comint-input-sender-no-newline
@@ -1856,7 +1854,7 @@ set the hook `comint-input-sender'."
1856 (comint-send-string proc "\n"))) 1854 (comint-send-string proc "\n")))
1857 1855
1858(defun comint-line-beginning-position () 1856(defun comint-line-beginning-position ()
1859 "Returns the buffer position of the beginning of the line, after any prompt. 1857 "Return the buffer position of the beginning of the line, after any prompt.
1860If `comint-use-prompt-regexp-instead-of-fields' is non-nil, then the 1858If `comint-use-prompt-regexp-instead-of-fields' is non-nil, then the
1861prompt skip is done by skipping text matching the regular expression 1859prompt skip is done by skipping text matching the regular expression
1862`comint-prompt-regexp', a buffer local variable." 1860`comint-prompt-regexp', a buffer local variable."
@@ -1876,7 +1874,7 @@ prompt skip is done by skipping text matching the regular expression
1876 (constrain-to-field (line-beginning-position) (line-end-position)))) 1874 (constrain-to-field (line-beginning-position) (line-end-position))))
1877 1875
1878(defun comint-bol (&optional arg) 1876(defun comint-bol (&optional arg)
1879 "Goes to the beginning of line, then skips past the prompt, if any. 1877 "Go to the beginning of line, then skip past the prompt, if any.
1880If prefix argument is given (\\[universal-argument]) the prompt is not skipped. 1878If prefix argument is given (\\[universal-argument]) the prompt is not skipped.
1881If `comint-use-prompt-regexp-instead-of-fields' is non-nil, then the 1879If `comint-use-prompt-regexp-instead-of-fields' is non-nil, then the
1882prompt skip is done by skipping text matching the regular expression 1880prompt skip is done by skipping text matching the regular expression
@@ -1901,7 +1899,7 @@ RET, LFD, or ESC. DEL or C-h rubs out. C-u kills line. C-g aborts (if
1901filter and C-g is pressed, this function returns nil rather than a string). 1899filter and C-g is pressed, this function returns nil rather than a string).
1902 1900
1903Note that the keystrokes comprising the text can still be recovered 1901Note that the keystrokes comprising the text can still be recovered
1904\(temporarily) with \\[view-lossage]. Some people find this worrysome (see, 1902\(temporarily) with \\[view-lossage]. Some people find this worrisome (see,
1905however, `clear-this-command-keys'). 1903however, `clear-this-command-keys').
1906Once the caller uses the password, it can erase the password 1904Once the caller uses the password, it can erase the password
1907by doing (clear-string STRING)." 1905by doing (clear-string STRING)."
@@ -1981,7 +1979,7 @@ This function could be in the list `comint-output-filter-functions'."
1981;; Low-level process communication 1979;; Low-level process communication
1982 1980
1983(defun comint-send-string (process string) 1981(defun comint-send-string (process string)
1984 "Like `process-send-string', but also does extra bookkeeping for comint mode." 1982 "Like `process-send-string', but also does extra bookkeeping for Comint mode."
1985 (if process 1983 (if process
1986 (with-current-buffer (if (processp process) 1984 (with-current-buffer (if (processp process)
1987 (process-buffer process) 1985 (process-buffer process)
@@ -1991,7 +1989,7 @@ This function could be in the list `comint-output-filter-functions'."
1991 (process-send-string process string)) 1989 (process-send-string process string))
1992 1990
1993(defun comint-send-region (process start end) 1991(defun comint-send-region (process start end)
1994 "Like `process-send-region', but also does extra bookkeeping for comint mode." 1992 "Like `process-send-region', but also does extra bookkeeping for Comint mode."
1995 (if process 1993 (if process
1996 (with-current-buffer (if (processp process) 1994 (with-current-buffer (if (processp process)
1997 (process-buffer process) 1995 (process-buffer process)
@@ -2077,7 +2075,7 @@ Sets mark to the value of point when this command is run."
2077(defun comint-interrupt-subjob () 2075(defun comint-interrupt-subjob ()
2078 "Interrupt the current subjob. 2076 "Interrupt the current subjob.
2079This command also kills the pending input 2077This command also kills the pending input
2080between the process-mark and point." 2078between the process mark and point."
2081 (interactive) 2079 (interactive)
2082 (comint-skip-input) 2080 (comint-skip-input)
2083 (interrupt-process nil comint-ptyp) 2081 (interrupt-process nil comint-ptyp)
@@ -2087,7 +2085,7 @@ between the process-mark and point."
2087(defun comint-kill-subjob () 2085(defun comint-kill-subjob ()
2088 "Send kill signal to the current subjob. 2086 "Send kill signal to the current subjob.
2089This command also kills the pending input 2087This command also kills the pending input
2090between the process-mark and point." 2088between the process mark and point."
2091 (interactive) 2089 (interactive)
2092 (comint-skip-input) 2090 (comint-skip-input)
2093 (kill-process nil comint-ptyp)) 2091 (kill-process nil comint-ptyp))
@@ -2095,7 +2093,7 @@ between the process-mark and point."
2095(defun comint-quit-subjob () 2093(defun comint-quit-subjob ()
2096 "Send quit signal to the current subjob. 2094 "Send quit signal to the current subjob.
2097This command also kills the pending input 2095This command also kills the pending input
2098between the process-mark and point." 2096between the process mark and point."
2099 (interactive) 2097 (interactive)
2100 (comint-skip-input) 2098 (comint-skip-input)
2101 (quit-process nil comint-ptyp)) 2099 (quit-process nil comint-ptyp))
@@ -2103,7 +2101,7 @@ between the process-mark and point."
2103(defun comint-stop-subjob () 2101(defun comint-stop-subjob ()
2104 "Stop the current subjob. 2102 "Stop the current subjob.
2105This command also kills the pending input 2103This command also kills the pending input
2106between the process-mark and point. 2104between the process mark and point.
2107 2105
2108WARNING: if there is no current subjob, you can end up suspending 2106WARNING: if there is no current subjob, you can end up suspending
2109the top-level process running in the buffer. If you accidentally do 2107the top-level process running in the buffer. If you accidentally do
@@ -2155,7 +2153,7 @@ Sends an EOF only if point is at the end of the buffer and there is no input."
2155 (process-send-eof)) 2153 (process-send-eof))
2156 2154
2157 2155
2158(defun comint-backward-matching-input (regexp arg) 2156(defun comint-backward-matching-input (regexp n)
2159 "Search backward through buffer for input fields that match REGEXP. 2157 "Search backward through buffer for input fields that match REGEXP.
2160If `comint-use-prompt-regexp-instead-of-fields' is non-nil, then input 2158If `comint-use-prompt-regexp-instead-of-fields' is non-nil, then input
2161fields are identified by lines that match `comint-prompt-regexp'. 2159fields are identified by lines that match `comint-prompt-regexp'.
@@ -2166,8 +2164,8 @@ If N is negative, find the next or Nth next match."
2166 (if comint-use-prompt-regexp-instead-of-fields 2164 (if comint-use-prompt-regexp-instead-of-fields
2167 ;; Use comint-prompt-regexp 2165 ;; Use comint-prompt-regexp
2168 (let* ((re (concat comint-prompt-regexp ".*" regexp)) 2166 (let* ((re (concat comint-prompt-regexp ".*" regexp))
2169 (pos (save-excursion (end-of-line (if (> arg 0) 0 1)) 2167 (pos (save-excursion (end-of-line (if (> n 0) 0 1))
2170 (if (re-search-backward re nil t arg) 2168 (if (re-search-backward re nil t n)
2171 (point))))) 2169 (point)))))
2172 (if (null pos) 2170 (if (null pos)
2173 (progn (message "Not found") 2171 (progn (message "Not found")
@@ -2175,14 +2173,14 @@ If N is negative, find the next or Nth next match."
2175 (goto-char pos) 2173 (goto-char pos)
2176 (comint-bol nil))) 2174 (comint-bol nil)))
2177 ;; Use input fields 2175 ;; Use input fields
2178 (let* ((dir (if (< arg 0) -1 1)) 2176 (let* ((dir (if (< n 0) -1 1))
2179 (pos 2177 (pos
2180 (save-excursion 2178 (save-excursion
2181 (while (/= arg 0) 2179 (while (/= n 0)
2182 (unless (re-search-backward regexp nil t dir) 2180 (unless (re-search-backward regexp nil t dir)
2183 (error "Not found")) 2181 (error "Not found"))
2184 (when (eq (get-char-property (point) 'field) 'input) 2182 (when (eq (get-char-property (point) 'field) 'input)
2185 (setq arg (- arg dir)))) 2183 (setq n (- n dir))))
2186 (field-beginning)))) 2184 (field-beginning))))
2187 (goto-char pos)))) 2185 (goto-char pos))))
2188 2186
@@ -2252,7 +2250,7 @@ occurrence of text matching `comint-prompt-regexp'."
2252;; Needs fixing: 2250;; Needs fixing:
2253;; make comint-arguments understand negative indices as bash does 2251;; make comint-arguments understand negative indices as bash does
2254(defun comint-insert-previous-argument (index) 2252(defun comint-insert-previous-argument (index)
2255 "Insert the INDEXth argument from the previous comint command-line at point. 2253 "Insert the INDEXth argument from the previous Comint command-line at point.
2256Spaces are added at beginning and/or end of the inserted string if 2254Spaces are added at beginning and/or end of the inserted string if
2257necessary to ensure that it's separated from adjacent arguments. 2255necessary to ensure that it's separated from adjacent arguments.
2258Interactively, if no prefix argument is given, the last argument is inserted. 2256Interactively, if no prefix argument is given, the last argument is inserted.
@@ -2325,39 +2323,35 @@ This command is like `M-.' in bash."
2325;; COMINT-GET-SOURCE -- used by the source-file processing commands to prompt 2323;; COMINT-GET-SOURCE -- used by the source-file processing commands to prompt
2326;; for the file to process. 2324;; for the file to process.
2327 2325
2328;; (COMINT-SOURCE-DEFAULT previous-dir/file source-modes)
2329;;============================================================================
2330;; This function computes the defaults for the load-file and compile-file
2331;; commands for tea, soar, cmulisp, and cmuscheme modes.
2332;;
2333;; - PREVIOUS-DIR/FILE is a pair (directory . filename) from the last
2334;; source-file processing command. nil if there hasn't been one yet.
2335;; - SOURCE-MODES is a list used to determine what buffers contain source
2336;; files: if the major mode of the buffer is in SOURCE-MODES, it's source.
2337;; Typically, (lisp-mode) or (scheme-mode).
2338;;
2339;; If the command is given while the cursor is inside a string, *and*
2340;; the string is an existing filename, *and* the filename is not a directory,
2341;; then the string is taken as default. This allows you to just position
2342;; your cursor over a string that's a filename and have it taken as default.
2343;;
2344;; If the command is given in a file buffer whose major mode is in
2345;; SOURCE-MODES, then the filename is the default file, and the
2346;; file's directory is the default directory.
2347;;
2348;; If the buffer isn't a source file buffer (e.g., it's the process buffer),
2349;; then the default directory & file are what was used in the last source-file
2350;; processing command (i.e., PREVIOUS-DIR/FILE). If this is the first time
2351;; the command has been run (PREVIOUS-DIR/FILE is nil), the default directory
2352;; is the cwd, with no default file. (\"no default file\" = nil)
2353;;
2354;; SOURCE-REGEXP is typically going to be something like (tea-mode)
2355;; for T programs, (lisp-mode) for Lisp programs, (soar-mode lisp-mode)
2356;; for Soar programs, etc.
2357;;
2358;; The function returns a pair: (default-directory . default-file).
2359
2360(defun comint-source-default (previous-dir/file source-modes) 2326(defun comint-source-default (previous-dir/file source-modes)
2327 "Compute the defaults for `load-file' and `compile-file' commands.
2328
2329PREVIOUS-DIR/FILE is a pair (directory . filename) from the last
2330source-file processing command. nil if there hasn't been one yet.
2331SOURCE-MODES is a list used to determine what buffers contain source
2332files: if the major mode of the buffer is in SOURCE-MODES, it's source.
2333Typically, (lisp-mode) or (scheme-mode).
2334
2335If the command is given while the cursor is inside a string, *and*
2336the string is an existing filename, *and* the filename is not a directory,
2337then the string is taken as default. This allows you to just position
2338your cursor over a string that's a filename and have it taken as default.
2339
2340If the command is given in a file buffer whose major mode is in
2341SOURCE-MODES, then the filename is the default file, and the
2342file's directory is the default directory.
2343
2344If the buffer isn't a source file buffer (e.g., it's the process buffer),
2345then the default directory & file are what was used in the last source-file
2346processing command (i.e., PREVIOUS-DIR/FILE). If this is the first time
2347the command has been run (PREVIOUS-DIR/FILE is nil), the default directory
2348is the cwd, with no default file. (\"no default file\" = nil)
2349
2350SOURCE-REGEXP is typically going to be something like (tea-mode)
2351for T programs, (lisp-mode) for Lisp programs, (soar-mode lisp-mode)
2352for Soar programs, etc.
2353
2354The function returns a pair: (default-directory . default-file)."
2361 (cond ((and buffer-file-name (memq major-mode source-modes)) 2355 (cond ((and buffer-file-name (memq major-mode source-modes))
2362 (cons (file-name-directory buffer-file-name) 2356 (cons (file-name-directory buffer-file-name)
2363 (file-name-nondirectory buffer-file-name))) 2357 (file-name-nondirectory buffer-file-name)))
@@ -2366,15 +2360,13 @@ This command is like `M-.' in bash."
2366 (cons default-directory nil)))) 2360 (cons default-directory nil))))
2367 2361
2368 2362
2369;; (COMINT-CHECK-SOURCE fname)
2370;;============================================================================
2371;; Prior to loading or compiling (or otherwise processing) a file (in the CMU
2372;; process-in-a-buffer modes), this function can be called on the filename.
2373;; If the file is loaded into a buffer, and the buffer is modified, the user
2374;; is queried to see if he wants to save the buffer before proceeding with
2375;; the load or compile.
2376
2377(defun comint-check-source (fname) 2363(defun comint-check-source (fname)
2364 "Check whether to save buffers visiting file FNAME.
2365Prior to loading or compiling (or otherwise processing) a file (in the CMU
2366process-in-a-buffer modes), this function can be called on the filename.
2367If the file is loaded into a buffer, and the buffer is modified, the user
2368is queried to see if he wants to save the buffer before proceeding with
2369the load or compile."
2378 (let ((buff (get-file-buffer fname))) 2370 (let ((buff (get-file-buffer fname)))
2379 (if (and buff 2371 (if (and buff
2380 (buffer-modified-p buff) 2372 (buffer-modified-p buff)
@@ -2385,44 +2377,33 @@ This command is like `M-.' in bash."
2385 (save-buffer) 2377 (save-buffer)
2386 (set-buffer old-buffer))))) 2378 (set-buffer old-buffer)))))
2387 2379
2388
2389;; (COMINT-GET-SOURCE prompt prev-dir/file source-modes mustmatch-p)
2390;;============================================================================
2391;; COMINT-GET-SOURCE is used to prompt for filenames in command-interpreter
2392;; commands that process source files (like loading or compiling a file).
2393;; It prompts for the filename, provides a default, if there is one,
2394;; and returns the result filename.
2395;;
2396;; See COMINT-SOURCE-DEFAULT for more on determining defaults.
2397;;
2398;; PROMPT is the prompt string. PREV-DIR/FILE is the (directory . file) pair
2399;; from the last source processing command. SOURCE-MODES is a list of major
2400;; modes used to determine what file buffers contain source files. (These
2401;; two arguments are used for determining defaults). If MUSTMATCH-P is true,
2402;; then the filename reader will only accept a file that exists.
2403;;
2404;; A typical use:
2405;; (interactive (comint-get-source "Compile file: " prev-lisp-dir/file
2406;; '(lisp-mode) t))
2407
2408;; This is pretty stupid about strings. It decides we're in a string
2409;; if there's a quote on both sides of point on the current line.
2410(defun comint-extract-string () 2380(defun comint-extract-string ()
2411 "Return string around POINT that starts the current line, or nil." 2381 "Return string around POINT, or nil."
2412 (save-excursion 2382 (let ((syntax (syntax-ppss)))
2413 (let* ((point (point)) 2383 (when (nth 3 syntax)
2414 (bol (progn (beginning-of-line) (point))) 2384 (condition-case ()
2415 (eol (progn (end-of-line) (point))) 2385 (buffer-substring-no-properties (1+ (nth 8 syntax))
2416 (start (progn (goto-char point) 2386 (progn (goto-char (nth 8 syntax))
2417 (and (search-backward "\"" bol t) 2387 (forward-sexp)
2418 (1+ (point))))) 2388 (1- (point))))
2419 (end (progn (goto-char point) 2389 (error nil)))))
2420 (and (search-forward "\"" eol t)
2421 (1- (point))))))
2422 (and start end
2423 (buffer-substring-no-properties start end)))))
2424 2390
2425(defun comint-get-source (prompt prev-dir/file source-modes mustmatch-p) 2391(defun comint-get-source (prompt prev-dir/file source-modes mustmatch-p)
2392 "Prompt for filenames in commands that process source files,
2393e.g. loading or compiling a file.
2394Provides a default, if there is one, and returns the result filename.
2395
2396See `comint-source-default' for more on determining defaults.
2397
2398PROMPT is the prompt string. PREV-DIR/FILE is the (directory . file) pair
2399from the last source processing command. SOURCE-MODES is a list of major
2400modes used to determine what file buffers contain source files. (These
2401two arguments are used for determining defaults). If MUSTMATCH-P is true,
2402then the filename reader will only accept a file that exists.
2403
2404A typical use:
2405 (interactive (comint-get-source \"Compile file: \" prev-lisp-dir/file
2406 '(lisp-mode) t))"
2426 (let* ((def (comint-source-default prev-dir/file source-modes)) 2407 (let* ((def (comint-source-default prev-dir/file source-modes))
2427 (stringfile (comint-extract-string)) 2408 (stringfile (comint-extract-string))
2428 (sfile-p (and stringfile 2409 (sfile-p (and stringfile
@@ -2464,9 +2445,10 @@ This command is like `M-.' in bash."
2464;; process responds with and put it in a pop-up window or on the message 2445;; process responds with and put it in a pop-up window or on the message
2465;; line. We just display the buffer. Low tech. Simple. Works good. 2446;; line. We just display the buffer. Low tech. Simple. Works good.
2466 2447
2467;; Send to the inferior process PROC the string STR. Pop-up but do not select
2468;; a window for the inferior process so that its response can be seen.
2469(defun comint-proc-query (proc str) 2448(defun comint-proc-query (proc str)
2449 "Send to the inferior process PROC the string STR.
2450Pop-up but do not select a window for the inferior process so that
2451its response can be seen."
2470 (let* ((proc-buf (process-buffer proc)) 2452 (let* ((proc-buf (process-buffer proc))
2471 (proc-mark (process-mark proc))) 2453 (proc-mark (process-mark proc)))
2472 (display-buffer proc-buf) 2454 (display-buffer proc-buf)
@@ -2545,7 +2527,7 @@ Note that this applies to `comint-dynamic-complete-filename' only."
2545 2527
2546(defvar comint-file-name-prefix "" 2528(defvar comint-file-name-prefix ""
2547 "Prefix prepended to absolute file names taken from process input. 2529 "Prefix prepended to absolute file names taken from process input.
2548This is used by comint's and shell's completion functions, and by shell's 2530This is used by Comint's and shell's completion functions, and by shell's
2549directory tracking functions.") 2531directory tracking functions.")
2550 2532
2551(defvar comint-file-name-chars 2533(defvar comint-file-name-chars
@@ -2565,14 +2547,14 @@ This is a good thing to set in mode hooks.")
2565 2547
2566 2548
2567(defun comint-directory (directory) 2549(defun comint-directory (directory)
2568 ;; Return expanded DIRECTORY, with `comint-file-name-prefix' if absolute. 2550 "Return expanded DIRECTORY, with `comint-file-name-prefix' if absolute."
2569 (expand-file-name (if (file-name-absolute-p directory) 2551 (expand-file-name (if (file-name-absolute-p directory)
2570 (concat comint-file-name-prefix directory) 2552 (concat comint-file-name-prefix directory)
2571 directory))) 2553 directory)))
2572 2554
2573 2555
2574(defun comint-word (word-chars) 2556(defun comint-word (word-chars)
2575 "Return the word of WORD-CHARS at point, or nil if non is found. 2557 "Return the word of WORD-CHARS at point, or nil if none is found.
2576Word constituents are considered to be those in WORD-CHARS, which is like the 2558Word constituents are considered to be those in WORD-CHARS, which is like the
2577inside of a \"[...]\" (see `skip-chars-forward'), 2559inside of a \"[...]\" (see `skip-chars-forward'),
2578plus all non-ASCII characters." 2560plus all non-ASCII characters."
@@ -2582,6 +2564,8 @@ plus all non-ASCII characters."
2582 (while (not giveup) 2564 (while (not giveup)
2583 (let ((startpoint (point))) 2565 (let ((startpoint (point)))
2584 (skip-chars-backward (concat "\\\\" word-chars)) 2566 (skip-chars-backward (concat "\\\\" word-chars))
2567 ;; Fixme: This isn't consistent with Bash, at least -- not
2568 ;; all non-ASCII chars should be word constituents.
2585 (if (and (> (- (point) 2) (point-min)) 2569 (if (and (> (- (point) 2) (point-min))
2586 (= (char-after (- (point) 2)) ?\\)) 2570 (= (char-after (- (point) 2)) ?\\))
2587 (forward-char -2)) 2571 (forward-char -2))
@@ -2773,7 +2757,6 @@ See also `comint-dynamic-complete-filename'."
2773 (suffix (cond ((not comint-completion-addsuffix) "") 2757 (suffix (cond ((not comint-completion-addsuffix) "")
2774 ((not (consp comint-completion-addsuffix)) " ") 2758 ((not (consp comint-completion-addsuffix)) " ")
2775 (t (cdr comint-completion-addsuffix)))) 2759 (t (cdr comint-completion-addsuffix))))
2776 (candidates (mapcar (function (lambda (x) (list x))) candidates))
2777 (completions (all-completions stub candidates))) 2760 (completions (all-completions stub candidates)))
2778 (cond ((null completions) 2761 (cond ((null completions)
2779 (message "No completions of %s" stub) 2762 (message "No completions of %s" stub)
@@ -2962,34 +2945,36 @@ the process mark is at the beginning of the accumulated input."
2962;; 2945;;
2963;; My particular use is SQL interpreters; I want to be able to execute a 2946;; My particular use is SQL interpreters; I want to be able to execute a
2964;; query using the process associated with a comint-buffer, and save that 2947;; query using the process associated with a comint-buffer, and save that
2965;; somewhere else. Because the process might have state (for example, it 2948;; somewhere else. Because the process might have state (for example, it
2966;; could be in an uncommitted transaction), just running starting a new 2949;; could be in an uncommitted transaction), just running starting a new
2967;; process and having it execute the query and then finish, would not 2950;; process and having it execute the query and then finish, would not
2968;; work. I'm sure there are other uses as well, although in many cases 2951;; work. I'm sure there are other uses as well, although in many cases
2969;; starting a new process is the simpler, and thus preferable, approach. 2952;; starting a new process is the simpler, and thus preferable, approach.
2970;; 2953;;
2971;; The basic implementation is as follows: comint-redirect changes the 2954;; The basic implementation is as follows: comint-redirect changes the
2972;; preoutput filter functions (comint-preoutput-filter-functions) to use 2955;; preoutput filter functions (`comint-preoutput-filter-functions') to use
2973;; its own filter. The filter puts the output into the designated buffer, 2956;; its own filter. The filter puts the output into the designated buffer,
2974;; or buffers, until it sees a regexp that tells it to stop (by default, 2957;; or buffers, until it sees a regexp that tells it to stop (by default,
2975;; this is the prompt for the interpreter, comint-prompt-regexp). When it 2958;; this is the prompt for the interpreter, `comint-prompt-regexp'). When it
2976;; sees the stop regexp, it restores the old filter functions, and runs 2959;; sees the stop regexp, it restores the old filter functions, and runs
2977;; comint-redirect-hook. 2960;; `comint-redirect-hook'.
2978;; 2961;;
2979;; Each comint buffer may only use one redirection at a time, but any number 2962;; Each comint buffer may only use one redirection at a time, but any number
2980;; of different comint buffers may be simultaneously redirected. 2963;; of different comint buffers may be simultaneously redirected.
2981;; 2964;;
2982;; NOTE: It is EXTREMELY important that `comint-prompt-regexp' be set to the 2965;; NOTE: It is EXTREMELY important that `comint-prompt-regexp' be set to the
2983;; correct prompt for your interpreter, or that you supply a regexp that says 2966;; correct prompt for your interpreter, or that you supply a regexp that says
2984;; when the redirection is finished. Otherwise, redirection will continue 2967;; when the redirection is finished. Otherwise, redirection will continue
2985;; indefinitely. The code now does a sanity check to ensure that it can find 2968;; indefinitely. The code now does a sanity check to ensure that it can find
2986;; a prompt in the comint buffer; however, it is still important to ensure that 2969;; a prompt in the comint buffer; however, it is still important to ensure that
2987;; this prompt is set correctly. 2970;; this prompt is set correctly.
2988;; 2971;;
2989;; XXX: This doesn't work so well unless comint-prompt-regexp is set; 2972;; XXX: This doesn't work so well unless `comint-prompt-regexp' is set;
2990;; perhaps it should prompt for a terminating string (with an 2973;; perhaps it should prompt for a terminating string (with an
2991;; appropriate magic default by examining what we think is the prompt)? 2974;; appropriate magic default by examining what we think is the prompt)?
2992;; 2975;;
2976;; Fixme: look for appropriate fields, rather than regexp, if
2977;; `comint-use-prompt-regexp-instead-of-fields' is true.
2993 2978
2994;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 2979;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2995;; Variables 2980;; Variables
@@ -3055,6 +3040,12 @@ in the process buffer already.")
3055When redirection is completed, the process filter is restored to 3040When redirection is completed, the process filter is restored to
3056this value.") 3041this value.")
3057 3042
3043(defvar comint-redirect-subvert-readonly nil
3044 "Non-nil means comint-redirect can insert into otherwise-readonly buffers.
3045The readonly status is toggled around insertion.
3046This is useful, for instance, for insertion into Help mode buffers.
3047You probably want to set it locally to the output buffer.")
3048
3058;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 3049;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3059;; Functions 3050;; Functions
3060;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 3051;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -3071,7 +3062,7 @@ Output from COMINT-BUFFER is redirected to OUTPUT-BUFFER, until something
3071in the output matches FINISHED-REGEXP. 3062in the output matches FINISHED-REGEXP.
3072 3063
3073If optional argument ECHO-INPUT is non-nil, output is echoed to the 3064If optional argument ECHO-INPUT is non-nil, output is echoed to the
3074original comint buffer. 3065original Comint buffer.
3075 3066
3076This function is called by `comint-redirect-send-command-to-process', 3067This function is called by `comint-redirect-send-command-to-process',
3077and does not normally need to be invoked by the end user or programmer." 3068and does not normally need to be invoked by the end user or programmer."
@@ -3117,7 +3108,7 @@ and does not normally need to be invoked by the end user or programmer."
3117The variable `comint-redirect-output-buffer' says which buffer(s) to 3108The variable `comint-redirect-output-buffer' says which buffer(s) to
3118place output in. 3109place output in.
3119 3110
3120INPUT-STRING is the input from the comint process. 3111INPUT-STRING is the input from the Comint process.
3121 3112
3122This function runs as a process filter, and does not need to be invoked by the 3113This function runs as a process filter, and does not need to be invoked by the
3123end user." 3114end user."
@@ -3132,11 +3123,11 @@ end user."
3132 3123
3133 3124
3134(defun comint-redirect-preoutput-filter (input-string) 3125(defun comint-redirect-preoutput-filter (input-string)
3135 "Comint filter function which redirects comint output to a buffer or buffers. 3126 "Comint filter function which redirects Comint output to a buffer or buffers.
3136The variable `comint-redirect-output-buffer' says which buffer(s) to 3127The variable `comint-redirect-output-buffer' says which buffer(s) to
3137place output in. 3128place output in.
3138 3129
3139INPUT-STRING is the input from the comint process. 3130INPUT-STRING is the input from the Comint process.
3140 3131
3141This function does not need to be invoked by the end user." 3132This function does not need to be invoked by the end user."
3142 (let ((output-buffer-list 3133 (let ((output-buffer-list
@@ -3168,15 +3159,14 @@ This function does not need to be invoked by the end user."
3168 3159
3169 ;; Send output to all registered buffers 3160 ;; Send output to all registered buffers
3170 (save-excursion 3161 (save-excursion
3171 (mapcar 3162 (dolist (buf output-buffer-list)
3172 (function (lambda(buf) 3163 ;; Set this buffer to the output buffer
3173 ;; Set this buffer to the output buffer 3164 (set-buffer (get-buffer-create buf))
3174 (set-buffer (get-buffer-create buf)) 3165 ;; Go to the end of the buffer
3175 ;; Go to the end of the buffer 3166 (goto-char (point-max))
3176 (goto-char (point-max)) 3167 ;; Insert the output
3177 ;; Insert the output 3168 (let ((inhibit-read-only comint-redirect-subvert-readonly))
3178 (insert filtered-input-string))) 3169 (insert filtered-input-string))))
3179 output-buffer-list))
3180 3170
3181 ;; Message 3171 ;; Message
3182 (and comint-redirect-verbose 3172 (and comint-redirect-verbose
@@ -3200,7 +3190,7 @@ This function does not need to be invoked by the end user."
3200;;;###autoload 3190;;;###autoload
3201(defun comint-redirect-send-command (command output-buffer echo &optional no-display) 3191(defun comint-redirect-send-command (command output-buffer echo &optional no-display)
3202 "Send COMMAND to process in current buffer, with output to OUTPUT-BUFFER. 3192 "Send COMMAND to process in current buffer, with output to OUTPUT-BUFFER.
3203With prefix arg, echo output in process buffer. 3193With prefix arg ECHO, echo output in process buffer.
3204 3194
3205If NO-DISPLAY is non-nil, do not show the output buffer." 3195If NO-DISPLAY is non-nil, do not show the output buffer."
3206 (interactive "sCommand: \nBOutput Buffer: \nP") 3196 (interactive "sCommand: \nBOutput Buffer: \nP")