annotate lisp/comint/comint.el @ 34:d620409f5eb8 r19-15b100

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