annotate lisp/comint/comint.el @ 0:376386a54a3c r19-14

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