annotate lisp/comint.el @ 8196:89db3662bcec

(Buffer-menu-not-modified): Make `Buffer-menu-not-modified' handle an argument like `not-modified'.
author Richard M. Stallman <rms@gnu.org>
date Mon, 11 Jul 1994 04:46:24 +0000
parents c22d7c5168f5
children c830f54843c2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
5476
155472377864 (comint-show-output): Use (point-max) rather than erring when the
Roland McGrath <roland@gnu.org>
parents: 5424
diff changeset
3 ;; Copyright (C) 1988, 1990, 1992, 1993, 1994 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>
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
6 ;; Adapted-by: Simon Marshall <s.marshall@dcs.hull.ac.uk>
2247
2c7997f249eb Add or correct keywords
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2025
diff changeset
7 ;; Keywords: processes
846
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 811
diff changeset
8
909
4c6cdb66c74c *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 870
diff changeset
9 ;; This file is part of GNU Emacs.
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
10
909
4c6cdb66c74c *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 870
diff changeset
11 ;; 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
12 ;; 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
13 ;; 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
14 ;; any later version.
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
15
909
4c6cdb66c74c *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 870
diff changeset
16 ;; 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
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
4c6cdb66c74c *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 870
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4c6cdb66c74c *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 870
diff changeset
19 ;; GNU General Public License for more details.
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
20
909
4c6cdb66c74c *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 870
diff changeset
21 ;; 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
22 ;; 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
23 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
24
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 793
diff changeset
25 ;;; Commentary:
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 793
diff changeset
26
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
27 ;;; Please send me bug reports, bug fixes, and extensions, so that I can
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
28 ;;; merge them into the master source.
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
29 ;;; - Olin Shivers (shivers@cs.cmu.edu)
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
30 ;;; - Simon Marshall (s.marshall@dcs.hull.ac.uk)
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
31
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
32 ;;; This file defines a general command-interpreter-in-a-buffer package
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
33 ;;; (comint mode). The idea is that you can build specific process-in-a-buffer
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
34 ;;; modes on top of comint mode -- e.g., lisp, shell, scheme, T, soar, ....
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
35 ;;; This way, all these specific packages share a common base functionality,
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
36 ;;; and a common set of bindings, which makes them easier to use (and
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
37 ;;; saves code, implementation time, etc., etc.).
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
38
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
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
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
41 ;;; - cmulisp.el defines a simple lisp-in-a-buffer mode.
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
42 ;;;
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
43 ;;; - The file cmuscheme.el defines a scheme-in-a-buffer mode.
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
44 ;;; - The file tea.el tunes scheme and inferior-scheme modes for T.
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
45 ;;; - The file soar.el tunes lisp and inferior-lisp modes for Soar.
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
46 ;;; - cmutex.el defines tex and latex modes that invoke tex, latex, bibtex,
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
47 ;;; previewers, and printers from within emacs.
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
48 ;;; - background.el allows csh-like job control inside emacs.
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
49 ;;; It is pretty easy to make new derived modes for other processes.
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
50
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
51 ;;; For documentation on the functionality provided by comint mode, and
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
52 ;;; the hooks available for customising it, see the comments below.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
53 ;;; For further information on the standard derived modes (shell,
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
54 ;;; inferior-lisp, inferior-scheme, ...), see the relevant source files.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
55
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
56 ;;; For hints on converting existing process modes (e.g., tex-mode,
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
57 ;;; background, dbx, gdb, kermit, prolog, telnet) to use comint-mode
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
58 ;;; instead of shell-mode, see the notes at the end of this file.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
59
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
60
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
61 ;;; Brief Command Documentation:
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
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
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
64 ;;; mode)
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
65 ;;;
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
66 ;;; m-p comint-previous-input Cycle backwards in input history
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
67 ;;; m-n comint-next-input Cycle forwards
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
68 ;;; m-r comint-previous-matching-input Previous input matching a regexp
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
69 ;;; m-s comint-next-matching-input Next input that matches
5284
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
70 ;;; m-c-l comint-show-output Show last batch of process output
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
71 ;;; return comint-send-input
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
72 ;;; c-a comint-bol Beginning of line; skip prompt
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
73 ;;; c-d comint-delchar-or-maybe-eof Delete char unless at end of buff
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
74 ;;; c-c c-u comint-kill-input ^u
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
75 ;;; c-c c-w backward-kill-word ^w
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
76 ;;; c-c c-c comint-interrupt-subjob ^c
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
77 ;;; c-c c-z comint-stop-subjob ^z
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
78 ;;; c-c c-\ comint-quit-subjob ^\
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
79 ;;; c-c c-o comint-kill-output Delete last batch of process output
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
80 ;;; c-c c-r comint-show-output Show last batch of process output
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
81 ;;; c-c c-h comint-dynamic-list-input-ring List input history
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
82 ;;;
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
83 ;;; Not bound by default in comint-mode (some are in shell mode)
6507
ff41e0e932b8 (comint-run): New command.
Richard M. Stallman <rms@gnu.org>
parents: 6256
diff changeset
84 ;;; comint-run Run a program under comint-mode
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
85 ;;; send-invisible Read a line w/o echo, and send to proc
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
86 ;;; comint-dynamic-complete-filename Complete filename at point.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
87 ;;; comint-dynamic-complete-variable Complete variable name at point.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
88 ;;; comint-dynamic-list-filename-completions List completions in help buffer.
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
89 ;;; comint-replace-by-expanded-filename Expand and complete filename at point;
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
90 ;;; replace with expanded/completed name.
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
91 ;;; comint-replace-by-expanded-history Expand history at point;
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
92 ;;; replace with expanded name.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
93 ;;; comint-magic-space Expand history and add (a) space(s).
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
94 ;;; comint-kill-subjob No mercy.
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
95 ;;; comint-show-maximum-output Show as much output as possible.
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
96 ;;; comint-continue-subjob Send CONT signal to buffer's process
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
97 ;;; group. Useful if you accidentally
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
98 ;;; suspend your process (with C-c C-z).
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
99
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
100 ;;; comint-mode-hook is the comint mode hook. Basically for your keybindings.
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
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
1131
853d0d4c61fb entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 932
diff changeset
104 (require 'ring)
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
105
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
106 ;;; Buffer Local Variables:
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
107 ;;;============================================================================
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
108 ;;; Comint mode buffer local variables:
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
109 ;;; comint-prompt-regexp - string comint-bol uses to match prompt
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
110 ;;; comint-delimiter-argument-list - list For delimiters and arguments
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
111 ;;; comint-last-input-start - marker Handy if inferior always echoes
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
112 ;;; 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
113 ;;; comint-input-ring-size - integer For the input history
345296f94a1e *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 846
diff changeset
114 ;;; 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
115 ;;; comint-input-ring-index - number ...
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
116 ;;; comint-input-autoexpand - symbol ...
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
117 ;;; comint-input-ignoredups - boolean ...
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
118 ;;; comint-last-input-match - string ...
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
119 ;;; comint-dynamic-complete-functions - hook For the completion mechanism
6256
3810012eb29f (comint-completion-fignore): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 6239
diff changeset
120 ;;; comint-completion-fignore - list ...
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
121 ;;; comint-get-old-input - function Hooks for specific
6187
280d4a97da69 (comint-input-filter-functions)
Richard M. Stallman <rms@gnu.org>
parents: 6185
diff changeset
122 ;;; comint-input-filter-functions - hook process-in-a-buffer
280d4a97da69 (comint-input-filter-functions)
Richard M. Stallman <rms@gnu.org>
parents: 6185
diff changeset
123 ;;; comint-output-filter-functions - hook function modes.
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
124 ;;; comint-input-filter - function ...
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
125 ;;; comint-input-send - function ...
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
126 ;;; comint-eol-on-send - boolean ...
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
127 ;;; comint-process-echoes - boolean ...
4923
63aed739d09d (comint-postoutput-scroll-to-bottom):
Richard M. Stallman <rms@gnu.org>
parents: 4899
diff changeset
128 ;;; comint-scroll-to-bottom-on-input - symbol For scroll behavior
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
129 ;;; comint-scroll-to-bottom-on-output - symbol ...
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
130 ;;; comint-scroll-show-maximum-output - boolean...
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
131 ;;;
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
132 ;;; Comint mode non-buffer local variables:
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
133 ;;; comint-completion-addsuffix - boolean For file name completion
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
134 ;;; comint-completion-autolist - boolean behavior
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
135 ;;; comint-completion-recexact - boolean ...
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
136
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
137 (defvar comint-prompt-regexp "^"
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
138 "Regexp to recognise prompts in the inferior process.
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
139 Defaults to \"^\", the null string at BOL.
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
140
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
141 Good choices:
5284
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
142 Canonical Lisp: \"^[^> \\n]*>+:? *\" (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
143 Lucid Common Lisp: \"^\\\\(>\\\\|\\\\(->\\\\)+\\\\) *\"
fc25d1816641 * comint.el (comint-prompt-regexp): Double the backslashes in the
Jim Blandy <jimb@redhat.com>
parents: 3591
diff changeset
144 franz: \"^\\\\(->\\\\|<[0-9]*>:\\\\) *\"
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
145 kcl: \"^>+ *\"
5284
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
146 shell: \"^[^#$%>\\n]*[#$%>] *\"
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
147 T: \"^>+ *\"
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
148
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
149 This is a good thing to set in mode hooks.")
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
150
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
151 (defvar comint-delimiter-argument-list ()
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
152 "List of characters to recognise as separate arguments in input.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
153 Strings comprising a character in this list will separate the arguments
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
154 surrounding them, and also be regarded as arguments in their own right (unlike
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
155 whitespace). See `comint-arguments'.
6154
385d5fe1c95c (comint-arguments): Use just one regexp to find end of arg
Richard M. Stallman <rms@gnu.org>
parents: 6148
diff changeset
156 Defaults to the empty list.
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
157
6154
385d5fe1c95c (comint-arguments): Use just one regexp to find end of arg
Richard M. Stallman <rms@gnu.org>
parents: 6148
diff changeset
158 For shells, a good value is (?\\| ?& ?< ?> ?\\( ?\\) ?;).
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
159
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
160 This is a good thing to set in mode hooks.")
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
161
5539
73389b4a4a9d (comint-input-autoexpand): Make default nil.
Richard M. Stallman <rms@gnu.org>
parents: 5476
diff changeset
162 (defvar comint-input-autoexpand nil
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
163 "*If non-nil, expand input command history references on completion.
4923
63aed739d09d (comint-postoutput-scroll-to-bottom):
Richard M. Stallman <rms@gnu.org>
parents: 4899
diff changeset
164 This mirrors the optional behavior of tcsh (its autoexpand and histlit).
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
165
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
166 If the value is `input', then the expansion is seen on input.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
167 If the value is `history', then the expansion is only when inserting
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
168 into the buffer's input ring. See also `comint-magic-space' and
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
169 `comint-dynamic-complete'.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
170
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
171 This variable is buffer-local.")
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
172
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
173 (defvar comint-input-ignoredups nil
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
174 "*If non-nil, don't add input matching the last on the input ring.
4923
63aed739d09d (comint-postoutput-scroll-to-bottom):
Richard M. Stallman <rms@gnu.org>
parents: 4899
diff changeset
175 This mirrors the optional behavior of bash.
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
176
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
177 This variable is buffer-local.")
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
178
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
179 (defvar comint-input-ring-file-name nil
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
180 "*If non-nil, name of the file to read/write input history.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
181 See also `comint-read-input-ring' and `comint-write-input-ring'.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
182
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
183 This variable is buffer-local, and is a good thing to set in mode hooks.")
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
184
4939
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
185 (defvar comint-scroll-to-bottom-on-input nil
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
186 "*Controls whether input to interpreter causes window to scroll.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
187 If nil, then do not scroll. If t or `all', scroll all windows showing buffer.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
188 If `this', scroll only the selected window.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
189
4939
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
190 The default is nil.
4880
a658d0e341b1 (comint-scroll-to-bottom-on-input)
Richard M. Stallman <rms@gnu.org>
parents: 4872
diff changeset
191
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
192 See `comint-preinput-scroll-to-bottom'. This variable is buffer-local.")
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
193
4939
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
194 (defvar comint-scroll-to-bottom-on-output nil
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
195 "*Controls whether interpreter output causes window to scroll.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
196 If nil, then do not scroll. If t or `all', scroll all windows showing buffer.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
197 If `this', scroll only the selected window.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
198 If `others', scroll only those that are not the selected window.
4939
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
199
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
200 The default is nil.
4880
a658d0e341b1 (comint-scroll-to-bottom-on-input)
Richard M. Stallman <rms@gnu.org>
parents: 4872
diff changeset
201
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
202 See variable `comint-scroll-show-maximum-output' and function
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
203 `comint-postoutput-scroll-to-bottom'. This variable is buffer-local.")
4939
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
204
5058
fb8f2a3f2178 (comint-scroll-show-maximum-output): Make default nil.
Richard M. Stallman <rms@gnu.org>
parents: 5050
diff changeset
205 (defvar comint-scroll-show-maximum-output nil
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
206 "*Controls how interpreter output causes window to scroll.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
207 If non-nil, then show the maximum output when the window is scrolled.
4939
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
208
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
209 See variable `comint-scroll-to-bottom-on-output' and function
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
210 `comint-postoutput-scroll-to-bottom'. This variable is buffer-local.")
4939
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
211
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
212 (defvar comint-input-ring-size 32
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
213 "Size of input history ring.")
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
214
2539
577c77cfd199 *** empty log message ***
Noah Friedman <friedman@splode.com>
parents: 2518
diff changeset
215 (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
216 "*If non-nil, assume that the subprocess echoes any input.
2539
577c77cfd199 *** empty log message ***
Noah Friedman <friedman@splode.com>
parents: 2518
diff changeset
217 If so, delete one copy of the input so that only one copy eventually
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
218 appears in the buffer.
2539
577c77cfd199 *** empty log message ***
Noah Friedman <friedman@splode.com>
parents: 2518
diff changeset
219
577c77cfd199 *** empty log message ***
Noah Friedman <friedman@splode.com>
parents: 2518
diff changeset
220 This variable is buffer-local.")
577c77cfd199 *** empty log message ***
Noah Friedman <friedman@splode.com>
parents: 2518
diff changeset
221
8087
c22d7c5168f5 comint-password-prompt-regexp: New variable.
Noah Friedman <friedman@splode.com>
parents: 8060
diff changeset
222 (defvar comint-password-prompt-regexp "\\b[Pp]assword:\\s *\\'"
c22d7c5168f5 comint-password-prompt-regexp: New variable.
Noah Friedman <friedman@splode.com>
parents: 8060
diff changeset
223 "*Regexp matching prompts for passwords in the inferior process.
c22d7c5168f5 comint-password-prompt-regexp: New variable.
Noah Friedman <friedman@splode.com>
parents: 8060
diff changeset
224 This is used by comint-watch-for-password-prompt.")
c22d7c5168f5 comint-password-prompt-regexp: New variable.
Noah Friedman <friedman@splode.com>
parents: 8060
diff changeset
225
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
226 ;;; Here are the per-interpreter hooks.
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
227 (defvar comint-get-old-input (function comint-get-old-input-default)
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
228 "Function that returns old text in comint mode.
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
229 This function is called when return is typed while the point is in old text.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
230 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
231 `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
232 leading text matching `comint-prompt-regexp'.")
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
233
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
234 (defvar comint-dynamic-complete-functions
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
235 '(comint-replace-by-expanded-history comint-dynamic-complete-filename)
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
236 "List of functions called to perform completion.
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
237 Functions should return non-nil if completion was performed.
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
238 See also `comint-dynamic-complete'.
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
239
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
240 This is a good thing to set in mode hooks.")
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
241
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
242 (defvar comint-input-filter
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
243 (function (lambda (str) (not (string-match "\\`\\s *\\'" str))))
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
244 "Predicate for filtering additions to input history.
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
245 Takes one argument, the input. If non-nil, the input may be saved on the input
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
246 history list. Default is to save anything that isn't all whitespace.")
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
247
6187
280d4a97da69 (comint-input-filter-functions)
Richard M. Stallman <rms@gnu.org>
parents: 6185
diff changeset
248 (defvar comint-input-filter-functions '()
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
249 "Functions to call before input is sent to the process.
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
250 These functions get one argument, a string containing the text to send.
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
251
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
252 This variable is buffer-local.")
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
253
6187
280d4a97da69 (comint-input-filter-functions)
Richard M. Stallman <rms@gnu.org>
parents: 6185
diff changeset
254 (defvar comint-output-filter-functions '(comint-postoutput-scroll-to-bottom)
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
255 "Functions to call after output is inserted into the buffer.
4890
dab300dfe449 (comint-scroll-to-bottom-on-input): Default to nil.
Richard M. Stallman <rms@gnu.org>
parents: 4880
diff changeset
256 One possible function is `comint-postoutput-scroll-to-bottom'.
dab300dfe449 (comint-scroll-to-bottom-on-input): Default to nil.
Richard M. Stallman <rms@gnu.org>
parents: 4880
diff changeset
257 These functions get one argument, a string containing the text just inserted.
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
258
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
259 This variable is buffer-local.")
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
260
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
261 (defvar comint-input-sender (function comint-simple-send)
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
262 "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
263 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
264 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
265 `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
266 This is called from the user command `comint-send-input'.")
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
267
3386
bc4729d67e6e (comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents: 3113
diff changeset
268 (defvar comint-eol-on-send t
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
269 "*Non-nil means go to the end of the line before sending input.
3386
bc4729d67e6e (comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents: 3113
diff changeset
270 See `comint-send-input'.")
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
271
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
272 (defvar comint-mode-hook '()
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
273 "Called upon entry into comint-mode
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
274 This is run before the process is cranked up.")
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
275
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
276 (defvar comint-exec-hook '()
3386
bc4729d67e6e (comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents: 3113
diff changeset
277 "Called each time a process is exec'd by `comint-exec'.
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
278 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
279 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
280 `(process-kill-without-query)'). In contrast, the `comint-mode-hook' is only
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
281 executed once when the buffer is created.")
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
282
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
283 (defvar comint-mode-map nil)
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
284
1131
853d0d4c61fb entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 932
diff changeset
285 (defvar comint-ptyp t
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
286 "Non-nil 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
287 This is to work around a bug in Emacs process signalling.")
1131
853d0d4c61fb entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 932
diff changeset
288
932
a93f0b1ba909 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 925
diff changeset
289 (defvar comint-input-ring nil)
861
345296f94a1e *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 846
diff changeset
290 (defvar comint-last-input-start)
345296f94a1e *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 846
diff changeset
291 (defvar comint-last-input-end)
5424
51eecae04837 (comint-last-output-start): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 5323
diff changeset
292 (defvar comint-last-output-start)
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
293 (defvar comint-input-ring-index nil
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
294 "Index of last matched history element.")
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
295 (defvar comint-matching-input-from-input-string ""
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
296 "Input previously used to match input history.")
6507
ff41e0e932b8 (comint-run): New command.
Richard M. Stallman <rms@gnu.org>
parents: 6256
diff changeset
297
ff41e0e932b8 (comint-run): New command.
Richard M. Stallman <rms@gnu.org>
parents: 6256
diff changeset
298 (put 'comint-replace-by-expanded-history 'menu-enable 'comint-input-autoexpand)
1131
853d0d4c61fb entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 932
diff changeset
299 (put 'comint-input-ring 'permanent-local t)
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
300 (put 'comint-input-ring-index 'permanent-local t)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
301 (put 'comint-input-autoexpand 'permanent-local t)
6187
280d4a97da69 (comint-input-filter-functions)
Richard M. Stallman <rms@gnu.org>
parents: 6185
diff changeset
302 (put 'comint-input-filter-functions 'permanent-local t)
280d4a97da69 (comint-input-filter-functions)
Richard M. Stallman <rms@gnu.org>
parents: 6185
diff changeset
303 (put 'comint-output-filter-functions 'permanent-local t)
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
304 (put 'comint-scroll-to-bottom-on-input 'permanent-local t)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
305 (put 'comint-scroll-to-bottom-on-output 'permanent-local t)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
306 (put 'comint-scroll-show-maximum-output 'permanent-local t)
1131
853d0d4c61fb entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 932
diff changeset
307 (put 'comint-ptyp 'permanent-local t)
861
345296f94a1e *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 846
diff changeset
308
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
309 (defun comint-mode ()
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
310 "Major mode for interacting with an inferior interpreter.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
311 Interpreter name is same as buffer name, sans the asterisks.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
312 Return at end of buffer sends line as input.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
313 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
314 Setting variable `comint-eol-on-send' means jump to the end of the line
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
315 before submitting new input.
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
316
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
317 This mode is customised to create major modes such as Inferior Lisp
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
318 mode, Shell mode, etc. This can be done by setting the hooks
6187
280d4a97da69 (comint-input-filter-functions)
Richard M. Stallman <rms@gnu.org>
parents: 6185
diff changeset
319 `comint-input-filter-functions', `comint-input-filter', `comint-input-sender'
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
320 and `comint-get-old-input' to appropriate functions, and the variable
3386
bc4729d67e6e (comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents: 3113
diff changeset
321 `comint-prompt-regexp' to the appropriate regular expression.
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
322
3386
bc4729d67e6e (comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents: 3113
diff changeset
323 An input history is maintained of size `comint-input-ring-size', and
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
324 can be accessed with the commands \\[comint-next-input], \\[comint-previous-input], and \\[comint-dynamic-list-input-ring].
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
325 Input ring history expansion can be achieved with the commands
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
326 \\[comint-replace-by-expanded-history] or \\[comint-magic-space].
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
327 Input ring expansion is controlled by the variable `comint-input-autoexpand',
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
328 and addition is controlled by the variable `comint-input-ignoredups'.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
329
3386
bc4729d67e6e (comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents: 3113
diff changeset
330 Commands with no default key bindings include `send-invisible',
6507
ff41e0e932b8 (comint-run): New command.
Richard M. Stallman <rms@gnu.org>
parents: 6256
diff changeset
331 `comint-dynamic-complete', `comint-dynamic-list-filename-completions', and
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
332 `comint-magic-space'.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
333
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
334 Input to, and output from, the subprocess can cause the window to scroll to
6187
280d4a97da69 (comint-input-filter-functions)
Richard M. Stallman <rms@gnu.org>
parents: 6185
diff changeset
335 the end of the buffer. See variables `comint-output-filter-functions',
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
336 `comint-scroll-to-bottom-on-input', and `comint-scroll-to-bottom-on-output'.
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
337
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
338 If you accidentally suspend your process, use \\[comint-continue-subjob]
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
339 to continue it.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
340
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
341 \\{comint-mode-map}
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
342
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
343 Entry to this mode runs the hooks on `comint-mode-hook'."
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
344 (interactive)
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
345 ;; Do not remove this. All major modes must do this.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
346 (kill-all-local-variables)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
347 (setq major-mode 'comint-mode)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
348 (setq mode-name "Comint")
7071
058f19d36c07 (comint-mode): Remove space after `:' in mode-line-process.
Richard M. Stallman <rms@gnu.org>
parents: 7048
diff changeset
349 (setq mode-line-process '(":%s"))
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
350 (use-local-map comint-mode-map)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
351 (make-local-variable 'comint-last-input-start)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
352 (setq comint-last-input-start (make-marker))
6998
40163ff9fc7c (comint-mode): Set comint-last-input-start and
Richard M. Stallman <rms@gnu.org>
parents: 6958
diff changeset
353 (set-marker comint-last-input-start (point-min))
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
354 (make-local-variable 'comint-last-input-end)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
355 (setq comint-last-input-end (make-marker))
6998
40163ff9fc7c (comint-mode): Set comint-last-input-start and
Richard M. Stallman <rms@gnu.org>
parents: 6958
diff changeset
356 (set-marker comint-last-input-end (point-min))
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
357 (make-local-variable 'comint-last-output-start)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
358 (setq comint-last-output-start (make-marker))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
359 (make-local-variable 'comint-prompt-regexp) ; Don't set; default
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
360 (make-local-variable 'comint-input-ring-size) ; ...to global val.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
361 (make-local-variable 'comint-input-ring)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
362 (make-local-variable 'comint-input-ring-file-name)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
363 (or (and (boundp 'comint-input-ring) comint-input-ring)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
364 (setq comint-input-ring (make-ring comint-input-ring-size)))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
365 (make-local-variable 'comint-input-ring-index)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
366 (or (and (boundp 'comint-input-ring-index) comint-input-ring-index)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
367 (setq comint-input-ring-index nil))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
368 (make-local-variable 'comint-matching-input-from-input-string)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
369 (make-local-variable 'comint-input-autoexpand)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
370 (make-local-variable 'comint-input-ignoredups)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
371 (make-local-variable 'comint-delimiter-argument-list)
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
372 (make-local-variable 'comint-dynamic-complete-functions)
6256
3810012eb29f (comint-completion-fignore): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 6239
diff changeset
373 (make-local-variable 'comint-completion-fignore)
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
374 (make-local-variable 'comint-get-old-input)
6187
280d4a97da69 (comint-input-filter-functions)
Richard M. Stallman <rms@gnu.org>
parents: 6185
diff changeset
375 (make-local-variable 'comint-input-filter-functions)
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
376 (make-local-variable 'comint-input-filter)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
377 (make-local-variable 'comint-input-sender)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
378 (make-local-variable 'comint-eol-on-send)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
379 (make-local-variable 'comint-scroll-to-bottom-on-input)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
380 (make-local-variable 'comint-scroll-to-bottom-on-output)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
381 (make-local-variable 'comint-scroll-show-maximum-output)
4890
dab300dfe449 (comint-scroll-to-bottom-on-input): Default to nil.
Richard M. Stallman <rms@gnu.org>
parents: 4880
diff changeset
382 (make-local-variable 'pre-command-hook)
dab300dfe449 (comint-scroll-to-bottom-on-input): Default to nil.
Richard M. Stallman <rms@gnu.org>
parents: 4880
diff changeset
383 (add-hook 'pre-command-hook 'comint-preinput-scroll-to-bottom)
6187
280d4a97da69 (comint-input-filter-functions)
Richard M. Stallman <rms@gnu.org>
parents: 6185
diff changeset
384 (make-local-variable 'comint-output-filter-functions)
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
385 (make-local-variable 'comint-ptyp)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
386 (make-local-variable 'comint-exec-hook)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
387 (make-local-variable 'comint-process-echoes)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
388 (run-hooks 'comint-mode-hook))
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
389
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
390 (if comint-mode-map
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
391 nil
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
392 ;; Keys:
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
393 (setq comint-mode-map (make-sparse-keymap))
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
394 (define-key comint-mode-map "\ep" 'comint-previous-input)
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
395 (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
396 (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
397 (define-key comint-mode-map "\es" 'comint-next-matching-input)
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
398 (define-key comint-mode-map [?\A-\M-r] 'comint-previous-matching-input-from-input)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
399 (define-key comint-mode-map [?\A-\M-s] 'comint-next-matching-input-from-input)
5284
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
400 (define-key comint-mode-map "\e\C-l" 'comint-show-output)
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
401 (define-key comint-mode-map "\C-m" 'comint-send-input)
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
402 (define-key comint-mode-map "\C-d" 'comint-delchar-or-maybe-eof)
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
403 (define-key comint-mode-map "\C-a" 'comint-bol)
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
404 (define-key comint-mode-map "\C-c\C-u" 'comint-kill-input)
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
405 (define-key comint-mode-map "\C-c\C-w" 'backward-kill-word)
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
406 (define-key comint-mode-map "\C-c\C-c" 'comint-interrupt-subjob)
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
407 (define-key comint-mode-map "\C-c\C-z" 'comint-stop-subjob)
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
408 (define-key comint-mode-map "\C-c\C-\\" 'comint-quit-subjob)
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
409 (define-key comint-mode-map "\C-c\C-m" 'comint-copy-old-input)
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
410 (define-key comint-mode-map "\C-c\C-o" 'comint-kill-output)
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
411 (define-key comint-mode-map "\C-c\C-r" 'comint-show-output)
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
412 (define-key comint-mode-map "\C-c\C-e" 'comint-show-maximum-output)
7048
d4575065e6aa (comint-mode-map): comint-dynamic-list-input-ring now on C-c C-l.
Richard M. Stallman <rms@gnu.org>
parents: 6998
diff changeset
413 (define-key comint-mode-map "\C-c\C-l" 'comint-dynamic-list-input-ring)
4112
ab7dee78e335 (comint-{next,prev}-prompt, comint-send-eof): New functions.
Roland McGrath <roland@gnu.org>
parents: 3985
diff changeset
414 (define-key comint-mode-map "\C-c\C-n" 'comint-next-prompt)
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
415 (define-key comint-mode-map "\C-c\C-p" 'comint-previous-prompt)
4112
ab7dee78e335 (comint-{next,prev}-prompt, comint-send-eof): New functions.
Roland McGrath <roland@gnu.org>
parents: 3985
diff changeset
416 (define-key comint-mode-map "\C-c\C-d" 'comint-send-eof)
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
417 ;; Menu bars:
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
418 ;; completion:
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
419 (define-key comint-mode-map [menu-bar completion]
4899
3b157c1195a6 (comint-mode-map): Merge menu bar item Output into Input.
Richard M. Stallman <rms@gnu.org>
parents: 4890
diff changeset
420 (cons "Complete" (make-sparse-keymap "Complete")))
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
421 (define-key comint-mode-map [menu-bar completion complete-expand]
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
422 '("Expand File Name" . comint-replace-by-expanded-filename))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
423 (define-key comint-mode-map [menu-bar completion complete-listing]
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
424 '("File Completion Listing" . comint-dynamic-list-filename-completions))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
425 (define-key comint-mode-map [menu-bar completion complete-file]
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
426 '("Complete File Name" . comint-dynamic-complete-filename))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
427 (define-key comint-mode-map [menu-bar completion complete]
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
428 '("Complete Before Point" . comint-dynamic-complete))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
429 ;; Input history:
6148
ec063baec3e0 (full-copy-sparse-keymap): Function deleted.
Richard M. Stallman <rms@gnu.org>
parents: 6095
diff changeset
430 (define-key comint-mode-map [menu-bar inout]
4899
3b157c1195a6 (comint-mode-map): Merge menu bar item Output into Input.
Richard M. Stallman <rms@gnu.org>
parents: 4890
diff changeset
431 (cons "In/Out" (make-sparse-keymap "In/Out")))
6148
ec063baec3e0 (full-copy-sparse-keymap): Function deleted.
Richard M. Stallman <rms@gnu.org>
parents: 6095
diff changeset
432 (define-key comint-mode-map [menu-bar inout kill-output]
4899
3b157c1195a6 (comint-mode-map): Merge menu bar item Output into Input.
Richard M. Stallman <rms@gnu.org>
parents: 4890
diff changeset
433 '("Kill Current Output Group" . comint-kill-output))
6148
ec063baec3e0 (full-copy-sparse-keymap): Function deleted.
Richard M. Stallman <rms@gnu.org>
parents: 6095
diff changeset
434 (define-key comint-mode-map [menu-bar inout next-prompt]
4899
3b157c1195a6 (comint-mode-map): Merge menu bar item Output into Input.
Richard M. Stallman <rms@gnu.org>
parents: 4890
diff changeset
435 '("Forward Output Group" . comint-next-prompt))
6148
ec063baec3e0 (full-copy-sparse-keymap): Function deleted.
Richard M. Stallman <rms@gnu.org>
parents: 6095
diff changeset
436 (define-key comint-mode-map [menu-bar inout previous-prompt]
4899
3b157c1195a6 (comint-mode-map): Merge menu bar item Output into Input.
Richard M. Stallman <rms@gnu.org>
parents: 4890
diff changeset
437 '("Backward Output Group" . comint-previous-prompt))
6148
ec063baec3e0 (full-copy-sparse-keymap): Function deleted.
Richard M. Stallman <rms@gnu.org>
parents: 6095
diff changeset
438 (define-key comint-mode-map [menu-bar inout show-maximum-output]
4899
3b157c1195a6 (comint-mode-map): Merge menu bar item Output into Input.
Richard M. Stallman <rms@gnu.org>
parents: 4890
diff changeset
439 '("Show Maximum Output" . comint-show-maximum-output))
6148
ec063baec3e0 (full-copy-sparse-keymap): Function deleted.
Richard M. Stallman <rms@gnu.org>
parents: 6095
diff changeset
440 (define-key comint-mode-map [menu-bar inout show-output]
4899
3b157c1195a6 (comint-mode-map): Merge menu bar item Output into Input.
Richard M. Stallman <rms@gnu.org>
parents: 4890
diff changeset
441 '("Show Current Output Group" . comint-show-output))
6148
ec063baec3e0 (full-copy-sparse-keymap): Function deleted.
Richard M. Stallman <rms@gnu.org>
parents: 6095
diff changeset
442 (define-key comint-mode-map [menu-bar inout kill-input]
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
443 '("Kill Current Input" . comint-kill-input))
6148
ec063baec3e0 (full-copy-sparse-keymap): Function deleted.
Richard M. Stallman <rms@gnu.org>
parents: 6095
diff changeset
444 (define-key comint-mode-map [menu-bar inout copy-input]
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
445 '("Copy Old Input" . comint-copy-old-input))
6148
ec063baec3e0 (full-copy-sparse-keymap): Function deleted.
Richard M. Stallman <rms@gnu.org>
parents: 6095
diff changeset
446 (define-key comint-mode-map [menu-bar inout forward-matching-history]
4899
3b157c1195a6 (comint-mode-map): Merge menu bar item Output into Input.
Richard M. Stallman <rms@gnu.org>
parents: 4890
diff changeset
447 '("Forward Matching Input..." . comint-forward-matching-input))
6148
ec063baec3e0 (full-copy-sparse-keymap): Function deleted.
Richard M. Stallman <rms@gnu.org>
parents: 6095
diff changeset
448 (define-key comint-mode-map [menu-bar inout backward-matching-history]
4899
3b157c1195a6 (comint-mode-map): Merge menu bar item Output into Input.
Richard M. Stallman <rms@gnu.org>
parents: 4890
diff changeset
449 '("Backward Matching Input..." . comint-backward-matching-input))
6148
ec063baec3e0 (full-copy-sparse-keymap): Function deleted.
Richard M. Stallman <rms@gnu.org>
parents: 6095
diff changeset
450 (define-key comint-mode-map [menu-bar inout next-matching-history]
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
451 '("Next Matching Input..." . comint-next-matching-input))
6148
ec063baec3e0 (full-copy-sparse-keymap): Function deleted.
Richard M. Stallman <rms@gnu.org>
parents: 6095
diff changeset
452 (define-key comint-mode-map [menu-bar inout previous-matching-history]
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
453 '("Previous Matching Input..." . comint-previous-matching-input))
6148
ec063baec3e0 (full-copy-sparse-keymap): Function deleted.
Richard M. Stallman <rms@gnu.org>
parents: 6095
diff changeset
454 (define-key comint-mode-map [menu-bar inout next-matching-history-from-input]
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
455 '("Next Matching Current Input" . comint-next-matching-input-from-input))
6148
ec063baec3e0 (full-copy-sparse-keymap): Function deleted.
Richard M. Stallman <rms@gnu.org>
parents: 6095
diff changeset
456 (define-key comint-mode-map [menu-bar inout previous-matching-history-from-input]
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
457 '("Previous Matching Current Input" . comint-previous-matching-input-from-input))
6148
ec063baec3e0 (full-copy-sparse-keymap): Function deleted.
Richard M. Stallman <rms@gnu.org>
parents: 6095
diff changeset
458 (define-key comint-mode-map [menu-bar inout next-history]
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
459 '("Next Input" . comint-next-input))
6148
ec063baec3e0 (full-copy-sparse-keymap): Function deleted.
Richard M. Stallman <rms@gnu.org>
parents: 6095
diff changeset
460 (define-key comint-mode-map [menu-bar inout previous-history]
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
461 '("Previous Input" . comint-previous-input))
6148
ec063baec3e0 (full-copy-sparse-keymap): Function deleted.
Richard M. Stallman <rms@gnu.org>
parents: 6095
diff changeset
462 (define-key comint-mode-map [menu-bar inout list-history]
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
463 '("List Input History" . comint-dynamic-list-input-ring))
6148
ec063baec3e0 (full-copy-sparse-keymap): Function deleted.
Richard M. Stallman <rms@gnu.org>
parents: 6095
diff changeset
464 (define-key comint-mode-map [menu-bar inout expand-history]
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
465 '("Expand History Before Point" . comint-replace-by-expanded-history))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
466 ;; Signals
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
467 (define-key comint-mode-map [menu-bar signals]
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
468 (cons "Signals" (make-sparse-keymap "Signals")))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
469 (define-key comint-mode-map [menu-bar signals eof]
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
470 '("EOF" . comint-send-eof))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
471 (define-key comint-mode-map [menu-bar signals kill]
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
472 '("KILL" . comint-kill-subjob))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
473 (define-key comint-mode-map [menu-bar signals quit]
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
474 '("QUIT" . comint-quit-subjob))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
475 (define-key comint-mode-map [menu-bar signals cont]
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
476 '("CONT" . comint-continue-subjob))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
477 (define-key comint-mode-map [menu-bar signals stop]
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
478 '("STOP" . comint-stop-subjob))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
479 (define-key comint-mode-map [menu-bar signals break]
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
480 '("BREAK" . comint-interrupt-subjob))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
481 ;; Put them in the menu bar:
6148
ec063baec3e0 (full-copy-sparse-keymap): Function deleted.
Richard M. Stallman <rms@gnu.org>
parents: 6095
diff changeset
482 (setq menu-bar-final-items (append '(completion inout signals)
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
483 menu-bar-final-items))
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
484 )
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
485
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
486 (defun comint-check-proc (buffer)
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
487 "Return t if there is a living process associated w/buffer BUFFER.
3386
bc4729d67e6e (comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents: 3113
diff changeset
488 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
489 BUFFER can be either a buffer or the name of one."
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
490 (let ((proc (get-buffer-process buffer)))
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
491 (and proc (memq (process-status proc) '(run stop)))))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
492
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
493 ;;; Note that this guy, unlike shell.el's make-shell, barfs if you pass it ()
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
494 ;;; for the second argument (program).
870
1b3af6ad85be *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 864
diff changeset
495 ;;;###autoload
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
496 (defun make-comint (name program &optional startfile &rest switches)
1839
e10cdcb857d2 (make-comint): Added docstring.
Roland McGrath <roland@gnu.org>
parents: 1821
diff changeset
497 "Make a comint process NAME in a buffer, running PROGRAM.
e10cdcb857d2 (make-comint): Added docstring.
Roland McGrath <roland@gnu.org>
parents: 1821
diff changeset
498 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
499 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
500 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
501 the process. Any more args are arguments to PROGRAM."
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
502 (let ((buffer (get-buffer-create (concat "*" name "*"))))
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
503 ;; 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
504 ;; comint mode. Otherwise, leave buffer and existing process alone.
182
35ea4993d08c *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 114
diff changeset
505 (cond ((not (comint-check-proc buffer))
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
506 (save-excursion
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
507 (set-buffer buffer)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
508 (comint-mode)) ; Install local vars, mode, keymap, ...
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
509 (comint-exec buffer name program startfile switches)))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
510 buffer))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
511
6507
ff41e0e932b8 (comint-run): New command.
Richard M. Stallman <rms@gnu.org>
parents: 6256
diff changeset
512 ;;;###autoload
ff41e0e932b8 (comint-run): New command.
Richard M. Stallman <rms@gnu.org>
parents: 6256
diff changeset
513 (defun comint-run (program)
ff41e0e932b8 (comint-run): New command.
Richard M. Stallman <rms@gnu.org>
parents: 6256
diff changeset
514 "Run PROGRAM in a comint buffer and switch to it.
ff41e0e932b8 (comint-run): New command.
Richard M. Stallman <rms@gnu.org>
parents: 6256
diff changeset
515 The buffer name is made by surrounding the file name of PROGRAM with `*'s.
ff41e0e932b8 (comint-run): New command.
Richard M. Stallman <rms@gnu.org>
parents: 6256
diff changeset
516 The file name is used to make a symbol name, such as `comint-sh-hook', and any
ff41e0e932b8 (comint-run): New command.
Richard M. Stallman <rms@gnu.org>
parents: 6256
diff changeset
517 hooks on this symbol are run in the buffer.
ff41e0e932b8 (comint-run): New command.
Richard M. Stallman <rms@gnu.org>
parents: 6256
diff changeset
518 See `make-comint' and `comint-exec'."
ff41e0e932b8 (comint-run): New command.
Richard M. Stallman <rms@gnu.org>
parents: 6256
diff changeset
519 (interactive "sRun program: ")
ff41e0e932b8 (comint-run): New command.
Richard M. Stallman <rms@gnu.org>
parents: 6256
diff changeset
520 (let ((name (file-name-nondirectory program)))
ff41e0e932b8 (comint-run): New command.
Richard M. Stallman <rms@gnu.org>
parents: 6256
diff changeset
521 (switch-to-buffer (make-comint name program))
ff41e0e932b8 (comint-run): New command.
Richard M. Stallman <rms@gnu.org>
parents: 6256
diff changeset
522 (run-hooks (intern-soft (concat "comint-" name "-hook")))))
ff41e0e932b8 (comint-run): New command.
Richard M. Stallman <rms@gnu.org>
parents: 6256
diff changeset
523
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
524 (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
525 "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
526 Blasts any old process running in the buffer. Doesn't set the buffer mode.
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
527 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
528 buffer. The hook `comint-exec-hook' is run after each exec."
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
529 (save-excursion
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
530 (set-buffer buffer)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
531 (let ((proc (get-buffer-process buffer))) ; Blast any old process.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
532 (if proc (delete-process proc)))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
533 ;; Crank up a new process
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
534 (let ((proc (comint-exec-1 name buffer command switches)))
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
535 (set-process-filter proc 'comint-output-filter)
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
536 (make-local-variable 'comint-ptyp)
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
537 (setq comint-ptyp process-connection-type) ; T if pty, NIL if pipe.
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
538 ;; Jump to the end, and set the process mark.
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
539 (goto-char (point-max))
705
c7d478752305 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
540 (set-marker (process-mark proc) (point))
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
541 ;; Feed it the startfile.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
542 (cond (startfile
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
543 ;;This is guaranteed to wait long enough
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
544 ;;but has bad results if the comint does not prompt at all
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
545 ;; (while (= size (buffer-size))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
546 ;; (sleep-for 1))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
547 ;;I hope 1 second is enough!
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
548 (sleep-for 1)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
549 (goto-char (point-max))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
550 (insert-file-contents startfile)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
551 (setq startfile (buffer-substring (point) (point-max)))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
552 (delete-region (point) (point-max))
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
553 (comint-send-string proc startfile)))
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
554 (run-hooks 'comint-exec-hook)
705
c7d478752305 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
555 buffer)))
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
556
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
557 ;;; This auxiliary function cranks up the process for comint-exec in
638
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 584
diff changeset
558 ;;; the appropriate environment.
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
559
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
560 (defun comint-exec-1 (name buffer command switches)
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
561 (let ((process-environment
6750
a864110c6fc7 (comint-exec-1): Handle both termcap and terminfo.
Karl Heuer <kwzh@gnu.org>
parents: 6507
diff changeset
562 (nconc
7327
1e2d4da6b5c4 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 7071
diff changeset
563 ;; If using termcap, we specify `emacs' as the terminal type
1e2d4da6b5c4 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 7071
diff changeset
564 ;; because that lets us specify a width.
1e2d4da6b5c4 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 7071
diff changeset
565 ;; If using terminfo, we specify `unknown' because that is
1e2d4da6b5c4 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 7071
diff changeset
566 ;; a defined terminal type. `emacs' is not a defined terminal type
1e2d4da6b5c4 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 7071
diff changeset
567 ;; and there is no way for us to define it here.
1e2d4da6b5c4 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 7071
diff changeset
568 ;; Some programs that use terminfo get very confused
1e2d4da6b5c4 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 7071
diff changeset
569 ;; if TERM is not a valid terminal type.
6750
a864110c6fc7 (comint-exec-1): Handle both termcap and terminfo.
Karl Heuer <kwzh@gnu.org>
parents: 6507
diff changeset
570 (if (and (boundp 'system-uses-terminfo) system-uses-terminfo)
a864110c6fc7 (comint-exec-1): Handle both termcap and terminfo.
Karl Heuer <kwzh@gnu.org>
parents: 6507
diff changeset
571 (list "EMACS=t" "TERM=unknown"
a864110c6fc7 (comint-exec-1): Handle both termcap and terminfo.
Karl Heuer <kwzh@gnu.org>
parents: 6507
diff changeset
572 (format "COLUMNS=%d" (frame-width)))
a864110c6fc7 (comint-exec-1): Handle both termcap and terminfo.
Karl Heuer <kwzh@gnu.org>
parents: 6507
diff changeset
573 (list "EMACS=t" "TERM=emacs"
a864110c6fc7 (comint-exec-1): Handle both termcap and terminfo.
Karl Heuer <kwzh@gnu.org>
parents: 6507
diff changeset
574 (format "TERMCAP=emacs:co#%d:tc=unknown" (frame-width))))
a864110c6fc7 (comint-exec-1): Handle both termcap and terminfo.
Karl Heuer <kwzh@gnu.org>
parents: 6507
diff changeset
575 process-environment)))
638
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 584
diff changeset
576 (apply 'start-process name buffer command switches)))
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
577
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
578 ;;; Input history processing in a buffer
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
579 ;;; ===========================================================================
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
580 ;;; Useful input history functions, courtesy of the Ergo group.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
581
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
582 ;;; Eleven commands:
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
583 ;;; comint-dynamic-list-input-ring List history in help buffer.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
584 ;;; comint-previous-input Previous input...
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
585 ;;; comint-previous-matching-input ...matching a string.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
586 ;;; comint-previous-matching-input-from-input ... matching the current input.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
587 ;;; comint-next-input Next input...
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
588 ;;; comint-next-matching-input ...matching a string.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
589 ;;; comint-next-matching-input-from-input ... matching the current input.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
590 ;;; comint-backward-matching-input Backwards input...
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
591 ;;; comint-forward-matching-input ...matching a string.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
592 ;;; comint-replace-by-expanded-history Expand history at point;
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
593 ;;; replace with expanded history.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
594 ;;; comint-magic-space Expand history and insert space.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
595 ;;;
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
596 ;;; Three functions:
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
597 ;;; comint-read-input-ring Read into comint-input-ring...
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
598 ;;; comint-write-input-ring Write to comint-input-ring-file-name.
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
599 ;;; comint-replace-by-expanded-history-before-point Workhorse function.
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
600
5284
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
601 (defun comint-read-input-ring (&optional silent)
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
602 "Sets the buffer's `comint-input-ring' from a history file.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
603 The name of the file is given by the variable `comint-input-ring-file-name'.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
604 The history ring is of size `comint-input-ring-size', regardless of file size.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
605 If `comint-input-ring-file-name' is nil this function does nothing.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
606
5284
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
607 If the optional argument SILENT is non-nil, we say nothing about a
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
608 failure to read the history file.
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
609
5284
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
610 This function is useful for major mode commands and mode hooks.
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
611
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
612 The structure of the history file should be one input command per line,
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
613 with the most recent command last.
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
614 See also `comint-input-ignoredups' and `comint-write-input-ring'."
5016
11f0a3153f63 (comint-read-input-ring, comint-write-input-ring):
Richard M. Stallman <rms@gnu.org>
parents: 4993
diff changeset
615 (cond ((or (null comint-input-ring-file-name)
11f0a3153f63 (comint-read-input-ring, comint-write-input-ring):
Richard M. Stallman <rms@gnu.org>
parents: 4993
diff changeset
616 (equal comint-input-ring-file-name ""))
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
617 nil)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
618 ((not (file-readable-p comint-input-ring-file-name))
5284
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
619 (or silent
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
620 (message "Cannot read history file %s"
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
621 comint-input-ring-file-name)))
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
622 (t
8032
936532a595dd (comint-read-input-ring): Use ring-insert-at-beginning.
Richard M. Stallman <rms@gnu.org>
parents: 7846
diff changeset
623 (let ((history-buf (get-buffer-create " *temp*"))
936532a595dd (comint-read-input-ring): Use ring-insert-at-beginning.
Richard M. Stallman <rms@gnu.org>
parents: 7846
diff changeset
624 (file comint-input-ring-file-name)
936532a595dd (comint-read-input-ring): Use ring-insert-at-beginning.
Richard M. Stallman <rms@gnu.org>
parents: 7846
diff changeset
625 (count 0)
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
626 (ring (make-ring comint-input-ring-size)))
8032
936532a595dd (comint-read-input-ring): Use ring-insert-at-beginning.
Richard M. Stallman <rms@gnu.org>
parents: 7846
diff changeset
627 (unwind-protect
936532a595dd (comint-read-input-ring): Use ring-insert-at-beginning.
Richard M. Stallman <rms@gnu.org>
parents: 7846
diff changeset
628 (save-excursion
936532a595dd (comint-read-input-ring): Use ring-insert-at-beginning.
Richard M. Stallman <rms@gnu.org>
parents: 7846
diff changeset
629 (set-buffer history-buf)
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
630 (widen)
8032
936532a595dd (comint-read-input-ring): Use ring-insert-at-beginning.
Richard M. Stallman <rms@gnu.org>
parents: 7846
diff changeset
631 (erase-buffer)
936532a595dd (comint-read-input-ring): Use ring-insert-at-beginning.
Richard M. Stallman <rms@gnu.org>
parents: 7846
diff changeset
632 (insert-file-contents file)
936532a595dd (comint-read-input-ring): Use ring-insert-at-beginning.
Richard M. Stallman <rms@gnu.org>
parents: 7846
diff changeset
633 ;; Save restriction in case file is already visited...
936532a595dd (comint-read-input-ring): Use ring-insert-at-beginning.
Richard M. Stallman <rms@gnu.org>
parents: 7846
diff changeset
634 ;; Watch for those date stamps in history files!
936532a595dd (comint-read-input-ring): Use ring-insert-at-beginning.
Richard M. Stallman <rms@gnu.org>
parents: 7846
diff changeset
635 (goto-char (point-max))
936532a595dd (comint-read-input-ring): Use ring-insert-at-beginning.
Richard M. Stallman <rms@gnu.org>
parents: 7846
diff changeset
636 (while (and (< count comint-input-ring-size)
936532a595dd (comint-read-input-ring): Use ring-insert-at-beginning.
Richard M. Stallman <rms@gnu.org>
parents: 7846
diff changeset
637 (re-search-backward "^[ \t]*\\([^#\n].*\\)[ \t]*$"
936532a595dd (comint-read-input-ring): Use ring-insert-at-beginning.
Richard M. Stallman <rms@gnu.org>
parents: 7846
diff changeset
638 nil t))
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
639 (let ((history (buffer-substring (match-beginning 1)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
640 (match-end 1))))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
641 (if (or (null comint-input-ignoredups)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
642 (ring-empty-p ring)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
643 (not (string-equal (ring-ref ring 0) history)))
8032
936532a595dd (comint-read-input-ring): Use ring-insert-at-beginning.
Richard M. Stallman <rms@gnu.org>
parents: 7846
diff changeset
644 (ring-insert-at-beginning ring history)))
936532a595dd (comint-read-input-ring): Use ring-insert-at-beginning.
Richard M. Stallman <rms@gnu.org>
parents: 7846
diff changeset
645 (setq count (1+ count))))
936532a595dd (comint-read-input-ring): Use ring-insert-at-beginning.
Richard M. Stallman <rms@gnu.org>
parents: 7846
diff changeset
646 (kill-buffer history-buf))
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
647 (setq comint-input-ring ring
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
648 comint-input-ring-index nil)))))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
649
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
650 (defun comint-write-input-ring ()
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
651 "Writes the buffer's `comint-input-ring' to a history file.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
652 The name of the file is given by the variable `comint-input-ring-file-name'.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
653 The original contents of the file are lost if `comint-input-ring' is not empty.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
654 If `comint-input-ring-file-name' is nil this function does nothing.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
655
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
656 Useful within process sentinels.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
657
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
658 See also `comint-read-input-ring'."
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
659 (cond ((or (null comint-input-ring-file-name)
5016
11f0a3153f63 (comint-read-input-ring, comint-write-input-ring):
Richard M. Stallman <rms@gnu.org>
parents: 4993
diff changeset
660 (equal comint-input-ring-file-name "")
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
661 (null comint-input-ring) (ring-empty-p comint-input-ring))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
662 nil)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
663 ((not (file-writable-p comint-input-ring-file-name))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
664 (message "Cannot write history file %s" comint-input-ring-file-name))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
665 (t
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
666 (let* ((history-buf (get-buffer-create " *Temp Input History*"))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
667 (ring comint-input-ring)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
668 (file comint-input-ring-file-name)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
669 (index (ring-length ring)))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
670 ;; Write it all out into a buffer first. Much faster, but messier,
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
671 ;; than writing it one line at a time.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
672 (save-excursion
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
673 (set-buffer history-buf)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
674 (erase-buffer)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
675 (while (> index 0)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
676 (setq index (1- index))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
677 (insert (ring-ref ring index) ?\n))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
678 (write-region (buffer-string) nil file nil 'no-message)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
679 (kill-buffer nil))))))
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
680
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
681
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
682 (defun comint-dynamic-list-input-ring ()
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
683 "List in help buffer the buffer's input history."
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
684 (interactive)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
685 (if (or (not (ring-p comint-input-ring))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
686 (ring-empty-p comint-input-ring))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
687 (message "No history")
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
688 (let ((history nil)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
689 (history-buffer " *Input History*")
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
690 (index (1- (ring-length comint-input-ring)))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
691 (conf (current-window-configuration)))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
692 ;; We have to build up a list ourselves from the ring vector.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
693 (while (>= index 0)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
694 (setq history (cons (ring-ref comint-input-ring index) history)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
695 index (1- index)))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
696 ;; Change "completion" to "history reference"
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
697 ;; to make the display accurate.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
698 (with-output-to-temp-buffer history-buffer
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
699 (display-completion-list history)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
700 (set-buffer history-buffer)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
701 (forward-line 3)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
702 (while (search-backward "completion" nil 'move)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
703 (replace-match "history reference")))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
704 (sit-for 0)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
705 (message "Hit space to flush")
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
706 (let ((ch (read-event)))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
707 (if (eq ch ?\ )
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
708 (set-window-configuration conf)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
709 (setq unread-command-events (list ch)))))))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
710
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
711
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
712 (defun comint-regexp-arg (prompt)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
713 ;; Return list of regexp and prefix arg using PROMPT.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
714 (let* ((minibuffer-history-sexp-flag nil)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
715 ;; Don't clobber this.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
716 (last-command last-command)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
717 (regexp (read-from-minibuffer prompt nil nil nil
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
718 'minibuffer-history-search-history)))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
719 (list (if (string-equal regexp "")
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
720 (setcar minibuffer-history-search-history
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
721 (nth 1 minibuffer-history-search-history))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
722 regexp)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
723 (prefix-numeric-value current-prefix-arg))))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
724
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
725 (defun comint-search-arg (arg)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
726 ;; First make sure there is a ring and that we are after the process mark
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
727 (cond ((not (comint-after-pmark-p))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
728 (error "Not at command line"))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
729 ((or (null comint-input-ring)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
730 (ring-empty-p comint-input-ring))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
731 (error "Empty input ring"))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
732 ((zerop arg)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
733 ;; arg of zero resets search from beginning, and uses arg of 1
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
734 (setq comint-input-ring-index nil)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
735 1)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
736 (t
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
737 arg)))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
738
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
739 (defun comint-search-start (arg)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
740 ;; Index to start a directional search, starting at comint-input-ring-index
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
741 (if comint-input-ring-index
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
742 ;; If a search is running, offset by 1 in direction of arg
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
743 (mod (+ comint-input-ring-index (if (> arg 0) 1 -1))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
744 (ring-length comint-input-ring))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
745 ;; For a new search, start from beginning or end, as appropriate
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
746 (if (>= arg 0)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
747 0 ; First elt for forward search
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
748 (1- (ring-length comint-input-ring))))) ; Last elt for backward search
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
749
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
750 (defun comint-previous-input-string (arg)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
751 "Return the string ARG places along the input ring.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
752 Moves relative to `comint-input-ring-index'."
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
753 (ring-ref comint-input-ring (if comint-input-ring-index
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
754 (mod (+ arg comint-input-ring-index)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
755 (ring-length comint-input-ring))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
756 arg)))
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
757
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
758 (defun comint-previous-input (arg)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
759 "Cycle backwards through input history."
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
760 (interactive "*p")
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
761 (comint-previous-matching-input "." arg))
909
4c6cdb66c74c *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 870
diff changeset
762
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
763 (defun comint-next-input (arg)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
764 "Cycle forwards through input history."
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
765 (interactive "*p")
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
766 (comint-previous-input (- arg)))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
767
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
768 (defun comint-previous-matching-input-string (regexp arg)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
769 "Return the string matching REGEXP ARG places along the input ring.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
770 Moves relative to `comint-input-ring-index'."
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
771 (let* ((pos (comint-previous-matching-input-string-position regexp arg)))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
772 (if pos (ring-ref comint-input-ring pos))))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
773
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
774 (defun comint-previous-matching-input-string-position (regexp arg &optional start)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
775 "Return the index matching REGEXP ARG places along the input ring.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
776 Moves relative to START, or `comint-input-ring-index'."
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
777 (if (or (not (ring-p comint-input-ring))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
778 (ring-empty-p comint-input-ring))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
779 (error "No history"))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
780 (let* ((len (ring-length comint-input-ring))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
781 (motion (if (> arg 0) 1 -1))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
782 (n (mod (- (or start (comint-search-start arg)) motion) len))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
783 (tried-each-ring-item nil)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
784 (prev nil))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
785 ;; Do the whole search as many times as the argument says.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
786 (while (and (/= arg 0) (not tried-each-ring-item))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
787 ;; Step once.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
788 (setq prev n
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
789 n (mod (+ n motion) len))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
790 ;; If we haven't reached a match, step some more.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
791 (while (and (< n len) (not tried-each-ring-item)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
792 (not (string-match regexp (ring-ref comint-input-ring n))))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
793 (setq n (mod (+ n motion) len)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
794 ;; If we have gone all the way around in this search.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
795 tried-each-ring-item (= n prev)))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
796 (setq arg (if (> arg 0) (1- arg) (1+ arg))))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
797 ;; Now that we know which ring element to use, if we found it, return that.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
798 (if (string-match regexp (ring-ref comint-input-ring n))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
799 n)))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
800
2673
27dd7479b158 (comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents: 2627
diff changeset
801 (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
802 "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
803 \(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
804 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
805 If N is negative, find the next or Nth next match."
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
806 (interactive (comint-regexp-arg "Previous input matching (regexp): "))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
807 (setq arg (comint-search-arg arg))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
808 (let ((pos (comint-previous-matching-input-string-position regexp arg)))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
809 ;; Has a match been found?
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
810 (if (null pos)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
811 (error "Not found")
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
812 (setq comint-input-ring-index pos)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
813 (message "History item: %d" (1+ pos))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
814 (delete-region
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
815 ;; Can't use kill-region as it sets this-command
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
816 (process-mark (get-buffer-process (current-buffer))) (point))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
817 (insert (ring-ref comint-input-ring pos)))))
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
818
2673
27dd7479b158 (comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents: 2627
diff changeset
819 (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
820 "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
821 \(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
822 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
823 If N is negative, find the previous or Nth previous match."
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
824 (interactive (comint-regexp-arg "Next input matching (regexp): "))
2673
27dd7479b158 (comint-previous-matching-input): New command, on M-r.
Richard M. Stallman <rms@gnu.org>
parents: 2627
diff changeset
825 (comint-previous-matching-input regexp (- arg)))
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
826
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
827 (defun comint-previous-matching-input-from-input (arg)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
828 "Search backwards through input history for match for current input.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
829 \(Previous history elements are earlier commands.)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
830 With prefix argument N, search for Nth previous match.
5323
44a59f6e114e (comint-next-matching-input-from-input): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5284
diff changeset
831 If N is negative, search forwards for the -Nth following match."
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
832 (interactive "p")
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
833 (if (not (memq last-command '(comint-previous-matching-input-from-input
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
834 comint-next-matching-input-from-input)))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
835 ;; Starting a new search
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
836 (setq comint-matching-input-from-input-string
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
837 (buffer-substring
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
838 (process-mark (get-buffer-process (current-buffer)))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
839 (point))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
840 comint-input-ring-index nil))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
841 (comint-previous-matching-input
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
842 (concat "^" (regexp-quote comint-matching-input-from-input-string))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
843 arg))
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
844
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
845 (defun comint-next-matching-input-from-input (arg)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
846 "Search forwards through input history for match for current input.
5323
44a59f6e114e (comint-next-matching-input-from-input): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5284
diff changeset
847 \(Following history elements are more recent commands.)
44a59f6e114e (comint-next-matching-input-from-input): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5284
diff changeset
848 With prefix argument N, search for Nth following match.
44a59f6e114e (comint-next-matching-input-from-input): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5284
diff changeset
849 If N is negative, search backwards for the -Nth previous match."
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
850 (interactive "p")
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
851 (comint-previous-matching-input-from-input (- arg)))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
852
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
853
5284
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
854 (defun comint-replace-by-expanded-history (&optional silent)
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
855 "Expand input command history references before point.
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
856 Expansion is dependent on the value of `comint-input-autoexpand'.
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
857
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
858 This function depends on the buffer's idea of the input history, which may not
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
859 match the command interpreter's idea, assuming it has one.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
860
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
861 Assumes history syntax is like typical Un*x shells'. However, since emacs
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
862 cannot know the interpreter's idea of input line numbers, assuming it has one,
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
863 it cannot expand absolute input line number references.
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
864
5284
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
865 If the optional argument SILENT is non-nil, never complain
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
866 even if history reference seems erroneous.
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
867
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
868 See `comint-magic-space' and `comint-replace-by-expanded-history-before-point'.
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
869
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
870 Returns t if successful."
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
871 (interactive)
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
872 (if (and comint-input-autoexpand
6958
6962dec6fe55 (comint-replace-by-expanded-history): Expand only at prompt.
Karl Heuer <kwzh@gnu.org>
parents: 6890
diff changeset
873 (string-match "[!^]" (funcall comint-get-old-input))
6962dec6fe55 (comint-replace-by-expanded-history): Expand only at prompt.
Karl Heuer <kwzh@gnu.org>
parents: 6890
diff changeset
874 (save-excursion (beginning-of-line)
6962dec6fe55 (comint-replace-by-expanded-history): Expand only at prompt.
Karl Heuer <kwzh@gnu.org>
parents: 6890
diff changeset
875 (looking-at comint-prompt-regexp)))
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
876 ;; Looks like there might be history references in the command.
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
877 (let ((previous-modified-tick (buffer-modified-tick)))
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
878 (message "Expanding history references...")
6958
6962dec6fe55 (comint-replace-by-expanded-history): Expand only at prompt.
Karl Heuer <kwzh@gnu.org>
parents: 6890
diff changeset
879 (comint-replace-by-expanded-history-before-point silent)
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
880 (/= previous-modified-tick (buffer-modified-tick)))))
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
881
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
882
6958
6962dec6fe55 (comint-replace-by-expanded-history): Expand only at prompt.
Karl Heuer <kwzh@gnu.org>
parents: 6890
diff changeset
883 (defun comint-replace-by-expanded-history-before-point (silent)
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
884 "Expand directory stack reference before point.
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
885 See `comint-replace-by-expanded-history'. Returns t if successful."
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
886 (save-excursion
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
887 (let ((toend (- (save-excursion (end-of-line nil) (point)) (point)))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
888 (start (progn (comint-bol nil) (point))))
5284
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
889 (while (progn
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
890 (skip-chars-forward "^!^"
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
891 (save-excursion
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
892 (end-of-line nil) (- (point) toend)))
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
893 (< (point)
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
894 (save-excursion
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
895 (end-of-line nil) (- (point) toend))))
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
896 ;; This seems a bit complex. We look for references such as !!, !-num,
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
897 ;; !foo, !?foo, !{bar}, !?{bar}, ^oh, ^my^, ^god^it, ^never^ends^.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
898 ;; If that wasn't enough, the plings can be suffixed with argument
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
899 ;; range specifiers.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
900 ;; Argument ranges are complex too, so we hive off the input line,
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
901 ;; referenced with plings, with the range string to `comint-args'.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
902 (setq comint-input-ring-index nil)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
903 (cond ((or (= (preceding-char) ?\\)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
904 (comint-within-quotes start (point)))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
905 ;; The history is quoted, or we're in quotes.
5284
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
906 (goto-char (1+ (point))))
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
907 ((looking-at "![0-9]+\\($\\|[^-]\\)")
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
908 ;; We cannot know the interpreter's idea of input line numbers.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
909 (goto-char (match-end 0))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
910 (message "Absolute reference cannot be expanded"))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
911 ((looking-at "!-\\([0-9]+\\)\\(:?[0-9^$*-]+\\)?")
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
912 ;; Just a number of args from `number' lines backward.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
913 (let ((number (1- (string-to-number
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
914 (buffer-substring (match-beginning 1)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
915 (match-end 1))))))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
916 (if (<= number (ring-length comint-input-ring))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
917 (progn
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
918 (replace-match
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
919 (comint-args (comint-previous-input-string number)
6187
280d4a97da69 (comint-input-filter-functions)
Richard M. Stallman <rms@gnu.org>
parents: 6185
diff changeset
920 (match-beginning 2) (match-end 2))
280d4a97da69 (comint-input-filter-functions)
Richard M. Stallman <rms@gnu.org>
parents: 6185
diff changeset
921 t t)
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
922 (setq comint-input-ring-index number)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
923 (message "History item: %d" (1+ number)))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
924 (goto-char (match-end 0))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
925 (message "Relative reference exceeds input history size"))))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
926 ((or (looking-at "!!?:?\\([0-9^$*-]+\\)") (looking-at "!!"))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
927 ;; Just a number of args from the previous input line.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
928 (replace-match
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
929 (comint-args (comint-previous-input-string 0)
6187
280d4a97da69 (comint-input-filter-functions)
Richard M. Stallman <rms@gnu.org>
parents: 6185
diff changeset
930 (match-beginning 1) (match-end 1))
280d4a97da69 (comint-input-filter-functions)
Richard M. Stallman <rms@gnu.org>
parents: 6185
diff changeset
931 t t)
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
932 (message "History item: previous"))
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
933 ((looking-at
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
934 "!\\??\\({\\(.+\\)}\\|\\(\\sw+\\)\\)\\(:?[0-9^$*-]+\\)?")
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
935 ;; Most recent input starting with or containing (possibly
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
936 ;; protected) string, maybe just a number of args. Phew.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
937 (let* ((mb1 (match-beginning 1)) (me1 (match-end 1))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
938 (mb2 (match-beginning 2)) (me2 (match-end 2))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
939 (exp (buffer-substring (or mb2 mb1) (or me2 me1)))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
940 (pref (if (save-match-data (looking-at "!\\?")) "" "^"))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
941 (pos (save-match-data
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
942 (comint-previous-matching-input-string-position
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
943 (concat pref (regexp-quote exp)) 1))))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
944 (if (null pos)
6886
d4010211153e (comint-replace-by-expanded-history-before-point): Advance point
Karl Heuer <kwzh@gnu.org>
parents: 6847
diff changeset
945 (progn
d4010211153e (comint-replace-by-expanded-history-before-point): Advance point
Karl Heuer <kwzh@gnu.org>
parents: 6847
diff changeset
946 (goto-char (match-end 0))
d4010211153e (comint-replace-by-expanded-history-before-point): Advance point
Karl Heuer <kwzh@gnu.org>
parents: 6847
diff changeset
947 (or silent
d4010211153e (comint-replace-by-expanded-history-before-point): Advance point
Karl Heuer <kwzh@gnu.org>
parents: 6847
diff changeset
948 (progn (message "Not found")
d4010211153e (comint-replace-by-expanded-history-before-point): Advance point
Karl Heuer <kwzh@gnu.org>
parents: 6847
diff changeset
949 (ding))))
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
950 (setq comint-input-ring-index pos)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
951 (replace-match
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
952 (comint-args (ring-ref comint-input-ring pos)
6187
280d4a97da69 (comint-input-filter-functions)
Richard M. Stallman <rms@gnu.org>
parents: 6185
diff changeset
953 (match-beginning 4) (match-end 4))
280d4a97da69 (comint-input-filter-functions)
Richard M. Stallman <rms@gnu.org>
parents: 6185
diff changeset
954 t t)
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
955 (message "History item: %d" (1+ pos)))))
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
956 ((looking-at "\\^\\([^^]+\\)\\^?\\([^^]*\\)\\^?")
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
957 ;; Quick substitution on the previous input line.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
958 (let ((old (buffer-substring (match-beginning 1) (match-end 1)))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
959 (new (buffer-substring (match-beginning 2) (match-end 2)))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
960 (pos nil))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
961 (replace-match (comint-previous-input-string 0) t t)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
962 (setq pos (point))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
963 (goto-char (match-beginning 0))
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
964 (if (not (search-forward old pos t))
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
965 (or silent
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
966 (error "Not found"))
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
967 (replace-match new t t)
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
968 (message "History item: substituted"))))
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
969 (t
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
970 (goto-char (match-end 0))))))))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
971
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
972
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
973 (defun comint-magic-space (arg)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
974 "Expand input history references before point and insert ARG spaces.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
975 A useful command to bind to SPC. See `comint-replace-by-expanded-history'."
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
976 (interactive "p")
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
977 (comint-replace-by-expanded-history)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
978 (self-insert-command arg))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
979
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
980 (defun comint-within-quotes (beg end)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
981 "Return t if the number of quotes between BEG and END is odd.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
982 Quotes are single and double."
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
983 (let ((countsq (comint-how-many-region "\\(^\\|[^\\\\]\\)\'" beg end))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
984 (countdq (comint-how-many-region "\\(^\\|[^\\\\]\\)\"" beg end)))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
985 (or (= (mod countsq 2) 1) (= (mod countdq 2) 1))))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
986
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
987 (defun comint-how-many-region (regexp beg end)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
988 "Return number of matches for REGEXP from BEG to END."
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
989 (let ((count 0))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
990 (save-excursion
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
991 (save-match-data
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
992 (goto-char beg)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
993 (while (re-search-forward regexp end t)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
994 (setq count (1+ count)))))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
995 count))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
996
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
997 (defun comint-args (string begin end)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
998 ;; From STRING, return the args depending on the range specified in the text
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
999 ;; from BEGIN to END. If BEGIN is nil, assume all args. Ignore leading `:'.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1000 ;; Range can be x-y, x-, -y, where x/y can be [0-9], *, ^, $.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1001 (save-match-data
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1002 (if (null begin)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1003 (comint-arguments string 0 nil)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1004 (let* ((range (buffer-substring
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1005 (if (eq (char-after begin) ?:) (1+ begin) begin) end))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1006 (nth (cond ((string-match "^[*^]" range) 1)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1007 ((string-match "^-" range) 0)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1008 ((string-equal range "$") nil)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1009 (t (string-to-number range))))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1010 (mth (cond ((string-match "[-*$]$" range) nil)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1011 ((string-match "-" range)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1012 (string-to-number (substring range (match-end 0))))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1013 (t nth))))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1014 (comint-arguments string nth mth)))))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1015
6154
385d5fe1c95c (comint-arguments): Use just one regexp to find end of arg
Richard M. Stallman <rms@gnu.org>
parents: 6148
diff changeset
1016 ;; Return a list of arguments from ARG. Break it up at the
385d5fe1c95c (comint-arguments): Use just one regexp to find end of arg
Richard M. Stallman <rms@gnu.org>
parents: 6148
diff changeset
1017 ;; delimiters in comint-delimiter-argument-list. Returned list is backwards.
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1018 (defun comint-delim-arg (arg)
6154
385d5fe1c95c (comint-arguments): Use just one regexp to find end of arg
Richard M. Stallman <rms@gnu.org>
parents: 6148
diff changeset
1019 (if (null comint-delimiter-argument-list)
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1020 (list arg)
6154
385d5fe1c95c (comint-arguments): Use just one regexp to find end of arg
Richard M. Stallman <rms@gnu.org>
parents: 6148
diff changeset
1021 (let ((args nil)
385d5fe1c95c (comint-arguments): Use just one regexp to find end of arg
Richard M. Stallman <rms@gnu.org>
parents: 6148
diff changeset
1022 (pos 0)
385d5fe1c95c (comint-arguments): Use just one regexp to find end of arg
Richard M. Stallman <rms@gnu.org>
parents: 6148
diff changeset
1023 (len (length arg)))
385d5fe1c95c (comint-arguments): Use just one regexp to find end of arg
Richard M. Stallman <rms@gnu.org>
parents: 6148
diff changeset
1024 (while (< pos len)
385d5fe1c95c (comint-arguments): Use just one regexp to find end of arg
Richard M. Stallman <rms@gnu.org>
parents: 6148
diff changeset
1025 (let ((char (aref arg pos))
385d5fe1c95c (comint-arguments): Use just one regexp to find end of arg
Richard M. Stallman <rms@gnu.org>
parents: 6148
diff changeset
1026 (start pos))
385d5fe1c95c (comint-arguments): Use just one regexp to find end of arg
Richard M. Stallman <rms@gnu.org>
parents: 6148
diff changeset
1027 (if (memq char comint-delimiter-argument-list)
385d5fe1c95c (comint-arguments): Use just one regexp to find end of arg
Richard M. Stallman <rms@gnu.org>
parents: 6148
diff changeset
1028 (while (and (< pos len) (eq (aref arg pos) char))
385d5fe1c95c (comint-arguments): Use just one regexp to find end of arg
Richard M. Stallman <rms@gnu.org>
parents: 6148
diff changeset
1029 (setq pos (1+ pos)))
385d5fe1c95c (comint-arguments): Use just one regexp to find end of arg
Richard M. Stallman <rms@gnu.org>
parents: 6148
diff changeset
1030 (while (and (< pos len)
385d5fe1c95c (comint-arguments): Use just one regexp to find end of arg
Richard M. Stallman <rms@gnu.org>
parents: 6148
diff changeset
1031 (not (memq (aref arg pos)
385d5fe1c95c (comint-arguments): Use just one regexp to find end of arg
Richard M. Stallman <rms@gnu.org>
parents: 6148
diff changeset
1032 comint-delimiter-argument-list)))
385d5fe1c95c (comint-arguments): Use just one regexp to find end of arg
Richard M. Stallman <rms@gnu.org>
parents: 6148
diff changeset
1033 (setq pos (1+ pos))))
385d5fe1c95c (comint-arguments): Use just one regexp to find end of arg
Richard M. Stallman <rms@gnu.org>
parents: 6148
diff changeset
1034 (setq args (cons (substring arg start pos) args))))
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1035 args)))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1036
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1037 (defun comint-arguments (string nth mth)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1038 "Return from STRING the NTH to MTH arguments.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1039 NTH and/or MTH can be nil, which means the last argument.
6154
385d5fe1c95c (comint-arguments): Use just one regexp to find end of arg
Richard M. Stallman <rms@gnu.org>
parents: 6148
diff changeset
1040 Returned arguments are separated by single spaces.
385d5fe1c95c (comint-arguments): Use just one regexp to find end of arg
Richard M. Stallman <rms@gnu.org>
parents: 6148
diff changeset
1041 We assume whitespace separates arguments, except within quotes.
385d5fe1c95c (comint-arguments): Use just one regexp to find end of arg
Richard M. Stallman <rms@gnu.org>
parents: 6148
diff changeset
1042 Also, a run of one or more of a single character
385d5fe1c95c (comint-arguments): Use just one regexp to find end of arg
Richard M. Stallman <rms@gnu.org>
parents: 6148
diff changeset
1043 in `comint-delimiter-argument-list' is a separate argument.
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1044 Argument 0 is the command name."
6154
385d5fe1c95c (comint-arguments): Use just one regexp to find end of arg
Richard M. Stallman <rms@gnu.org>
parents: 6148
diff changeset
1045 (let ((arg "\\(\\(\"[^\"]*\"\\|\'[^\']*\'\\|\`[^\`]*\`\\)\\|\\S \\)+")
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1046 (args ()) (pos 0) (str nil))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1047 ;; We build a list of all the args. Unnecessary, but more efficient, when
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1048 ;; ranges of args are required, than picking out one by one and recursing.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1049 (while (string-match arg string pos)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1050 (setq pos (match-end 0)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1051 str (substring string (match-beginning 0) pos)
6154
385d5fe1c95c (comint-arguments): Use just one regexp to find end of arg
Richard M. Stallman <rms@gnu.org>
parents: 6148
diff changeset
1052 ;; (match-end 2) is non-nil if we found quotes.
385d5fe1c95c (comint-arguments): Use just one regexp to find end of arg
Richard M. Stallman <rms@gnu.org>
parents: 6148
diff changeset
1053 args (if (match-end 2) (cons str args)
385d5fe1c95c (comint-arguments): Use just one regexp to find end of arg
Richard M. Stallman <rms@gnu.org>
parents: 6148
diff changeset
1054 (nconc (comint-delim-arg str) args))))
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1055 (let ((n (or nth (1- (length args))))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1056 (m (if mth (1- (- (length args) mth)) 0)))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1057 (mapconcat
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1058 (function (lambda (a) a)) (nthcdr n (nreverse (nthcdr m args))) " "))))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1059
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1060 ;;;
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1061 ;;; Input processing stuff
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1062 ;;;
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1063
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1064 (defun comint-send-input ()
1356
dcf780f7ae1b Doc fix.
Christopher Zaborsky <rogue@erratum.com>
parents: 1131
diff changeset
1065 "Send input to process.
dcf780f7ae1b Doc fix.
Christopher Zaborsky <rogue@erratum.com>
parents: 1131
diff changeset
1066 After the process output mark, sends all text from the process mark to
dcf780f7ae1b Doc fix.
Christopher Zaborsky <rogue@erratum.com>
parents: 1131
diff changeset
1067 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
1068 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
1069 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
1070 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
1071 \(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
1072 since it is assumed the remote process will re-echo it).
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1073
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1074 Any history reference may be expanded depending on the value of the variable
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1075 `comint-input-autoexpand'. The list of function names contained in the value
6187
280d4a97da69 (comint-input-filter-functions)
Richard M. Stallman <rms@gnu.org>
parents: 6185
diff changeset
1076 of `comint-input-filter-functions' is called on the input before sending it.
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1077 The input is entered into the input history ring, if the value of variable
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1078 `comint-input-filter' returns non-nil when called on the input.
3386
bc4729d67e6e (comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents: 3113
diff changeset
1079
bc4729d67e6e (comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents: 3113
diff changeset
1080 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
1081 end of line before sending the input.
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1082
6187
280d4a97da69 (comint-input-filter-functions)
Richard M. Stallman <rms@gnu.org>
parents: 6185
diff changeset
1083 The values of `comint-get-old-input', `comint-input-filter-functions', and
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1084 `comint-input-filter' are chosen according to the command interpreter running
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1085 in the buffer. E.g.,
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1086
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1087 If the interpreter is the csh,
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1088 comint-get-old-input is the default: take the current line, discard any
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1089 initial string matching regexp comint-prompt-regexp.
6187
280d4a97da69 (comint-input-filter-functions)
Richard M. Stallman <rms@gnu.org>
parents: 6185
diff changeset
1090 comint-input-filter-functions monitors input for \"cd\", \"pushd\", and
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1091 \"popd\" commands. When it sees one, it cd's the buffer.
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1092 comint-input-filter is the default: returns t if the input isn't all white
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1093 space.
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1094
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1095 If the comint is Lucid Common Lisp,
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1096 comint-get-old-input snarfs the sexp ending at point.
6187
280d4a97da69 (comint-input-filter-functions)
Richard M. Stallman <rms@gnu.org>
parents: 6185
diff changeset
1097 comint-input-filter-functions does nothing.
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1098 comint-input-filter returns nil if the input matches input-filter-regexp,
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1099 which matches (1) all whitespace (2) :a, :c, etc.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1100
909
4c6cdb66c74c *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 870
diff changeset
1101 Similarly for Soar, Scheme, etc."
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1102 (interactive)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1103 ;; Note that the input string does not include its terminal newline.
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1104 (let ((proc (get-buffer-process (current-buffer))))
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1105 (if (not proc) (error "Current buffer has no process")
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1106 (let* ((pmark (process-mark proc))
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1107 (intxt (if (>= (point) (marker-position pmark))
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1108 (progn (if comint-eol-on-send (end-of-line))
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1109 (buffer-substring pmark (point)))
705
c7d478752305 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
1110 (let ((copy (funcall comint-get-old-input)))
c7d478752305 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
1111 (goto-char pmark)
c7d478752305 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
1112 (insert copy)
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1113 copy)))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1114 (input (if (not (eq comint-input-autoexpand 'input))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1115 ;; Just whatever's already there
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1116 intxt
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1117 ;; Expand and leave it visible in buffer
5284
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
1118 (comint-replace-by-expanded-history t)
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1119 (buffer-substring pmark (point))))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1120 (history (if (not (eq comint-input-autoexpand 'history))
5166
7e66b092f331 (comint-send-input): Don't call comint-arguments
Richard M. Stallman <rms@gnu.org>
parents: 5152
diff changeset
1121 input
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1122 ;; This is messy 'cos ultimately the original
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1123 ;; functions used do insertion, rather than return
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1124 ;; strings. We have to expand, then insert back.
5284
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
1125 (comint-replace-by-expanded-history t)
5166
7e66b092f331 (comint-send-input): Don't call comint-arguments
Richard M. Stallman <rms@gnu.org>
parents: 5152
diff changeset
1126 (let ((copy (buffer-substring pmark (point))))
7e66b092f331 (comint-send-input): Don't call comint-arguments
Richard M. Stallman <rms@gnu.org>
parents: 5152
diff changeset
1127 (delete-region pmark (point))
7e66b092f331 (comint-send-input): Don't call comint-arguments
Richard M. Stallman <rms@gnu.org>
parents: 5152
diff changeset
1128 (insert input)
7e66b092f331 (comint-send-input): Don't call comint-arguments
Richard M. Stallman <rms@gnu.org>
parents: 5152
diff changeset
1129 copy))))
2539
577c77cfd199 *** empty log message ***
Noah Friedman <friedman@splode.com>
parents: 2518
diff changeset
1130 (if comint-process-echoes
577c77cfd199 *** empty log message ***
Noah Friedman <friedman@splode.com>
parents: 2518
diff changeset
1131 (delete-region pmark (point))
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1132 (insert ?\n))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1133 (if (and (funcall comint-input-filter history)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1134 (or (null comint-input-ignoredups)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1135 (not (ring-p comint-input-ring))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1136 (ring-empty-p comint-input-ring)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1137 (not (string-equal (ring-ref comint-input-ring 0)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1138 history))))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1139 (ring-insert comint-input-ring history))
6187
280d4a97da69 (comint-input-filter-functions)
Richard M. Stallman <rms@gnu.org>
parents: 6185
diff changeset
1140 (let ((functions comint-input-filter-functions))
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1141 (while functions
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1142 (funcall (car functions) (concat input "\n"))
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1143 (setq functions (cdr functions))))
909
4c6cdb66c74c *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 870
diff changeset
1144 (setq comint-input-ring-index nil)
8060
5b9bbe66631c (comint-send-input): Update markers before actually sending the input.
Richard M. Stallman <rms@gnu.org>
parents: 8032
diff changeset
1145 ;; Update the markers before we send the input
5b9bbe66631c (comint-send-input): Update markers before actually sending the input.
Richard M. Stallman <rms@gnu.org>
parents: 8032
diff changeset
1146 ;; in case we get output amidst sending the input.
705
c7d478752305 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
1147 (set-marker comint-last-input-start pmark)
c7d478752305 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
1148 (set-marker comint-last-input-end (point))
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1149 (set-marker (process-mark proc) (point))
8060
5b9bbe66631c (comint-send-input): Update markers before actually sending the input.
Richard M. Stallman <rms@gnu.org>
parents: 8032
diff changeset
1150 (funcall comint-input-sender proc input)
6998
40163ff9fc7c (comint-mode): Set comint-last-input-start and
Richard M. Stallman <rms@gnu.org>
parents: 6958
diff changeset
1151 (comint-output-filter proc "")))))
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1152
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1153 ;; The purpose of using this filter for comint processes
2683
21ab70613c42 (comint-filter): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2680
diff changeset
1154 ;; 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
1155 ;; when output is inserted.
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1156 (defun comint-output-filter (process string)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1157 ;; First check for killed buffer
4939
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
1158 (let ((oprocbuf (process-buffer process)))
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
1159 (if (and oprocbuf (buffer-name oprocbuf))
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
1160 (let ((obuf (current-buffer))
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
1161 (opoint nil) (obeg nil) (oend nil))
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
1162 (set-buffer oprocbuf)
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
1163 (setq opoint (point))
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
1164 (setq obeg (point-min))
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
1165 (setq oend (point-max))
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
1166 (let ((buffer-read-only nil)
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
1167 (nchars (length string))
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
1168 (ostart nil))
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
1169 (widen)
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
1170 (goto-char (process-mark process))
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
1171 (setq ostart (point))
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
1172 (if (<= (point) opoint)
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
1173 (setq opoint (+ opoint nchars)))
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
1174 ;; Insert after old_begv, but before old_zv.
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
1175 (if (< (point) obeg)
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
1176 (setq obeg (+ obeg nchars)))
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
1177 (if (<= (point) oend)
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
1178 (setq oend (+ oend nchars)))
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
1179 (insert-before-markers string)
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
1180 ;; Don't insert initial prompt outside the top of the window.
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
1181 (if (= (window-start (selected-window)) (point))
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
1182 (set-window-start (selected-window) (- (point) (length string))))
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
1183 (if (and comint-last-input-end
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
1184 (marker-buffer comint-last-input-end)
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
1185 (= (point) comint-last-input-end))
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
1186 (set-marker comint-last-input-end (- comint-last-input-end nchars)))
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
1187 (set-marker comint-last-output-start ostart)
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
1188 (set-marker (process-mark process) (point))
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
1189 (force-mode-line-update))
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1190
4939
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
1191 (narrow-to-region obeg oend)
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
1192 (goto-char opoint)
6187
280d4a97da69 (comint-input-filter-functions)
Richard M. Stallman <rms@gnu.org>
parents: 6185
diff changeset
1193 (let ((functions comint-output-filter-functions))
4939
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
1194 (while functions
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
1195 (funcall (car functions) string)
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
1196 (setq functions (cdr functions))))
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
1197 (set-buffer obuf)))))
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1198
4890
dab300dfe449 (comint-scroll-to-bottom-on-input): Default to nil.
Richard M. Stallman <rms@gnu.org>
parents: 4880
diff changeset
1199 (defun comint-preinput-scroll-to-bottom ()
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1200 "Go to the end of buffer in all windows showing it.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1201 Movement occurs if point in the selected window is not after the process mark,
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1202 and `this-command' is an insertion command. Insertion commands recognised
5284
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
1203 are `self-insert-command', `comint-magic-space', `yank', and `hilit-yank'.
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1204 Depends on the value of `comint-scroll-to-bottom-on-input'.
2683
21ab70613c42 (comint-filter): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2680
diff changeset
1205
4890
dab300dfe449 (comint-scroll-to-bottom-on-input): Default to nil.
Richard M. Stallman <rms@gnu.org>
parents: 4880
diff changeset
1206 This function should be a pre-command hook."
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1207 (if (and comint-scroll-to-bottom-on-input
4939
d9ad390ef4e3 (comint-preinput-scroll-to-bottom): Added
Richard M. Stallman <rms@gnu.org>
parents: 4928
diff changeset
1208 (memq this-command '(self-insert-command comint-magic-space yank
5284
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
1209 hilit-yank)))
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1210 (let* ((selected (selected-window))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1211 (current (current-buffer))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1212 (process (get-buffer-process current))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1213 (scroll comint-scroll-to-bottom-on-input))
5284
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
1214 (if (and process (< (point) (process-mark process)))
5122
23f6d57ced16 (comint-preinput-scroll-to-bottom): If SCROLL is `this',
Richard M. Stallman <rms@gnu.org>
parents: 5058
diff changeset
1215 (if (eq scroll 'this)
23f6d57ced16 (comint-preinput-scroll-to-bottom): If SCROLL is `this',
Richard M. Stallman <rms@gnu.org>
parents: 5058
diff changeset
1216 (goto-char (point-max))
23f6d57ced16 (comint-preinput-scroll-to-bottom): If SCROLL is `this',
Richard M. Stallman <rms@gnu.org>
parents: 5058
diff changeset
1217 (walk-windows
23f6d57ced16 (comint-preinput-scroll-to-bottom): If SCROLL is `this',
Richard M. Stallman <rms@gnu.org>
parents: 5058
diff changeset
1218 (function (lambda (window)
23f6d57ced16 (comint-preinput-scroll-to-bottom): If SCROLL is `this',
Richard M. Stallman <rms@gnu.org>
parents: 5058
diff changeset
1219 (if (and (eq (window-buffer window) current)
5284
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
1220 (or (eq scroll t) (eq scroll 'all)))
5122
23f6d57ced16 (comint-preinput-scroll-to-bottom): If SCROLL is `this',
Richard M. Stallman <rms@gnu.org>
parents: 5058
diff changeset
1221 (progn
23f6d57ced16 (comint-preinput-scroll-to-bottom): If SCROLL is `this',
Richard M. Stallman <rms@gnu.org>
parents: 5058
diff changeset
1222 (select-window window)
23f6d57ced16 (comint-preinput-scroll-to-bottom): If SCROLL is `this',
Richard M. Stallman <rms@gnu.org>
parents: 5058
diff changeset
1223 (goto-char (point-max))
23f6d57ced16 (comint-preinput-scroll-to-bottom): If SCROLL is `this',
Richard M. Stallman <rms@gnu.org>
parents: 5058
diff changeset
1224 (select-window selected)))))
5284
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
1225 nil t))))))
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1226
4890
dab300dfe449 (comint-scroll-to-bottom-on-input): Default to nil.
Richard M. Stallman <rms@gnu.org>
parents: 4880
diff changeset
1227 (defun comint-postoutput-scroll-to-bottom (string)
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1228 "Go to the end of buffer in all windows showing it.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1229 Does not scroll if the current line is the last line in the buffer.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1230 Depends on the value of `comint-scroll-to-bottom-on-output' and
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1231 `comint-scroll-show-maximum-output'.
3386
bc4729d67e6e (comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents: 3113
diff changeset
1232
6187
280d4a97da69 (comint-input-filter-functions)
Richard M. Stallman <rms@gnu.org>
parents: 6185
diff changeset
1233 This function should be in the list `comint-output-filter-functions'."
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1234 (let* ((selected (selected-window))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1235 (current (current-buffer))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1236 (process (get-buffer-process current))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1237 (scroll comint-scroll-to-bottom-on-output))
5284
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
1238 (unwind-protect
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
1239 (if process
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
1240 (walk-windows
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
1241 (function (lambda (window)
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
1242 (if (eq (window-buffer window) current)
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
1243 (progn
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
1244 (select-window window)
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
1245 (if (and (< (point) (process-mark process))
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
1246 (or (eq scroll t) (eq scroll 'all)
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
1247 ;; Maybe user wants point to jump to the end.
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
1248 (and (eq scroll 'this) (eq selected window))
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
1249 (and (eq scroll 'others) (not (eq selected window)))
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
1250 ;; If point was at the end, keep it at the end.
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
1251 (>= (point)
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
1252 (- (process-mark process) (length string)))))
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
1253 (goto-char (process-mark process)))
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
1254 ;; Optionally scroll so that the text
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
1255 ;; ends at the bottom of the window.
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
1256 (if (and comint-scroll-show-maximum-output
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
1257 (>= (point) (process-mark process)))
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
1258 (save-excursion
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
1259 (goto-char (point-max))
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
1260 (recenter -1)))
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
1261 (select-window selected)))))
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
1262 nil t))
9c8749be37da (comint-read-input-ring): New arg SILENT.
Richard M. Stallman <rms@gnu.org>
parents: 5166
diff changeset
1263 (set-buffer current))))
2683
21ab70613c42 (comint-filter): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2680
diff changeset
1264
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1265 (defun comint-show-maximum-output ()
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1266 "Put the end of the buffer at the bottom of the window."
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1267 (interactive)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1268 (goto-char (point-max))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1269 (recenter -1))
2683
21ab70613c42 (comint-filter): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2680
diff changeset
1270
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1271 (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
1272 "Default for `comint-get-old-input'.
1356
dcf780f7ae1b Doc fix.
Christopher Zaborsky <rogue@erratum.com>
parents: 1131
diff changeset
1273 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
1274 `comint-prompt-regexp'."
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1275 (save-excursion
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1276 (beginning-of-line)
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1277 (comint-skip-prompt)
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1278 (let ((beg (point)))
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1279 (end-of-line)
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1280 (buffer-substring beg (point)))))
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1281
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1282 (defun comint-copy-old-input ()
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1283 "Insert after prompt old input at point as new input to be edited.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1284 Calls `comint-get-old-input' to get old input."
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1285 (interactive)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1286 (let ((input (funcall comint-get-old-input))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1287 (process (get-buffer-process (current-buffer))))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1288 (if (not process)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1289 (error "Current buffer has no process")
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1290 (goto-char (process-mark process))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1291 (insert input))))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1292
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1293 (defun comint-skip-prompt ()
3386
bc4729d67e6e (comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents: 3113
diff changeset
1294 "Skip past the text matching regexp `comint-prompt-regexp'.
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1295 If this takes us past the end of the current line, don't skip at all."
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1296 (let ((eol (save-excursion (end-of-line) (point))))
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1297 (if (and (looking-at comint-prompt-regexp)
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1298 (<= (match-end 0) eol))
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1299 (goto-char (match-end 0)))))
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1300
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1301 (defun comint-after-pmark-p ()
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1302 "Return t if point is after the process output marker."
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1303 (let ((pmark (process-mark (get-buffer-process (current-buffer)))))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1304 (<= (marker-position pmark) (point))))
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1305
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1306 (defun comint-simple-send (proc string)
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1307 "Default function for sending to PROC input STRING.
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1308 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
1309 set the hook `comint-input-sender'."
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1310 (comint-send-string proc string)
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1311 (comint-send-string proc "\n"))
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1312
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1313 (defun comint-bol (arg)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1314 "Goes to the beginning of line, then skips past the prompt, if any.
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1315 If prefix argument is given (\\[universal-argument]) the prompt is not skipped.
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1316
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1317 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
1318 `comint-prompt-regexp', a buffer local variable.
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1319
3386
bc4729d67e6e (comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents: 3113
diff changeset
1320 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
1321 in your hook, `comint-mode-hook'."
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1322 (interactive "P")
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1323 (beginning-of-line)
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1324 (if (null arg) (comint-skip-prompt)))
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1325
6507
ff41e0e932b8 (comint-run): New command.
Richard M. Stallman <rms@gnu.org>
parents: 6256
diff changeset
1326 ;;; These three functions are for entering text you don't want echoed or
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1327 ;;; saved -- typically passwords to ftp, telnet, or somesuch.
6507
ff41e0e932b8 (comint-run): New command.
Richard M. Stallman <rms@gnu.org>
parents: 6256
diff changeset
1328 ;;; Just enter m-x send-invisible and type in your line, or add
ff41e0e932b8 (comint-run): New command.
Richard M. Stallman <rms@gnu.org>
parents: 6256
diff changeset
1329 ;;; `comint-watch-for-password-prompt' to `comint-output-filter-functions'.
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1330
705
c7d478752305 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
1331 (defun comint-read-noecho (prompt &optional stars)
2455
27d28402ee59 new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents: 2307
diff changeset
1332 "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
1333 Prompt with argument PROMPT, a string. Optional argument STARS causes
27d28402ee59 new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents: 2307
diff changeset
1334 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
1335 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
1336 `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
1337 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
1338
27d28402ee59 new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents: 2307
diff changeset
1339 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
1340 \(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
1341 applications."
27d28402ee59 new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents: 2307
diff changeset
1342 (let ((ans "")
27d28402ee59 new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents: 2307
diff changeset
1343 (c 0)
27d28402ee59 new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents: 2307
diff changeset
1344 (echo-keystrokes 0)
705
c7d478752305 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
1345 (cursor-in-echo-area t)
2455
27d28402ee59 new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents: 2307
diff changeset
1346 (done nil))
27d28402ee59 new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents: 2307
diff changeset
1347 (while (not done)
27d28402ee59 new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents: 2307
diff changeset
1348 (if stars
27d28402ee59 new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents: 2307
diff changeset
1349 (message "%s%s" prompt (make-string (length ans) ?*))
27d28402ee59 new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents: 2307
diff changeset
1350 (message prompt))
27d28402ee59 new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents: 2307
diff changeset
1351 (setq c (read-char))
27d28402ee59 new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents: 2307
diff changeset
1352 (cond ((= c ?\C-g)
27d28402ee59 new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents: 2307
diff changeset
1353 ;; This function may get called from a process filter, where
27d28402ee59 new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents: 2307
diff changeset
1354 ;; 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
1355 ;; 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
1356 ;; 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
1357 ;; re-enable it here (for backward-compatibility the check for
6239
31e12709b654 Comment fix.
Karl Heuer <kwzh@gnu.org>
parents: 6187
diff changeset
1358 ;; quit-flag below would still be necessary, so this seems
2455
27d28402ee59 new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents: 2307
diff changeset
1359 ;; like the simplest way to do things).
27d28402ee59 new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents: 2307
diff changeset
1360 (setq quit-flag t
27d28402ee59 new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents: 2307
diff changeset
1361 done t))
27d28402ee59 new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents: 2307
diff changeset
1362 ((or (= c ?\r) (= c ?\n) (= c ?\e))
27d28402ee59 new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents: 2307
diff changeset
1363 (setq done t))
27d28402ee59 new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents: 2307
diff changeset
1364 ((= c ?\C-u)
27d28402ee59 new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents: 2307
diff changeset
1365 (setq ans ""))
27d28402ee59 new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents: 2307
diff changeset
1366 ((and (/= c ?\b) (/= c ?\177))
27d28402ee59 new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents: 2307
diff changeset
1367 (setq ans (concat ans (char-to-string c))))
27d28402ee59 new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents: 2307
diff changeset
1368 ((> (length ans) 0)
27d28402ee59 new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents: 2307
diff changeset
1369 (setq ans (substring ans 0 -1)))))
27d28402ee59 new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents: 2307
diff changeset
1370 (if quit-flag
27d28402ee59 new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents: 2307
diff changeset
1371 ;; 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
1372 (prog1
27d28402ee59 new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents: 2307
diff changeset
1373 (setq quit-flag nil)
27d28402ee59 new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents: 2307
diff changeset
1374 (message "Quit")
27d28402ee59 new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents: 2307
diff changeset
1375 (beep t))
27d28402ee59 new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents: 2307
diff changeset
1376 (message "")
27d28402ee59 new comint-read-noecho.
Noah Friedman <friedman@splode.com>
parents: 2307
diff changeset
1377 ans)))
705
c7d478752305 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
1378
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1379 (defun send-invisible (str)
1356
dcf780f7ae1b Doc fix.
Christopher Zaborsky <rogue@erratum.com>
parents: 1131
diff changeset
1380 "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
1381 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
1382 is additionally sent. String is not saved on comint input history list.
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1383 Security bug: your string can still be temporarily recovered with
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1384 \\[view-lossage]."
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1385 (interactive "P") ; Defeat snooping via C-x esc
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1386 (let ((proc (get-buffer-process (current-buffer))))
6507
ff41e0e932b8 (comint-run): New command.
Richard M. Stallman <rms@gnu.org>
parents: 6256
diff changeset
1387 (if (not proc)
ff41e0e932b8 (comint-run): New command.
Richard M. Stallman <rms@gnu.org>
parents: 6256
diff changeset
1388 (error "Current buffer has no process")
ff41e0e932b8 (comint-run): New command.
Richard M. Stallman <rms@gnu.org>
parents: 6256
diff changeset
1389 (comint-send-string
ff41e0e932b8 (comint-run): New command.
Richard M. Stallman <rms@gnu.org>
parents: 6256
diff changeset
1390 proc (if (stringp str) str (comint-read-noecho "Non-echoed text: " t)))
ff41e0e932b8 (comint-run): New command.
Richard M. Stallman <rms@gnu.org>
parents: 6256
diff changeset
1391 (comint-send-string proc "\n"))))
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1392
6507
ff41e0e932b8 (comint-run): New command.
Richard M. Stallman <rms@gnu.org>
parents: 6256
diff changeset
1393 (defun comint-watch-for-password-prompt (string)
ff41e0e932b8 (comint-run): New command.
Richard M. Stallman <rms@gnu.org>
parents: 6256
diff changeset
1394 "Prompt in the minibuffer for password and send without echoing.
ff41e0e932b8 (comint-run): New command.
Richard M. Stallman <rms@gnu.org>
parents: 6256
diff changeset
1395 This function uses `send-invisible' to read and send a password to the buffer's
8087
c22d7c5168f5 comint-password-prompt-regexp: New variable.
Noah Friedman <friedman@splode.com>
parents: 8060
diff changeset
1396 process if STRING contains a password prompt defined by
c22d7c5168f5 comint-password-prompt-regexp: New variable.
Noah Friedman <friedman@splode.com>
parents: 8060
diff changeset
1397 `comint-password-prompt-regexp'.
6507
ff41e0e932b8 (comint-run): New command.
Richard M. Stallman <rms@gnu.org>
parents: 6256
diff changeset
1398
ff41e0e932b8 (comint-run): New command.
Richard M. Stallman <rms@gnu.org>
parents: 6256
diff changeset
1399 This function could be in the list `comint-output-filter-functions'."
8087
c22d7c5168f5 comint-password-prompt-regexp: New variable.
Noah Friedman <friedman@splode.com>
parents: 8060
diff changeset
1400 (if (string-match comint-password-prompt-regexp string)
6507
ff41e0e932b8 (comint-run): New command.
Richard M. Stallman <rms@gnu.org>
parents: 6256
diff changeset
1401 (send-invisible nil)))
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1402
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1403 ;;; Low-level process communication
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1404
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1405 (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
1406 "*Long inputs are sent to comint processes in chunks of this size.
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1407 If your process is choking on big inputs, try lowering the value.")
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1408
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1409 (defun comint-send-string (proc str)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1410 "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
1411 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
1412 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
1413 are given a chance to output between chunks. This can help prevent processes
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1414 from hanging when you send them long inputs on some OS's."
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1415 (let* ((len (length str))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1416 (i (min len comint-input-chunk-size)))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1417 (process-send-string proc (substring str 0 i))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1418 (while (< i len)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1419 (let ((next-i (+ i comint-input-chunk-size)))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1420 (accept-process-output)
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1421 (sit-for 0)
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1422 (process-send-string proc (substring str i (min len next-i)))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1423 (setq i next-i)))))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1424
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1425 (defun comint-send-region (proc start end)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1426 "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
1427 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
1428 your process from hanging on long inputs. See `comint-send-string'."
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1429 (comint-send-string proc (buffer-substring start end)))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1430
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1431 ;;; Random input hackage
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1432
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1433 (defun comint-kill-output ()
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1434 "Kill all output from interpreter since last input.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1435 Does not delete the prompt."
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1436 (interactive)
6998
40163ff9fc7c (comint-mode): Set comint-last-input-start and
Richard M. Stallman <rms@gnu.org>
parents: 6958
diff changeset
1437 (let ((proc (get-buffer-process (current-buffer)))
40163ff9fc7c (comint-mode): Set comint-last-input-start and
Richard M. Stallman <rms@gnu.org>
parents: 6958
diff changeset
1438 (replacement nil))
40163ff9fc7c (comint-mode): Set comint-last-input-start and
Richard M. Stallman <rms@gnu.org>
parents: 6958
diff changeset
1439 (save-excursion
40163ff9fc7c (comint-mode): Set comint-last-input-start and
Richard M. Stallman <rms@gnu.org>
parents: 6958
diff changeset
1440 (let ((pmark (progn (goto-char (process-mark proc))
40163ff9fc7c (comint-mode): Set comint-last-input-start and
Richard M. Stallman <rms@gnu.org>
parents: 6958
diff changeset
1441 (beginning-of-line nil)
40163ff9fc7c (comint-mode): Set comint-last-input-start and
Richard M. Stallman <rms@gnu.org>
parents: 6958
diff changeset
1442 (point-marker))))
40163ff9fc7c (comint-mode): Set comint-last-input-start and
Richard M. Stallman <rms@gnu.org>
parents: 6958
diff changeset
1443 (delete-region comint-last-input-end pmark)
40163ff9fc7c (comint-mode): Set comint-last-input-start and
Richard M. Stallman <rms@gnu.org>
parents: 6958
diff changeset
1444 (comint-skip-prompt)
40163ff9fc7c (comint-mode): Set comint-last-input-start and
Richard M. Stallman <rms@gnu.org>
parents: 6958
diff changeset
1445 (setq replacement (concat "*** output flushed ***\n"
40163ff9fc7c (comint-mode): Set comint-last-input-start and
Richard M. Stallman <rms@gnu.org>
parents: 6958
diff changeset
1446 (buffer-substring pmark (point))))
40163ff9fc7c (comint-mode): Set comint-last-input-start and
Richard M. Stallman <rms@gnu.org>
parents: 6958
diff changeset
1447 (delete-region pmark (point))))
40163ff9fc7c (comint-mode): Set comint-last-input-start and
Richard M. Stallman <rms@gnu.org>
parents: 6958
diff changeset
1448 ;; Output message and put back prompt
40163ff9fc7c (comint-mode): Set comint-last-input-start and
Richard M. Stallman <rms@gnu.org>
parents: 6958
diff changeset
1449 (comint-output-filter proc replacement)))
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1450
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1451 (defun comint-show-output ()
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1452 "Display start of this batch of interpreter output at top of window.
6507
ff41e0e932b8 (comint-run): New command.
Richard M. Stallman <rms@gnu.org>
parents: 6256
diff changeset
1453 Sets mark to the value of point when this command is run."
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1454 (interactive)
5593
58c0f2c7dfae (comint-show-output): Leave point at start of output, but push the mark.
Richard M. Stallman <rms@gnu.org>
parents: 5539
diff changeset
1455 (push-mark)
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1456 (let ((pos (point)))
5476
155472377864 (comint-show-output): Use (point-max) rather than erring when the
Roland McGrath <roland@gnu.org>
parents: 5424
diff changeset
1457 (goto-char (or (marker-position comint-last-input-end) (point-max)))
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1458 (beginning-of-line 0)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1459 (set-window-start (selected-window) (point))
5593
58c0f2c7dfae (comint-show-output): Leave point at start of output, but push the mark.
Richard M. Stallman <rms@gnu.org>
parents: 5539
diff changeset
1460 (comint-skip-prompt)))
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1461
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1462 (defun comint-interrupt-subjob ()
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1463 "Interrupt the current subjob."
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1464 (interactive)
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1465 (interrupt-process nil comint-ptyp))
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1466
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1467 (defun comint-kill-subjob ()
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1468 "Send kill signal to the current subjob."
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1469 (interactive)
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1470 (kill-process nil comint-ptyp))
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1471
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1472 (defun comint-quit-subjob ()
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1473 "Send quit signal to the current subjob."
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1474 (interactive)
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1475 (quit-process nil comint-ptyp))
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1476
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1477 (defun comint-stop-subjob ()
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1478 "Stop the current subjob.
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1479 WARNING: if there is no current subjob, you can end up suspending
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1480 the top-level process running in the buffer. If you accidentally do
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1481 this, use \\[comint-continue-subjob] to resume the process. (This
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1482 is not a problem with most shells, since they ignore this signal.)"
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1483 (interactive)
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1484 (stop-process nil comint-ptyp))
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1485
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1486 (defun comint-continue-subjob ()
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1487 "Send CONT signal to process buffer's process group.
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1488 Useful if you accidentally suspend the top-level process."
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1489 (interactive)
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1490 (continue-process nil comint-ptyp))
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1491
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1492 (defun comint-kill-input ()
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1493 "Kill all text from last stuff output by interpreter to point."
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1494 (interactive)
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1495 (let ((pmark (process-mark (get-buffer-process (current-buffer)))))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1496 (if (> (point) (marker-position pmark))
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1497 (kill-region pmark (point)))))
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1498
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1499 (defun comint-delchar-or-maybe-eof (arg)
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1500 "Delete ARG characters forward, or (if at eob) send an EOF to subprocess."
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1501 (interactive "p")
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1502 (if (eobp)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1503 (process-send-eof)
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1504 (delete-char arg)))
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1505
4112
ab7dee78e335 (comint-{next,prev}-prompt, comint-send-eof): New functions.
Roland McGrath <roland@gnu.org>
parents: 3985
diff changeset
1506 (defun comint-send-eof ()
ab7dee78e335 (comint-{next,prev}-prompt, comint-send-eof): New functions.
Roland McGrath <roland@gnu.org>
parents: 3985
diff changeset
1507 "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
1508 (interactive)
ab7dee78e335 (comint-{next,prev}-prompt, comint-send-eof): New functions.
Roland McGrath <roland@gnu.org>
parents: 3985
diff changeset
1509 (process-send-eof))
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1510
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1511
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1512 (defun comint-backward-matching-input (regexp arg)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1513 "Search backward through buffer for match for REGEXP.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1514 Matches are searched for on lines that match `comint-prompt-regexp'.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1515 With prefix argument N, search for Nth previous match.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1516 If N is negative, find the next or Nth next match."
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1517 (interactive (comint-regexp-arg "Backward input matching (regexp): "))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1518 (let* ((re (concat comint-prompt-regexp ".*" regexp))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1519 (pos (save-excursion (end-of-line (if (> arg 0) 0 1))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1520 (if (re-search-backward re nil t arg)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1521 (point)))))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1522 (if (null pos)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1523 (progn (message "Not found")
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1524 (ding))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1525 (goto-char pos)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1526 (comint-bol nil))))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1527
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1528 (defun comint-forward-matching-input (regexp arg)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1529 "Search forward through buffer for match for REGEXP.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1530 Matches are searched for on lines that match `comint-prompt-regexp'.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1531 With prefix argument N, search for Nth following match.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1532 If N is negative, find the previous or Nth previous match."
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1533 (interactive (comint-regexp-arg "Forward input matching (regexp): "))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1534 (comint-backward-matching-input regexp (- arg)))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1535
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1536
4112
ab7dee78e335 (comint-{next,prev}-prompt, comint-send-eof): New functions.
Roland McGrath <roland@gnu.org>
parents: 3985
diff changeset
1537 (defun comint-next-prompt (n)
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1538 "Move to end of Nth next prompt in the buffer.
4112
ab7dee78e335 (comint-{next,prev}-prompt, comint-send-eof): New functions.
Roland McGrath <roland@gnu.org>
parents: 3985
diff changeset
1539 See `comint-prompt-regexp'."
ab7dee78e335 (comint-{next,prev}-prompt, comint-send-eof): New functions.
Roland McGrath <roland@gnu.org>
parents: 3985
diff changeset
1540 (interactive "p")
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1541 (let ((paragraph-start comint-prompt-regexp))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1542 (end-of-line (if (> n 0) 1 0))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1543 (forward-paragraph n)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1544 (comint-skip-prompt)))
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1545
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1546 (defun comint-previous-prompt (n)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1547 "Move to end of Nth previous prompt in the buffer.
4112
ab7dee78e335 (comint-{next,prev}-prompt, comint-send-eof): New functions.
Roland McGrath <roland@gnu.org>
parents: 3985
diff changeset
1548 See `comint-prompt-regexp'."
ab7dee78e335 (comint-{next,prev}-prompt, comint-send-eof): New functions.
Roland McGrath <roland@gnu.org>
parents: 3985
diff changeset
1549 (interactive "p")
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1550 (comint-next-prompt (- n)))
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1551
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1552 ;;; Support for source-file processing commands.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1553 ;;;============================================================================
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1554 ;;; Many command-interpreters (e.g., Lisp, Scheme, Soar) have
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1555 ;;; commands that process files of source text (e.g. loading or compiling
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1556 ;;; files). So the corresponding process-in-a-buffer modes have commands
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1557 ;;; for doing this (e.g., lisp-load-file). The functions below are useful
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1558 ;;; for defining these commands.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1559 ;;;
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1560 ;;; Alas, these guys don't do exactly the right thing for Lisp, Scheme
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1561 ;;; and Soar, in that they don't know anything about file extensions.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1562 ;;; So the compile/load interface gets the wrong default occasionally.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1563 ;;; The load-file/compile-file default mechanism could be smarter -- it
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1564 ;;; doesn't know about the relationship between filename extensions and
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1565 ;;; whether the file is source or executable. If you compile foo.lisp
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1566 ;;; with compile-file, then the next load-file should use foo.bin for
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1567 ;;; the default, not foo.lisp. This is tricky to do right, particularly
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1568 ;;; because the extension for executable files varies so much (.o, .bin,
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1569 ;;; .lbin, .mo, .vo, .ao, ...).
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1570
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1571
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1572 ;;; COMINT-SOURCE-DEFAULT -- determines defaults for source-file processing
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1573 ;;; commands.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1574 ;;;
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1575 ;;; COMINT-CHECK-SOURCE -- if FNAME is in a modified buffer, asks you if you
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1576 ;;; want to save the buffer before issuing any process requests to the command
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1577 ;;; interpreter.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1578 ;;;
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1579 ;;; COMINT-GET-SOURCE -- used by the source-file processing commands to prompt
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1580 ;;; for the file to process.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1581
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1582 ;;; (COMINT-SOURCE-DEFAULT previous-dir/file source-modes)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1583 ;;;============================================================================
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1584 ;;; This function computes the defaults for the load-file and compile-file
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1585 ;;; commands for tea, soar, cmulisp, and cmuscheme modes.
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1586 ;;;
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1587 ;;; - PREVIOUS-DIR/FILE is a pair (directory . filename) from the last
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1588 ;;; source-file processing command. NIL if there hasn't been one yet.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1589 ;;; - SOURCE-MODES is a list used to determine what buffers contain source
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1590 ;;; files: if the major mode of the buffer is in SOURCE-MODES, it's source.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1591 ;;; Typically, (lisp-mode) or (scheme-mode).
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1592 ;;;
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1593 ;;; If the command is given while the cursor is inside a string, *and*
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1594 ;;; the string is an existing filename, *and* the filename is not a directory,
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1595 ;;; then the string is taken as default. This allows you to just position
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1596 ;;; your cursor over a string that's a filename and have it taken as default.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1597 ;;;
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1598 ;;; If the command is given in a file buffer whose major mode is in
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1599 ;;; SOURCE-MODES, then the the filename is the default file, and the
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1600 ;;; file's directory is the default directory.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1601 ;;;
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1602 ;;; If the buffer isn't a source file buffer (e.g., it's the process buffer),
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1603 ;;; then the default directory & file are what was used in the last source-file
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1604 ;;; processing command (i.e., PREVIOUS-DIR/FILE). If this is the first time
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1605 ;;; the command has been run (PREVIOUS-DIR/FILE is nil), the default directory
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1606 ;;; is the cwd, with no default file. (\"no default file\" = nil)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1607 ;;;
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1608 ;;; SOURCE-REGEXP is typically going to be something like (tea-mode)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1609 ;;; for T programs, (lisp-mode) for Lisp programs, (soar-mode lisp-mode)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1610 ;;; for Soar programs, etc.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1611 ;;;
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1612 ;;; The function returns a pair: (default-directory . default-file).
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1613
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1614 (defun comint-source-default (previous-dir/file source-modes)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1615 (cond ((and buffer-file-name (memq major-mode source-modes))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1616 (cons (file-name-directory buffer-file-name)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1617 (file-name-nondirectory buffer-file-name)))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1618 (previous-dir/file)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1619 (t
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1620 (cons default-directory nil))))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1621
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1622
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1623 ;;; (COMINT-CHECK-SOURCE fname)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1624 ;;;============================================================================
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1625 ;;; Prior to loading or compiling (or otherwise processing) a file (in the CMU
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1626 ;;; process-in-a-buffer modes), this function can be called on the filename.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1627 ;;; If the file is loaded into a buffer, and the buffer is modified, the user
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1628 ;;; is queried to see if he wants to save the buffer before proceeding with
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1629 ;;; the load or compile.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1630
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1631 (defun comint-check-source (fname)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1632 (let ((buff (get-file-buffer fname)))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1633 (if (and buff
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1634 (buffer-modified-p buff)
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1635 (y-or-n-p (format "Save buffer %s first? " (buffer-name buff))))
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1636 ;; save BUFF.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1637 (let ((old-buffer (current-buffer)))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1638 (set-buffer buff)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1639 (save-buffer)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1640 (set-buffer old-buffer)))))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1641
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1642
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1643 ;;; (COMINT-GET-SOURCE prompt prev-dir/file source-modes mustmatch-p)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1644 ;;;============================================================================
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1645 ;;; COMINT-GET-SOURCE is used to prompt for filenames in command-interpreter
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1646 ;;; commands that process source files (like loading or compiling a file).
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1647 ;;; It prompts for the filename, provides a default, if there is one,
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1648 ;;; and returns the result filename.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1649 ;;;
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1650 ;;; See COMINT-SOURCE-DEFAULT for more on determining defaults.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1651 ;;;
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1652 ;;; PROMPT is the prompt string. PREV-DIR/FILE is the (directory . file) pair
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1653 ;;; from the last source processing command. SOURCE-MODES is a list of major
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1654 ;;; modes used to determine what file buffers contain source files. (These
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1655 ;;; two arguments are used for determining defaults). If MUSTMATCH-P is true,
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1656 ;;; then the filename reader will only accept a file that exists.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1657 ;;;
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1658 ;;; A typical use:
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1659 ;;; (interactive (comint-get-source "Compile file: " prev-lisp-dir/file
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1660 ;;; '(lisp-mode) t))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1661
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1662 ;;; This is pretty stupid about strings. It decides we're in a string
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1663 ;;; if there's a quote on both sides of point on the current line.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1664 (defun comint-extract-string ()
3386
bc4729d67e6e (comint-filter): Put window-start before the input.
Richard M. Stallman <rms@gnu.org>
parents: 3113
diff changeset
1665 "Return string around POINT that starts the current line, or nil."
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1666 (save-excursion
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1667 (let* ((point (point))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1668 (bol (progn (beginning-of-line) (point)))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1669 (eol (progn (end-of-line) (point)))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1670 (start (progn (goto-char point)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1671 (and (search-backward "\"" bol t)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1672 (1+ (point)))))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1673 (end (progn (goto-char point)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1674 (and (search-forward "\"" eol t)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1675 (1- (point))))))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1676 (and start end
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1677 (buffer-substring start end)))))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1678
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1679 (defun comint-get-source (prompt prev-dir/file source-modes mustmatch-p)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1680 (let* ((def (comint-source-default prev-dir/file source-modes))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1681 (stringfile (comint-extract-string))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1682 (sfile-p (and stringfile
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1683 (condition-case ()
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1684 (file-exists-p stringfile)
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1685 (error nil))
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1686 (not (file-directory-p stringfile))))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1687 (defdir (if sfile-p (file-name-directory stringfile)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1688 (car def)))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1689 (deffile (if sfile-p (file-name-nondirectory stringfile)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1690 (cdr def)))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1691 (ans (read-file-name (if deffile (format "%s(default %s) "
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1692 prompt deffile)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1693 prompt)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1694 defdir
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1695 (concat defdir deffile)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1696 mustmatch-p)))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1697 (list (expand-file-name (substitute-in-file-name ans)))))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1698
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1699 ;;; I am somewhat divided on this string-default feature. It seems
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1700 ;;; to violate the principle-of-least-astonishment, in that it makes
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1701 ;;; the default harder to predict, so you actually have to look and see
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1702 ;;; what the default really is before choosing it. This can trip you up.
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1703 ;;; On the other hand, it can be useful, I guess. I would appreciate feedback
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1704 ;;; on this.
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1705 ;;; -Olin
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1706
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1707
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1708 ;;; Simple process query facility.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1709 ;;; ===========================================================================
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1710 ;;; This function is for commands that want to send a query to the process
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1711 ;;; and show the response to the user. For example, a command to get the
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1712 ;;; arglist for a Common Lisp function might send a "(arglist 'foo)" query
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1713 ;;; to an inferior Common Lisp process.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1714 ;;;
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1715 ;;; This simple facility just sends strings to the inferior process and pops
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1716 ;;; up a window for the process buffer so you can see what the process
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1717 ;;; responds with. We don't do anything fancy like try to intercept what the
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1718 ;;; process responds with and put it in a pop-up window or on the message
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1719 ;;; line. We just display the buffer. Low tech. Simple. Works good.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1720
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1721 ;;; Send to the inferior process PROC the string STR. Pop-up but do not select
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1722 ;;; a window for the inferior process so that its response can be seen.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1723 (defun comint-proc-query (proc str)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1724 (let* ((proc-buf (process-buffer proc))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1725 (proc-mark (process-mark proc)))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1726 (display-buffer proc-buf)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1727 (set-buffer proc-buf) ; but it's not the selected *window*
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1728 (let ((proc-win (get-buffer-window proc-buf))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1729 (proc-pt (marker-position proc-mark)))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1730 (comint-send-string proc str) ; send the query
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1731 (accept-process-output proc) ; wait for some output
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1732 ;; Try to position the proc window so you can see the answer.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1733 ;; This is bogus code. If you delete the (sit-for 0), it breaks.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1734 ;; I don't know why. Wizards invited to improve it.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1735 (if (not (pos-visible-in-window-p proc-pt proc-win))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1736 (let ((opoint (window-point proc-win)))
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1737 (set-window-point proc-win proc-mark)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1738 (sit-for 0)
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1739 (if (not (pos-visible-in-window-p opoint proc-win))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1740 (push-mark opoint)
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1741 (set-window-point proc-win opoint)))))))
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1742
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1743
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1744 ;;; Filename/command/history completion in a buffer
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1745 ;;; ===========================================================================
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1746 ;;; Useful completion functions, courtesy of the Ergo group.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1747
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1748 ;;; Six commands:
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1749 ;;; comint-dynamic-complete Complete or expand command, filename,
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1750 ;;; history at point.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1751 ;;; comint-dynamic-complete-filename Complete filename at point.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1752 ;;; comint-dynamic-list-filename-completions List completions in help buffer.
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1753 ;;; comint-replace-by-expanded-filename Expand and complete filename at point;
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1754 ;;; replace with expanded/completed name.
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1755 ;;; comint-dynamic-simple-complete Complete stub given candidates.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1756
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1757 ;;; These are not installed in the comint-mode keymap. But they are
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1758 ;;; 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
1759 ;;; (define-key shell-mode-map "\t" 'comint-dynamic-complete)
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1760 ;;; (define-key shell-mode-map "\M-?"
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1761 ;;; 'comint-dynamic-list-filename-completions)))
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1762 ;;;
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1763 ;;; 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
1764 ;;; want them present in specific modes.
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1765
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1766 (defvar comint-completion-autolist nil
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1767 "*If non-nil, automatically list possiblities on partial completion.
4923
63aed739d09d (comint-postoutput-scroll-to-bottom):
Richard M. Stallman <rms@gnu.org>
parents: 4899
diff changeset
1768 This mirrors the optional behavior of tcsh.")
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1769
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1770 (defvar comint-completion-addsuffix t
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1771 "*If non-nil, add a `/' to completed directories, ` ' to file names.
4923
63aed739d09d (comint-postoutput-scroll-to-bottom):
Richard M. Stallman <rms@gnu.org>
parents: 4899
diff changeset
1772 This mirrors the optional behavior of tcsh.")
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1773
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1774 (defvar comint-completion-recexact nil
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1775 "*If non-nil, use shortest completion if characters cannot be added.
4923
63aed739d09d (comint-postoutput-scroll-to-bottom):
Richard M. Stallman <rms@gnu.org>
parents: 4899
diff changeset
1776 This mirrors the optional behavior of tcsh.
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1777
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1778 A non-nil value is useful if `comint-completion-autolist' is non-nil too.")
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1779
6256
3810012eb29f (comint-completion-fignore): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 6239
diff changeset
1780 (defvar comint-completion-fignore nil
3810012eb29f (comint-completion-fignore): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 6239
diff changeset
1781 "*List of suffixes to be disregarded during file completion.
3810012eb29f (comint-completion-fignore): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 6239
diff changeset
1782 This mirrors the optional behavior of bash and tcsh.
3810012eb29f (comint-completion-fignore): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 6239
diff changeset
1783
3810012eb29f (comint-completion-fignore): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 6239
diff changeset
1784 Note that this applies to `comint-dynamic-complete-filename' only.")
3810012eb29f (comint-completion-fignore): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 6239
diff changeset
1785
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1786 (defvar comint-file-name-prefix ""
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1787 "Prefix prepended to absolute file names taken from process input.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1788 This is used by comint's and shell's completion functions, and by shell's
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1789 directory tracking functions.")
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1790
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1791
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1792 (defun comint-directory (directory)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1793 ;; Return expanded DIRECTORY, with `comint-file-name-prefix' if absolute.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1794 (expand-file-name (if (file-name-absolute-p directory)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1795 (concat comint-file-name-prefix directory)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1796 directory)))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1797
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1798
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1799 (defun comint-word (word-chars)
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1800 "Return the word of WORD-CHARS at point, or nil if non is found.
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1801 Word constituents are considered to be those in WORD-CHARS, which is like the
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1802 inside of a \"[...]\" (see `skip-chars-forward')."
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1803 (save-excursion
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1804 (let ((limit (point))
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1805 (word (concat "[" word-chars "]"))
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1806 (non-word (concat "[^" word-chars "]")))
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1807 (if (re-search-backward non-word nil 'move)
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1808 (forward-char 1))
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1809 ;; Anchor the search forwards.
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1810 (if (or (eolp) (looking-at non-word))
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1811 nil
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1812 (re-search-forward (concat word "+") limit)
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1813 (buffer-substring (match-beginning 0) (match-end 0))))))
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1814
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1815
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1816 (defun comint-match-partial-filename ()
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1817 "Return the filename at point, or nil if non is found.
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1818 Environment variables are substituted. See `comint-word'."
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1819 (let ((filename (comint-word "~/A-Za-z0-9+@:_.$#,={}-")))
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1820 (and filename (substitute-in-file-name filename))))
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1821
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1822
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1823 (defun comint-dynamic-complete ()
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1824 "Dynamically perform completion at point.
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1825 Calls the functions in `comint-dynamic-complete-functions' to perform
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1826 completion until a function returns non-nil, at which point completion is
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1827 assumed to have occurred."
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1828 (interactive)
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1829 (let ((functions comint-dynamic-complete-functions))
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1830 (while (and functions (null (funcall (car functions))))
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1831 (setq functions (cdr functions)))))
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1832
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1833
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1834 (defun comint-dynamic-complete-filename ()
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
1835 "Dynamically complete the filename at point.
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1836 Completes if after a filename. See `comint-match-partial-filename' and
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1837 `comint-dynamic-complete-as-filename'.
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1838 This function is similar to `comint-replace-by-expanded-filename', except that
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1839 it won't change parts of the filename already entered in the buffer; it just
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1840 adds completion characters to the end of the filename. A completions listing
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1841 may be shown in a help buffer if completion is ambiguous.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1842
6256
3810012eb29f (comint-completion-fignore): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 6239
diff changeset
1843 Completion is dependent on the value of `comint-completion-addsuffix',
3810012eb29f (comint-completion-fignore): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 6239
diff changeset
1844 `comint-completion-recexact' and `comint-completion-fignore', and the timing of
3810012eb29f (comint-completion-fignore): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 6239
diff changeset
1845 completions listing is dependent on the value of `comint-completion-autolist'.
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1846
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1847 Returns t if successful."
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1848 (interactive)
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1849 (if (comint-match-partial-filename)
7766
4a427472e21f (comint-dynamic-complete-as-filename)
Richard M. Stallman <rms@gnu.org>
parents: 7756
diff changeset
1850 (prog2 (or (eq (selected-window) (minibuffer-window))
4a427472e21f (comint-dynamic-complete-as-filename)
Richard M. Stallman <rms@gnu.org>
parents: 7756
diff changeset
1851 (message "Completing file name..."))
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1852 (comint-dynamic-complete-as-filename))))
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1853
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1854
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1855 (defun comint-dynamic-complete-as-filename ()
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1856 "Dynamically complete at point as a filename.
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1857 See `comint-dynamic-complete-filename'. Returns t if successful."
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1858 (let* ((completion-ignore-case nil)
6256
3810012eb29f (comint-completion-fignore): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 6239
diff changeset
1859 (completion-ignored-extensions comint-completion-fignore)
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1860 (success t)
6847
9481abcaa7de (comint-dynamic-complete-as-filename): Simplify.
Karl Heuer <kwzh@gnu.org>
parents: 6797
diff changeset
1861 (filename (or (comint-match-partial-filename) ""))
9481abcaa7de (comint-dynamic-complete-as-filename): Simplify.
Karl Heuer <kwzh@gnu.org>
parents: 6797
diff changeset
1862 (pathdir (file-name-directory filename))
9481abcaa7de (comint-dynamic-complete-as-filename): Simplify.
Karl Heuer <kwzh@gnu.org>
parents: 6797
diff changeset
1863 (pathnondir (file-name-nondirectory filename))
9481abcaa7de (comint-dynamic-complete-as-filename): Simplify.
Karl Heuer <kwzh@gnu.org>
parents: 6797
diff changeset
1864 (directory (if pathdir (comint-directory pathdir) default-directory))
7766
4a427472e21f (comint-dynamic-complete-as-filename)
Richard M. Stallman <rms@gnu.org>
parents: 7756
diff changeset
1865 (completion (file-name-completion pathnondir directory))
4a427472e21f (comint-dynamic-complete-as-filename)
Richard M. Stallman <rms@gnu.org>
parents: 7756
diff changeset
1866 (mini-flag (eq (selected-window) (minibuffer-window))))
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1867 (cond ((null completion)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1868 (message "No completions of %s" filename)
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1869 (setq success nil))
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1870 ((eq completion t) ; Means already completed "file".
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1871 (if comint-completion-addsuffix (insert " "))
7766
4a427472e21f (comint-dynamic-complete-as-filename)
Richard M. Stallman <rms@gnu.org>
parents: 7756
diff changeset
1872 (or mini-flag (message "Sole completion")))
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1873 ((string-equal completion "") ; Means completion on "directory/".
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1874 (comint-dynamic-list-filename-completions))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1875 (t ; Completion string returned.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1876 (let ((file (concat (file-name-as-directory directory) completion)))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1877 (insert (substring (directory-file-name completion)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1878 (length pathnondir)))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1879 (cond ((symbolp (file-name-completion completion directory))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1880 ;; We inserted a unique completion.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1881 (if comint-completion-addsuffix
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1882 (insert (if (file-directory-p file) "/" " ")))
7766
4a427472e21f (comint-dynamic-complete-as-filename)
Richard M. Stallman <rms@gnu.org>
parents: 7756
diff changeset
1883 (or mini-flag (message "Completed")))
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1884 ((and comint-completion-recexact comint-completion-addsuffix
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1885 (string-equal pathnondir completion)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1886 (file-exists-p file))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1887 ;; It's not unique, but user wants shortest match.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1888 (insert (if (file-directory-p file) "/" " "))
7766
4a427472e21f (comint-dynamic-complete-as-filename)
Richard M. Stallman <rms@gnu.org>
parents: 7756
diff changeset
1889 (or mini-flag (message "Completed shortest")))
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1890 ((or comint-completion-autolist
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1891 (string-equal pathnondir completion))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1892 ;; It's not unique, list possible completions.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1893 (comint-dynamic-list-filename-completions))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1894 (t
7766
4a427472e21f (comint-dynamic-complete-as-filename)
Richard M. Stallman <rms@gnu.org>
parents: 7756
diff changeset
1895 (or mini-flag (message "Partially completed")))))))
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1896 success))
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1897
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1898
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1899 (defun comint-replace-by-expanded-filename ()
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1900 "Dynamically expand and complete the filename at point.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1901 Replace the filename with an expanded, canonicalised and completed replacement.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1902 \"Expanded\" means environment variables (e.g., $HOME) and `~'s are replaced
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1903 with the corresponding directories. \"Canonicalised\" means `..' and `.' are
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1904 removed, and the filename is made absolute instead of relative. For expansion
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1905 see `expand-file-name' and `substitute-in-file-name'. For completion see
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1906 `comint-dynamic-complete-filename'."
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1907 (interactive)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1908 (replace-match (expand-file-name (comint-match-partial-filename)) t t)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1909 (comint-dynamic-complete-filename))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1910
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1911
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1912 (defun comint-dynamic-simple-complete (stub candidates)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1913 "Dynamically complete STUB from CANDIDATES list.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1914 This function inserts completion characters at point by completing STUB from
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1915 the strings in CANDIDATES. A completions listing may be shown in a help buffer
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1916 if completion is ambiguous.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1917
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1918 Returns nil if no completion was inserted.
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1919 Returns `sole' if completed with the only completion match.
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1920 Returns `shortest' if completed with the shortest of the completion matches.
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1921 Returns `partial' if completed as far as possible with the completion matches.
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1922 Returns `listed' if a completion listing was shown.
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1923
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1924 See also `comint-dynamic-complete-filename'."
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1925 (let* ((completion-ignore-case nil)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1926 (candidates (mapcar (function (lambda (x) (list x))) candidates))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1927 (completions (all-completions stub candidates)))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1928 (cond ((null completions)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1929 (message "No completions of %s" stub)
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1930 nil)
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1931 ((= 1 (length completions)) ; Gotcha!
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1932 (let ((completion (car completions)))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1933 (if (string-equal completion stub)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1934 (message "Sole completion")
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1935 (insert (substring completion (length stub)))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1936 (message "Completed"))
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1937 (if comint-completion-addsuffix (insert " "))
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1938 'sole))
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1939 (t ; There's no unique completion.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1940 (let ((completion (try-completion stub candidates)))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1941 ;; Insert the longest substring.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1942 (insert (substring completion (length stub)))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1943 (cond ((and comint-completion-recexact comint-completion-addsuffix
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1944 (string-equal stub completion)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1945 (member completion completions))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1946 ;; It's not unique, but user wants shortest match.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1947 (insert " ")
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1948 (message "Completed shortest")
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1949 'shortest)
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1950 ((or comint-completion-autolist
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1951 (string-equal stub completion))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1952 ;; It's not unique, list possible completions.
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1953 (comint-dynamic-list-completions completions)
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1954 'listed)
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1955 (t
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1956 (message "Partially completed")
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1957 'partial)))))))
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1958
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1959
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1960 (defun comint-dynamic-list-filename-completions ()
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1961 "List in help buffer possible completions of the filename at point."
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1962 (interactive)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1963 (let* ((completion-ignore-case nil)
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1964 (filename (or (comint-match-partial-filename) ""))
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1965 (pathdir (file-name-directory filename))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1966 (pathnondir (file-name-nondirectory filename))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1967 (directory (if pathdir (comint-directory pathdir) default-directory))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1968 (completions (file-name-all-completions pathnondir directory)))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1969 (if completions
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1970 (comint-dynamic-list-completions completions)
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
1971 (message "No completions of %s" filename))))
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1972
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1973
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1974 (defun comint-dynamic-list-completions (completions)
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1975 "List in help buffer sorted COMPLETIONS.
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1976 Typing SPC flushes the help buffer."
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1977 (let ((conf (current-window-configuration)))
7846
46db50437ebb (comint-dynamic-list-completions): No space in *Completions*.
Richard M. Stallman <rms@gnu.org>
parents: 7766
diff changeset
1978 (with-output-to-temp-buffer "*Completions*"
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1979 (display-completion-list (sort completions 'string-lessp)))
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
1980 (message "Hit space to flush")
5424
51eecae04837 (comint-last-output-start): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 5323
diff changeset
1981 (let (key first)
51eecae04837 (comint-last-output-start): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 5323
diff changeset
1982 (if (save-excursion
7846
46db50437ebb (comint-dynamic-list-completions): No space in *Completions*.
Richard M. Stallman <rms@gnu.org>
parents: 7766
diff changeset
1983 (set-buffer (get-buffer "*Completions*"))
5424
51eecae04837 (comint-last-output-start): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 5323
diff changeset
1984 (setq key (read-key-sequence nil)
51eecae04837 (comint-last-output-start): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 5323
diff changeset
1985 first (aref key 0))
51eecae04837 (comint-last-output-start): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 5323
diff changeset
1986 (and (consp first)
51eecae04837 (comint-last-output-start): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 5323
diff changeset
1987 (eq (window-buffer (posn-window (event-start first)))
7846
46db50437ebb (comint-dynamic-list-completions): No space in *Completions*.
Richard M. Stallman <rms@gnu.org>
parents: 7766
diff changeset
1988 (get-buffer "*Completions*"))
5424
51eecae04837 (comint-last-output-start): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 5323
diff changeset
1989 (eq (key-binding key) 'mouse-choose-completion)))
51eecae04837 (comint-last-output-start): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 5323
diff changeset
1990 ;; If the user does mouse-choose-completion with the mouse,
51eecae04837 (comint-last-output-start): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 5323
diff changeset
1991 ;; execute the command, then delete the completion window.
51eecae04837 (comint-last-output-start): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 5323
diff changeset
1992 (progn
51eecae04837 (comint-last-output-start): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 5323
diff changeset
1993 (mouse-choose-completion first)
51eecae04837 (comint-last-output-start): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 5323
diff changeset
1994 (set-window-configuration conf))
51eecae04837 (comint-last-output-start): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 5323
diff changeset
1995 (if (eq first ?\ )
51eecae04837 (comint-last-output-start): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 5323
diff changeset
1996 (set-window-configuration conf)
51eecae04837 (comint-last-output-start): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 5323
diff changeset
1997 (setq unread-command-events (append key nil)))))))
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1998
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
1999 ;;; Converting process modes to use comint mode
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
2000 ;;; ===========================================================================
768
4abf65b235d9 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 705
diff changeset
2001 ;;; 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
2002 ;;; 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
2003 ;;; still use the old shell mode. Here's a guide to conversion.
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
2004 ;;;
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
2005 ;;; Renaming variables
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
2006 ;;; Most of the work is renaming variables and functions. These are the common
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
2007 ;;; ones:
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
2008 ;;; Local variables:
705
c7d478752305 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
2009 ;;; last-input-start comint-last-input-start
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
2010 ;;; last-input-end comint-last-input-end
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
2011 ;;; shell-prompt-pattern comint-prompt-regexp
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
2012 ;;; shell-set-directory-error-hook <no equivalent>
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
2013 ;;; Miscellaneous:
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
2014 ;;; shell-set-directory <unnecessary>
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
2015 ;;; shell-mode-map comint-mode-map
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
2016 ;;; Commands:
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
2017 ;;; shell-send-input comint-send-input
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
2018 ;;; shell-send-eof comint-delchar-or-maybe-eof
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
2019 ;;; kill-shell-input comint-kill-input
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
2020 ;;; interrupt-shell-subjob comint-interrupt-subjob
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
2021 ;;; stop-shell-subjob comint-stop-subjob
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
2022 ;;; quit-shell-subjob comint-quit-subjob
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
2023 ;;; kill-shell-subjob comint-kill-subjob
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
2024 ;;; kill-output-from-shell comint-kill-output
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
2025 ;;; show-output-from-shell comint-show-output
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
2026 ;;; copy-last-shell-input Use comint-previous-input/comint-next-input
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
2027 ;;;
705
c7d478752305 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
2028 ;;; SHELL-SET-DIRECTORY is gone, its functionality taken over by
6187
280d4a97da69 (comint-input-filter-functions)
Richard M. Stallman <rms@gnu.org>
parents: 6185
diff changeset
2029 ;;; SHELL-DIRECTORY-TRACKER, the shell mode's comint-input-filter-functions.
705
c7d478752305 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
2030 ;;; Comint mode does not provide functionality equivalent to
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
2031 ;;; shell-set-directory-error-hook; it is gone.
705
c7d478752305 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
2032 ;;;
c7d478752305 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
2033 ;;; comint-last-input-start is provided for modes which want to munge
c7d478752305 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
2034 ;;; the buffer after input is sent, perhaps because the inferior
c7d478752305 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
2035 ;;; insists on echoing the input. The LAST-INPUT-START variable in
c7d478752305 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
2036 ;;; the old shell package was used to implement a history mechanism,
c7d478752305 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
2037 ;;; but you should think twice before using comint-last-input-start
c7d478752305 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
2038 ;;; for this; the input history ring often does the job better.
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
2039 ;;;
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
2040 ;;; If you are implementing some process-in-a-buffer mode, called foo-mode, do
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
2041 ;;; *not* create the comint-mode local variables in your foo-mode function.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
2042 ;;; This is not modular. Instead, call comint-mode, and let *it* create the
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
2043 ;;; necessary comint-specific local variables. Then create the
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
2044 ;;; foo-mode-specific local variables in foo-mode. Set the buffer's keymap to
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
2045 ;;; be foo-mode-map, and its mode to be foo-mode. Set the comint-mode hooks
6187
280d4a97da69 (comint-input-filter-functions)
Richard M. Stallman <rms@gnu.org>
parents: 6185
diff changeset
2046 ;;; (comint-{prompt-regexp, input-filter, input-filter-functions,
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
2047 ;;; get-old-input) that need to be different from the defaults. Call
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
2048 ;;; 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
2049 ;;; comint-mode will take care of it. The following example, from shell.el,
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
2050 ;;; is typical:
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
2051 ;;;
4983
3be990e478dc Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 4949
diff changeset
2052 ;;; (defvar shell-mode-map '())
3be990e478dc Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 4949
diff changeset
2053 ;;; (cond ((not shell-mode-map)
6890
7462c6006494 Doc fix.
Karl Heuer <kwzh@gnu.org>
parents: 6886
diff changeset
2054 ;;; (setq shell-mode-map (copy-keymap comint-mode-map))
4983
3be990e478dc Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 4949
diff changeset
2055 ;;; (define-key shell-mode-map "\C-c\C-f" 'shell-forward-command)
3be990e478dc Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 4949
diff changeset
2056 ;;; (define-key shell-mode-map "\C-c\C-b" 'shell-backward-command)
3be990e478dc Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 4949
diff changeset
2057 ;;; (define-key shell-mode-map "\t" 'comint-dynamic-complete)
3be990e478dc Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 4949
diff changeset
2058 ;;; (define-key shell-mode-map "\M-?"
3be990e478dc Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 4949
diff changeset
2059 ;;; 'comint-dynamic-list-filename-completions)))
3be990e478dc Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 4949
diff changeset
2060 ;;;
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
2061 ;;; (defun shell-mode ()
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
2062 ;;; (interactive)
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
2063 ;;; (comint-mode)
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
2064 ;;; (setq comint-prompt-regexp shell-prompt-pattern)
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
2065 ;;; (setq major-mode 'shell-mode)
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
2066 ;;; (setq mode-name "Shell")
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
2067 ;;; (use-local-map shell-mode-map)
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
2068 ;;; (make-local-variable 'shell-directory-stack)
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
2069 ;;; (setq shell-directory-stack nil)
6187
280d4a97da69 (comint-input-filter-functions)
Richard M. Stallman <rms@gnu.org>
parents: 6185
diff changeset
2070 ;;; (add-hook 'comint-input-filter-functions 'shell-directory-tracker)
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
2071 ;;; (run-hooks 'shell-mode-hook))
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
2072 ;;;
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
2073 ;;;
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
2074 ;;; Note that make-comint is different from make-shell in that it
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
2075 ;;; doesn't have a default program argument. If you give make-shell
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
2076 ;;; a program name of NIL, it cleverly chooses one of explicit-shell-name,
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
2077 ;;; $ESHELL, $SHELL, or /bin/sh. If you give make-comint a program argument
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
2078 ;;; of NIL, it barfs. Adjust your code accordingly...
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
2079 ;;;
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
2080 ;;; Completion for comint-mode users
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
2081 ;;;
6185
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
2082 ;;; For modes that use comint-mode, comint-dynamic-complete-functions is the
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
2083 ;;; hook to add completion functions to. Functions on this list should return
82a92cf44059 (comint-after-partial-filename-command,
Richard M. Stallman <rms@gnu.org>
parents: 6154
diff changeset
2084 ;;; non-nil if completion occurs (i.e., further completion should not occur).
4872
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
2085 ;;; You could use comint-dynamic-simple-complete to do the bulk of the
628cbf7e7005 (comint-after-partial-file-name-command):
Richard M. Stallman <rms@gnu.org>
parents: 4675
diff changeset
2086 ;;; completion job.
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
2087
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 182
diff changeset
2088 (provide 'comint)
662
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 638
diff changeset
2089
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 638
diff changeset
2090 ;;; comint.el ends here