annotate lisp/comint/comint.el @ 110:fe104dbd9147 r20-1b7

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