annotate lisp/comint/comint.el @ 131:869e1851236b xemacs-20-1p4

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