Mercurial > emacs
annotate lisp/comint.el @ 4733:4d378f483cf4
Set up keymap at load time.
(iso-accents-mode): Not here. Just setq iso-accents-minor-mode.
(iso-accents-minor-mode): Make it local in all buffers.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Fri, 17 Sep 1993 16:49:28 +0000 |
parents | f4ab5299a1e4 |
children | 628cbf7e7005 |
rev | line source |
---|---|
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
638
diff
changeset
|
1 ;;; comint.el --- general command interpreter in a window stuff |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
2 |
1839
e10cdcb857d2
(make-comint): Added docstring.
Roland McGrath <roland@gnu.org>
parents:
1821
diff
changeset
|
3 ;; Copyright (C) 1988, 1990, 1992, 1993 Free Software Foundation, Inc. |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
638
diff
changeset
|
4 |
909
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
870
diff
changeset
|
5 ;; Author: Olin Shivers <shivers@cs.cmu.edu> |
2247
2c7997f249eb
Add or correct keywords
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2025
diff
changeset
|
6 ;; Keywords: processes |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
811
diff
changeset
|
7 |
909
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
870
diff
changeset
|
8 ;; This file is part of GNU Emacs. |
114 | 9 |
909
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
870
diff
changeset
|
10 ;; GNU Emacs is free software; you can redistribute it and/or modify |
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
870
diff
changeset
|
11 ;; it under the terms of the GNU General Public License as published by |
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
870
diff
changeset
|
12 ;; the Free Software Foundation; either version 2, or (at your option) |
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
870
diff
changeset
|
13 ;; any later version. |
114 | 14 |
909
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
870
diff
changeset
|
15 ;; GNU Emacs is distributed in the hope that it will be useful, |
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
870
diff
changeset
|
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
870
diff
changeset
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
870
diff
changeset
|
18 ;; GNU General Public License for more details. |
114 | 19 |
909
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
870
diff
changeset
|
20 ;; You should have received a copy of the GNU General Public License |
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
870
diff
changeset
|
21 ;; along with GNU Emacs; see the file COPYING. If not, write to |
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
870
diff
changeset
|
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
114 | 23 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
793
diff
changeset
|
24 ;;; Commentary: |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
793
diff
changeset
|
25 |
584 | 26 ;;; The changelog is at the end of this file. |
27 | |
28 ;;; Please send me bug reports, bug fixes, and extensions, so that I can | |
29 ;;; merge them into the master source. | |
30 ;;; - Olin Shivers (shivers@cs.cmu.edu) | |
31 | |
114 | 32 ;;; This file defines a general command-interpreter-in-a-buffer package |
33 ;;; (comint mode). The idea is that you can build specific process-in-a-buffer | |
34 ;;; modes on top of comint mode -- e.g., lisp, shell, scheme, T, soar, .... | |
35 ;;; This way, all these specific packages share a common base functionality, | |
36 ;;; and a common set of bindings, which makes them easier to use (and | |
37 ;;; saves code, implementation time, etc., etc.). | |
38 | |
584 | 39 ;;; Several packages are already defined using comint mode: |
2518
10509afe2588
Clean up cmu* uses in header comments.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2455
diff
changeset
|
40 ;;; - shell.el defines a shell-in-a-buffer mode. |
584 | 41 ;;; - cmulisp.el defines a simple lisp-in-a-buffer mode. |
42 ;;; | |
43 ;;; - The file cmuscheme.el defines a scheme-in-a-buffer mode. | |
44 ;;; - The file tea.el tunes scheme and inferior-scheme modes for T. | |
45 ;;; - The file soar.el tunes lisp and inferior-lisp modes for Soar. | |
46 ;;; - cmutex.el defines tex and latex modes that invoke tex, latex, bibtex, | |
47 ;;; previewers, and printers from within emacs. | |
48 ;;; - background.el allows csh-like job control inside emacs. | |
49 ;;; It is pretty easy to make new derived modes for other processes. | |
50 | |
114 | 51 ;;; For documentation on the functionality provided by comint mode, and |
52 ;;; the hooks available for customising it, see the comments below. | |
53 ;;; For further information on the standard derived modes (shell, | |
54 ;;; inferior-lisp, inferior-scheme, ...), see the relevant source files. | |
55 | |
584 | 56 ;;; For hints on converting existing process modes (e.g., tex-mode, |
57 ;;; background, dbx, gdb, kermit, prolog, telnet) to use comint-mode | |
114 | 58 ;;; instead of shell-mode, see the notes at the end of this file. |
59 | |
60 | |
584 | 61 ;;; Brief Command Documentation: |
62 ;;;============================================================================ | |
2518
10509afe2588
Clean up cmu* uses in header comments.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2455
diff
changeset
|
63 ;;; Comint Mode Commands: (common to all derived modes, like shell & cmulisp |
584 | 64 ;;; mode) |
65 ;;; | |
66 ;;; m-p comint-previous-input Cycle backwards in input history | |
67 ;;; m-n comint-next-input Cycle forwards | |
2673
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
68 ;;; m-r comint-previous-matching-input Previous input matching a regexp |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
69 ;;; m-s comint-next-matching-input Next input that matches |
584 | 70 ;;; return comint-send-input |
71 ;;; c-a comint-bol Beginning of line; skip prompt. | |
72 ;;; c-d comint-delchar-or-maybe-eof Delete char unless at end of buff. | |
73 ;;; c-c c-u comint-kill-input ^u | |
74 ;;; c-c c-w backward-kill-word ^w | |
75 ;;; c-c c-c comint-interrupt-subjob ^c | |
76 ;;; c-c c-z comint-stop-subjob ^z | |
77 ;;; c-c c-\ comint-quit-subjob ^\ | |
78 ;;; c-c c-o comint-kill-output Delete last batch of process output | |
79 ;;; c-c c-r comint-show-output Show last batch of process output | |
80 ;;; | |
114 | 81 ;;; Not bound by default in comint-mode |
82 ;;; send-invisible Read a line w/o echo, and send to proc | |
83 ;;; (These are bound in shell-mode) | |
84 ;;; comint-dynamic-complete Complete filename at point. | |
85 ;;; comint-dynamic-list-completions List completions in help buffer. | |
86 ;;; comint-replace-by-expanded-filename Expand and complete filename at point; | |
87 ;;; replace with expanded/completed name. | |
584 | 88 ;;; comint-kill-subjob No mercy. |
89 ;;; comint-continue-subjob Send CONT signal to buffer's process | |
90 ;;; group. Useful if you accidentally | |
91 ;;; suspend your process (with C-c C-z). | |
92 ;;; | |
93 ;;; These used to be bound for RMS -- I prefer the input history stuff, | |
94 ;;; but you might like 'em. | |
95 ;;; m-P comint-msearch-input Search backwards for prompt | |
96 ;;; m-N comint-psearch-input Search forwards for prompt | |
97 ;;; C-cR comint-msearch-input-matching Search backwards for prompt & string | |
114 | 98 |
584 | 99 ;;; comint-mode-hook is the comint mode hook. Basically for your keybindings. |
100 ;;; comint-load-hook is run after loading in this package. | |
101 | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
793
diff
changeset
|
102 ;;; Code: |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
793
diff
changeset
|
103 |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
793
diff
changeset
|
104 (defconst comint-version "2.03") |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
793
diff
changeset
|
105 |
1131 | 106 (require 'ring) |
114 | 107 |
108 ;;; Buffer Local Variables: | |
109 ;;;============================================================================ | |
110 ;;; Comint mode buffer local variables: | |
111 ;;; comint-prompt-regexp - string comint-bol uses to match prompt. | |
705 | 112 ;;; comint-last-input-start - marker Handy if inferior always echos |
584 | 113 ;;; comint-last-input-end - marker For comint-kill-output command |
861
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
114 ;;; comint-input-ring-size - integer For the input history |
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
115 ;;; comint-input-ring - ring mechanism |
2673
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
116 ;;; comint-input-ring-index - number ... |
114 | 117 ;;; comint-last-input-match - string ... |
118 ;;; comint-get-old-input - function Hooks for specific | |
119 ;;; comint-input-sentinel - function process-in-a-buffer | |
120 ;;; comint-input-filter - function modes. | |
121 ;;; comint-input-send - function | |
122 ;;; comint-eol-on-send - boolean | |
2539
577c77cfd199
*** empty log message ***
Noah Friedman <friedman@splode.com>
parents:
2518
diff
changeset
|
123 ;;; comint-process-echoes - boolean |
114 | 124 |
584 | 125 (defvar comint-prompt-regexp "^" |
126 "Regexp to recognise prompts in the inferior process. | |
127 Defaults to \"^\", the null string at BOL. | |
114 | 128 |
129 Good choices: | |
584 | 130 Canonical Lisp: \"^[^> ]*>+:? *\" (Lucid, franz, kcl, T, cscheme, oaklisp) |
3985
fc25d1816641
* comint.el (comint-prompt-regexp): Double the backslashes in the
Jim Blandy <jimb@redhat.com>
parents:
3591
diff
changeset
|
131 Lucid Common Lisp: \"^\\\\(>\\\\|\\\\(->\\\\)+\\\\) *\" |
fc25d1816641
* comint.el (comint-prompt-regexp): Double the backslashes in the
Jim Blandy <jimb@redhat.com>
parents:
3591
diff
changeset
|
132 franz: \"^\\\\(->\\\\|<[0-9]*>:\\\\) *\" |
584 | 133 kcl: \"^>+ *\" |
134 shell: \"^[^#$%>]*[#$%>] *\" | |
135 T: \"^>+ *\" | |
114 | 136 |
584 | 137 This is a good thing to set in mode hooks.") |
114 | 138 |
861
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
139 (defvar comint-input-ring-size 30 |
584 | 140 "Size of input history ring.") |
114 | 141 |
2539
577c77cfd199
*** empty log message ***
Noah Friedman <friedman@splode.com>
parents:
2518
diff
changeset
|
142 (defvar comint-process-echoes nil |
3386
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
143 "*If non-nil, assume that the subprocess echoes any input. |
2539
577c77cfd199
*** empty log message ***
Noah Friedman <friedman@splode.com>
parents:
2518
diff
changeset
|
144 If so, delete one copy of the input so that only one copy eventually |
577c77cfd199
*** empty log message ***
Noah Friedman <friedman@splode.com>
parents:
2518
diff
changeset
|
145 appears in the buffer. |
577c77cfd199
*** empty log message ***
Noah Friedman <friedman@splode.com>
parents:
2518
diff
changeset
|
146 |
577c77cfd199
*** empty log message ***
Noah Friedman <friedman@splode.com>
parents:
2518
diff
changeset
|
147 This variable is buffer-local.") |
577c77cfd199
*** empty log message ***
Noah Friedman <friedman@splode.com>
parents:
2518
diff
changeset
|
148 |
114 | 149 ;;; Here are the per-interpreter hooks. |
584 | 150 (defvar comint-get-old-input (function comint-get-old-input-default) |
151 "Function that submits old text in comint mode. | |
114 | 152 This function is called when return is typed while the point is in old text. |
153 It returns the text to be submitted as process input. The default is | |
3386
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
154 `comint-get-old-input-default', which grabs the current line, and strips off |
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
155 leading text matching `comint-prompt-regexp'.") |
114 | 156 |
584 | 157 (defvar comint-input-sentinel (function ignore) |
3386
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
158 "Called on each input submitted to comint mode process by `comint-send-input'. |
584 | 159 Thus it can, for instance, track cd/pushd/popd commands issued to the csh.") |
114 | 160 |
584 | 161 (defvar comint-input-filter |
162 (function (lambda (str) (not (string-match "\\`\\s *\\'" str)))) | |
163 "Predicate for filtering additions to input history. | |
114 | 164 Only inputs answering true to this function are saved on the input |
3386
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
165 history list. Default is to save anything that isn't all whitespace") |
584 | 166 |
167 (defvar comint-input-sender (function comint-simple-send) | |
168 "Function to actually send to PROCESS the STRING submitted by user. | |
3386
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
169 Usually this is just `comint-simple-send', but if your mode needs to |
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
170 massage the input string, put a different function here. |
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
171 `comint-simple-send' just sends the string plus a newline. |
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
172 This is called from the user command `comint-send-input'.") |
584 | 173 |
3386
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
174 (defvar comint-eol-on-send t |
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
175 "*Non-nil means go to the end of the line before sending input to process. |
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
176 See `comint-send-input'.") |
114 | 177 |
178 (defvar comint-mode-hook '() | |
584 | 179 "Called upon entry into comint-mode |
180 This is run before the process is cranked up.") | |
181 | |
182 (defvar comint-exec-hook '() | |
3386
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
183 "Called each time a process is exec'd by `comint-exec'. |
584 | 184 This is called after the process is cranked up. It is useful for things that |
3386
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
185 must be done each time a process is executed in a comint mode buffer (e.g., |
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
186 `(process-kill-without-query)'). In contrast, the `comint-mode-hook' is only |
584 | 187 executed once when the buffer is created.") |
188 | |
189 (defvar comint-mode-map nil) | |
114 | 190 |
1131 | 191 (defvar comint-ptyp t |
192 "True if communications via pty; false if by pipe. Buffer local. | |
3386
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
193 This is to work around a bug in Emacs process signalling.") |
1131 | 194 |
2673
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
195 ;;(defvar comint-last-input-match "" |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
196 ;; "Last string searched for by comint input history search, for defaulting. |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
197 ;;Buffer local variable.") |
1376
dd83ec6103fe
(comint-last-input-match): defvar moved up.
Richard M. Stallman <rms@gnu.org>
parents:
1373
diff
changeset
|
198 |
932
a93f0b1ba909
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
925
diff
changeset
|
199 (defvar comint-input-ring nil) |
861
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
200 (defvar comint-last-input-start) |
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
201 (defvar comint-last-input-end) |
1131 | 202 (defvar comint-input-ring-index) |
203 (put 'comint-input-ring 'permanent-local t) | |
204 (put 'comint-ptyp 'permanent-local t) | |
861
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
205 |
114 | 206 (defun comint-mode () |
207 "Major mode for interacting with an inferior interpreter. | |
208 Interpreter name is same as buffer name, sans the asterisks. | |
209 Return at end of buffer sends line as input. | |
210 Return not at end copies rest of line to end and sends it. | |
3386
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
211 Setting variable `comint-eol-on-send' means jump to the end of the line |
584 | 212 before submitting new input. |
114 | 213 |
3386
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
214 This mode is typically customised to create Inferior Lisp mode, |
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
215 Shell mode, etc. This can be done by setting the hooks |
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
216 `comint-input-sentinel', `comint-input-filter', `comint-input-sender' and |
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
217 `comint-get-old-input' to appropriate functions, and the variable |
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
218 `comint-prompt-regexp' to the appropriate regular expression. |
114 | 219 |
3386
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
220 An input history is maintained of size `comint-input-ring-size', and |
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
221 can be accessed with the commands \\[comint-next-input] and \\[comint-previous-input]. |
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
222 Commands with no default key bindings include `send-invisible', |
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
223 `comint-dynamic-complete', and `comint-list-dynamic-completions'. |
114 | 224 |
225 If you accidentally suspend your process, use \\[comint-continue-subjob] | |
226 to continue it. | |
227 | |
228 \\{comint-mode-map} | |
229 | |
584 | 230 Entry to this mode runs the hooks on comint-mode-hook" |
114 | 231 (interactive) |
1131 | 232 ;; Do not remove this. All major modes must do this. |
233 (kill-all-local-variables) | |
584 | 234 (setq major-mode 'comint-mode) |
235 (setq mode-name "Comint") | |
236 (setq mode-line-process '(": %s")) | |
237 (use-local-map comint-mode-map) | |
705 | 238 (make-local-variable 'comint-last-input-start) |
239 (setq comint-last-input-start (make-marker)) | |
584 | 240 (make-local-variable 'comint-last-input-end) |
241 (setq comint-last-input-end (make-marker)) | |
2673
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
242 ;;; (make-local-variable 'comint-last-input-match) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
243 ;;; (setq comint-last-input-match "") |
584 | 244 (make-local-variable 'comint-prompt-regexp) ; Don't set; default |
861
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
245 (make-local-variable 'comint-input-ring-size) ; ...to global val. |
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
246 (make-local-variable 'comint-input-ring) |
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
247 (make-local-variable 'comint-input-ring-index) |
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
248 (setq comint-input-ring-index 0) |
584 | 249 (make-local-variable 'comint-get-old-input) |
250 (make-local-variable 'comint-input-sentinel) | |
251 (make-local-variable 'comint-input-filter) | |
252 (make-local-variable 'comint-input-sender) | |
253 (make-local-variable 'comint-eol-on-send) | |
254 (make-local-variable 'comint-ptyp) | |
705 | 255 (make-local-variable 'comint-exec-hook) |
2539
577c77cfd199
*** empty log message ***
Noah Friedman <friedman@splode.com>
parents:
2518
diff
changeset
|
256 (make-local-variable 'comint-process-echoes) |
584 | 257 (run-hooks 'comint-mode-hook) |
1131 | 258 (or comint-input-ring |
259 (setq comint-input-ring (make-ring comint-input-ring-size)))) | |
114 | 260 |
584 | 261 (if comint-mode-map |
262 nil | |
263 (setq comint-mode-map (make-sparse-keymap)) | |
264 (define-key comint-mode-map "\ep" 'comint-previous-input) | |
265 (define-key comint-mode-map "\en" 'comint-next-input) | |
2673
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
266 (define-key comint-mode-map "\er" 'comint-previous-matching-input) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
267 (define-key comint-mode-map "\es" 'comint-next-matching-input) |
584 | 268 (define-key comint-mode-map "\C-m" 'comint-send-input) |
269 (define-key comint-mode-map "\C-d" 'comint-delchar-or-maybe-eof) | |
270 (define-key comint-mode-map "\C-a" 'comint-bol) | |
271 (define-key comint-mode-map "\C-c\C-u" 'comint-kill-input) | |
272 (define-key comint-mode-map "\C-c\C-w" 'backward-kill-word) | |
273 (define-key comint-mode-map "\C-c\C-c" 'comint-interrupt-subjob) | |
274 (define-key comint-mode-map "\C-c\C-z" 'comint-stop-subjob) | |
275 (define-key comint-mode-map "\C-c\C-\\" 'comint-quit-subjob) | |
276 (define-key comint-mode-map "\C-c\C-o" 'comint-kill-output) | |
277 (define-key comint-mode-map "\C-c\C-r" 'comint-show-output) | |
278 ;;; prompt-search commands commented out 3/90 -Olin | |
279 ; (define-key comint-mode-map "\eP" 'comint-msearch-input) | |
280 ; (define-key comint-mode-map "\eN" 'comint-psearch-input) | |
281 ; (define-key comint-mode-map "\C-cR" 'comint-msearch-input-matching) | |
4112
ab7dee78e335
(comint-{next,prev}-prompt, comint-send-eof): New functions.
Roland McGrath <roland@gnu.org>
parents:
3985
diff
changeset
|
282 (define-key comint-mode-map "\C-c\C-n" 'comint-next-prompt) |
ab7dee78e335
(comint-{next,prev}-prompt, comint-send-eof): New functions.
Roland McGrath <roland@gnu.org>
parents:
3985
diff
changeset
|
283 (define-key comint-mode-map "\C-c\C-p" 'comint-prev-prompt) |
ab7dee78e335
(comint-{next,prev}-prompt, comint-send-eof): New functions.
Roland McGrath <roland@gnu.org>
parents:
3985
diff
changeset
|
284 (define-key comint-mode-map "\C-c\C-d" 'comint-send-eof) |
584 | 285 ) |
286 | |
287 | |
288 ;;; This function is used to make a full copy of the comint mode map, | |
289 ;;; so that client modes won't interfere with each other. This function | |
290 ;;; isn't necessary in emacs 18.5x, but we keep it around for 18.4x versions. | |
291 (defun full-copy-sparse-keymap (km) | |
3386
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
292 "Recursively copy the sparse keymap KM." |
584 | 293 (cond ((consp km) |
294 (cons (full-copy-sparse-keymap (car km)) | |
295 (full-copy-sparse-keymap (cdr km)))) | |
296 (t km))) | |
297 | |
298 (defun comint-check-proc (buffer) | |
3386
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
299 "True if there is a living process associated w/buffer BUFFER. |
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
300 Living means the status is `run' or `stop'. |
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
301 BUFFER can be either a buffer or the name of one." |
584 | 302 (let ((proc (get-buffer-process buffer))) |
114 | 303 (and proc (memq (process-status proc) '(run stop))))) |
304 | |
305 ;;; Note that this guy, unlike shell.el's make-shell, barfs if you pass it () | |
306 ;;; for the second argument (program). | |
870
1b3af6ad85be
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
864
diff
changeset
|
307 ;;;###autoload |
114 | 308 (defun make-comint (name program &optional startfile &rest switches) |
1839
e10cdcb857d2
(make-comint): Added docstring.
Roland McGrath <roland@gnu.org>
parents:
1821
diff
changeset
|
309 "Make a comint process NAME in a buffer, running PROGRAM. |
e10cdcb857d2
(make-comint): Added docstring.
Roland McGrath <roland@gnu.org>
parents:
1821
diff
changeset
|
310 The name of the buffer is made by surrounding NAME with `*'s. |
e10cdcb857d2
(make-comint): Added docstring.
Roland McGrath <roland@gnu.org>
parents:
1821
diff
changeset
|
311 If there is already a running process in that buffer, it is not restarted. |
e10cdcb857d2
(make-comint): Added docstring.
Roland McGrath <roland@gnu.org>
parents:
1821
diff
changeset
|
312 Optional third arg STARTFILE is the name of a file to send the contents of to |
e10cdcb857d2
(make-comint): Added docstring.
Roland McGrath <roland@gnu.org>
parents:
1821
diff
changeset
|
313 the process. Any more args are arguments to PROGRAM." |
584 | 314 (let ((buffer (get-buffer-create (concat "*" name "*")))) |
114 | 315 ;; If no process, or nuked process, crank up a new one and put buffer in |
1839
e10cdcb857d2
(make-comint): Added docstring.
Roland McGrath <roland@gnu.org>
parents:
1821
diff
changeset
|
316 ;; comint mode. Otherwise, leave buffer and existing process alone. |
182 | 317 (cond ((not (comint-check-proc buffer)) |
584 | 318 (save-excursion |
114 | 319 (set-buffer buffer) |
320 (comint-mode)) ; Install local vars, mode, keymap, ... | |
321 (comint-exec buffer name program startfile switches))) | |
322 buffer)) | |
323 | |
324 (defun comint-exec (buffer name command startfile switches) | |
3386
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
325 "Start up a process in buffer BUFFER for comint modes. |
1839
e10cdcb857d2
(make-comint): Added docstring.
Roland McGrath <roland@gnu.org>
parents:
1821
diff
changeset
|
326 Blasts any old process running in the buffer. Doesn't set the buffer mode. |
584 | 327 You can use this to cheaply run a series of processes in the same comint |
3386
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
328 buffer. The hook `comint-exec-hook' is run after each exec." |
114 | 329 (save-excursion |
330 (set-buffer buffer) | |
331 (let ((proc (get-buffer-process buffer))) ; Blast any old process. | |
332 (if proc (delete-process proc))) | |
333 ;; Crank up a new process | |
334 (let ((proc (comint-exec-1 name buffer command switches))) | |
2683
21ab70613c42
(comint-filter): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2680
diff
changeset
|
335 (set-process-filter proc 'comint-filter) |
584 | 336 (make-local-variable 'comint-ptyp) |
337 (setq comint-ptyp process-connection-type) ; T if pty, NIL if pipe. | |
114 | 338 ;; Jump to the end, and set the process mark. |
584 | 339 (goto-char (point-max)) |
705 | 340 (set-marker (process-mark proc) (point)) |
114 | 341 ;; Feed it the startfile. |
342 (cond (startfile | |
343 ;;This is guaranteed to wait long enough | |
344 ;;but has bad results if the comint does not prompt at all | |
345 ;; (while (= size (buffer-size)) | |
346 ;; (sleep-for 1)) | |
347 ;;I hope 1 second is enough! | |
348 (sleep-for 1) | |
349 (goto-char (point-max)) | |
350 (insert-file-contents startfile) | |
351 (setq startfile (buffer-substring (point) (point-max))) | |
352 (delete-region (point) (point-max)) | |
584 | 353 (comint-send-string proc startfile))) |
354 (run-hooks 'comint-exec-hook) | |
705 | 355 buffer))) |
114 | 356 |
357 ;;; This auxiliary function cranks up the process for comint-exec in | |
638 | 358 ;;; the appropriate environment. |
114 | 359 |
360 (defun comint-exec-1 (name buffer command switches) | |
638 | 361 (let ((process-environment |
362 (comint-update-env process-environment | |
363 (list (format "TERMCAP=emacs:co#%d:tc=unknown" | |
778 | 364 (frame-width)) |
638 | 365 "TERM=emacs" |
366 "EMACS=t")))) | |
367 (apply 'start-process name buffer command switches))) | |
584 | 368 |
369 | |
114 | 370 |
371 ;; This is just (append new old-env) that compresses out shadowed entries. | |
793
6fb68a1460a6
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
778
diff
changeset
|
372 ;; It's also pretty ugly, mostly due to lisp's horrible iteration structures. |
114 | 373 (defun comint-update-env (old-env new) |
374 (let ((ans (reverse new)) | |
375 (vars (mapcar (function (lambda (vv) | |
376 (and (string-match "^[^=]*=" vv) | |
377 (substring vv 0 (match-end 0))))) | |
378 new))) | |
379 (while old-env | |
380 (let* ((vv (car old-env)) ; vv is var=value | |
381 (var (and (string-match "^[^=]*=" vv) | |
382 (substring vv 0 (match-end 0))))) | |
383 (setq old-env (cdr old-env)) | |
2583
308da27928f2
(comint-mod): Nuked. A call to ring-mod replaces it.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2539
diff
changeset
|
384 (cond ((not (and var (member var vars))) |
114 | 385 (if var (setq var (cons var vars))) |
386 (setq ans (cons vv ans)))))) | |
387 (nreverse ans))) | |
584 | 388 |
114 | 389 |
390 ;;; Input history retrieval commands | |
391 ;;; M-p -- previous input M-n -- next input | |
584 | 392 ;;; M-C-r -- previous input matching |
114 | 393 ;;; =========================================================================== |
394 | |
395 (defun comint-previous-input (arg) | |
396 "Cycle backwards through input history." | |
397 (interactive "*p") | |
861
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
398 (let ((len (ring-length comint-input-ring))) |
584 | 399 (cond ((<= len 0) |
400 (message "Empty input ring") | |
401 (ding)) | |
402 ((not (comint-after-pmark-p)) | |
403 (message "Not after process mark") | |
404 (ding)) | |
405 (t | |
909
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
870
diff
changeset
|
406 (delete-region (point) |
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
870
diff
changeset
|
407 (process-mark (get-buffer-process (current-buffer)))) |
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
870
diff
changeset
|
408 ;; Initialize the index on the first use of this command |
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
870
diff
changeset
|
409 ;; so that the first M-p gets index 0, and the first M-n gets |
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
870
diff
changeset
|
410 ;; index -1. |
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
870
diff
changeset
|
411 (if (null comint-input-ring-index) |
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
870
diff
changeset
|
412 (setq comint-input-ring-index |
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
870
diff
changeset
|
413 (if (> arg 0) -1 |
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
870
diff
changeset
|
414 (if (< arg 0) 1 0)))) |
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
870
diff
changeset
|
415 (setq comint-input-ring-index |
4513 | 416 (mod (+ comint-input-ring-index arg) len)) |
861
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
417 (message "%d" (1+ comint-input-ring-index)) |
909
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
870
diff
changeset
|
418 (insert (ring-ref comint-input-ring comint-input-ring-index)))))) |
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
870
diff
changeset
|
419 |
114 | 420 (defun comint-next-input (arg) |
421 "Cycle forwards through input history." | |
422 (interactive "*p") | |
423 (comint-previous-input (- arg))) | |
424 | |
2673
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
425 (defun comint-previous-matching-input (regexp arg) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
426 "Search backwards through input history for match for REGEXP. |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
427 \(Previous history elements are earlier commands.) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
428 With prefix argument N, search for Nth previous match. |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
429 If N is negative, find the next or Nth next match." |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
430 (interactive |
2680
ac4af95b962f
(comint-previous-matching-input): Use let* in the interactive.
Richard M. Stallman <rms@gnu.org>
parents:
2673
diff
changeset
|
431 (let* ((minibuffer-history-sexp-flag nil) |
ac4af95b962f
(comint-previous-matching-input): Use let* in the interactive.
Richard M. Stallman <rms@gnu.org>
parents:
2673
diff
changeset
|
432 ;; Don't clobber this. |
ac4af95b962f
(comint-previous-matching-input): Use let* in the interactive.
Richard M. Stallman <rms@gnu.org>
parents:
2673
diff
changeset
|
433 (last-command last-command) |
ac4af95b962f
(comint-previous-matching-input): Use let* in the interactive.
Richard M. Stallman <rms@gnu.org>
parents:
2673
diff
changeset
|
434 (regexp (read-from-minibuffer "Previous input matching (regexp): " |
ac4af95b962f
(comint-previous-matching-input): Use let* in the interactive.
Richard M. Stallman <rms@gnu.org>
parents:
2673
diff
changeset
|
435 nil |
ac4af95b962f
(comint-previous-matching-input): Use let* in the interactive.
Richard M. Stallman <rms@gnu.org>
parents:
2673
diff
changeset
|
436 minibuffer-local-map |
ac4af95b962f
(comint-previous-matching-input): Use let* in the interactive.
Richard M. Stallman <rms@gnu.org>
parents:
2673
diff
changeset
|
437 nil |
ac4af95b962f
(comint-previous-matching-input): Use let* in the interactive.
Richard M. Stallman <rms@gnu.org>
parents:
2673
diff
changeset
|
438 'minibuffer-history-search-history))) |
2673
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
439 (list (if (string= regexp "") |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
440 (setcar minibuffer-history-search-history |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
441 (nth 1 minibuffer-history-search-history)) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
442 regexp) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
443 (prefix-numeric-value current-prefix-arg)))) |
909
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
870
diff
changeset
|
444 (if (null comint-input-ring-index) |
861
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
445 (setq comint-input-ring-index -1)) |
2673
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
446 (let* ((len (ring-length comint-input-ring)) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
447 (motion (if (> arg 0) 1 -1)) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
448 (n comint-input-ring-index)) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
449 ;; Do the whole search as many times as the argument says. |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
450 (while (/= arg 0) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
451 (let ((prev n)) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
452 ;; Step once. |
4513 | 453 (setq n (mod (+ n motion) len)) |
2673
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
454 ;; If we haven't reached a match, step some more. |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
455 (while (and (< n len) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
456 (not (string-match regexp (ring-ref comint-input-ring n)))) |
4513 | 457 (setq n (mod (+ n motion) len)) |
2673
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
458 ;; If we have gone all the way around in this search, error. |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
459 (if (= n prev) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
460 (error "Not found")))) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
461 (setq arg (if (> arg 0) (1- arg) (1+ arg)))) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
462 ;; Now that we know which ring element to use, |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
463 ;; substitute that for the current input. |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
464 (comint-previous-input (- n comint-input-ring-index)))) |
584 | 465 |
2673
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
466 (defun comint-next-matching-input (regexp arg) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
467 "Search forwards through input history for match for REGEXP. |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
468 \(Later history elements are more recent commands.) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
469 With prefix argument N, search for Nth following match. |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
470 If N is negative, find the previous or Nth previous match." |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
471 (interactive |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
472 (let ((minibuffer-history-sexp-flag nil) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
473 ;; Don't clobber this. |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
474 (last-command last-command) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
475 (regexp (read-from-minibuffer "Previous input matching (regexp): " |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
476 nil |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
477 minibuffer-local-map |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
478 nil |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
479 'minibuffer-history-search-history))) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
480 (list (if (string= regexp "") |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
481 (setcar minibuffer-history-search-history |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
482 (nth 1 minibuffer-history-search-history)) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
483 regexp) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
484 (prefix-numeric-value current-prefix-arg)))) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
485 (comint-previous-matching-input regexp (- arg))) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
486 |
584 | 487 ;;; These next three commands are alternatives to the input history commands |
2673
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
488 ;;; They search through the process buffer |
584 | 489 ;;; text looking for occurrences of the prompt. Bound to M-P, M-N, and C-c R |
490 ;;; (uppercase P, N, and R) for now. Try'em out. Go with what you like... | |
491 | |
492 ;;; comint-msearch-input-matching prompts for a string, not a regexp. | |
493 ;;; This could be considered to be the wrong thing. I decided to keep it | |
494 ;;; simple, and not make the user worry about regexps. This, of course, | |
495 ;;; limits functionality. | |
496 | |
497 ;;; These commands were deemed non-winning and have been commented out. | |
498 ;;; Feel free to re-enable them if you like. -Olin 3/91 | |
499 | |
500 ;(defun comint-psearch-input () | |
501 ; "Search forwards for next occurrence of prompt and skip to end of line. | |
502 ;\(prompt is anything matching regexp comint-prompt-regexp)" | |
503 ; (interactive) | |
504 ; (if (re-search-forward comint-prompt-regexp (point-max) t) | |
505 ; (end-of-line) | |
506 ; (error "No occurrence of prompt found"))) | |
507 ; | |
508 ;(defun comint-msearch-input () | |
509 ; "Search backwards for previous occurrence of prompt and skip to end of line. | |
510 ;Search starts from beginning of current line." | |
511 ; (interactive) | |
512 ; (let ((p (save-excursion | |
513 ; (beginning-of-line) | |
514 ; (cond ((re-search-backward comint-prompt-regexp (point-min) t) | |
515 ; (end-of-line) | |
516 ; (point)) | |
517 ; (t nil))))) | |
518 ; (if p (goto-char p) | |
519 ; (error "No occurrence of prompt found")))) | |
520 ; | |
521 ;(defun comint-msearch-input-matching (str) | |
522 ; "Search backwards for occurrence of prompt followed by STRING. | |
523 ;STRING is prompted for, and is NOT a regular expression." | |
524 ; (interactive (let ((s (read-from-minibuffer | |
525 ; (format "Command (default %s): " | |
526 ; comint-last-input-match)))) | |
527 ; (list (if (string= s "") comint-last-input-match s)))) | |
528 ;; (interactive "sCommand: ") | |
529 ; (setq comint-last-input-match str) ; update default | |
530 ; (let* ((r (concat comint-prompt-regexp (regexp-quote str))) | |
531 ; (p (save-excursion | |
532 ; (beginning-of-line) | |
533 ; (cond ((re-search-backward r (point-min) t) | |
534 ; (end-of-line) | |
535 ; (point)) | |
536 ; (t nil))))) | |
537 ; (if p (goto-char p) | |
538 ; (error "No match")))) | |
114 | 539 |
540 ;;; | |
541 ;;; Similar input -- contributed by ccm and highly winning. | |
542 ;;; | |
543 ;;; Reenter input, removing back to the last insert point if it exists. | |
544 ;;; | |
2673
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
545 ;;(defvar comint-last-similar-string "" |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
546 ;; "The string last used in a similar string search.") |
584 | 547 |
2673
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
548 ;;(defun comint-previous-similar-input (arg) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
549 ;; "Fetch the previous (older) input that matches the string typed so far. |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
550 ;;Successive repetitions find successively older matching inputs. |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
551 ;;A prefix argument serves as a repeat count; a negative argument |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
552 ;;fetches following (more recent) inputs." |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
553 ;; (interactive "p") |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
554 ;; (if (not (comint-after-pmark-p)) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
555 ;; (error "Not after process mark")) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
556 ;; (if (null comint-input-ring-index) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
557 ;; (setq comint-input-ring-index |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
558 ;; (if (> arg 0) -1 |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
559 ;; (if (< arg 0) 1 0)))) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
560 ;; (if (not (or (eq last-command 'comint-previous-similar-input) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
561 ;; (eq last-command 'comint-next-similar-input))) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
562 ;; (setq comint-last-similar-string |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
563 ;; (buffer-substring |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
564 ;; (process-mark (get-buffer-process (current-buffer))) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
565 ;; (point)))) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
566 ;; (let* ((size (length comint-last-similar-string)) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
567 ;; (len (ring-length comint-input-ring)) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
568 ;; (n (+ comint-input-ring-index arg)) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
569 ;; entry) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
570 ;; (while (and (< n len) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
571 ;; (or (< (length (setq entry (ring-ref comint-input-ring n))) size) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
572 ;; (not (equal comint-last-similar-string |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
573 ;; (substring entry 0 size))))) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
574 ;; (setq n (+ n arg))) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
575 ;; (cond ((< n len) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
576 ;; (setq comint-input-ring-index n) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
577 ;; (if (or (eq last-command 'comint-previous-similar-input) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
578 ;; (eq last-command 'comint-next-similar-input)) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
579 ;; (delete-region (mark) (point)) ; repeat |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
580 ;; (push-mark (point))) ; 1st time |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
581 ;; (insert (substring entry size))) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
582 ;; (t (error "Not found"))) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
583 ;; (message "%d" (1+ comint-input-ring-index)))) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
584 |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
585 ;;(defun comint-next-similar-input (arg) |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
586 ;; "Fetch the next (newer) input that matches the string typed so far. |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
587 ;;Successive repetitions find successively newer matching inputs. |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
588 ;;A prefix argument serves as a repeat count; a negative argument |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
589 ;;fetches previous (older) inputs." |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
590 ;; (interactive "p") |
27dd7479b158
(comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents:
2627
diff
changeset
|
591 ;; (comint-previous-similar-input (- arg))) |
114 | 592 |
584 | 593 (defun comint-send-input () |
1356 | 594 "Send input to process. |
595 After the process output mark, sends all text from the process mark to | |
596 point as input to the process. Before the process output mark, calls value | |
2539
577c77cfd199
*** empty log message ***
Noah Friedman <friedman@splode.com>
parents:
2518
diff
changeset
|
597 of variable `comint-get-old-input' to retrieve old input, copies it to the |
3386
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
598 process mark, and sends it. If variable `comint-process-echoes' is nil, |
2539
577c77cfd199
*** empty log message ***
Noah Friedman <friedman@splode.com>
parents:
2518
diff
changeset
|
599 a terminal newline is also inserted into the buffer and sent to the process |
3386
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
600 \(if it is non-nil, all text from the process mark to point is deleted, |
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
601 since it is assumed the remote process will re-echo it). |
114 | 602 |
3386
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
603 The value of variable `comint-input-sentinel' is called on the input |
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
604 before sending it. The input is entered into the input history ring, |
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
605 if the value of variable `comint-input-filter' returns non-nil when |
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
606 called on the input. |
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
607 |
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
608 If variable `comint-eol-on-send' is non-nil, then point is moved to the |
2539
577c77cfd199
*** empty log message ***
Noah Friedman <friedman@splode.com>
parents:
2518
diff
changeset
|
609 end of line before sending the input. |
114 | 610 |
2539
577c77cfd199
*** empty log message ***
Noah Friedman <friedman@splode.com>
parents:
2518
diff
changeset
|
611 `comint-get-old-input', `comint-input-sentinel', and `comint-input-filter' |
577c77cfd199
*** empty log message ***
Noah Friedman <friedman@splode.com>
parents:
2518
diff
changeset
|
612 are chosen according to the command interpreter running in the buffer. E.g., |
114 | 613 If the interpreter is the csh, |
584 | 614 comint-get-old-input is the default: take the current line, discard any |
615 initial string matching regexp comint-prompt-regexp. | |
616 comint-input-sentinel monitors input for \"cd\", \"pushd\", and \"popd\" | |
617 commands. When it sees one, it cd's the buffer. | |
618 comint-input-filter is the default: returns T if the input isn't all white | |
619 space. | |
114 | 620 |
621 If the comint is Lucid Common Lisp, | |
584 | 622 comint-get-old-input snarfs the sexp ending at point. |
623 comint-input-sentinel does nothing. | |
624 comint-input-filter returns NIL if the input matches input-filter-regexp, | |
114 | 625 which matches (1) all whitespace (2) :a, :c, etc. |
626 | |
909
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
870
diff
changeset
|
627 Similarly for Soar, Scheme, etc." |
114 | 628 (interactive) |
629 ;; Note that the input string does not include its terminal newline. | |
584 | 630 (let ((proc (get-buffer-process (current-buffer)))) |
631 (if (not proc) (error "Current buffer has no process") | |
632 (let* ((pmark (process-mark proc)) | |
633 (pmark-val (marker-position pmark)) | |
634 (input (if (>= (point) pmark-val) | |
635 (progn (if comint-eol-on-send (end-of-line)) | |
636 (buffer-substring pmark (point))) | |
705 | 637 (let ((copy (funcall comint-get-old-input))) |
638 (goto-char pmark) | |
639 (insert copy) | |
640 copy)))) | |
2539
577c77cfd199
*** empty log message ***
Noah Friedman <friedman@splode.com>
parents:
2518
diff
changeset
|
641 (if comint-process-echoes |
577c77cfd199
*** empty log message ***
Noah Friedman <friedman@splode.com>
parents:
2518
diff
changeset
|
642 (delete-region pmark (point)) |
577c77cfd199
*** empty log message ***
Noah Friedman <friedman@splode.com>
parents:
2518
diff
changeset
|
643 (insert ?\n)) |
861
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
644 (if (funcall comint-input-filter input) |
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
645 (ring-insert comint-input-ring input)) |
584 | 646 (funcall comint-input-sentinel input) |
647 (funcall comint-input-sender proc input) | |
909
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
870
diff
changeset
|
648 (setq comint-input-ring-index nil) |
705 | 649 (set-marker comint-last-input-start pmark) |
650 (set-marker comint-last-input-end (point)) | |
651 (set-marker (process-mark proc) (point)))))) | |
114 | 652 |
2683
21ab70613c42
(comint-filter): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2680
diff
changeset
|
653 ;; The sole purpose of using this filter for comint processes |
21ab70613c42
(comint-filter): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2680
diff
changeset
|
654 ;; is to keep comint-last-input-end from moving forward |
21ab70613c42
(comint-filter): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2680
diff
changeset
|
655 ;; when output is inserted. |
21ab70613c42
(comint-filter): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2680
diff
changeset
|
656 (defun comint-filter (process string) |
21ab70613c42
(comint-filter): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2680
diff
changeset
|
657 (let ((obuf (current-buffer)) |
21ab70613c42
(comint-filter): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2680
diff
changeset
|
658 opoint obeg oend) |
21ab70613c42
(comint-filter): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2680
diff
changeset
|
659 (set-buffer (process-buffer process)) |
21ab70613c42
(comint-filter): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2680
diff
changeset
|
660 (setq opoint (point)) |
21ab70613c42
(comint-filter): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2680
diff
changeset
|
661 (setq obeg (point-min)) |
21ab70613c42
(comint-filter): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2680
diff
changeset
|
662 (setq oend (point-max)) |
21ab70613c42
(comint-filter): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2680
diff
changeset
|
663 (let ((buffer-read-only nil) |
21ab70613c42
(comint-filter): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2680
diff
changeset
|
664 (nchars (length string))) |
21ab70613c42
(comint-filter): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2680
diff
changeset
|
665 (widen) |
21ab70613c42
(comint-filter): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2680
diff
changeset
|
666 (goto-char (process-mark process)) |
2749
305044e75269
(comint-filter): Increment opoint only if after insertion point.
Richard M. Stallman <rms@gnu.org>
parents:
2683
diff
changeset
|
667 (if (<= (point) opoint) |
305044e75269
(comint-filter): Increment opoint only if after insertion point.
Richard M. Stallman <rms@gnu.org>
parents:
2683
diff
changeset
|
668 (setq opoint (+ opoint nchars))) |
2683
21ab70613c42
(comint-filter): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2680
diff
changeset
|
669 ;; Insert after old_begv, but before old_zv. |
21ab70613c42
(comint-filter): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2680
diff
changeset
|
670 (if (< (point) obeg) |
21ab70613c42
(comint-filter): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2680
diff
changeset
|
671 (setq obeg (+ obeg nchars))) |
21ab70613c42
(comint-filter): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2680
diff
changeset
|
672 (if (<= (point) oend) |
21ab70613c42
(comint-filter): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2680
diff
changeset
|
673 (setq oend (+ oend nchars))) |
21ab70613c42
(comint-filter): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2680
diff
changeset
|
674 |
21ab70613c42
(comint-filter): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2680
diff
changeset
|
675 (insert-before-markers string) |
3386
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
676 ;; Don't insert initial prompt outside the top of the window. |
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
677 (if (= (window-start (selected-window)) (point)) |
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
678 (set-window-start (selected-window) (- (point) (length string)))) |
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
679 |
2683
21ab70613c42
(comint-filter): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2680
diff
changeset
|
680 (and comint-last-input-end |
21ab70613c42
(comint-filter): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2680
diff
changeset
|
681 (marker-buffer comint-last-input-end) |
21ab70613c42
(comint-filter): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2680
diff
changeset
|
682 (= (point) comint-last-input-end) |
21ab70613c42
(comint-filter): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2680
diff
changeset
|
683 (set-marker comint-last-input-end |
21ab70613c42
(comint-filter): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2680
diff
changeset
|
684 (- comint-last-input-end nchars))) |
21ab70613c42
(comint-filter): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2680
diff
changeset
|
685 (set-marker (process-mark process) (point) nil) |
3113
598d05b3eb3b
(comint-filter): Restore buffer-read-only in proper buffer.
Richard M. Stallman <rms@gnu.org>
parents:
2749
diff
changeset
|
686 (force-mode-line-update)) |
2683
21ab70613c42
(comint-filter): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2680
diff
changeset
|
687 |
3113
598d05b3eb3b
(comint-filter): Restore buffer-read-only in proper buffer.
Richard M. Stallman <rms@gnu.org>
parents:
2749
diff
changeset
|
688 (narrow-to-region obeg oend) |
598d05b3eb3b
(comint-filter): Restore buffer-read-only in proper buffer.
Richard M. Stallman <rms@gnu.org>
parents:
2749
diff
changeset
|
689 (goto-char opoint) |
598d05b3eb3b
(comint-filter): Restore buffer-read-only in proper buffer.
Richard M. Stallman <rms@gnu.org>
parents:
2749
diff
changeset
|
690 (set-buffer obuf))) |
2683
21ab70613c42
(comint-filter): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2680
diff
changeset
|
691 |
114 | 692 (defun comint-get-old-input-default () |
3386
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
693 "Default for `comint-get-old-input'. |
1356 | 694 Take the current line, and discard any initial text matching |
3386
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
695 `comint-prompt-regexp'." |
114 | 696 (save-excursion |
584 | 697 (beginning-of-line) |
698 (comint-skip-prompt) | |
699 (let ((beg (point))) | |
700 (end-of-line) | |
701 (buffer-substring beg (point))))) | |
702 | |
703 (defun comint-skip-prompt () | |
3386
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
704 "Skip past the text matching regexp `comint-prompt-regexp'. |
584 | 705 If this takes us past the end of the current line, don't skip at all." |
706 (let ((eol (save-excursion (end-of-line) (point)))) | |
707 (if (and (looking-at comint-prompt-regexp) | |
708 (<= (match-end 0) eol)) | |
709 (goto-char (match-end 0))))) | |
710 | |
711 | |
712 (defun comint-after-pmark-p () | |
713 "Is point after the process output marker?" | |
714 ;; Since output could come into the buffer after we looked at the point | |
715 ;; but before we looked at the process marker's value, we explicitly | |
716 ;; serialise. This is just because I don't know whether or not emacs | |
717 ;; services input during execution of lisp commands. | |
718 (let ((proc-pos (marker-position | |
719 (process-mark (get-buffer-process (current-buffer)))))) | |
720 (<= proc-pos (point)))) | |
721 | |
722 (defun comint-simple-send (proc string) | |
723 "Default function for sending to PROC input STRING. | |
724 This just sends STRING plus a newline. To override this, | |
3386
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
725 set the hook `comint-input-sender'." |
584 | 726 (comint-send-string proc string) |
727 (comint-send-string proc "\n")) | |
114 | 728 |
729 (defun comint-bol (arg) | |
730 "Goes to the beginning of line, then skips past the prompt, if any. | |
584 | 731 If a prefix argument is given (\\[universal-argument]), then no prompt skip |
732 -- go straight to column 0. | |
114 | 733 |
584 | 734 The prompt skip is done by skipping text matching the regular expression |
3386
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
735 `comint-prompt-regexp', a buffer local variable. |
584 | 736 |
3386
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
737 If you don't like this command, bind C-a to `beginning-of-line' |
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
738 in your hook, `comint-mode-hook'." |
114 | 739 (interactive "P") |
740 (beginning-of-line) | |
584 | 741 (if (null arg) (comint-skip-prompt))) |
114 | 742 |
743 ;;; These two functions are for entering text you don't want echoed or | |
744 ;;; saved -- typically passwords to ftp, telnet, or somesuch. | |
584 | 745 ;;; Just enter m-x send-invisible and type in your line. |
746 | |
705 | 747 (defun comint-read-noecho (prompt &optional stars) |
2455
27d28402ee59
new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents:
2307
diff
changeset
|
748 "Read a single line of text from user without echoing, and return it. |
27d28402ee59
new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents:
2307
diff
changeset
|
749 Prompt with argument PROMPT, a string. Optional argument STARS causes |
27d28402ee59
new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents:
2307
diff
changeset
|
750 input to be echoed with '*' characters on the prompt line. Input ends with |
27d28402ee59
new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents:
2307
diff
changeset
|
751 RET, LFD, or ESC. DEL or C-h rubs out. C-u kills line. C-g aborts (if |
3386
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
752 `inhibit-quit' is set because e.g. this function was called from a process |
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
753 filter and C-g is pressed, this function returns nil rather than a string). |
2455
27d28402ee59
new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents:
2307
diff
changeset
|
754 |
27d28402ee59
new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents:
2307
diff
changeset
|
755 Note that the keystrokes comprising the text can still be recovered |
3386
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
756 \(temporarily) with \\[view-lossage]. This may be a security bug for some |
2455
27d28402ee59
new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents:
2307
diff
changeset
|
757 applications." |
27d28402ee59
new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents:
2307
diff
changeset
|
758 (let ((ans "") |
27d28402ee59
new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents:
2307
diff
changeset
|
759 (c 0) |
27d28402ee59
new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents:
2307
diff
changeset
|
760 (echo-keystrokes 0) |
705 | 761 (cursor-in-echo-area t) |
2455
27d28402ee59
new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents:
2307
diff
changeset
|
762 (done nil)) |
27d28402ee59
new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents:
2307
diff
changeset
|
763 (while (not done) |
27d28402ee59
new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents:
2307
diff
changeset
|
764 (if stars |
27d28402ee59
new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents:
2307
diff
changeset
|
765 (message "%s%s" prompt (make-string (length ans) ?*)) |
27d28402ee59
new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents:
2307
diff
changeset
|
766 (message prompt)) |
27d28402ee59
new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents:
2307
diff
changeset
|
767 (setq c (read-char)) |
27d28402ee59
new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents:
2307
diff
changeset
|
768 (cond ((= c ?\C-g) |
27d28402ee59
new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents:
2307
diff
changeset
|
769 ;; This function may get called from a process filter, where |
27d28402ee59
new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents:
2307
diff
changeset
|
770 ;; inhibit-quit is set. In later versions of emacs read-char |
27d28402ee59
new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents:
2307
diff
changeset
|
771 ;; may clear quit-flag itself and return C-g. That would make |
27d28402ee59
new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents:
2307
diff
changeset
|
772 ;; it impossible to quit this loop in a simple way, so |
27d28402ee59
new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents:
2307
diff
changeset
|
773 ;; re-enable it here (for backward-compatibility the check for |
27d28402ee59
new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents:
2307
diff
changeset
|
774 ;; quit-flag below would still be necessary, so this is seems |
27d28402ee59
new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents:
2307
diff
changeset
|
775 ;; like the simplest way to do things). |
27d28402ee59
new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents:
2307
diff
changeset
|
776 (setq quit-flag t |
27d28402ee59
new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents:
2307
diff
changeset
|
777 done t)) |
27d28402ee59
new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents:
2307
diff
changeset
|
778 ((or (= c ?\r) (= c ?\n) (= c ?\e)) |
27d28402ee59
new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents:
2307
diff
changeset
|
779 (setq done t)) |
27d28402ee59
new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents:
2307
diff
changeset
|
780 ((= c ?\C-u) |
27d28402ee59
new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents:
2307
diff
changeset
|
781 (setq ans "")) |
27d28402ee59
new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents:
2307
diff
changeset
|
782 ((and (/= c ?\b) (/= c ?\177)) |
27d28402ee59
new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents:
2307
diff
changeset
|
783 (setq ans (concat ans (char-to-string c)))) |
27d28402ee59
new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents:
2307
diff
changeset
|
784 ((> (length ans) 0) |
27d28402ee59
new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents:
2307
diff
changeset
|
785 (setq ans (substring ans 0 -1))))) |
27d28402ee59
new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents:
2307
diff
changeset
|
786 (if quit-flag |
27d28402ee59
new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents:
2307
diff
changeset
|
787 ;; Emulate a true quit, except that we have to return a value. |
27d28402ee59
new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents:
2307
diff
changeset
|
788 (prog1 |
27d28402ee59
new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents:
2307
diff
changeset
|
789 (setq quit-flag nil) |
27d28402ee59
new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents:
2307
diff
changeset
|
790 (message "Quit") |
27d28402ee59
new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents:
2307
diff
changeset
|
791 (beep t)) |
27d28402ee59
new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents:
2307
diff
changeset
|
792 (message "") |
27d28402ee59
new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents:
2307
diff
changeset
|
793 ans))) |
705 | 794 |
114 | 795 (defun send-invisible (str) |
1356 | 796 "Read a string without echoing. |
3386
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
797 Then send it to the process running in the current buffer. A new-line |
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
798 is additionally sent. String is not saved on comint input history list. |
584 | 799 Security bug: your string can still be temporarily recovered with |
800 \\[view-lossage]." | |
114 | 801 ; (interactive (list (comint-read-noecho "Enter non-echoed text"))) |
802 (interactive "P") ; Defeat snooping via C-x esc | |
803 (let ((proc (get-buffer-process (current-buffer)))) | |
804 (if (not proc) (error "Current buffer has no process") | |
805 (comint-send-string proc | |
806 (if (stringp str) str | |
705 | 807 (comint-read-noecho "Non-echoed text: " t))) |
114 | 808 (comint-send-string proc "\n")))) |
809 | |
810 | |
811 ;;; Low-level process communication | |
812 | |
813 (defvar comint-input-chunk-size 512 | |
3386
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
814 "*Long inputs are sent to comint processes in chunks of this size. |
114 | 815 If your process is choking on big inputs, try lowering the value.") |
816 | |
817 (defun comint-send-string (proc str) | |
818 "Send PROCESS the contents of STRING as input. | |
3386
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
819 This is equivalent to `process-send-string', except that long input strings |
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
820 are broken up into chunks of size `comint-input-chunk-size'. Processes |
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
821 are given a chance to output between chunks. This can help prevent processes |
114 | 822 from hanging when you send them long inputs on some OS's." |
823 (let* ((len (length str)) | |
824 (i (min len comint-input-chunk-size))) | |
825 (process-send-string proc (substring str 0 i)) | |
826 (while (< i len) | |
827 (let ((next-i (+ i comint-input-chunk-size))) | |
828 (accept-process-output) | |
829 (process-send-string proc (substring str i (min len next-i))) | |
830 (setq i next-i))))) | |
831 | |
832 (defun comint-send-region (proc start end) | |
833 "Sends to PROC the region delimited by START and END. | |
3386
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
834 This is a replacement for `process-send-region' that tries to keep |
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
835 your process from hanging on long inputs. See `comint-send-string'." |
114 | 836 (comint-send-string proc (buffer-substring start end))) |
837 | |
838 | |
839 ;;; Random input hackage | |
840 | |
584 | 841 (defun comint-kill-output () |
114 | 842 "Kill all output from interpreter since last input." |
843 (interactive) | |
584 | 844 (let ((pmark (process-mark (get-buffer-process (current-buffer))))) |
845 (kill-region comint-last-input-end pmark) | |
846 (goto-char pmark) | |
847 (insert "*** output flushed ***\n") | |
848 (set-marker pmark (point)))) | |
114 | 849 |
850 (defun comint-show-output () | |
584 | 851 "Display start of this batch of interpreter output at top of window. |
852 Also put cursor there." | |
114 | 853 (interactive) |
854 (goto-char comint-last-input-end) | |
584 | 855 (backward-char) |
114 | 856 (beginning-of-line) |
857 (set-window-start (selected-window) (point)) | |
584 | 858 (end-of-line)) |
114 | 859 |
860 (defun comint-interrupt-subjob () | |
584 | 861 "Interrupt the current subjob." |
114 | 862 (interactive) |
584 | 863 (interrupt-process nil comint-ptyp)) |
114 | 864 |
865 (defun comint-kill-subjob () | |
584 | 866 "Send kill signal to the current subjob." |
114 | 867 (interactive) |
584 | 868 (kill-process nil comint-ptyp)) |
114 | 869 |
870 (defun comint-quit-subjob () | |
584 | 871 "Send quit signal to the current subjob." |
114 | 872 (interactive) |
584 | 873 (quit-process nil comint-ptyp)) |
114 | 874 |
875 (defun comint-stop-subjob () | |
584 | 876 "Stop the current subjob. |
114 | 877 WARNING: if there is no current subjob, you can end up suspending |
584 | 878 the top-level process running in the buffer. If you accidentally do |
879 this, use \\[comint-continue-subjob] to resume the process. (This | |
880 is not a problem with most shells, since they ignore this signal.)" | |
114 | 881 (interactive) |
584 | 882 (stop-process nil comint-ptyp)) |
114 | 883 |
884 (defun comint-continue-subjob () | |
584 | 885 "Send CONT signal to process buffer's process group. |
114 | 886 Useful if you accidentally suspend the top-level process." |
887 (interactive) | |
584 | 888 (continue-process nil comint-ptyp)) |
114 | 889 |
890 (defun comint-kill-input () | |
584 | 891 "Kill all text from last stuff output by interpreter to point." |
114 | 892 (interactive) |
584 | 893 (let* ((pmark (process-mark (get-buffer-process (current-buffer)))) |
894 (p-pos (marker-position pmark))) | |
895 (if (> (point) p-pos) | |
896 (kill-region pmark (point))))) | |
114 | 897 |
898 (defun comint-delchar-or-maybe-eof (arg) | |
899 "Delete ARG characters forward, or send an EOF to process if at end of buffer." | |
900 (interactive "p") | |
901 (if (eobp) | |
902 (process-send-eof) | |
584 | 903 (delete-char arg))) |
904 | |
4112
ab7dee78e335
(comint-{next,prev}-prompt, comint-send-eof): New functions.
Roland McGrath <roland@gnu.org>
parents:
3985
diff
changeset
|
905 (defun comint-send-eof () |
ab7dee78e335
(comint-{next,prev}-prompt, comint-send-eof): New functions.
Roland McGrath <roland@gnu.org>
parents:
3985
diff
changeset
|
906 "Send an EOF to the current buffer's process." |
ab7dee78e335
(comint-{next,prev}-prompt, comint-send-eof): New functions.
Roland McGrath <roland@gnu.org>
parents:
3985
diff
changeset
|
907 (interactive) |
ab7dee78e335
(comint-{next,prev}-prompt, comint-send-eof): New functions.
Roland McGrath <roland@gnu.org>
parents:
3985
diff
changeset
|
908 (process-send-eof)) |
584 | 909 |
4112
ab7dee78e335
(comint-{next,prev}-prompt, comint-send-eof): New functions.
Roland McGrath <roland@gnu.org>
parents:
3985
diff
changeset
|
910 (defun comint-next-prompt (n) |
ab7dee78e335
(comint-{next,prev}-prompt, comint-send-eof): New functions.
Roland McGrath <roland@gnu.org>
parents:
3985
diff
changeset
|
911 "\ |
ab7dee78e335
(comint-{next,prev}-prompt, comint-send-eof): New functions.
Roland McGrath <roland@gnu.org>
parents:
3985
diff
changeset
|
912 Move to end of next prompt in the buffer (with prefix arg, Nth next). |
ab7dee78e335
(comint-{next,prev}-prompt, comint-send-eof): New functions.
Roland McGrath <roland@gnu.org>
parents:
3985
diff
changeset
|
913 See `comint-prompt-regexp'." |
ab7dee78e335
(comint-{next,prev}-prompt, comint-send-eof): New functions.
Roland McGrath <roland@gnu.org>
parents:
3985
diff
changeset
|
914 (interactive "p") |
ab7dee78e335
(comint-{next,prev}-prompt, comint-send-eof): New functions.
Roland McGrath <roland@gnu.org>
parents:
3985
diff
changeset
|
915 (re-search-forward comint-prompt-regexp nil nil n)) |
584 | 916 |
4112
ab7dee78e335
(comint-{next,prev}-prompt, comint-send-eof): New functions.
Roland McGrath <roland@gnu.org>
parents:
3985
diff
changeset
|
917 (defun comint-prev-prompt (n) |
ab7dee78e335
(comint-{next,prev}-prompt, comint-send-eof): New functions.
Roland McGrath <roland@gnu.org>
parents:
3985
diff
changeset
|
918 "\ |
ab7dee78e335
(comint-{next,prev}-prompt, comint-send-eof): New functions.
Roland McGrath <roland@gnu.org>
parents:
3985
diff
changeset
|
919 Move to end of previous prompt in the buffer (with prefix arg, Nth previous). |
ab7dee78e335
(comint-{next,prev}-prompt, comint-send-eof): New functions.
Roland McGrath <roland@gnu.org>
parents:
3985
diff
changeset
|
920 See `comint-prompt-regexp'." |
ab7dee78e335
(comint-{next,prev}-prompt, comint-send-eof): New functions.
Roland McGrath <roland@gnu.org>
parents:
3985
diff
changeset
|
921 (interactive "p") |
ab7dee78e335
(comint-{next,prev}-prompt, comint-send-eof): New functions.
Roland McGrath <roland@gnu.org>
parents:
3985
diff
changeset
|
922 (if (= (save-excursion (re-search-backward comint-prompt-regexp nil t) |
ab7dee78e335
(comint-{next,prev}-prompt, comint-send-eof): New functions.
Roland McGrath <roland@gnu.org>
parents:
3985
diff
changeset
|
923 (match-end 0)) |
ab7dee78e335
(comint-{next,prev}-prompt, comint-send-eof): New functions.
Roland McGrath <roland@gnu.org>
parents:
3985
diff
changeset
|
924 (point)) |
ab7dee78e335
(comint-{next,prev}-prompt, comint-send-eof): New functions.
Roland McGrath <roland@gnu.org>
parents:
3985
diff
changeset
|
925 (setq n (1+ n))) |
ab7dee78e335
(comint-{next,prev}-prompt, comint-send-eof): New functions.
Roland McGrath <roland@gnu.org>
parents:
3985
diff
changeset
|
926 (re-search-backward comint-prompt-regexp nil nil n) |
ab7dee78e335
(comint-{next,prev}-prompt, comint-send-eof): New functions.
Roland McGrath <roland@gnu.org>
parents:
3985
diff
changeset
|
927 (goto-char (match-end 0))) |
114 | 928 |
929 ;;; Support for source-file processing commands. | |
930 ;;;============================================================================ | |
931 ;;; Many command-interpreters (e.g., Lisp, Scheme, Soar) have | |
932 ;;; commands that process files of source text (e.g. loading or compiling | |
933 ;;; files). So the corresponding process-in-a-buffer modes have commands | |
934 ;;; for doing this (e.g., lisp-load-file). The functions below are useful | |
935 ;;; for defining these commands. | |
936 ;;; | |
937 ;;; Alas, these guys don't do exactly the right thing for Lisp, Scheme | |
938 ;;; and Soar, in that they don't know anything about file extensions. | |
939 ;;; So the compile/load interface gets the wrong default occasionally. | |
940 ;;; The load-file/compile-file default mechanism could be smarter -- it | |
941 ;;; doesn't know about the relationship between filename extensions and | |
942 ;;; whether the file is source or executable. If you compile foo.lisp | |
943 ;;; with compile-file, then the next load-file should use foo.bin for | |
944 ;;; the default, not foo.lisp. This is tricky to do right, particularly | |
945 ;;; because the extension for executable files varies so much (.o, .bin, | |
946 ;;; .lbin, .mo, .vo, .ao, ...). | |
947 | |
948 | |
949 ;;; COMINT-SOURCE-DEFAULT -- determines defaults for source-file processing | |
950 ;;; commands. | |
951 ;;; | |
952 ;;; COMINT-CHECK-SOURCE -- if FNAME is in a modified buffer, asks you if you | |
953 ;;; want to save the buffer before issuing any process requests to the command | |
954 ;;; interpreter. | |
955 ;;; | |
956 ;;; COMINT-GET-SOURCE -- used by the source-file processing commands to prompt | |
957 ;;; for the file to process. | |
958 | |
959 ;;; (COMINT-SOURCE-DEFAULT previous-dir/file source-modes) | |
960 ;;;============================================================================ | |
961 ;;; This function computes the defaults for the load-file and compile-file | |
584 | 962 ;;; commands for tea, soar, cmulisp, and cmuscheme modes. |
114 | 963 ;;; |
964 ;;; - PREVIOUS-DIR/FILE is a pair (directory . filename) from the last | |
965 ;;; source-file processing command. NIL if there hasn't been one yet. | |
966 ;;; - SOURCE-MODES is a list used to determine what buffers contain source | |
967 ;;; files: if the major mode of the buffer is in SOURCE-MODES, it's source. | |
968 ;;; Typically, (lisp-mode) or (scheme-mode). | |
969 ;;; | |
970 ;;; If the command is given while the cursor is inside a string, *and* | |
971 ;;; the string is an existing filename, *and* the filename is not a directory, | |
972 ;;; then the string is taken as default. This allows you to just position | |
973 ;;; your cursor over a string that's a filename and have it taken as default. | |
974 ;;; | |
975 ;;; If the command is given in a file buffer whose major mode is in | |
976 ;;; SOURCE-MODES, then the the filename is the default file, and the | |
977 ;;; file's directory is the default directory. | |
978 ;;; | |
979 ;;; If the buffer isn't a source file buffer (e.g., it's the process buffer), | |
980 ;;; then the default directory & file are what was used in the last source-file | |
981 ;;; processing command (i.e., PREVIOUS-DIR/FILE). If this is the first time | |
982 ;;; the command has been run (PREVIOUS-DIR/FILE is nil), the default directory | |
983 ;;; is the cwd, with no default file. (\"no default file\" = nil) | |
984 ;;; | |
985 ;;; SOURCE-REGEXP is typically going to be something like (tea-mode) | |
986 ;;; for T programs, (lisp-mode) for Lisp programs, (soar-mode lisp-mode) | |
987 ;;; for Soar programs, etc. | |
988 ;;; | |
989 ;;; The function returns a pair: (default-directory . default-file). | |
990 | |
991 (defun comint-source-default (previous-dir/file source-modes) | |
992 (cond ((and buffer-file-name (memq major-mode source-modes)) | |
993 (cons (file-name-directory buffer-file-name) | |
994 (file-name-nondirectory buffer-file-name))) | |
995 (previous-dir/file) | |
996 (t | |
997 (cons default-directory nil)))) | |
998 | |
584 | 999 |
114 | 1000 ;;; (COMINT-CHECK-SOURCE fname) |
1001 ;;;============================================================================ | |
584 | 1002 ;;; Prior to loading or compiling (or otherwise processing) a file (in the CMU |
114 | 1003 ;;; process-in-a-buffer modes), this function can be called on the filename. |
1004 ;;; If the file is loaded into a buffer, and the buffer is modified, the user | |
1005 ;;; is queried to see if he wants to save the buffer before proceeding with | |
1006 ;;; the load or compile. | |
1007 | |
1008 (defun comint-check-source (fname) | |
1009 (let ((buff (get-file-buffer fname))) | |
1010 (if (and buff | |
1011 (buffer-modified-p buff) | |
1012 (y-or-n-p (format "Save buffer %s first? " | |
1013 (buffer-name buff)))) | |
1014 ;; save BUFF. | |
1015 (let ((old-buffer (current-buffer))) | |
1016 (set-buffer buff) | |
1017 (save-buffer) | |
1018 (set-buffer old-buffer))))) | |
1019 | |
584 | 1020 |
114 | 1021 ;;; (COMINT-GET-SOURCE prompt prev-dir/file source-modes mustmatch-p) |
1022 ;;;============================================================================ | |
1023 ;;; COMINT-GET-SOURCE is used to prompt for filenames in command-interpreter | |
1024 ;;; commands that process source files (like loading or compiling a file). | |
1025 ;;; It prompts for the filename, provides a default, if there is one, | |
1026 ;;; and returns the result filename. | |
1027 ;;; | |
1028 ;;; See COMINT-SOURCE-DEFAULT for more on determining defaults. | |
1029 ;;; | |
1030 ;;; PROMPT is the prompt string. PREV-DIR/FILE is the (directory . file) pair | |
1031 ;;; from the last source processing command. SOURCE-MODES is a list of major | |
1032 ;;; modes used to determine what file buffers contain source files. (These | |
1033 ;;; two arguments are used for determining defaults). If MUSTMATCH-P is true, | |
1034 ;;; then the filename reader will only accept a file that exists. | |
1035 ;;; | |
1036 ;;; A typical use: | |
1037 ;;; (interactive (comint-get-source "Compile file: " prev-lisp-dir/file | |
1038 ;;; '(lisp-mode) t)) | |
1039 | |
1040 ;;; This is pretty stupid about strings. It decides we're in a string | |
1041 ;;; if there's a quote on both sides of point on the current line. | |
1042 (defun comint-extract-string () | |
3386
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
1043 "Return string around POINT that starts the current line, or nil." |
114 | 1044 (save-excursion |
1045 (let* ((point (point)) | |
1046 (bol (progn (beginning-of-line) (point))) | |
1047 (eol (progn (end-of-line) (point))) | |
1048 (start (progn (goto-char point) | |
1049 (and (search-backward "\"" bol t) | |
1050 (1+ (point))))) | |
1051 (end (progn (goto-char point) | |
1052 (and (search-forward "\"" eol t) | |
1053 (1- (point)))))) | |
1054 (and start end | |
1055 (buffer-substring start end))))) | |
1056 | |
1057 (defun comint-get-source (prompt prev-dir/file source-modes mustmatch-p) | |
1058 (let* ((def (comint-source-default prev-dir/file source-modes)) | |
1059 (stringfile (comint-extract-string)) | |
1060 (sfile-p (and stringfile | |
584 | 1061 (condition-case () |
1062 (file-exists-p stringfile) | |
1063 (error nil)) | |
114 | 1064 (not (file-directory-p stringfile)))) |
1065 (defdir (if sfile-p (file-name-directory stringfile) | |
1066 (car def))) | |
1067 (deffile (if sfile-p (file-name-nondirectory stringfile) | |
1068 (cdr def))) | |
1069 (ans (read-file-name (if deffile (format "%s(default %s) " | |
1070 prompt deffile) | |
1071 prompt) | |
1072 defdir | |
1073 (concat defdir deffile) | |
1074 mustmatch-p))) | |
1075 (list (expand-file-name (substitute-in-file-name ans))))) | |
1076 | |
584 | 1077 ;;; I am somewhat divided on this string-default feature. It seems |
1078 ;;; to violate the principle-of-least-astonishment, in that it makes | |
1079 ;;; the default harder to predict, so you actually have to look and see | |
1080 ;;; what the default really is before choosing it. This can trip you up. | |
1081 ;;; On the other hand, it can be useful, I guess. I would appreciate feedback | |
1082 ;;; on this. | |
1083 ;;; -Olin | |
1084 | |
114 | 1085 |
1086 ;;; Simple process query facility. | |
1087 ;;; =========================================================================== | |
1088 ;;; This function is for commands that want to send a query to the process | |
1089 ;;; and show the response to the user. For example, a command to get the | |
1090 ;;; arglist for a Common Lisp function might send a "(arglist 'foo)" query | |
1091 ;;; to an inferior Common Lisp process. | |
1092 ;;; | |
1093 ;;; This simple facility just sends strings to the inferior process and pops | |
1094 ;;; up a window for the process buffer so you can see what the process | |
1095 ;;; responds with. We don't do anything fancy like try to intercept what the | |
1096 ;;; process responds with and put it in a pop-up window or on the message | |
1097 ;;; line. We just display the buffer. Low tech. Simple. Works good. | |
1098 | |
1099 ;;; Send to the inferior process PROC the string STR. Pop-up but do not select | |
1100 ;;; a window for the inferior process so that its response can be seen. | |
1101 (defun comint-proc-query (proc str) | |
1102 (let* ((proc-buf (process-buffer proc)) | |
1103 (proc-mark (process-mark proc))) | |
1104 (display-buffer proc-buf) | |
1105 (set-buffer proc-buf) ; but it's not the selected *window* | |
1106 (let ((proc-win (get-buffer-window proc-buf)) | |
1107 (proc-pt (marker-position proc-mark))) | |
1108 (comint-send-string proc str) ; send the query | |
1109 (accept-process-output proc) ; wait for some output | |
1110 ;; Try to position the proc window so you can see the answer. | |
1111 ;; This is bogus code. If you delete the (sit-for 0), it breaks. | |
1112 ;; I don't know why. Wizards invited to improve it. | |
1113 (if (not (pos-visible-in-window-p proc-pt proc-win)) | |
1114 (let ((opoint (window-point proc-win))) | |
1115 (set-window-point proc-win proc-mark) (sit-for 0) | |
1116 (if (not (pos-visible-in-window-p opoint proc-win)) | |
1117 (push-mark opoint) | |
1118 (set-window-point proc-win opoint))))))) | |
1119 | |
1120 | |
1121 ;;; Filename completion in a buffer | |
1122 ;;; =========================================================================== | |
1123 ;;; Useful completion functions, courtesy of the Ergo group. | |
1124 | |
1125 ;;; Three commands: | |
1126 ;;; comint-dynamic-complete Complete filename at point. | |
1127 ;;; comint-dynamic-list-completions List completions in help buffer. | |
1128 ;;; comint-replace-by-expanded-filename Expand and complete filename at point; | |
1129 ;;; replace with expanded/completed name. | |
1130 | |
1131 ;;; These are not installed in the comint-mode keymap. But they are | |
584 | 1132 ;;; available for people who want them. Shell-mode installs them: |
2518
10509afe2588
Clean up cmu* uses in header comments.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2455
diff
changeset
|
1133 ;;; (define-key shell-mode-map "\t" 'comint-dynamic-complete) |
10509afe2588
Clean up cmu* uses in header comments.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2455
diff
changeset
|
1134 ;;; (define-key shell-mode-map "\M-?" 'comint-dynamic-list-completions))) |
584 | 1135 ;;; |
1136 ;;; Commands like this are fine things to put in load hooks if you | |
909
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
870
diff
changeset
|
1137 ;;; want them present in specific modes. |
584 | 1138 |
114 | 1139 |
1140 (defun comint-match-partial-pathname () | |
3386
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
1141 "Return the filename at point, or signal an error." |
584 | 1142 (save-excursion |
2627
bc86243d1361
* comint.el (comint-match-partial-pathname): Move "---" range in
Jim Blandy <jimb@redhat.com>
parents:
2583
diff
changeset
|
1143 (if (re-search-backward "[^~/A-Za-z0-9_.$#,=-]" nil 'move) |
584 | 1144 (forward-char 1)) |
1145 ;; Anchor the search forwards. | |
2627
bc86243d1361
* comint.el (comint-match-partial-pathname): Move "---" range in
Jim Blandy <jimb@redhat.com>
parents:
2583
diff
changeset
|
1146 (if (not (looking-at "[~/A-Za-z0-9_.$#,=-]")) (error "")) |
bc86243d1361
* comint.el (comint-match-partial-pathname): Move "---" range in
Jim Blandy <jimb@redhat.com>
parents:
2583
diff
changeset
|
1147 (re-search-forward "[~/A-Za-z0-9_.$#,=-]+") |
584 | 1148 (substitute-in-file-name |
1149 (buffer-substring (match-beginning 0) (match-end 0))))) | |
1150 | |
4675
f4ab5299a1e4
(comint-filename-prefix): New variable.
Roland McGrath <roland@gnu.org>
parents:
4513
diff
changeset
|
1151 (defvar comint-filename-prefix nil |
f4ab5299a1e4
(comint-filename-prefix): New variable.
Roland McGrath <roland@gnu.org>
parents:
4513
diff
changeset
|
1152 "Prefix prepended to all absolute file names taken from process input. |
f4ab5299a1e4
(comint-filename-prefix): New variable.
Roland McGrath <roland@gnu.org>
parents:
4513
diff
changeset
|
1153 This is used by the completion functions, and by directory tracking in shell |
f4ab5299a1e4
(comint-filename-prefix): New variable.
Roland McGrath <roland@gnu.org>
parents:
4513
diff
changeset
|
1154 mode.") |
114 | 1155 |
1156 (defun comint-replace-by-expanded-filename () | |
3386
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
1157 "Expand the filename at point. |
1356 | 1158 Replace the filename with an expanded, canonicalised, and completed |
1159 replacement. | |
114 | 1160 \"Expanded\" means environment variables (e.g., $HOME) and ~'s are |
1161 replaced with the corresponding directories. \"Canonicalised\" means .. | |
584 | 1162 and \. are removed, and the filename is made absolute instead of relative. |
3386
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
1163 See functions `expand-file-name' and `substitute-in-file-name'. See also |
bc4729d67e6e
(comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents:
3113
diff
changeset
|
1164 `comint-dynamic-complete'." |
114 | 1165 (interactive) |
1166 (let* ((pathname (comint-match-partial-pathname)) | |
1167 (pathdir (file-name-directory pathname)) | |
1168 (pathnondir (file-name-nondirectory pathname)) | |
4675
f4ab5299a1e4
(comint-filename-prefix): New variable.
Roland McGrath <roland@gnu.org>
parents:
4513
diff
changeset
|
1169 (completion (file-name-completion |
f4ab5299a1e4
(comint-filename-prefix): New variable.
Roland McGrath <roland@gnu.org>
parents:
4513
diff
changeset
|
1170 pathnondir |
f4ab5299a1e4
(comint-filename-prefix): New variable.
Roland McGrath <roland@gnu.org>
parents:
4513
diff
changeset
|
1171 (if pathdir |
f4ab5299a1e4
(comint-filename-prefix): New variable.
Roland McGrath <roland@gnu.org>
parents:
4513
diff
changeset
|
1172 ;; It is important to expand PATHDIR because |
f4ab5299a1e4
(comint-filename-prefix): New variable.
Roland McGrath <roland@gnu.org>
parents:
4513
diff
changeset
|
1173 ;; default-directory might be a handled name, and |
f4ab5299a1e4
(comint-filename-prefix): New variable.
Roland McGrath <roland@gnu.org>
parents:
4513
diff
changeset
|
1174 ;; the unexpanded PATHDIR won't necessarily match |
f4ab5299a1e4
(comint-filename-prefix): New variable.
Roland McGrath <roland@gnu.org>
parents:
4513
diff
changeset
|
1175 ;; the handler regexp. |
f4ab5299a1e4
(comint-filename-prefix): New variable.
Roland McGrath <roland@gnu.org>
parents:
4513
diff
changeset
|
1176 (expand-file-name (concat |
f4ab5299a1e4
(comint-filename-prefix): New variable.
Roland McGrath <roland@gnu.org>
parents:
4513
diff
changeset
|
1177 (if (file-name-absolute-p pathdir) |
f4ab5299a1e4
(comint-filename-prefix): New variable.
Roland McGrath <roland@gnu.org>
parents:
4513
diff
changeset
|
1178 comint-filename-prefix) |
f4ab5299a1e4
(comint-filename-prefix): New variable.
Roland McGrath <roland@gnu.org>
parents:
4513
diff
changeset
|
1179 pathdir)) |
f4ab5299a1e4
(comint-filename-prefix): New variable.
Roland McGrath <roland@gnu.org>
parents:
4513
diff
changeset
|
1180 default-directory)))) |
114 | 1181 (cond ((null completion) |
909
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
870
diff
changeset
|
1182 (message "No completions of %s" pathname) |
584 | 1183 (ding)) |
114 | 1184 ((eql completion t) |
4326
37a37a8300c4
(comint-replace-by-expanded-filename, comint-dynamic-complete): Say "Sole
Roland McGrath <roland@gnu.org>
parents:
4112
diff
changeset
|
1185 (message "Sole completion")) |
114 | 1186 (t ; this means a string was returned. |
1187 (delete-region (match-beginning 0) (match-end 0)) | |
1188 (insert (expand-file-name (concat pathdir completion))))))) | |
1189 | |
584 | 1190 |
114 | 1191 (defun comint-dynamic-complete () |
584 | 1192 "Dynamically complete the filename at point. |
1373 | 1193 This function is similar to `comint-replace-by-expanded-filename', except |
114 | 1194 that it won't change parts of the filename already entered in the buffer; |
1195 it just adds completion characters to the end of the filename." | |
1196 (interactive) | |
4428
b95bd397d6b7
(comint-dynamic-complete): If called interactively twice in a row, give the
Roland McGrath <roland@gnu.org>
parents:
4427
diff
changeset
|
1197 (if (and (interactive-p) |
b95bd397d6b7
(comint-dynamic-complete): If called interactively twice in a row, give the
Roland McGrath <roland@gnu.org>
parents:
4427
diff
changeset
|
1198 (eq last-command this-command)) |
b95bd397d6b7
(comint-dynamic-complete): If called interactively twice in a row, give the
Roland McGrath <roland@gnu.org>
parents:
4427
diff
changeset
|
1199 ;; If you hit TAB twice in a row, you get a completion list. |
b95bd397d6b7
(comint-dynamic-complete): If called interactively twice in a row, give the
Roland McGrath <roland@gnu.org>
parents:
4427
diff
changeset
|
1200 (comint-dynamic-list-completions) |
b95bd397d6b7
(comint-dynamic-complete): If called interactively twice in a row, give the
Roland McGrath <roland@gnu.org>
parents:
4427
diff
changeset
|
1201 (let* ((pathname (comint-match-partial-pathname)) |
b95bd397d6b7
(comint-dynamic-complete): If called interactively twice in a row, give the
Roland McGrath <roland@gnu.org>
parents:
4427
diff
changeset
|
1202 (pathdir (file-name-directory pathname)) |
b95bd397d6b7
(comint-dynamic-complete): If called interactively twice in a row, give the
Roland McGrath <roland@gnu.org>
parents:
4427
diff
changeset
|
1203 (pathnondir (file-name-nondirectory pathname)) |
b95bd397d6b7
(comint-dynamic-complete): If called interactively twice in a row, give the
Roland McGrath <roland@gnu.org>
parents:
4427
diff
changeset
|
1204 (completion (file-name-completion |
b95bd397d6b7
(comint-dynamic-complete): If called interactively twice in a row, give the
Roland McGrath <roland@gnu.org>
parents:
4427
diff
changeset
|
1205 pathnondir |
b95bd397d6b7
(comint-dynamic-complete): If called interactively twice in a row, give the
Roland McGrath <roland@gnu.org>
parents:
4427
diff
changeset
|
1206 (if pathdir |
4675
f4ab5299a1e4
(comint-filename-prefix): New variable.
Roland McGrath <roland@gnu.org>
parents:
4513
diff
changeset
|
1207 ;; It is important to expand PATHDIR because |
f4ab5299a1e4
(comint-filename-prefix): New variable.
Roland McGrath <roland@gnu.org>
parents:
4513
diff
changeset
|
1208 ;; default-directory might be a handled name, and |
f4ab5299a1e4
(comint-filename-prefix): New variable.
Roland McGrath <roland@gnu.org>
parents:
4513
diff
changeset
|
1209 ;; the unexpanded PATHDIR won't necessarily match |
f4ab5299a1e4
(comint-filename-prefix): New variable.
Roland McGrath <roland@gnu.org>
parents:
4513
diff
changeset
|
1210 ;; the handler regexp. |
f4ab5299a1e4
(comint-filename-prefix): New variable.
Roland McGrath <roland@gnu.org>
parents:
4513
diff
changeset
|
1211 (expand-file-name |
f4ab5299a1e4
(comint-filename-prefix): New variable.
Roland McGrath <roland@gnu.org>
parents:
4513
diff
changeset
|
1212 (concat (if (file-name-absolute-p pathdir) |
f4ab5299a1e4
(comint-filename-prefix): New variable.
Roland McGrath <roland@gnu.org>
parents:
4513
diff
changeset
|
1213 comint-filename-prefix) |
f4ab5299a1e4
(comint-filename-prefix): New variable.
Roland McGrath <roland@gnu.org>
parents:
4513
diff
changeset
|
1214 pathdir)) |
4428
b95bd397d6b7
(comint-dynamic-complete): If called interactively twice in a row, give the
Roland McGrath <roland@gnu.org>
parents:
4427
diff
changeset
|
1215 default-directory)))) |
b95bd397d6b7
(comint-dynamic-complete): If called interactively twice in a row, give the
Roland McGrath <roland@gnu.org>
parents:
4427
diff
changeset
|
1216 (cond ((null completion) |
b95bd397d6b7
(comint-dynamic-complete): If called interactively twice in a row, give the
Roland McGrath <roland@gnu.org>
parents:
4427
diff
changeset
|
1217 (message "No completions of %s" pathname) |
b95bd397d6b7
(comint-dynamic-complete): If called interactively twice in a row, give the
Roland McGrath <roland@gnu.org>
parents:
4427
diff
changeset
|
1218 (ding)) |
b95bd397d6b7
(comint-dynamic-complete): If called interactively twice in a row, give the
Roland McGrath <roland@gnu.org>
parents:
4427
diff
changeset
|
1219 ((eql completion t) |
b95bd397d6b7
(comint-dynamic-complete): If called interactively twice in a row, give the
Roland McGrath <roland@gnu.org>
parents:
4427
diff
changeset
|
1220 (message "Sole completion")) |
b95bd397d6b7
(comint-dynamic-complete): If called interactively twice in a row, give the
Roland McGrath <roland@gnu.org>
parents:
4427
diff
changeset
|
1221 (t ; this means a string was returned. |
b95bd397d6b7
(comint-dynamic-complete): If called interactively twice in a row, give the
Roland McGrath <roland@gnu.org>
parents:
4427
diff
changeset
|
1222 (goto-char (match-end 0)) |
b95bd397d6b7
(comint-dynamic-complete): If called interactively twice in a row, give the
Roland McGrath <roland@gnu.org>
parents:
4427
diff
changeset
|
1223 (insert (substring completion (length pathnondir)))))))) |
114 | 1224 |
1225 (defun comint-dynamic-list-completions () | |
584 | 1226 "List in help buffer all possible completions of the filename at point." |
114 | 1227 (interactive) |
1228 (let* ((pathname (comint-match-partial-pathname)) | |
1229 (pathdir (file-name-directory pathname)) | |
1230 (pathnondir (file-name-nondirectory pathname)) | |
1231 (completions | |
4675
f4ab5299a1e4
(comint-filename-prefix): New variable.
Roland McGrath <roland@gnu.org>
parents:
4513
diff
changeset
|
1232 (file-name-all-completions |
f4ab5299a1e4
(comint-filename-prefix): New variable.
Roland McGrath <roland@gnu.org>
parents:
4513
diff
changeset
|
1233 pathnondir |
f4ab5299a1e4
(comint-filename-prefix): New variable.
Roland McGrath <roland@gnu.org>
parents:
4513
diff
changeset
|
1234 (if pathdir |
f4ab5299a1e4
(comint-filename-prefix): New variable.
Roland McGrath <roland@gnu.org>
parents:
4513
diff
changeset
|
1235 ;; It is important to expand PATHDIR because |
f4ab5299a1e4
(comint-filename-prefix): New variable.
Roland McGrath <roland@gnu.org>
parents:
4513
diff
changeset
|
1236 ;; default-directory might be a handled name, and |
f4ab5299a1e4
(comint-filename-prefix): New variable.
Roland McGrath <roland@gnu.org>
parents:
4513
diff
changeset
|
1237 ;; the unexpanded PATHDIR won't necessarily match |
f4ab5299a1e4
(comint-filename-prefix): New variable.
Roland McGrath <roland@gnu.org>
parents:
4513
diff
changeset
|
1238 ;; the handler regexp. |
f4ab5299a1e4
(comint-filename-prefix): New variable.
Roland McGrath <roland@gnu.org>
parents:
4513
diff
changeset
|
1239 (expand-file-name |
f4ab5299a1e4
(comint-filename-prefix): New variable.
Roland McGrath <roland@gnu.org>
parents:
4513
diff
changeset
|
1240 (concat (if (file-name-absolute-p pathdir) |
f4ab5299a1e4
(comint-filename-prefix): New variable.
Roland McGrath <roland@gnu.org>
parents:
4513
diff
changeset
|
1241 comint-filename-prefix) |
f4ab5299a1e4
(comint-filename-prefix): New variable.
Roland McGrath <roland@gnu.org>
parents:
4513
diff
changeset
|
1242 pathdir)) |
f4ab5299a1e4
(comint-filename-prefix): New variable.
Roland McGrath <roland@gnu.org>
parents:
4513
diff
changeset
|
1243 default-directory)))) |
114 | 1244 (cond ((null completions) |
909
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
870
diff
changeset
|
1245 (message "No completions of %s" pathname) |
584 | 1246 (ding)) |
114 | 1247 (t |
1248 (let ((conf (current-window-configuration))) | |
584 | 1249 (with-output-to-temp-buffer "*Help*" |
114 | 1250 (display-completion-list completions)) |
1251 (sit-for 0) | |
909
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
870
diff
changeset
|
1252 (message "Hit space to flush") |
2022
9a765951a9b9
(comint-dynamic-list-completions): Handle any event when flushing the display.
Richard M. Stallman <rms@gnu.org>
parents:
1839
diff
changeset
|
1253 (let ((ch (read-event))) |
2025
3f02dc3e10a8
Fix bug in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
2022
diff
changeset
|
1254 (if (eq ch ?\ ) |
114 | 1255 (set-window-configuration conf) |
2022
9a765951a9b9
(comint-dynamic-list-completions): Handle any event when flushing the display.
Richard M. Stallman <rms@gnu.org>
parents:
1839
diff
changeset
|
1256 (setq unread-command-events (list ch))))))))) |
114 | 1257 |
1258 ;;; Converting process modes to use comint mode | |
1259 ;;; =========================================================================== | |
768
4abf65b235d9
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
705
diff
changeset
|
1260 ;;; The code in the Emacs 19 distribution has all been modified to use comint |
4abf65b235d9
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
705
diff
changeset
|
1261 ;;; where needed. However, there are `third-party' packages out there that |
4abf65b235d9
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
705
diff
changeset
|
1262 ;;; still use the old shell mode. Here's a guide to conversion. |
584 | 1263 ;;; |
114 | 1264 ;;; Renaming variables |
584 | 1265 ;;; Most of the work is renaming variables and functions. These are the common |
1266 ;;; ones: | |
1267 ;;; Local variables: | |
705 | 1268 ;;; last-input-start comint-last-input-start |
584 | 1269 ;;; last-input-end comint-last-input-end |
1270 ;;; shell-prompt-pattern comint-prompt-regexp | |
1271 ;;; shell-set-directory-error-hook <no equivalent> | |
1272 ;;; Miscellaneous: | |
114 | 1273 ;;; shell-set-directory <unnecessary> |
1274 ;;; shell-mode-map comint-mode-map | |
584 | 1275 ;;; Commands: |
114 | 1276 ;;; shell-send-input comint-send-input |
1277 ;;; shell-send-eof comint-delchar-or-maybe-eof | |
1278 ;;; kill-shell-input comint-kill-input | |
1279 ;;; interrupt-shell-subjob comint-interrupt-subjob | |
1280 ;;; stop-shell-subjob comint-stop-subjob | |
1281 ;;; quit-shell-subjob comint-quit-subjob | |
1282 ;;; kill-shell-subjob comint-kill-subjob | |
1283 ;;; kill-output-from-shell comint-kill-output | |
1284 ;;; show-output-from-shell comint-show-output | |
1285 ;;; copy-last-shell-input Use comint-previous-input/comint-next-input | |
1286 ;;; | |
705 | 1287 ;;; SHELL-SET-DIRECTORY is gone, its functionality taken over by |
1288 ;;; SHELL-DIRECTORY-TRACKER, the shell mode's comint-input-sentinel. | |
1289 ;;; Comint mode does not provide functionality equivalent to | |
114 | 1290 ;;; shell-set-directory-error-hook; it is gone. |
705 | 1291 ;;; |
1292 ;;; comint-last-input-start is provided for modes which want to munge | |
1293 ;;; the buffer after input is sent, perhaps because the inferior | |
1294 ;;; insists on echoing the input. The LAST-INPUT-START variable in | |
1295 ;;; the old shell package was used to implement a history mechanism, | |
1296 ;;; but you should think twice before using comint-last-input-start | |
1297 ;;; for this; the input history ring often does the job better. | |
114 | 1298 ;;; |
1299 ;;; If you are implementing some process-in-a-buffer mode, called foo-mode, do | |
1300 ;;; *not* create the comint-mode local variables in your foo-mode function. | |
1301 ;;; This is not modular. Instead, call comint-mode, and let *it* create the | |
1302 ;;; necessary comint-specific local variables. Then create the | |
1303 ;;; foo-mode-specific local variables in foo-mode. Set the buffer's keymap to | |
1304 ;;; be foo-mode-map, and its mode to be foo-mode. Set the comint-mode hooks | |
1305 ;;; (comint-prompt-regexp, comint-input-filter, comint-input-sentinel, | |
1306 ;;; comint-get-old-input) that need to be different from the defaults. Call | |
1307 ;;; foo-mode-hook, and you're done. Don't run the comint-mode hook yourself; | |
2518
10509afe2588
Clean up cmu* uses in header comments.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2455
diff
changeset
|
1308 ;;; comint-mode will take care of it. The following example, from shell.el, |
584 | 1309 ;;; is typical: |
1310 ;;; | |
1311 ;;; (defun shell-mode () | |
1312 ;;; (interactive) | |
1313 ;;; (comint-mode) | |
1314 ;;; (setq comint-prompt-regexp shell-prompt-pattern) | |
1315 ;;; (setq major-mode 'shell-mode) | |
1316 ;;; (setq mode-name "Shell") | |
1317 ;;; (cond ((not shell-mode-map) | |
1318 ;;; (setq shell-mode-map (full-copy-sparse-keymap comint-mode-map)) | |
1319 ;;; (define-key shell-mode-map "\M-\t" 'comint-dynamic-complete) | |
1320 ;;; (define-key shell-mode-map "\M-?" | |
1321 ;;; 'comint-dynamic-list-completions))) | |
1322 ;;; (use-local-map shell-mode-map) | |
1323 ;;; (make-local-variable 'shell-directory-stack) | |
1324 ;;; (setq shell-directory-stack nil) | |
1325 ;;; (setq comint-input-sentinel 'shell-directory-tracker) | |
1326 ;;; (run-hooks 'shell-mode-hook)) | |
1327 ;;; | |
114 | 1328 ;;; |
1329 ;;; Note that make-comint is different from make-shell in that it | |
1330 ;;; doesn't have a default program argument. If you give make-shell | |
1331 ;;; a program name of NIL, it cleverly chooses one of explicit-shell-name, | |
1332 ;;; $ESHELL, $SHELL, or /bin/sh. If you give make-comint a program argument | |
1333 ;;; of NIL, it barfs. Adjust your code accordingly... | |
584 | 1334 ;;; |
1335 | |
1336 ;;; Do the user's customisation... | |
1337 | |
1338 (defvar comint-load-hook nil | |
1339 "This hook is run when comint is loaded in. | |
1340 This is a good place to put keybindings.") | |
1341 | |
1342 (run-hooks 'comint-load-hook) | |
1343 | |
1344 ;;; Change log: | |
1345 ;;; 9/12/89 | |
1346 ;;; - Souped up the filename expansion procedures. | |
1347 ;;; Doc strings are much clearer and more detailed. | |
1348 ;;; Fixed a bug where doing a filename completion when the point | |
1349 ;;; was in the middle of the filename instead of at the end would lose. | |
1350 ;;; | |
1351 ;;; 2/17/90 | |
1352 ;;; - Souped up the command history stuff so that text inserted | |
1353 ;;; by comint-previous-input-matching is removed by following | |
1354 ;;; command history recalls. comint-next/previous-input-matching | |
1355 ;;; is now much more smoothly integrated w/the command history stuff. | |
1356 ;;; - Added comint-eol-on-send flag and comint-input-sender hook. | |
1357 ;;; Comint-input-sender based on code contributed by Jeff Peck | |
1358 ;;; (peck@sun.com). | |
1359 ;;; | |
1360 ;;; 3/13/90 ccm@cmu.cs.edu | |
1361 ;;; - Added comint-previous-similar-input for looking up similar inputs. | |
1362 ;;; - Added comint-send-and-get-output to allow snarfing input from | |
1363 ;;; buffer. | |
1364 ;;; - Added the ability to pick up a source file by positioning over | |
1365 ;;; a string in comint-get-source. | |
1366 ;;; - Added add-hook to make it a little easier for the user to use | |
1367 ;;; multiple hooks. | |
1368 ;;; | |
1369 ;;; 5/22/90 shivers | |
1370 ;;; - Moved Chris' multiplexed ipc stuff to comint-ipc.el. | |
1371 ;;; - Altered Chris' comint-get-source string feature. The string | |
1372 ;;; is only offered as a default if it names an existing file. | |
1373 ;;; - Changed comint-exec to directly crank up the process, instead | |
1374 ;;; of calling the env program. This made background.el happy. | |
1375 ;;; - Added new buffer-local var comint-ptyp. The problem is that | |
1376 ;;; the signalling functions don't work as advertised. If you are | |
1377 ;;; communicating via pipes, the CURRENT-GROUP arg is supposed to | |
1378 ;;; be ignored, but, unfortunately it seems to be the case that you | |
1379 ;;; must pass a NIL for this arg in the pipe case. COMINT-PTYP | |
1380 ;;; is a flag that tells whether the process is communicating | |
1381 ;;; via pipes or a pty. The comint signalling functions use it | |
1382 ;;; to determine the necessary CURRENT-GROUP arg value. The bug | |
1383 ;;; has been reported to the Gnu folks. | |
1384 ;;; - comint-dynamic-complete flushes the help window if you hit space | |
1385 ;;; after you execute it. | |
1386 ;;; - Added functions comint-send-string, comint-send-region and var | |
1387 ;;; comint-input-chunk-size. comint-send-string tries to prevent processes | |
1388 ;;; from hanging when you send them long strings by breaking them into | |
1389 ;;; chunks and allowing process output between chunks. I got the idea from | |
1390 ;;; Eero Simoncelli's Common Lisp package. Note that using | |
1391 ;;; comint-send-string means that the process buffer's contents can change | |
1392 ;;; during a call! If you depend on process output only happening between | |
1393 ;;; toplevel commands, this could be a problem. In such a case, use | |
1394 ;;; process-send-string instead. If this is a problem for people, I'd like | |
1395 ;;; to hear about it. | |
1396 ;;; - Added comint-proc-query as a simple mechanism for commands that | |
1397 ;;; want to query an inferior process and display its response. For a | |
1398 ;;; typical use, see lisp-show-arglist in cmulisp.el. | |
1399 ;;; - Added constant comint-version, which is now "2.01". | |
1400 ;;; | |
1401 ;;; 6/14/90 shivers | |
1402 ;;; - Had comint-update-env defined twice. Removed extra copy. Also | |
1403 ;;; renamed mem to be comint-mem, for modularity. The duplication | |
1404 ;;; was reported by Michael Meissner. | |
1405 ;;; 6/16/90 shivers | |
1406 ;;; - Emacs has two different mechanisms for maintaining the process | |
1407 ;;; environment, determined at compile time by the MAINTAIN-ENVIRONMENT | |
1408 ;;; #define. One uses the process-environment global variable, and | |
1409 ;;; one uses a getenv/setenv interface. comint-exec assumed the | |
1410 ;;; process-environment interface; it has been generalised (with | |
1411 ;;; comint-exec-1) to handle both cases. Pretty bogus. We could, | |
1412 ;;; of course, skip all this and just use the etc/env program to | |
1413 ;;; handle the environment tweaking, but that obscures process | |
1414 ;;; queries that other modules (like background.el) depend on. etc/env | |
1415 ;;; is also fairly bogus. This bug, and some of the fix code was | |
1416 ;;; reported by Dan Pierson. | |
1417 ;;; | |
1418 ;;; 9/5/90 shivers | |
1419 ;;; - Changed make-variable-buffer-local's to make-local-variable's. | |
1420 ;;; This leaves non-comint-mode buffers alone. Stephane Payrard | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3386
diff
changeset
|
1421 ;;; reported the sloppy usage. |
584 | 1422 ;;; - You can now go from comint-previous-similar-input to |
1423 ;;; comint-previous-input with no problem. | |
1424 ;;; | |
1425 ;;; 12/21/90 shivers | |
1426 ;;; - Added a condition-case to comint-get-source. Bogus strings | |
1427 ;;; beginning with ~ were making the file-exists-p barf. | |
1428 ;;; - Added "=" to the set of chars recognised by file completion | |
1429 ;;; as constituting a filename. | |
1430 ;;; | |
1431 ;;; 1/90 shivers | |
1432 ;;; These changes comprise release 2.02: | |
1433 ;;; - Removed the kill-all-local-variables in comint-mode. This | |
1434 ;;; made it impossible for client modes to set things before calling | |
1435 ;;; comint-mode. (In particular, it messed up ilisp.el) In general, | |
1436 ;;; the client mode should be responsible for a k-a-l-v's. | |
1437 ;;; - Fixed comint-match-partial-pathname so that it works in | |
1438 ;;; more cases: if the filename begins at the start-of-buffer; | |
1439 ;;; if point is on the first char of the filename. Just a question | |
1440 ;;; of getting the tricky bits right. | |
1441 ;;; - Added a hook, comint-exec-hook that is run each time a process | |
1442 ;;; is cranked up. Useful for things like process-kill-without-query. | |
1443 ;;; | |
705 | 1444 ;;; These two were pointed out by tale: |
584 | 1445 ;;; - Improved the doc string in comint-send-input a little bit. |
1446 ;;; - Tweaked make-comint to check process status with comint-check-proc | |
1447 ;;; instead of equivalent inline code. | |
705 | 1448 ;;; |
584 | 1449 ;;; - Prompt-search history commands have been commented out. I never |
1450 ;;; liked them; I don't think anyone used them. | |
705 | 1451 ;;; - Made comint-exec-hook a local var, as it should have been. |
2518
10509afe2588
Clean up cmu* uses in header comments.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2455
diff
changeset
|
1452 ;;; (This way, for instance, you can have shell procs kill-w/o-query, |
705 | 1453 ;;; but let Scheme procs be default.) |
1454 ;;; | |
1455 ;;; 7/91 Shivers | |
1456 ;;; - Souped up comint-read-noecho with an optional argument, STARS. | |
1457 ;;; Suggested by mjlx@EAGLE.CNSF.CORNELL.EDU. | |
1458 ;;; - Moved comint-previous-input-matching from C-c r to C-M-r. | |
1459 ;;; C-c <letter> bindings are reserved for the user. | |
1460 ;;; These bindings were done by Jim Blandy. | |
1461 ;;; These changes comprise version 2.03. | |
584 | 1462 |
1463 (provide 'comint) | |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
638
diff
changeset
|
1464 |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
638
diff
changeset
|
1465 ;;; comint.el ends here |