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