annotate lisp/eterm/term.el @ 143:50e7fedfe353

Added tag r20-2b5 for changeset 1856695b1fa9
author cvs
date Mon, 13 Aug 2007 09:33:20 +0200
parents 34a5b81f86ba
children 59463afc5666
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;; term.el --- general command interpreter in a window stuff
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;; Copyright (C) 1988, 1990, 1992, 1994, 1995 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; Author: Per Bothner <bothner@cygnus.com>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Based on comint mode written by: Olin Shivers <shivers@cs.cmu.edu>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Keyword: processes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;; The changelog is at the end of this file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;;; Please send me bug reports, bug fixes, and extensions, so that I can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;;; merge them into the master source.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;;; - Per Bothner (bothner@cygnus.com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;;; This file defines a general command-interpreter-in-a-buffer package
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;; (term mode). The idea is that you can build specific process-in-a-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;;; modes on top of term mode -- e.g., lisp, shell, scheme, T, soar, ....
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;;; This way, all these specific packages share a common base functionality,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;;; and a common set of bindings, which makes them easier to use (and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;;; saves code, implementation time, etc., etc.).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;;; For hints on converting existing process modes (e.g., tex-mode,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;;; background, dbx, gdb, kermit, prolog, telnet) to use term-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;;; instead of shell-mode, see the notes at the end of this file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;;; Brief Command Documentation:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;;;============================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;;; Term Mode Commands: (common to all derived modes, like cmushell & cmulisp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;;; mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;;; m-p term-previous-input Cycle backwards in input history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;;; m-n term-next-input Cycle forwards
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;;; m-r term-previous-matching-input Previous input matching a regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;;; m-s comint-next-matching-input Next input that matches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;;; return term-send-input
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;;; c-c c-a term-bol Beginning of line; skip prompt.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;;; c-d term-delchar-or-maybe-eof Delete char unless at end of buff.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;;; c-c c-u term-kill-input ^u
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;;; c-c c-w backward-kill-word ^w
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;;; c-c c-c term-interrupt-subjob ^c
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;;; c-c c-z term-stop-subjob ^z
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 ;;; c-c c-\ term-quit-subjob ^\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;;; c-c c-o term-kill-output Delete last batch of process output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ;;; c-c c-r term-show-output Show last batch of process output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;;; c-c c-h term-dynamic-list-input-ring List input history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 ;;; Not bound by default in term-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ;;; term-send-invisible Read a line w/o echo, and send to proc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 ;;; (These are bound in shell-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 ;;; term-dynamic-complete Complete filename at point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 ;;; term-dynamic-list-completions List completions in help buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ;;; term-replace-by-expanded-filename Expand and complete filename at point;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ;;; replace with expanded/completed name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 ;;; term-kill-subjob No mercy.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ;;; term-show-maximum-output Show as much output as possible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 ;;; term-continue-subjob Send CONT signal to buffer's process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 ;;; group. Useful if you accidentally
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 ;;; suspend your process (with C-c C-z).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 ;;; term-mode-hook is the term mode hook. Basically for your keybindings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 ;;; term-load-hook is run after loading in this package.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 ;;; This is passed to the inferior in the EMACS environment variable,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 ;;; so it is important to increase it if there are protocol-relevant changes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (defconst term-protocol-version "0.95")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (require 'ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (require 'ehelp)
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
89
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
90 (defgroup term nil
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
91 "General command interpreter in a window"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
92 :group 'processes
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
93 :group 'unix)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
94
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 ;;; Buffer Local Variables:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 ;;;============================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 ;;; Term mode buffer local variables:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 ;;; term-prompt-regexp - string term-bol uses to match prompt.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 ;;; term-delimiter-argument-list - list For delimiters and arguments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 ;;; term-last-input-start - marker Handy if inferior always echoes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 ;;; term-last-input-end - marker For term-kill-output command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 ;; For the input history mechanism:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (defvar term-input-ring-size 32 "Size of input history ring.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 ;;; term-input-ring-size - integer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 ;;; term-input-ring - ring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 ;;; term-input-ring-index - number ...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 ;;; term-input-autoexpand - symbol ...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 ;;; term-input-ignoredups - boolean ...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 ;;; term-last-input-match - string ...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 ;;; term-dynamic-complete-functions - hook For the completion mechanism
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 ;;; term-completion-fignore - list ...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 ;;; term-get-old-input - function Hooks for specific
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 ;;; term-input-filter-functions - hook process-in-a-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 ;;; term-input-filter - function modes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 ;;; term-input-send - function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 ;;; term-scroll-to-bottom-on-output - symbol ...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 ;;; term-scroll-show-maximum-output - boolean...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (defvar term-height) ;; Number of lines in window.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (defvar term-width) ;; Number of columns in window.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (defvar term-home-marker) ;; Marks the "home" position for cursor addressing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (defvar term-saved-home-marker nil) ;; When using alternate sub-buffer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 ;; contains saved term-home-marker from original sub-buffer .
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (defvar term-start-line-column 0) ;; (current-column) at start of screen line,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 ;; or nil if unknown.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (defvar term-current-column 0) ;; If non-nil, is cache for (current-column).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (defvar term-current-row 0) ;; Current vertical row (relative to home-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 ;; or nil if unknown.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (defvar term-insert-mode nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (defvar term-vertical-motion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (defvar term-terminal-state 0) ;; State of the terminal emulator:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 ;; state 0: Normal state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 ;; state 1: Last character was a graphic in the last column.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 ;; If next char is graphic, first move one column right
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 ;; (and line warp) before displaying it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 ;; This emulates (more or less) the behavior of xterm.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 ;; state 2: seen ESC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 ;; state 3: seen ESC [ (or ESC [ ?)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 ;; state 4: term-terminal-parameter contains pending output.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (defvar term-kill-echo-list nil) ;; A queue of strings whose echo
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 ;; we want suppressed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (defvar term-terminal-parameter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (defvar term-terminal-previous-parameter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (defvar term-current-face 'default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (defvar term-scroll-start 0) ;; Top-most line (inclusive) of scrolling region.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (defvar term-scroll-end) ;; Number of line (zero-based) after scrolling region.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (defvar term-pager-count nil) ;; If nil, paging is disabled.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 ;; Otherwise, number of lines before we need to page.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (defvar term-saved-cursor nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (defvar term-command-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (defvar term-log-buffer nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (defvar term-scroll-with-delete nil) ;; term-scroll-with-delete is t if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 ;; forward scrolling should be implemented by delete to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 ;; top-most line(s); and nil if scrolling should be implemented
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 ;; by moving term-home-marker. It is set to t iff there is a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 ;; (non-default) scroll-region OR the alternate buffer is used.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (defvar term-pending-delete-marker) ;; New user input in line mode needs to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 ;; be deleted, because it gets echoed by the inferior.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 ;; To reduce flicker, we defer the delete until the next output.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (defvar term-old-mode-map nil) ;; Saves the old keymap when in char mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (defvar term-old-mode-line-format) ;; Saves old mode-line-format while paging.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (defvar term-pager-old-local-map nil) ;; Saves old keymap while paging.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (defvar term-pager-old-filter) ;; Saved process-filter while paging.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
165 (defcustom explicit-shell-file-name nil
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
166 "*If non-nil, is file name to use for explicitly requested inferior shell."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
167 :type '(choice (const nil) file)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
168 :group 'term)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (defvar term-prompt-regexp "^"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 "Regexp to recognise prompts in the inferior process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 Defaults to \"^\", the null string at BOL.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 Good choices:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 Canonical Lisp: \"^[^> \\n]*>+:? *\" (Lucid, franz, kcl, T, cscheme, oaklisp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 Lucid Common Lisp: \"^\\\\(>\\\\|\\\\(->\\\\)+\\\\) *\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 franz: \"^\\\\(->\\\\|<[0-9]*>:\\\\) *\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 kcl: \"^>+ *\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 shell: \"^[^#$%>\\n]*[#$%>] *\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 T: \"^>+ *\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 This is a good thing to set in mode hooks.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (defvar term-delimiter-argument-list ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 "List of characters to recognise as separate arguments in input.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 Strings comprising a character in this list will separate the arguments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 surrounding them, and also be regarded as arguments in their own right (unlike
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 whitespace). See `term-arguments'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 Defaults to the empty list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 For shells, a good value is (?\\| ?& ?< ?> ?\\( ?\\) ?;).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 This is a good thing to set in mode hooks.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
195 (defcustom term-input-autoexpand nil
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 "*If non-nil, expand input command history references on completion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 This mirrors the optional behavior of tcsh (its autoexpand and histlit).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 If the value is `input', then the expansion is seen on input.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 If the value is `history', then the expansion is only when inserting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 into the buffer's input ring. See also `term-magic-space' and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 `term-dynamic-complete'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
204 This variable is buffer-local."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
205 :type '(choice (const nil) (const t) (const input) (const history))
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
206 :group 'term)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
208 (defcustom term-input-ignoredups nil
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 "*If non-nil, don't add input matching the last on the input ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 This mirrors the optional behavior of bash.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
212 This variable is buffer-local."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
213 :type 'boolean
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
214 :group 'term)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
216 (defcustom term-input-ring-file-name nil
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 "*If non-nil, name of the file to read/write input history.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 See also `term-read-input-ring' and `term-write-input-ring'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
220 This variable is buffer-local, and is a good thing to set in mode hooks."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
221 :type 'boolean
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
222 :group 'term)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
224 (defcustom term-scroll-to-bottom-on-output nil
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 "*Controls whether interpreter output causes window to scroll.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 If nil, then do not scroll. If t or `all', scroll all windows showing buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 If `this', scroll only the selected window.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 If `others', scroll only those that are not the selected window.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 The default is nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 See variable `term-scroll-show-maximum-output'.
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
233 This variable is buffer-local."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
234 :type 'boolean
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
235 :group 'term)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
237 (defcustom term-scroll-show-maximum-output nil
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 "*Controls how interpreter output causes window to scroll.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 If non-nil, then show the maximum output when the window is scrolled.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 See variable `term-scroll-to-bottom-on-output'.
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
242 This variable is buffer-local."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
243 :type 'boolean
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
244 :group 'term)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 ;; Where gud-display-frame should put the debugging arrow. This is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 ;; set by the marker-filter, which scans the debugger's output for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 ;; indications of the current pc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (defvar term-pending-frame nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 ;;; Here are the per-interpreter hooks.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (defvar term-get-old-input (function term-get-old-input-default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 "Function that submits old text in term mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 This function is called when return is typed while the point is in old text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 It returns the text to be submitted as process input. The default is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 term-get-old-input-default, which grabs the current line, and strips off
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 leading text matching term-prompt-regexp")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (defvar term-dynamic-complete-functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 '(term-replace-by-expanded-history term-dynamic-complete-filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 "List of functions called to perform completion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 Functions should return non-nil if completion was performed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 See also `term-dynamic-complete'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 This is a good thing to set in mode hooks.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (defvar term-input-filter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (function (lambda (str) (not (string-match "\\`\\s *\\'" str))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 "Predicate for filtering additions to input history.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 Only inputs answering true to this function are saved on the input
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 history list. Default is to save anything that isn't all whitespace")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (defvar term-input-filter-functions '()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 "Functions to call before input is sent to the process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 These functions get one argument, a string containing the text to send.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 This variable is buffer-local.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (defvar term-input-sender (function term-simple-send)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 "Function to actually send to PROCESS the STRING submitted by user.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 Usually this is just 'term-simple-send, but if your mode needs to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 massage the input string, this is your hook. This is called from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 the user command term-send-input. term-simple-send just sends
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 the string plus a newline.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
286 (defcustom term-eol-on-send t
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 "*Non-nil means go to the end of the line before sending input.
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
288 See `term-send-input'."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
289 :type 'boolean
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
290 :group 'term)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
292 (defcustom term-mode-hook '()
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 "Called upon entry into term-mode
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
294 This is run before the process is cranked up."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
295 :type 'hook
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
296 :group 'term)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
298 (defcustom term-exec-hook '()
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 "Called each time a process is exec'd by term-exec.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 This is called after the process is cranked up. It is useful for things that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 must be done each time a process is executed in a term-mode buffer (e.g.,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (process-kill-without-query)). In contrast, the term-mode-hook is only
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
303 executed once when the buffer is created."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
304 :type 'hook
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 108
diff changeset
305 :group 'term)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (defvar term-mode-map nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (defvar term-raw-map nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 "Keyboard map for sending characters directly to the inferior process.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (defvar term-escape-char nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 "Escape character for char-sub-mode of term mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 Do not change it directly; use term-set-escape-char instead.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (defvar term-raw-escape-map nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (defvar term-pager-break-map nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (defvar term-ptyp t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 "True if communications via pty; false if by pipe. Buffer local.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 This is to work around a bug in emacs process signalling.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (defvar term-last-input-match ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 "Last string searched for by term input history search, for defaulting.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 Buffer local variable.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (defvar term-input-ring nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (defvar term-last-input-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (defvar term-last-input-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (defvar term-input-ring-index nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 "Index of last matched history element.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (defvar term-matching-input-from-input-string ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 "Input previously used to match input history.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 ; This argument to set-process-filter disables reading from the process,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 ; assuming this is emacs-19.20 or newer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (defvar term-pager-filter t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (put 'term-replace-by-expanded-history 'menu-enable 'term-input-autoexpand)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (put 'term-input-ring 'permanent-local t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (put 'term-input-ring-index 'permanent-local t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 (put 'term-input-autoexpand 'permanent-local t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (put 'term-input-filter-functions 'permanent-local t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (put 'term-scroll-to-bottom-on-output 'permanent-local t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (put 'term-scroll-show-maximum-output 'permanent-local t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (put 'term-ptyp 'permanent-local t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 ;; Do FORMS if running under Emacs-19.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (defmacro term-if-emacs19 (&rest forms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (if (string-match "^19" emacs-version) (cons 'progn forms)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 ;; True if running under XEmacs (previously Lucid emacs).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (defmacro term-is-xemacs () '(string-match "Lucid" emacs-version))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 ;; Do FORM if running under XEmacs (previously Lucid emacs).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (defmacro term-if-xemacs (&rest forms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 (if (term-is-xemacs) (cons 'progn forms)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 ;; Do FORM if NOT running under XEmacs (previously Lucid emacs).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (defmacro term-ifnot-xemacs (&rest forms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (if (not (term-is-xemacs)) (cons 'progn forms)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (defmacro term-in-char-mode () '(eq (current-local-map) term-raw-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (defmacro term-in-line-mode () '(not (term-in-char-mode)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 ;; True if currently doing PAGER handling.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (defmacro term-pager-enabled () 'term-pager-count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (defmacro term-handling-pager () 'term-pager-old-local-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (defmacro term-using-alternate-sub-buffer () 'term-saved-home-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (defvar term-signals-menu)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 (defvar term-terminal-menu)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 (term-if-xemacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 (defvar term-terminal-menu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 '("Terminal"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 [ "Character mode" term-char-mode (term-in-line-mode)]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 [ "Line mode" term-line-mode (term-in-char-mode)]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 [ "Enable paging" term-pager-toggle (not term-pager-count)]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 [ "Disable paging" term-pager-toggle term-pager-count])))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (defun term-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 "Major mode for interacting with an inferior interpreter.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 Interpreter name is same as buffer name, sans the asterisks.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 In line sub-mode, return at end of buffer sends line as input,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 while return not at end copies rest of line to end and sends it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 In char sub-mode, each character (except `term-escape-char`) is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 set immediately.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 This mode is typically customised to create inferior-lisp-mode,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 shell-mode, etc.. This can be done by setting the hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 term-input-filter-functions, term-input-filter, term-input-sender and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 term-get-old-input to appropriate functions, and the variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 term-prompt-regexp to the appropriate regular expression.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 An input history is maintained of size `term-input-ring-size', and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 can be accessed with the commands \\[term-next-input], \\[term-previous-input], and \\[term-dynamic-list-input-ring].
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 Input ring history expansion can be achieved with the commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 \\[term-replace-by-expanded-history] or \\[term-magic-space].
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 Input ring expansion is controlled by the variable `term-input-autoexpand',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 and addition is controlled by the variable `term-input-ignoredups'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 Input to, and output from, the subprocess can cause the window to scroll to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 the end of the buffer. See variables `term-scroll-to-bottom-on-input',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 and `term-scroll-to-bottom-on-output'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 If you accidentally suspend your process, use \\[term-continue-subjob]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 to continue it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 \\{term-mode-map}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 Entry to this mode runs the hooks on term-mode-hook"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 ;; Do not remove this. All major modes must do this.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 (kill-all-local-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (setq major-mode 'term-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (setq mode-name "Term")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 (use-local-map term-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (make-local-variable 'term-home-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (setq term-home-marker (copy-marker 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 (make-local-variable 'term-saved-home-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (make-local-variable 'term-height)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (make-local-variable 'term-width)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (setq term-width (1- (window-width)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 (setq term-height (1- (window-height)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 (make-local-variable 'term-terminal-parameter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (make-local-variable 'term-saved-cursor)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 (make-local-variable 'term-last-input-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (setq term-last-input-start (make-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 (make-local-variable 'term-last-input-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (setq term-last-input-end (make-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 (make-local-variable 'term-last-input-match)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (setq term-last-input-match "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (make-local-variable 'term-prompt-regexp) ; Don't set; default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (make-local-variable 'term-input-ring-size) ; ...to global val.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 (make-local-variable 'term-input-ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (make-local-variable 'term-input-ring-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 (or (and (boundp 'term-input-ring) term-input-ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (setq term-input-ring (make-ring term-input-ring-size)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 (make-local-variable 'term-input-ring-index)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (or (and (boundp 'term-input-ring-index) term-input-ring-index)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (setq term-input-ring-index nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 (make-local-variable 'term-command-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (setq term-command-hook (symbol-function 'term-command-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 (make-local-variable 'term-terminal-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 (make-local-variable 'term-kill-echo-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 (make-local-variable 'term-start-line-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 (make-local-variable 'term-current-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 (make-local-variable 'term-current-row)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 (make-local-variable 'term-log-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (make-local-variable 'term-scroll-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 (make-local-variable 'term-scroll-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 (setq term-scroll-end term-height)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (make-local-variable 'term-scroll-with-delete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (make-local-variable 'term-pager-count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (make-local-variable 'term-pager-old-local-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 (make-local-variable 'term-old-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 (make-local-variable 'term-insert-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 (make-local-variable 'term-dynamic-complete-functions)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (make-local-variable 'term-completion-fignore)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 (make-local-variable 'term-get-old-input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 (make-local-variable 'term-matching-input-from-input-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 (make-local-variable 'term-input-autoexpand)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (make-local-variable 'term-input-ignoredups)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (make-local-variable 'term-delimiter-argument-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 (make-local-variable 'term-input-filter-functions)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (make-local-variable 'term-input-filter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 (make-local-variable 'term-input-sender)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 (make-local-variable 'term-eol-on-send)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 (make-local-variable 'term-scroll-to-bottom-on-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 (make-local-variable 'term-scroll-show-maximum-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 (make-local-variable 'term-ptyp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 (make-local-variable 'term-exec-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 (make-local-variable 'term-vertical-motion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (make-local-variable 'term-pending-delete-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 (setq term-pending-delete-marker (make-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 (make-local-variable 'term-current-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (make-local-variable 'term-pending-frame)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 (setq term-pending-frame nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (run-hooks 'term-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (term-if-xemacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (if (fboundp 'add-submenu)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 (set (make-local-variable 'current-menubar)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (copy-sequence current-menubar))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 (add-submenu nil term-terminal-menu))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 (or term-input-ring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 (setq term-input-ring (make-ring term-input-ring-size)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 (term-update-mode-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 (if term-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 (setq term-mode-map (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 (define-key term-mode-map "\ep" 'term-previous-input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 (define-key term-mode-map "\en" 'term-next-input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (define-key term-mode-map "\er" 'term-previous-matching-input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 (define-key term-mode-map "\es" 'term-next-matching-input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 (term-ifnot-xemacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 (define-key term-mode-map [?\A-\M-r] 'term-previous-matching-input-from-input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (define-key term-mode-map [?\A-\M-s] 'term-next-matching-input-from-input))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (define-key term-mode-map "\e\C-l" 'term-show-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (define-key term-mode-map "\C-m" 'term-send-input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 (define-key term-mode-map "\C-d" 'term-delchar-or-maybe-eof)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 (define-key term-mode-map "\C-c\C-a" 'term-bol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 (define-key term-mode-map "\C-c\C-u" 'term-kill-input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (define-key term-mode-map "\C-c\C-w" 'backward-kill-word)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 (define-key term-mode-map "\C-c\C-c" 'term-interrupt-subjob)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (define-key term-mode-map "\C-c\C-z" 'term-stop-subjob)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 (define-key term-mode-map "\C-c\C-\\" 'term-quit-subjob)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 (define-key term-mode-map "\C-c\C-m" 'term-copy-old-input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 (define-key term-mode-map "\C-c\C-o" 'term-kill-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 (define-key term-mode-map "\C-c\C-r" 'term-show-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 (define-key term-mode-map "\C-c\C-e" 'term-show-maximum-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 (define-key term-mode-map "\C-c\C-l" 'term-dynamic-list-input-ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 (define-key term-mode-map "\C-c\C-n" 'term-next-prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 (define-key term-mode-map "\C-c\C-p" 'term-previous-prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 (define-key term-mode-map "\C-c\C-d" 'term-send-eof)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 (define-key term-mode-map "\C-c\C-k" 'term-char-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 (define-key term-mode-map "\C-c\C-j" 'term-line-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 (define-key term-mode-map "\C-c\C-q" 'term-pager-toggle)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 (copy-face 'default 'term-underline-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (set-face-underline-p 'term-underline-face t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 ; ;; completion:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 ; (define-key term-mode-map [menu-bar completion]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 ; (cons "Complete" (make-sparse-keymap "Complete")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 ; (define-key term-mode-map [menu-bar completion complete-expand]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 ; '("Expand File Name" . term-replace-by-expanded-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 ; (define-key term-mode-map [menu-bar completion complete-listing]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 ; '("File Completion Listing" . term-dynamic-list-filename-completions))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 ; (define-key term-mode-map [menu-bar completion complete-file]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 ; '("Complete File Name" . term-dynamic-complete-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 ; (define-key term-mode-map [menu-bar completion complete]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 ; '("Complete Before Point" . term-dynamic-complete))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 ; ;; Put them in the menu bar:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 ; (setq menu-bar-final-items (append '(terminal completion inout signals)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 ; menu-bar-final-items))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 ;; Menu bars:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 (term-ifnot-xemacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 (term-if-emacs19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 ;; terminal:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 (let (newmap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 (setq newmap (make-sparse-keymap "Terminal"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 (define-key newmap [terminal-pager-enable]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 '("Enable paging" . term-fake-pager-enable))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 (define-key newmap [terminal-pager-disable]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 '("Disable paging" . term-fake-pager-disable))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 (define-key newmap [terminal-char-mode]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 '("Character mode" . term-char-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 (define-key newmap [terminal-line-mode]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 '("Line mode" . term-line-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 (define-key newmap [menu-bar terminal]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 (setq term-terminal-menu (cons "Terminal" newmap)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 ;; completion: (line mode only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 (defvar term-completion-menu (make-sparse-keymap "Complete"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 (define-key term-mode-map [menu-bar completion]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 (cons "Complete" term-completion-menu))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 (define-key term-completion-menu [complete-expand]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 '("Expand File Name" . term-replace-by-expanded-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 (define-key term-completion-menu [complete-listing]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 '("File Completion Listing" . term-dynamic-list-filename-completions))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 (define-key term-completion-menu [menu-bar completion complete-file]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 '("Complete File Name" . term-dynamic-complete-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 (define-key term-completion-menu [menu-bar completion complete]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 '("Complete Before Point" . term-dynamic-complete))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 ;; Input history: (line mode only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 (defvar term-inout-menu (make-sparse-keymap "In/Out"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 (define-key term-mode-map [menu-bar inout]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 (cons "In/Out" term-inout-menu))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 (define-key term-inout-menu [kill-output]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 '("Kill Current Output Group" . term-kill-output))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 (define-key term-inout-menu [next-prompt]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 '("Forward Output Group" . term-next-prompt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 (define-key term-inout-menu [previous-prompt]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 '("Backward Output Group" . term-previous-prompt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 (define-key term-inout-menu [show-maximum-output]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 '("Show Maximum Output" . term-show-maximum-output))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 (define-key term-inout-menu [show-output]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 '("Show Current Output Group" . term-show-output))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 (define-key term-inout-menu [kill-input]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 '("Kill Current Input" . term-kill-input))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 (define-key term-inout-menu [copy-input]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 '("Copy Old Input" . term-copy-old-input))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 (define-key term-inout-menu [forward-matching-history]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 '("Forward Matching Input..." . term-forward-matching-input))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 (define-key term-inout-menu [backward-matching-history]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 '("Backward Matching Input..." . term-backward-matching-input))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 (define-key term-inout-menu [next-matching-history]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 '("Next Matching Input..." . term-next-matching-input))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 (define-key term-inout-menu [previous-matching-history]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 '("Previous Matching Input..." . term-previous-matching-input))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 (define-key term-inout-menu [next-matching-history-from-input]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 '("Next Matching Current Input" . term-next-matching-input-from-input))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 (define-key term-inout-menu [previous-matching-history-from-input]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 '("Previous Matching Current Input" . term-previous-matching-input-from-input))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 (define-key term-inout-menu [next-history]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 '("Next Input" . term-next-input))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 (define-key term-inout-menu [previous-history]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 '("Previous Input" . term-previous-input))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 (define-key term-inout-menu [list-history]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 '("List Input History" . term-dynamic-list-input-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 (define-key term-inout-menu [expand-history]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 '("Expand History Before Point" . term-replace-by-expanded-history))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 ;; Signals
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 (setq newmap (make-sparse-keymap "Signals"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 (define-key newmap [eof] '("EOF" . term-send-eof))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 (define-key newmap [kill] '("KILL" . term-kill-subjob))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 (define-key newmap [quit] '("QUIT" . term-quit-subjob))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 (define-key newmap [cont] '("CONT" . term-continue-subjob))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 (define-key newmap [stop] '("STOP" . term-stop-subjob))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 (define-key newmap [] '("BREAK" . term-interrupt-subjob))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 (define-key term-mode-map [menu-bar signals]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 (setq term-signals-menu (cons "Signals" newmap)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 (defun term-reset-size (height width)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 (setq term-height height)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 (setq term-width width)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 (setq term-start-line-column nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 (setq term-current-row nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 (setq term-current-column nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 (term-scroll-region 0 height))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 ;; Recursive routine used to check if any string in term-kill-echo-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 ;; matches part of the buffer before point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 ;; If so, delete that matched part of the buffer - this suppresses echo.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 ;; Also, remove that string from the term-kill-echo-list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 ;; We *also* remove any older string on the list, as a sanity measure,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 ;; in case something gets out of sync. (Except for type-ahead, there
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 ;; should only be one element in the list.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 (defun term-check-kill-echo-list ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 (let ((cur term-kill-echo-list) (found nil) (save-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 (while cur
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 (let* ((str (car cur)) (len (length str)) (start (- (point) len)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 (if (and (>= start (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 (string= str (buffer-substring start (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 (progn (delete-backward-char len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 (setq term-kill-echo-list (cdr cur))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 (setq term-current-column nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 (setq term-current-row nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 (setq term-start-line-column nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 (setq cur nil found t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 (setq cur (cdr cur))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 (if (not found)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 (goto-char save-point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 found))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 (defun term-check-size (process)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 (if (or (/= term-height (1- (window-height)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 (/= term-width (1- (window-width))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 (term-reset-size (1- (window-height)) (1- (window-width)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 (set-process-window-size process term-height term-width))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 (defun term-send-raw-string (chars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 (let ((proc (get-buffer-process (current-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 (if (not proc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 (error "Current buffer has no process")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 ;; Note that (term-current-row) must be called *after*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 ;; (point) has been updated to (process-mark proc).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 (goto-char (process-mark proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 (if (term-pager-enabled)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 (setq term-pager-count (term-current-row)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 (send-string proc chars))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 (defun term-send-raw ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 "Send the last character typed through the terminal-emulator
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 without any interpretation."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 (term-if-xemacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 (if (key-press-event-p last-input-event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 (let ((mods (event-modifiers last-input-event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 (key (event-key last-input-event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 meta)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 (if (memq 'meta mods)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 (setq meta t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 (setq mods (delq 'meta mods))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 (let ((ascii (event-to-character (character-to-event
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 (append mods (list key)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 t ;; lenient
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 nil ;; no meta mucking
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 t ;; allow non-ASCII
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 (if ascii
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 (if meta
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 (term-send-raw-string (format "\e%c" ascii))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 (term-send-raw-string (make-string 1 ascii)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 (command-execute (key-binding last-input-event)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 (term-ifnot-xemacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 ;; Convert `return' to C-m, etc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 (if (and (symbolp last-input-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 (get last-input-char 'ascii-character))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 (setq last-input-char (get last-input-char 'ascii-character)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 (term-send-raw-string (make-string 1 last-input-char))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 (defun term-send-raw-meta ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 (if (symbolp last-input-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 ;; Convert `return' to C-m, etc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 (let ((tmp (get last-input-char 'event-symbol-elements)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 (if tmp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 (setq last-input-char (car tmp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 (if (symbolp last-input-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 (setq tmp (get last-input-char 'ascii-character))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 (if tmp (setq last-input-char tmp))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 (term-send-raw-string (if (and (numberp last-input-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 (> last-input-char 127)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 (< last-input-char 256))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 (make-string 1 last-input-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 (format "\e%c" last-input-char))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 (defun term-mouse-paste (click arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 "Insert the last stretch of killed text at the position clicked on."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 (interactive "e\nP")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 (term-if-xemacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 (term-send-raw-string (or (condition-case () (x-get-selection) (error ()))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 (x-get-cutbuffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 (error "No selection or cut buffer available"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 (term-ifnot-xemacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 ;; Give temporary modes such as isearch a chance to turn off.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 (run-hooks 'mouse-leave-buffer-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 (setq this-command 'yank)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 (term-send-raw-string (current-kill (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 ((listp arg) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 ((eq arg '-) -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 (t (1- arg)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 ;; Which would be better: "\e[A" or "\eOA"? readline accepts either.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 (defun term-send-up () (interactive) (term-send-raw-string "\e[A"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 (defun term-send-down () (interactive) (term-send-raw-string "\e[B"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 (defun term-send-right () (interactive) (term-send-raw-string "\e[C"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 (defun term-send-left () (interactive) (term-send-raw-string "\e[D"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 (defun term-set-escape-char (c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 "Change term-escape-char and keymaps that depend on it."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 (if term-escape-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 (define-key term-raw-map term-escape-char 'term-send-raw))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 (setq c (make-string 1 c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 (define-key term-raw-map c term-raw-escape-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 ;; Define standard binings in term-raw-escape-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 (define-key term-raw-escape-map "\C-x"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 (lookup-key (current-global-map) "\C-x"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 (define-key term-raw-escape-map "\C-v"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 (lookup-key (current-global-map) "\C-v"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 (define-key term-raw-escape-map "\C-u"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 (lookup-key (current-global-map) "\C-u"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 (define-key term-raw-escape-map c 'term-send-raw)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 (define-key term-raw-escape-map "\C-q" 'term-pager-toggle)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 ;; The keybinding for term-char-mode is needed by the menubar code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 (define-key term-raw-escape-map "\C-k" 'term-char-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 (define-key term-raw-escape-map "\C-j" 'term-line-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 (defun term-char-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 "Switch to char (\"raw\") sub-mode of term mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 Each character you type is sent directly to the inferior without
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 intervention from emacs, except for the escape character (usually C-c)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 (if (not term-raw-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 (let ((map (make-keymap)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 (term-if-xemacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 (set (make-local-variable 'meta-prefix-char) -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 (set-keymap-default-binding map 'term-send-raw))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 (term-ifnot-xemacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 (let ((esc-map (make-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 (i 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 (while (< i 128)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 (define-key map (make-string 1 i) 'term-send-raw)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 (define-key esc-map (make-string 1 i) 'term-send-raw-meta)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 (setq i (1+ i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 (define-key map "\e" esc-map)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 (setq term-raw-map map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 (setq term-raw-escape-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 (copy-keymap (lookup-key (current-global-map) "\C-x")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 (term-if-emacs19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 (term-if-xemacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 (define-key term-raw-map [button2] 'term-mouse-paste))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 (term-ifnot-xemacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 (define-key term-raw-map [mouse-2] 'term-mouse-paste)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 (define-key term-raw-map [menu-bar terminal] term-terminal-menu)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 (define-key term-raw-map [menu-bar signals] term-signals-menu))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 (define-key term-raw-map [up] 'term-send-up)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 (define-key term-raw-map [down] 'term-send-down)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 (define-key term-raw-map [right] 'term-send-right)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 (define-key term-raw-map [left] 'term-send-left))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 (term-set-escape-char ?\C-c)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 ;; FIXME: Emit message? Cfr ilisp-raw-message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 (if (term-in-line-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 (setq term-old-mode-map (current-local-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 (use-local-map term-raw-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 ;; Send existing partial line to inferior (without newline).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 (let ((pmark (process-mark (get-buffer-process (current-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 (save-input-sender term-input-sender))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 (if (> (point) pmark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 (setq term-input-sender
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 (symbol-function 'term-send-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 (term-send-input))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 (setq term-input-sender save-input-sender))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 (term-update-mode-line))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 (defun term-line-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 "Switch to line (\"cooked\") sub-mode of term mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 This means that emacs editing commands work as normally, until
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 you type \\[term-send-input] which sends the current line to the inferior."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 (if (term-in-char-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 (use-local-map term-old-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 (term-update-mode-line))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 (defun term-update-mode-line ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 (setq mode-line-process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 (if (term-in-char-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 (if (term-pager-enabled) '(": char page %s") '(": char %s"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 (if (term-pager-enabled) '(": line page %s") '(": line %s"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 (set-buffer-modified-p (buffer-modified-p))) ;; Force mode line update.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 (defun term-check-proc (buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 "True if there is a process associated w/buffer BUFFER, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 it is alive (status RUN or STOP). BUFFER can be either a buffer or the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 name of one"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 (let ((proc (get-buffer-process buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 (and proc (memq (process-status proc) '(run stop)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 ;;; Note that this guy, unlike shell.el's make-shell, barfs if you pass it ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 ;;; for the second argument (program).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 (defun make-term (name program &optional startfile &rest switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 "Make a term process NAME in a buffer, running PROGRAM.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 The name of the buffer is made by surrounding NAME with `*'s.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 If there is already a running process in that buffer, it is not restarted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 Optional third arg STARTFILE is the name of a file to send the contents of to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 the process. Any more args are arguments to PROGRAM."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 (let ((buffer (get-buffer-create (concat "*" name "*"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 ;; If no process, or nuked process, crank up a new one and put buffer in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 ;; term mode. Otherwise, leave buffer and existing process alone.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 (cond ((not (term-check-proc buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 (term-mode)) ; Install local vars, mode, keymap, ...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 (term-exec buffer name program startfile switches)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 (defun term (program)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 "Start a terminal-emulator in a new buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 (interactive (list (read-from-minibuffer "Run program: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 (or explicit-shell-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 (getenv "ESHELL")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 (getenv "SHELL")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 "/bin/sh"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 (set-buffer (make-term "terminal" program))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 (term-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 (term-char-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 (switch-to-buffer "*terminal*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 (defun term-exec (buffer name command startfile switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 "Start up a process in buffer for term modes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 Blasts any old process running in the buffer. Doesn't set the buffer mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 You can use this to cheaply run a series of processes in the same term
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 buffer. The hook term-exec-hook is run after each exec."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 (let ((proc (get-buffer-process buffer))) ; Blast any old process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 (if proc (delete-process proc)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 ;; Crank up a new process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 (let ((proc (term-exec-1 name buffer command switches)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 (make-local-variable 'term-ptyp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 (setq term-ptyp process-connection-type) ; T if pty, NIL if pipe.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 ;; Jump to the end, and set the process mark.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 (set-marker (process-mark proc) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 (set-process-filter proc 'term-emulate-terminal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 ;; Feed it the startfile.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 (cond (startfile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 ;;This is guaranteed to wait long enough
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 ;;but has bad results if the term does not prompt at all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 ;; (while (= size (buffer-size))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 ;; (sleep-for 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 ;;I hope 1 second is enough!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 (sleep-for 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 (insert-file-contents startfile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 (setq startfile (buffer-substring (point) (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 (delete-region (point) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 (term-send-string proc startfile)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 (run-hooks 'term-exec-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 ;;; Name to use for TERM.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 ;;; Using "emacs" loses, because bash disables editing if TERM == emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 (defvar term-term-name "eterm")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 ; Format string, usage: (format term-termcap-string emacs-term-name "TERMCAP=" 24 80)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 (defvar term-termcap-format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 "%s%s:li#%d:co#%d:cl=\\E[H\\E[J:cd=\\E[J:bs:am:xn:cm=\\E[%%i%%d;%%dH\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 :nd=\\E[C:up=\\E[A:ce=\\E[K:ho=\\E[H:pt\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 :al=\\E[L:dl=\\E[M:DL=\\E[%%dM:AL=\\E[%%dL:cs=\\E[%%i%%d;%%dr:sf=\\n\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 :te=\\E[2J\\E[?47l\\E8:ti=\\E7\\E[?47h\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 :dc=\\E[P:DC=\\E[%%dP:IC=\\E[%%d@:im=\\E[4h:ei=\\E[4l:mi:\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 :so=\\E[7m:se=\\E[m:us=\\E[4m:ue=\\E[m:md=\\E[1m:mr=\\E[7m:me=\\E[m\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 :UP=\\E[%%dA:DO=\\E[%%dB:LE=\\E[%%dD:RI=\\E[%%dC"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 ;;; : -undefine ic
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 "termcap capabilties supported")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 ;;; This auxiliary function cranks up the process for term-exec in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 ;;; the appropriate environment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922 (defun term-exec-1 (name buffer command switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923 ;; We need to do an extra (fork-less) exec to run stty.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 ;; (This would not be needed if we had suitable emacs primitives.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 ;; The 'if ...; then shift; fi' hack is because Bourne shell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 ;; loses one arg when called with -c, and newer shells (bash, ksh) don't.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 ;; Thus we add an extra dummy argument "..", and then remove it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 (let ((process-environment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 (nconc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 (format "TERM=%s" term-term-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 (if (and (boundp 'system-uses-terminfo) system-uses-terminfo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 (format "TERMINFO=%s" data-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 (format term-termcap-format "TERMCAP="
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 term-term-name term-height term-width))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 (format "EMACS=%s (term:%s)" emacs-version term-protocol-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 (format "LINES=%d" term-height)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 (format "COLUMNS=%d" term-width))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 process-environment)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 (apply 'start-process name buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941 "/bin/sh" "-c"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942 (format "stty -nl echo rows %d columns %d sane 2>/dev/null;\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943 if [ $1 = .. ]; then shift; fi; exec \"$@\""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 term-height term-width)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 ".."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946 command switches)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948 ;;; This should be in emacs, but it isn't.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949 (defun term-mem (item list &optional elt=)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950 "Test to see if ITEM is equal to an item in LIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 Option comparison function ELT= defaults to equal."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 (let ((elt= (or elt= (function equal)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953 (done nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954 (while (and list (not done))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955 (if (funcall elt= item (car list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 (setq done list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957 (setq list (cdr list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958 done))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961 ;;; Input history processing in a buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962 ;;; ===========================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963 ;;; Useful input history functions, courtesy of the Ergo group.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 ;;; Eleven commands:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966 ;;; term-dynamic-list-input-ring List history in help buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967 ;;; term-previous-input Previous input...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968 ;;; term-previous-matching-input ...matching a string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 ;;; term-previous-matching-input-from-input ... matching the current input.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 ;;; term-next-input Next input...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971 ;;; term-next-matching-input ...matching a string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972 ;;; term-next-matching-input-from-input ... matching the current input.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 ;;; term-backward-matching-input Backwards input...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974 ;;; term-forward-matching-input ...matching a string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975 ;;; term-replace-by-expanded-history Expand history at point;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 ;;; replace with expanded history.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977 ;;; term-magic-space Expand history and insert space.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979 ;;; Three functions:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980 ;;; term-read-input-ring Read into term-input-ring...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981 ;;; term-write-input-ring Write to term-input-ring-file-name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982 ;;; term-replace-by-expanded-history-before-point Workhorse function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984 (defun term-read-input-ring (&optional silent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985 "Sets the buffer's `term-input-ring' from a history file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986 The name of the file is given by the variable `term-input-ring-file-name'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987 The history ring is of size `term-input-ring-size', regardless of file size.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988 If `term-input-ring-file-name' is nil this function does nothing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990 If the optional argument SILENT is non-nil, we say nothing about a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991 failure to read the history file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
992
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993 This function is useful for major mode commands and mode hooks.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995 The structure of the history file should be one input command per line,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996 with the most recent command last.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997 See also `term-input-ignoredups' and `term-write-input-ring'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998 (cond ((or (null term-input-ring-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999 (equal term-input-ring-file-name ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001 ((not (file-readable-p term-input-ring-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002 (or silent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003 (message "Cannot read history file %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004 term-input-ring-file-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006 (let ((history-buf (get-buffer-create " *temp*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007 (file term-input-ring-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 (count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009 (ring (make-ring term-input-ring-size)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 (set-buffer history-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015 (insert-file-contents file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016 ;; Save restriction in case file is already visited...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1017 ;; Watch for those date stamps in history files!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019 (while (and (< count term-input-ring-size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020 (re-search-backward "^[ \t]*\\([^#\n].*\\)[ \t]*$"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1021 nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022 (let ((history (buffer-substring (match-beginning 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023 (match-end 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024 (if (or (null term-input-ignoredups)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1025 (ring-empty-p ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026 (not (string-equal (ring-ref ring 0) history)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1027 (ring-insert-at-beginning ring history)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1028 (setq count (1+ count))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029 (kill-buffer history-buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030 (setq term-input-ring ring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031 term-input-ring-index nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1032
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1033 (defun term-write-input-ring ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034 "Writes the buffer's `term-input-ring' to a history file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035 The name of the file is given by the variable `term-input-ring-file-name'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036 The original contents of the file are lost if `term-input-ring' is not empty.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1037 If `term-input-ring-file-name' is nil this function does nothing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1038
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1039 Useful within process sentinels.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1040
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1041 See also `term-read-input-ring'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1042 (cond ((or (null term-input-ring-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043 (equal term-input-ring-file-name "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1044 (null term-input-ring) (ring-empty-p term-input-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1046 ((not (file-writable-p term-input-ring-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1047 (message "Cannot write history file %s" term-input-ring-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1048 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1049 (let* ((history-buf (get-buffer-create " *Temp Input History*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1050 (ring term-input-ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1051 (file term-input-ring-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1052 (index (ring-length ring)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1053 ;; Write it all out into a buffer first. Much faster, but messier,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1054 ;; than writing it one line at a time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1055 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1056 (set-buffer history-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1057 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1058 (while (> index 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1059 (setq index (1- index))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1060 (insert (ring-ref ring index) ?\n))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1061 (write-region (buffer-string) nil file nil 'no-message)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1062 (kill-buffer nil))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1063
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1064
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1065 (defun term-dynamic-list-input-ring ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1066 "List in help buffer the buffer's input history."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1067 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1068 (if (or (not (ring-p term-input-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1069 (ring-empty-p term-input-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1070 (message "No history")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1071 (let ((history nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1072 (history-buffer " *Input History*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1073 (index (1- (ring-length term-input-ring)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1074 (conf (current-window-configuration)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1075 ;; We have to build up a list ourselves from the ring vector.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1076 (while (>= index 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1077 (setq history (cons (ring-ref term-input-ring index) history)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1078 index (1- index)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1079 ;; Change "completion" to "history reference"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1080 ;; to make the display accurate.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1081 (with-output-to-temp-buffer history-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1082 (display-completion-list history)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1083 (set-buffer history-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1084 (forward-line 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1085 (while (search-backward "completion" nil 'move)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1086 (replace-match "history reference")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1087 (sit-for 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1088 (message "Hit space to flush")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1089 (let ((ch (read-event)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1090 (if (eq ch ?\ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1091 (set-window-configuration conf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1092 (setq unread-command-events (list ch)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1093
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1094
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1095 (defun term-regexp-arg (prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1096 ;; Return list of regexp and prefix arg using PROMPT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1097 (let* ((minibuffer-history-sexp-flag nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1098 ;; Don't clobber this.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1099 (last-command last-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1100 (regexp (read-from-minibuffer prompt nil nil nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1101 'minibuffer-history-search-history)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1102 (list (if (string-equal regexp "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1103 (setcar minibuffer-history-search-history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1104 (nth 1 minibuffer-history-search-history))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1105 regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1106 (prefix-numeric-value current-prefix-arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1107
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1108 (defun term-search-arg (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1109 ;; First make sure there is a ring and that we are after the process mark
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1110 (cond ((not (term-after-pmark-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1111 (error "Not at command line"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1112 ((or (null term-input-ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1113 (ring-empty-p term-input-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1114 (error "Empty input ring"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1115 ((zerop arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1116 ;; arg of zero resets search from beginning, and uses arg of 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1117 (setq term-input-ring-index nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1118 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1119 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1120 arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1121
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1122 (defun term-search-start (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1123 ;; Index to start a directional search, starting at term-input-ring-index
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1124 (if term-input-ring-index
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1125 ;; If a search is running, offset by 1 in direction of arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1126 (mod (+ term-input-ring-index (if (> arg 0) 1 -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1127 (ring-length term-input-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1128 ;; For a new search, start from beginning or end, as appropriate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1129 (if (>= arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1130 0 ; First elt for forward search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1131 (1- (ring-length term-input-ring))))) ; Last elt for backward search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1132
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1133 (defun term-previous-input-string (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1134 "Return the string ARG places along the input ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1135 Moves relative to `term-input-ring-index'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1136 (ring-ref term-input-ring (if term-input-ring-index
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1137 (mod (+ arg term-input-ring-index)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1138 (ring-length term-input-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1139 arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1140
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1141 (defun term-previous-input (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1142 "Cycle backwards through input history."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1143 (interactive "*p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1144 (term-previous-matching-input "." arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1145
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1146 (defun term-next-input (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1147 "Cycle forwards through input history."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1148 (interactive "*p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1149 (term-previous-input (- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1150
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1151 (defun term-previous-matching-input-string (regexp arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1152 "Return the string matching REGEXP ARG places along the input ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1153 Moves relative to `term-input-ring-index'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1154 (let* ((pos (term-previous-matching-input-string-position regexp arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1155 (if pos (ring-ref term-input-ring pos))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1156
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1157 (defun term-previous-matching-input-string-position (regexp arg &optional start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1158 "Return the index matching REGEXP ARG places along the input ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1159 Moves relative to START, or `term-input-ring-index'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1160 (if (or (not (ring-p term-input-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1161 (ring-empty-p term-input-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1162 (error "No history"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1163 (let* ((len (ring-length term-input-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1164 (motion (if (> arg 0) 1 -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1165 (n (mod (- (or start (term-search-start arg)) motion) len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1166 (tried-each-ring-item nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1167 (prev nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1168 ;; Do the whole search as many times as the argument says.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1169 (while (and (/= arg 0) (not tried-each-ring-item))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1170 ;; Step once.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1171 (setq prev n
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1172 n (mod (+ n motion) len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1173 ;; If we haven't reached a match, step some more.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1174 (while (and (< n len) (not tried-each-ring-item)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1175 (not (string-match regexp (ring-ref term-input-ring n))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1176 (setq n (mod (+ n motion) len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1177 ;; If we have gone all the way around in this search.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1178 tried-each-ring-item (= n prev)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1179 (setq arg (if (> arg 0) (1- arg) (1+ arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1180 ;; Now that we know which ring element to use, if we found it, return that.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1181 (if (string-match regexp (ring-ref term-input-ring n))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1182 n)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1183
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1184 (defun term-previous-matching-input (regexp arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1185 "Search backwards through input history for match for REGEXP.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1186 \(Previous history elements are earlier commands.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1187 With prefix argument N, search for Nth previous match.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1188 If N is negative, find the next or Nth next match."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1189 (interactive (term-regexp-arg "Previous input matching (regexp): "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1190 (setq arg (term-search-arg arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1191 (let ((pos (term-previous-matching-input-string-position regexp arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1192 ;; Has a match been found?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1193 (if (null pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1194 (error "Not found")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1195 (setq term-input-ring-index pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1196 (message "History item: %d" (1+ pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1197 (delete-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1198 ;; Can't use kill-region as it sets this-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1199 (process-mark (get-buffer-process (current-buffer))) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1200 (insert (ring-ref term-input-ring pos)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1201
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1202 (defun term-next-matching-input (regexp arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1203 "Search forwards through input history for match for REGEXP.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1204 \(Later history elements are more recent commands.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1205 With prefix argument N, search for Nth following match.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1206 If N is negative, find the previous or Nth previous match."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1207 (interactive (term-regexp-arg "Next input matching (regexp): "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1208 (term-previous-matching-input regexp (- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1209
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1210 (defun term-previous-matching-input-from-input (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1211 "Search backwards through input history for match for current input.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1212 \(Previous history elements are earlier commands.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1213 With prefix argument N, search for Nth previous match.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1214 If N is negative, search forwards for the -Nth following match."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1215 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1216 (if (not (memq last-command '(term-previous-matching-input-from-input
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1217 term-next-matching-input-from-input)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1218 ;; Starting a new search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1219 (setq term-matching-input-from-input-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1220 (buffer-substring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1221 (process-mark (get-buffer-process (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1222 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1223 term-input-ring-index nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1224 (term-previous-matching-input
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1225 (concat "^" (regexp-quote term-matching-input-from-input-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1226 arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1227
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1228 (defun term-next-matching-input-from-input (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1229 "Search forwards through input history for match for current input.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1230 \(Following history elements are more recent commands.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1231 With prefix argument N, search for Nth following match.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1232 If N is negative, search backwards for the -Nth previous match."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1233 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1234 (term-previous-matching-input-from-input (- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1235
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1236
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1237 (defun term-replace-by-expanded-history (&optional silent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1238 "Expand input command history references before point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1239 Expansion is dependent on the value of `term-input-autoexpand'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1240
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1241 This function depends on the buffer's idea of the input history, which may not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1242 match the command interpreter's idea, assuming it has one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1243
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1244 Assumes history syntax is like typical Un*x shells'. However, since emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1245 cannot know the interpreter's idea of input line numbers, assuming it has one,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1246 it cannot expand absolute input line number references.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1247
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1248 If the optional argument SILENT is non-nil, never complain
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1249 even if history reference seems erroneous.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1250
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1251 See `term-magic-space' and `term-replace-by-expanded-history-before-point'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1252
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1253 Returns t if successful."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1254 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1255 (if (and term-input-autoexpand
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1256 (string-match "[!^]" (funcall term-get-old-input))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1257 (save-excursion (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1258 (looking-at term-prompt-regexp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1259 ;; Looks like there might be history references in the command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1260 (let ((previous-modified-tick (buffer-modified-tick)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1261 (message "Expanding history references...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1262 (term-replace-by-expanded-history-before-point silent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1263 (/= previous-modified-tick (buffer-modified-tick)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1264
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1265
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1266 (defun term-replace-by-expanded-history-before-point (silent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1267 "Expand directory stack reference before point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1268 See `term-replace-by-expanded-history'. Returns t if successful."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1269 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1270 (let ((toend (- (save-excursion (end-of-line nil) (point)) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1271 (start (progn (term-bol nil) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1272 (while (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1273 (skip-chars-forward "^!^"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1274 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1275 (end-of-line nil) (- (point) toend)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1276 (< (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1277 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1278 (end-of-line nil) (- (point) toend))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1279 ;; This seems a bit complex. We look for references such as !!, !-num,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1280 ;; !foo, !?foo, !{bar}, !?{bar}, ^oh, ^my^, ^god^it, ^never^ends^.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1281 ;; If that wasn't enough, the plings can be suffixed with argument
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1282 ;; range specifiers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1283 ;; Argument ranges are complex too, so we hive off the input line,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1284 ;; referenced with plings, with the range string to `term-args'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1285 (setq term-input-ring-index nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1286 (cond ((or (= (preceding-char) ?\\)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1287 (term-within-quotes start (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1288 ;; The history is quoted, or we're in quotes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1289 (goto-char (1+ (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1290 ((looking-at "![0-9]+\\($\\|[^-]\\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1291 ;; We cannot know the interpreter's idea of input line numbers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1292 (goto-char (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1293 (message "Absolute reference cannot be expanded"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1294 ((looking-at "!-\\([0-9]+\\)\\(:?[0-9^$*-]+\\)?")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1295 ;; Just a number of args from `number' lines backward.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1296 (let ((number (1- (string-to-number
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1297 (buffer-substring (match-beginning 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1298 (match-end 1))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1299 (if (<= number (ring-length term-input-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1300 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1301 (replace-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1302 (term-args (term-previous-input-string number)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1303 (match-beginning 2) (match-end 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1304 t t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1305 (setq term-input-ring-index number)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1306 (message "History item: %d" (1+ number)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1307 (goto-char (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1308 (message "Relative reference exceeds input history size"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1309 ((or (looking-at "!!?:?\\([0-9^$*-]+\\)") (looking-at "!!"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1310 ;; Just a number of args from the previous input line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1311 (replace-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1312 (term-args (term-previous-input-string 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1313 (match-beginning 1) (match-end 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1314 t t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1315 (message "History item: previous"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1316 ((looking-at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1317 "!\\??\\({\\(.+\\)}\\|\\(\\sw+\\)\\)\\(:?[0-9^$*-]+\\)?")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1318 ;; Most recent input starting with or containing (possibly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1319 ;; protected) string, maybe just a number of args. Phew.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1320 (let* ((mb1 (match-beginning 1)) (me1 (match-end 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1321 (mb2 (match-beginning 2)) (me2 (match-end 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1322 (exp (buffer-substring (or mb2 mb1) (or me2 me1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1323 (pref (if (save-match-data (looking-at "!\\?")) "" "^"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1324 (pos (save-match-data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1325 (term-previous-matching-input-string-position
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1326 (concat pref (regexp-quote exp)) 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1327 (if (null pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1328 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1329 (goto-char (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1330 (or silent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1331 (progn (message "Not found")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1332 (ding))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1333 (setq term-input-ring-index pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1334 (replace-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1335 (term-args (ring-ref term-input-ring pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1336 (match-beginning 4) (match-end 4))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1337 t t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1338 (message "History item: %d" (1+ pos)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1339 ((looking-at "\\^\\([^^]+\\)\\^?\\([^^]*\\)\\^?")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1340 ;; Quick substitution on the previous input line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1341 (let ((old (buffer-substring (match-beginning 1) (match-end 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1342 (new (buffer-substring (match-beginning 2) (match-end 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1343 (pos nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1344 (replace-match (term-previous-input-string 0) t t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1345 (setq pos (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1346 (goto-char (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1347 (if (not (search-forward old pos t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1348 (or silent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1349 (error "Not found"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1350 (replace-match new t t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1351 (message "History item: substituted"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1352 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1353 (goto-char (match-end 0))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1354
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1355
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1356 (defun term-magic-space (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1357 "Expand input history references before point and insert ARG spaces.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1358 A useful command to bind to SPC. See `term-replace-by-expanded-history'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1359 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1360 (term-replace-by-expanded-history)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1361 (self-insert-command arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1362
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1363 (defun term-within-quotes (beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1364 "Return t if the number of quotes between BEG and END is odd.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1365 Quotes are single and double."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1366 (let ((countsq (term-how-many-region "\\(^\\|[^\\\\]\\)\'" beg end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1367 (countdq (term-how-many-region "\\(^\\|[^\\\\]\\)\"" beg end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1368 (or (= (mod countsq 2) 1) (= (mod countdq 2) 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1369
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1370 (defun term-how-many-region (regexp beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1371 "Return number of matches for REGEXP from BEG to END."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1372 (let ((count 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1373 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1374 (save-match-data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1375 (goto-char beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1376 (while (re-search-forward regexp end t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1377 (setq count (1+ count)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1378 count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1379
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1380 (defun term-args (string begin end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1381 ;; From STRING, return the args depending on the range specified in the text
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1382 ;; from BEGIN to END. If BEGIN is nil, assume all args. Ignore leading `:'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1383 ;; Range can be x-y, x-, -y, where x/y can be [0-9], *, ^, $.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1384 (save-match-data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1385 (if (null begin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1386 (term-arguments string 0 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1387 (let* ((range (buffer-substring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1388 (if (eq (char-after begin) ?:) (1+ begin) begin) end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1389 (nth (cond ((string-match "^[*^]" range) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1390 ((string-match "^-" range) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1391 ((string-equal range "$") nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1392 (t (string-to-number range))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1393 (mth (cond ((string-match "[-*$]$" range) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1394 ((string-match "-" range)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1395 (string-to-number (substring range (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1396 (t nth))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1397 (term-arguments string nth mth)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1398
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1399 ;; Return a list of arguments from ARG. Break it up at the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1400 ;; delimiters in term-delimiter-argument-list. Returned list is backwards.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1401 (defun term-delim-arg (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1402 (if (null term-delimiter-argument-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1403 (list arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1404 (let ((args nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1405 (pos 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1406 (len (length arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1407 (while (< pos len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1408 (let ((char (aref arg pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1409 (start pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1410 (if (memq char term-delimiter-argument-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1411 (while (and (< pos len) (eq (aref arg pos) char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1412 (setq pos (1+ pos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1413 (while (and (< pos len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1414 (not (memq (aref arg pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1415 term-delimiter-argument-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1416 (setq pos (1+ pos))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1417 (setq args (cons (substring arg start pos) args))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1418 args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1419
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1420 (defun term-arguments (string nth mth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1421 "Return from STRING the NTH to MTH arguments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1422 NTH and/or MTH can be nil, which means the last argument.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1423 Returned arguments are separated by single spaces.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1424 We assume whitespace separates arguments, except within quotes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1425 Also, a run of one or more of a single character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1426 in `term-delimiter-argument-list' is a separate argument.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1427 Argument 0 is the command name."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1428 (let ((argpart "[^ \n\t\"'`]+\\|\\(\"[^\"]*\"\\|'[^']*'\\|`[^`]*`\\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1429 (args ()) (pos 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1430 (count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1431 beg str value quotes)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1432 ;; Build a list of all the args until we have as many as we want.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1433 (while (and (or (null mth) (<= count mth))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1434 (string-match argpart string pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1435 (if (and beg (= pos (match-beginning 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1436 ;; It's contiguous, part of the same arg.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1437 (setq pos (match-end 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1438 quotes (or quotes (match-beginning 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1439 ;; It's a new separate arg.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1440 (if beg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1441 ;; Put the previous arg, if there was one, onto ARGS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1442 (setq str (substring string beg pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1443 args (if quotes (cons str args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1444 (nconc (term-delim-arg str) args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1445 count (1+ count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1446 (setq quotes (match-beginning 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1447 (setq beg (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1448 (setq pos (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1449 (if beg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1450 (setq str (substring string beg pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1451 args (if quotes (cons str args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1452 (nconc (term-delim-arg str) args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1453 count (1+ count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1454 (let ((n (or nth (1- count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1455 (m (if mth (1- (- count mth)) 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1456 (mapconcat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1457 (function (lambda (a) a)) (nthcdr n (nreverse (nthcdr m args))) " "))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1458
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1459 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1460 ;;; Input processing stuff [line mode]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1461 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1462
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1463 (defun term-send-input ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1464 "Send input to process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1465 After the process output mark, sends all text from the process mark to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1466 point as input to the process. Before the process output mark, calls value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1467 of variable term-get-old-input to retrieve old input, copies it to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1468 process mark, and sends it. A terminal newline is also inserted into the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1469 buffer and sent to the process. The list of function names contained in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1470 value of `term-input-filter-functions' is called on the input before sending
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1471 it. The input is entered into the input history ring, if the value of variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1472 term-input-filter returns non-nil when called on the input.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1473
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1474 Any history reference may be expanded depending on the value of the variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1475 `term-input-autoexpand'. The list of function names contained in the value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1476 of `term-input-filter-functions' is called on the input before sending it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1477 The input is entered into the input history ring, if the value of variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1478 `term-input-filter' returns non-nil when called on the input.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1479
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1480 If variable `term-eol-on-send' is non-nil, then point is moved to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1481 end of line before sending the input.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1482
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1483 The values of `term-get-old-input', `term-input-filter-functions', and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1484 `term-input-filter' are chosen according to the command interpreter running
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1485 in the buffer. E.g.,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1486
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1487 If the interpreter is the csh,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1488 term-get-old-input is the default: take the current line, discard any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1489 initial string matching regexp term-prompt-regexp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1490 term-input-filter-functions monitors input for \"cd\", \"pushd\", and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1491 \"popd\" commands. When it sees one, it cd's the buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1492 term-input-filter is the default: returns T if the input isn't all white
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1493 space.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1494
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1495 If the term is Lucid Common Lisp,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1496 term-get-old-input snarfs the sexp ending at point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1497 term-input-filter-functions does nothing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1498 term-input-filter returns NIL if the input matches input-filter-regexp,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1499 which matches (1) all whitespace (2) :a, :c, etc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1500
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1501 Similarly for Soar, Scheme, etc."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1502 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1503 ;; Note that the input string does not include its terminal newline.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1504 (let ((proc (get-buffer-process (current-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1505 (if (not proc) (error "Current buffer has no process")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1506 (let* ((pmark (process-mark proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1507 (pmark-val (marker-position pmark))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1508 (input-is-new (>= (point) pmark-val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1509 (intxt (if input-is-new
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1510 (progn (if term-eol-on-send (end-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1511 (buffer-substring pmark (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1512 (funcall term-get-old-input)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1513 (input (if (not (eq term-input-autoexpand 'input))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1514 ;; Just whatever's already there
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1515 intxt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1516 ;; Expand and leave it visible in buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1517 (term-replace-by-expanded-history t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1518 (buffer-substring pmark (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1519 (history (if (not (eq term-input-autoexpand 'history))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1520 input
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1521 ;; This is messy 'cos ultimately the original
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1522 ;; functions used do insertion, rather than return
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1523 ;; strings. We have to expand, then insert back.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1524 (term-replace-by-expanded-history t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1525 (let ((copy (buffer-substring pmark (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1526 (delete-region pmark (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1527 (insert input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1528 copy))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1529 (if (term-pager-enabled)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1530 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1531 (goto-char (process-mark proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1532 (setq term-pager-count (term-current-row))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1533 (if (and (funcall term-input-filter history)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1534 (or (null term-input-ignoredups)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1535 (not (ring-p term-input-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1536 (ring-empty-p term-input-ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1537 (not (string-equal (ring-ref term-input-ring 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1538 history))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1539 (ring-insert term-input-ring history))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1540 (let ((functions term-input-filter-functions))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1541 (while functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1542 (funcall (car functions) (concat input "\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1543 (setq functions (cdr functions))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1544 (setq term-input-ring-index nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1545
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1546 ;; Update the markers before we send the input
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1547 ;; in case we get output amidst sending the input.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1548 (set-marker term-last-input-start pmark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1549 (set-marker term-last-input-end (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1550 (if input-is-new
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1551 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1552 ;; Set up to delete, because inferior should echo.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1553 (if (marker-buffer term-pending-delete-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1554 (delete-region term-pending-delete-marker pmark))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1555 (set-marker term-pending-delete-marker pmark-val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1556 (set-marker (process-mark proc) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1557 (goto-char pmark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1558 (funcall term-input-sender proc input)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1559
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1560 (defun term-get-old-input-default ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1561 "Default for term-get-old-input.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1562 Take the current line, and discard any initial text matching
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1563 term-prompt-regexp."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1564 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1565 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1566 (term-skip-prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1567 (let ((beg (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1568 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1569 (buffer-substring beg (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1570
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1571 (defun term-copy-old-input ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1572 "Insert after prompt old input at point as new input to be edited.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1573 Calls `term-get-old-input' to get old input."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1574 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1575 (let ((input (funcall term-get-old-input))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1576 (process (get-buffer-process (current-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1577 (if (not process)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1578 (error "Current buffer has no process")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1579 (goto-char (process-mark process))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1580 (insert input))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1581
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1582 (defun term-skip-prompt ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1583 "Skip past the text matching regexp term-prompt-regexp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1584 If this takes us past the end of the current line, don't skip at all."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1585 (let ((eol (save-excursion (end-of-line) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1586 (if (and (looking-at term-prompt-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1587 (<= (match-end 0) eol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1588 (goto-char (match-end 0)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1589
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1590
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1591 (defun term-after-pmark-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1592 "Is point after the process output marker?"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1593 ;; Since output could come into the buffer after we looked at the point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1594 ;; but before we looked at the process marker's value, we explicitly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1595 ;; serialise. This is just because I don't know whether or not emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1596 ;; services input during execution of lisp commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1597 (let ((proc-pos (marker-position
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1598 (process-mark (get-buffer-process (current-buffer))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1599 (<= proc-pos (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1600
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1601 (defun term-simple-send (proc string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1602 "Default function for sending to PROC input STRING.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1603 This just sends STRING plus a newline. To override this,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1604 set the hook TERM-INPUT-SENDER."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1605 (term-send-string proc string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1606 (term-send-string proc "\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1607
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1608 (defun term-bol (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1609 "Goes to the beginning of line, then skips past the prompt, if any.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1610 If a prefix argument is given (\\[universal-argument]), then no prompt skip
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1611 -- go straight to column 0.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1612
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1613 The prompt skip is done by skipping text matching the regular expression
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1614 term-prompt-regexp, a buffer local variable."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1615 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1616 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1617 (if (null arg) (term-skip-prompt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1618
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1619 ;;; These two functions are for entering text you don't want echoed or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1620 ;;; saved -- typically passwords to ftp, telnet, or somesuch.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1621 ;;; Just enter m-x term-send-invisible and type in your line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1622
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1623 (defun term-read-noecho (prompt &optional stars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1624 "Read a single line of text from user without echoing, and return it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1625 Prompt with argument PROMPT, a string. Optional argument STARS causes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1626 input to be echoed with '*' characters on the prompt line. Input ends with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1627 RET, LFD, or ESC. DEL or C-h rubs out. C-u kills line. C-g aborts (if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1628 `inhibit-quit' is set because e.g. this function was called from a process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1629 filter and C-g is pressed, this function returns nil rather than a string).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1630
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1631 Note that the keystrokes comprising the text can still be recovered
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1632 \(temporarily) with \\[view-lossage]. This may be a security bug for some
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1633 applications."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1634 (let ((ans "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1635 (c 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1636 (echo-keystrokes 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1637 (cursor-in-echo-area t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1638 (done nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1639 (while (not done)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1640 (if stars
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1641 (message "%s%s" prompt (make-string (length ans) ?*))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1642 (message prompt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1643 (setq c (read-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1644 (cond ((= c ?\C-g)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1645 ;; This function may get called from a process filter, where
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1646 ;; inhibit-quit is set. In later versions of emacs read-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1647 ;; may clear quit-flag itself and return C-g. That would make
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1648 ;; it impossible to quit this loop in a simple way, so
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1649 ;; re-enable it here (for backward-compatibility the check for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1650 ;; quit-flag below would still be necessary, so this seems
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1651 ;; like the simplest way to do things).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1652 (setq quit-flag t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1653 done t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1654 ((or (= c ?\r) (= c ?\n) (= c ?\e))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1655 (setq done t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1656 ((= c ?\C-u)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1657 (setq ans ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1658 ((and (/= c ?\b) (/= c ?\177))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1659 (setq ans (concat ans (char-to-string c))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1660 ((> (length ans) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1661 (setq ans (substring ans 0 -1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1662 (if quit-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1663 ;; Emulate a true quit, except that we have to return a value.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1664 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1665 (setq quit-flag nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1666 (message "Quit")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1667 (beep t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1668 (message "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1669 ans)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1670
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1671 (defun term-send-invisible (str &optional proc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1672 "Read a string without echoing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1673 Then send it to the process running in the current buffer. A new-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1674 is additionally sent. String is not saved on term input history list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1675 Security bug: your string can still be temporarily recovered with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1676 \\[view-lossage]."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1677 (interactive "P") ; Defeat snooping via C-x esc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1678 (if (not (stringp str))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1679 (setq str (term-read-noecho "Non-echoed text: " t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1680 (if (not proc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1681 (setq proc (get-buffer-process (current-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1682 (if (not proc) (error "Current buffer has no process")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1683 (setq term-kill-echo-list (nconc term-kill-echo-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1684 (cons str nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1685 (term-send-string proc str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1686 (term-send-string proc "\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1687
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1688
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1689 ;;; Low-level process communication
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1690
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1691 (defvar term-input-chunk-size 512
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1692 "*Long inputs send to term processes are broken up into chunks of this size.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1693 If your process is choking on big inputs, try lowering the value.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1694
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1695 (defun term-send-string (proc str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1696 "Send PROCESS the contents of STRING as input.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1697 This is equivalent to process-send-string, except that long input strings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1698 are broken up into chunks of size term-input-chunk-size. Processes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1699 are given a chance to output between chunks. This can help prevent processes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1700 from hanging when you send them long inputs on some OS's."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1701 (let* ((len (length str))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1702 (i (min len term-input-chunk-size)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1703 (process-send-string proc (substring str 0 i))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1704 (while (< i len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1705 (let ((next-i (+ i term-input-chunk-size)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1706 (accept-process-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1707 (process-send-string proc (substring str i (min len next-i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1708 (setq i next-i)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1709
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1710 (defun term-send-region (proc start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1711 "Sends to PROC the region delimited by START and END.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1712 This is a replacement for process-send-region that tries to keep
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1713 your process from hanging on long inputs. See term-send-string."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1714 (term-send-string proc (buffer-substring start end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1715
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1716
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1717 ;;; Random input hackage
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1718
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1719 (defun term-kill-output ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1720 "Kill all output from interpreter since last input."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1721 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1722 (let ((pmark (process-mark (get-buffer-process (current-buffer)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1723 (kill-region term-last-input-end pmark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1724 (goto-char pmark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1725 (insert "*** output flushed ***\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1726 (set-marker pmark (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1727
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1728 (defun term-show-output ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1729 "Display start of this batch of interpreter output at top of window.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1730 Sets mark to the value of point when this command is run."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1731 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1732 (goto-char term-last-input-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1733 (backward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1734 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1735 (set-window-start (selected-window) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1736 (end-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1737
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1738 (defun term-interrupt-subjob ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1739 "Interrupt the current subjob."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1740 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1741 (interrupt-process nil term-ptyp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1742
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1743 (defun term-kill-subjob ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1744 "Send kill signal to the current subjob."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1745 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1746 (kill-process nil term-ptyp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1747
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1748 (defun term-quit-subjob ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1749 "Send quit signal to the current subjob."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1750 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1751 (quit-process nil term-ptyp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1752
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1753 (defun term-stop-subjob ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1754 "Stop the current subjob.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1755 WARNING: if there is no current subjob, you can end up suspending
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1756 the top-level process running in the buffer. If you accidentally do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1757 this, use \\[term-continue-subjob] to resume the process. (This
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1758 is not a problem with most shells, since they ignore this signal.)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1759 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1760 (stop-process nil term-ptyp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1761
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1762 (defun term-continue-subjob ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1763 "Send CONT signal to process buffer's process group.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1764 Useful if you accidentally suspend the top-level process."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1765 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1766 (continue-process nil term-ptyp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1767
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1768 (defun term-kill-input ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1769 "Kill all text from last stuff output by interpreter to point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1770 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1771 (let* ((pmark (process-mark (get-buffer-process (current-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1772 (p-pos (marker-position pmark)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1773 (if (> (point) p-pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1774 (kill-region pmark (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1775
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1776 (defun term-delchar-or-maybe-eof (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1777 "Delete ARG characters forward, or send an EOF to process if at end of buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1778 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1779 (if (eobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1780 (process-send-eof)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1781 (delete-char arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1782
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1783 (defun term-send-eof ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1784 "Send an EOF to the current buffer's process."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1785 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1786 (process-send-eof))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1787
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1788 (defun term-backward-matching-input (regexp arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1789 "Search backward through buffer for match for REGEXP.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1790 Matches are searched for on lines that match `term-prompt-regexp'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1791 With prefix argument N, search for Nth previous match.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1792 If N is negative, find the next or Nth next match."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1793 (interactive (term-regexp-arg "Backward input matching (regexp): "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1794 (let* ((re (concat term-prompt-regexp ".*" regexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1795 (pos (save-excursion (end-of-line (if (> arg 0) 0 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1796 (if (re-search-backward re nil t arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1797 (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1798 (if (null pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1799 (progn (message "Not found")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1800 (ding))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1801 (goto-char pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1802 (term-bol nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1803
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1804 (defun term-forward-matching-input (regexp arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1805 "Search forward through buffer for match for REGEXP.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1806 Matches are searched for on lines that match `term-prompt-regexp'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1807 With prefix argument N, search for Nth following match.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1808 If N is negative, find the previous or Nth previous match."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1809 (interactive (term-regexp-arg "Forward input matching (regexp): "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1810 (term-backward-matching-input regexp (- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1811
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1812
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1813 (defun term-next-prompt (n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1814 "Move to end of Nth next prompt in the buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1815 See `term-prompt-regexp'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1816 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1817 (let ((paragraph-start term-prompt-regexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1818 (end-of-line (if (> n 0) 1 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1819 (forward-paragraph n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1820 (term-skip-prompt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1821
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1822 (defun term-previous-prompt (n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1823 "Move to end of Nth previous prompt in the buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1824 See `term-prompt-regexp'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1825 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1826 (term-next-prompt (- n)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1827
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1828 ;;; Support for source-file processing commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1829 ;;;============================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1830 ;;; Many command-interpreters (e.g., Lisp, Scheme, Soar) have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1831 ;;; commands that process files of source text (e.g. loading or compiling
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1832 ;;; files). So the corresponding process-in-a-buffer modes have commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1833 ;;; for doing this (e.g., lisp-load-file). The functions below are useful
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1834 ;;; for defining these commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1835 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1836 ;;; Alas, these guys don't do exactly the right thing for Lisp, Scheme
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1837 ;;; and Soar, in that they don't know anything about file extensions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1838 ;;; So the compile/load interface gets the wrong default occasionally.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1839 ;;; The load-file/compile-file default mechanism could be smarter -- it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1840 ;;; doesn't know about the relationship between filename extensions and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1841 ;;; whether the file is source or executable. If you compile foo.lisp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1842 ;;; with compile-file, then the next load-file should use foo.bin for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1843 ;;; the default, not foo.lisp. This is tricky to do right, particularly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1844 ;;; because the extension for executable files varies so much (.o, .bin,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1845 ;;; .lbin, .mo, .vo, .ao, ...).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1846
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1847
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1848 ;;; TERM-SOURCE-DEFAULT -- determines defaults for source-file processing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1849 ;;; commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1850 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1851 ;;; TERM-CHECK-SOURCE -- if FNAME is in a modified buffer, asks you if you
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1852 ;;; want to save the buffer before issuing any process requests to the command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1853 ;;; interpreter.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1854 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1855 ;;; TERM-GET-SOURCE -- used by the source-file processing commands to prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1856 ;;; for the file to process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1857
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1858 ;;; (TERM-SOURCE-DEFAULT previous-dir/file source-modes)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1859 ;;;============================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1860 ;;; This function computes the defaults for the load-file and compile-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1861 ;;; commands for tea, soar, cmulisp, and cmuscheme modes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1862 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1863 ;;; - PREVIOUS-DIR/FILE is a pair (directory . filename) from the last
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1864 ;;; source-file processing command. NIL if there hasn't been one yet.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1865 ;;; - SOURCE-MODES is a list used to determine what buffers contain source
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1866 ;;; files: if the major mode of the buffer is in SOURCE-MODES, it's source.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1867 ;;; Typically, (lisp-mode) or (scheme-mode).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1868 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1869 ;;; If the command is given while the cursor is inside a string, *and*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1870 ;;; the string is an existing filename, *and* the filename is not a directory,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1871 ;;; then the string is taken as default. This allows you to just position
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1872 ;;; your cursor over a string that's a filename and have it taken as default.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1873 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1874 ;;; If the command is given in a file buffer whose major mode is in
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1875 ;;; SOURCE-MODES, then the filename is the default file, and the
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1876 ;;; file's directory is the default directory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1877 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1878 ;;; If the buffer isn't a source file buffer (e.g., it's the process buffer),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1879 ;;; then the default directory & file are what was used in the last source-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1880 ;;; processing command (i.e., PREVIOUS-DIR/FILE). If this is the first time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1881 ;;; the command has been run (PREVIOUS-DIR/FILE is nil), the default directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1882 ;;; is the cwd, with no default file. (\"no default file\" = nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1883 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1884 ;;; SOURCE-REGEXP is typically going to be something like (tea-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1885 ;;; for T programs, (lisp-mode) for Lisp programs, (soar-mode lisp-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1886 ;;; for Soar programs, etc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1887 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1888 ;;; The function returns a pair: (default-directory . default-file).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1889
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1890 (defun term-source-default (previous-dir/file source-modes)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1891 (cond ((and buffer-file-name (memq major-mode source-modes))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1892 (cons (file-name-directory buffer-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1893 (file-name-nondirectory buffer-file-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1894 (previous-dir/file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1895 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1896 (cons default-directory nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1897
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1898
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1899 ;;; (TERM-CHECK-SOURCE fname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1900 ;;;============================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1901 ;;; Prior to loading or compiling (or otherwise processing) a file (in the CMU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1902 ;;; process-in-a-buffer modes), this function can be called on the filename.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1903 ;;; If the file is loaded into a buffer, and the buffer is modified, the user
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1904 ;;; is queried to see if he wants to save the buffer before proceeding with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1905 ;;; the load or compile.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1906
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1907 (defun term-check-source (fname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1908 (let ((buff (get-file-buffer fname)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1909 (if (and buff
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1910 (buffer-modified-p buff)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1911 (y-or-n-p (format "Save buffer %s first? "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1912 (buffer-name buff))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1913 ;; save BUFF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1914 (let ((old-buffer (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1915 (set-buffer buff)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1916 (save-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1917 (set-buffer old-buffer)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1918
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1919
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1920 ;;; (TERM-GET-SOURCE prompt prev-dir/file source-modes mustmatch-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1921 ;;;============================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1922 ;;; TERM-GET-SOURCE is used to prompt for filenames in command-interpreter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1923 ;;; commands that process source files (like loading or compiling a file).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1924 ;;; It prompts for the filename, provides a default, if there is one,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1925 ;;; and returns the result filename.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1926 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1927 ;;; See TERM-SOURCE-DEFAULT for more on determining defaults.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1928 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1929 ;;; PROMPT is the prompt string. PREV-DIR/FILE is the (directory . file) pair
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1930 ;;; from the last source processing command. SOURCE-MODES is a list of major
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1931 ;;; modes used to determine what file buffers contain source files. (These
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1932 ;;; two arguments are used for determining defaults). If MUSTMATCH-P is true,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1933 ;;; then the filename reader will only accept a file that exists.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1934 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1935 ;;; A typical use:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1936 ;;; (interactive (term-get-source "Compile file: " prev-lisp-dir/file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1937 ;;; '(lisp-mode) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1938
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1939 ;;; This is pretty stupid about strings. It decides we're in a string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1940 ;;; if there's a quote on both sides of point on the current line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1941 (defun term-extract-string ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1942 "Returns string around POINT that starts the current line or nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1943 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1944 (let* ((point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1945 (bol (progn (beginning-of-line) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1946 (eol (progn (end-of-line) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1947 (start (progn (goto-char point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1948 (and (search-backward "\"" bol t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1949 (1+ (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1950 (end (progn (goto-char point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1951 (and (search-forward "\"" eol t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1952 (1- (point))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1953 (and start end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1954 (buffer-substring start end)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1955
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1956 (defun term-get-source (prompt prev-dir/file source-modes mustmatch-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1957 (let* ((def (term-source-default prev-dir/file source-modes))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1958 (stringfile (term-extract-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1959 (sfile-p (and stringfile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1960 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1961 (file-exists-p stringfile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1962 (error nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1963 (not (file-directory-p stringfile))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1964 (defdir (if sfile-p (file-name-directory stringfile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1965 (car def)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1966 (deffile (if sfile-p (file-name-nondirectory stringfile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1967 (cdr def)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1968 (ans (read-file-name (if deffile (format "%s(default %s) "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1969 prompt deffile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1970 prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1971 defdir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1972 (concat defdir deffile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1973 mustmatch-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1974 (list (expand-file-name (substitute-in-file-name ans)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1975
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1976 ;;; I am somewhat divided on this string-default feature. It seems
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1977 ;;; to violate the principle-of-least-astonishment, in that it makes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1978 ;;; the default harder to predict, so you actually have to look and see
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1979 ;;; what the default really is before choosing it. This can trip you up.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1980 ;;; On the other hand, it can be useful, I guess. I would appreciate feedback
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1981 ;;; on this.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1982 ;;; -Olin
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1983
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1984
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1985 ;;; Simple process query facility.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1986 ;;; ===========================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1987 ;;; This function is for commands that want to send a query to the process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1988 ;;; and show the response to the user. For example, a command to get the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1989 ;;; arglist for a Common Lisp function might send a "(arglist 'foo)" query
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1990 ;;; to an inferior Common Lisp process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1991 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1992 ;;; This simple facility just sends strings to the inferior process and pops
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1993 ;;; up a window for the process buffer so you can see what the process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1994 ;;; responds with. We don't do anything fancy like try to intercept what the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1995 ;;; process responds with and put it in a pop-up window or on the message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1996 ;;; line. We just display the buffer. Low tech. Simple. Works good.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1997
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1998 ;;; Send to the inferior process PROC the string STR. Pop-up but do not select
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1999 ;;; a window for the inferior process so that its response can be seen.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2000 (defun term-proc-query (proc str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2001 (let* ((proc-buf (process-buffer proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2002 (proc-mark (process-mark proc)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2003 (display-buffer proc-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2004 (set-buffer proc-buf) ; but it's not the selected *window*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2005 (let ((proc-win (get-buffer-window proc-buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2006 (proc-pt (marker-position proc-mark)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2007 (term-send-string proc str) ; send the query
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2008 (accept-process-output proc) ; wait for some output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2009 ;; Try to position the proc window so you can see the answer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2010 ;; This is bogus code. If you delete the (sit-for 0), it breaks.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2011 ;; I don't know why. Wizards invited to improve it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2012 (if (not (pos-visible-in-window-p proc-pt proc-win))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2013 (let ((opoint (window-point proc-win)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2014 (set-window-point proc-win proc-mark) (sit-for 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2015 (if (not (pos-visible-in-window-p opoint proc-win))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2016 (push-mark opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2017 (set-window-point proc-win opoint)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2018
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2019 ;;; Returns the current column in the current screen line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2020 ;;; Note: (current-column) yields column in buffer line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2021
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2022 (defun term-horizontal-column ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2023 (- (term-current-column) (term-start-line-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2024
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2025 ;; Calls either vertical-motion or buffer-vertical-motion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2026 (defmacro term-vertical-motion (count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2027 (list 'funcall 'term-vertical-motion count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2028
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2029 ;; An emulation of vertical-motion that is independent of having a window.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2030 ;; Instead, it uses the term-width variable as the logical window width.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2031
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2032 (defun buffer-vertical-motion (count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2033 (cond ((= count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2034 (move-to-column (* term-width (/ (current-column) term-width)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2035 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2036 ((> count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2037 (let ((H)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2038 (todo (+ count (/ (current-column) term-width))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2039 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2040 ;; The loop interates over buffer lines;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2041 ;; H is the number of screen lines in the current line, i.e.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2042 ;; the ceiling of dividing the buffer line width by term-width.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2043 (while (and (<= (setq H (max (/ (+ (current-column) term-width -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2044 term-width)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2045 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2046 todo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2047 (not (eobp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2048 (setq todo (- todo H))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2049 (forward-char) ;; Move past the ?\n
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2050 (end-of-line)) ;; and on to the end of the next line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2051 (if (and (>= todo H) (> todo 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2052 (+ (- count todo) H -1) ;; Hit end of buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2053 (move-to-column (* todo term-width))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2054 count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2055 (t ;; (< count 0) ;; Similar algorithm, but for upward motion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2056 (let ((H)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2057 (todo (- count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2058 (while (and (<= (setq H (max (/ (+ (current-column) term-width -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2059 term-width)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2060 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2061 todo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2062 (progn (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2063 (not (bobp))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2064 (setq todo (- todo H))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2065 (backward-char)) ;; Move to end of previos line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2066 (if (and (>= todo H) (> todo 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2067 (+ count todo (- 1 H)) ;; Hit beginning of buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2068 (move-to-column (* (- H todo 1) term-width))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2069 count)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2070
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2071 ;;; The term-start-line-column variable is used as a cache.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2072 (defun term-start-line-column ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2073 (cond (term-start-line-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2074 ((let ((save-pos (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2075 (term-vertical-motion 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2076 (setq term-start-line-column (current-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2077 (goto-char save-pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2078 term-start-line-column))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2079
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2080 ;;; Same as (current-column), but uses term-current-column as a cache.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2081 (defun term-current-column ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2082 (cond (term-current-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2083 ((setq term-current-column (current-column)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2084
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2085 ;;; Move DELTA column right (or left if delta < 0).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2086
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2087 (defun term-move-columns (delta)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2088 (setq term-current-column (+ (term-current-column) delta))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2089 (move-to-column term-current-column t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2090
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2091 ;; Insert COUNT copies of CHAR in the default face.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2092 (defun term-insert-char (char count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2093 (let ((old-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2094 (insert-char char count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2095 (put-text-property old-point (point) 'face 'default)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2096
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2097 (defun term-current-row ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2098 (cond (term-current-row)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2099 ((setq term-current-row
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2100 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2101 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2102 (narrow-to-region term-home-marker (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2103 (- (term-vertical-motion -9999))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2104
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2105 (defun term-adjust-current-row-cache (delta)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2106 (if term-current-row
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2107 (setq term-current-row (+ term-current-row delta))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2108
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2109 (defun term-terminal-pos ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2110 (save-excursion ; save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2111 (let ((save-col (term-current-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2112 x y)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2113 (term-vertical-motion 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2114 (setq x (- save-col (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2115 (setq y (term-vertical-motion term-height))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2116 (cons x y))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2118 ;;; Terminal emulation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2119 ;;; This is the standard process filter for term buffers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2120 ;;; It emulates (most of the features of) a VT100/ANSI-style terminal.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2121
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2122 (defun term-emulate-terminal (proc str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2123 (let* ((previous-buffer (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2124 (i 0) char funny count save-point save-marker old-point temp win
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2125 (selected (selected-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2126 (str-length (length str)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2127 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2128 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2129 (set-buffer (process-buffer proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2130
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2131 (if (marker-buffer term-pending-delete-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2132 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2133 ;; Delete text following term-pending-delete-marker.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2134 (delete-region term-pending-delete-marker (process-mark proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2135 (set-marker term-pending-delete-marker nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2136
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2137 (if (eq (window-buffer) (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2138 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2139 (setq term-vertical-motion (symbol-function 'vertical-motion))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2140 (term-check-size proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2141 (setq term-vertical-motion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2142 (symbol-function 'buffer-vertical-motion)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2143
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2144 (setq save-marker (copy-marker (process-mark proc)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2145
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2146 (if (/= (point) (process-mark proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2147 (progn (setq save-point (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2148 (goto-char (process-mark proc))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2149
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2150 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2151 ;; If the buffer is in line mode, and there is a partial
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2152 ;; input line, save the line (by narrowing to leave it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2153 ;; outside the restriction ) until we're done with output.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2154 (if (and (> (point-max) (process-mark proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2155 (term-in-line-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2156 (narrow-to-region (point-min) (process-mark proc)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2157
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2158 (if term-log-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2159 (princ str term-log-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2160 (cond ((eq term-terminal-state 4) ;; Have saved pending output.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2161 (setq str (concat term-terminal-parameter str))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2162 (setq term-terminal-parameter nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2163 (setq str-length (length str))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2164 (setq term-terminal-state 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2165
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2166 (while (< i str-length)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2167 (setq char (aref str i))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2168 (cond ((< term-terminal-state 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2169 ;; Look for prefix of regular chars
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2170 (setq funny
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2171 (string-match "[\r\n\000\007\033\t\b\032\016\017]"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2172 str i))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2173 (if (not funny) (setq funny str-length))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2174 (cond ((> funny i)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2175 (cond ((eq term-terminal-state 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2176 (term-move-columns 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2177 (setq term-terminal-state 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2178 (setq count (- funny i))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2179 (setq temp (- (+ (term-horizontal-column) count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2180 term-width))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2181 (cond ((<= temp 0)) ;; All count chars fit in line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2182 ((> count temp) ;; Some chars fit.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2183 ;; This iteration, handle only what fits.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2184 (setq count (- count temp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2185 (setq funny (+ count i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2186 ((or (not (or term-pager-count
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2187 term-scroll-with-delete))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2188 (> (term-handle-scroll 1) 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2189 (term-adjust-current-row-cache 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2190 (setq count (min count term-width))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2191 (setq funny (+ count i))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2192 (setq term-start-line-column
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2193 term-current-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2194 (t ;; Doing PAGER processing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2195 (setq count 0 funny i)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2196 (setq term-current-column nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2197 (setq term-start-line-column nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2198 (setq old-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2199 ;; In the common case that we're at the end of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2200 ;; the buffer, we can save a little work.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2201 (cond ((/= (point) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2202 (if term-insert-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2203 ;; Inserting spaces, then deleting them,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2204 ;; then inserting the actual text is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2205 ;; inefficient, but it is simple, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2206 ;; the actual overhead is miniscule.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2207 (term-insert-spaces count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2208 (term-move-columns count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2209 (delete-region old-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2210 (t (setq term-current-column (+ (term-current-column) count))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2211 (insert (substring str i funny))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2212 (put-text-property old-point (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2213 'face term-current-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2214 ;; If the last char was written in last column,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2215 ;; back up one column, but remember we did so.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2216 ;; Thus we emulate xterm/vt100-style line-wrapping.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2217 (cond ((eq temp 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2218 (term-move-columns -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2219 (setq term-terminal-state 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2220 (setq i (1- funny)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2221 ((and (setq term-terminal-state 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2222 (eq char ?\^I)) ; TAB
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2223 ;; FIXME: Does not handle line wrap!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2224 (setq count (term-current-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2225 (setq count (+ count 8 (- (mod count 8))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2226 (if (< (move-to-column count nil) count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2227 (term-insert-char char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2228 (setq term-current-column count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2229 ((eq char ?\r)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2230 ;; Optimize CRLF at end of buffer:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2231 (cond ((and (< (setq temp (1+ i)) str-length)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2232 (eq (aref str temp) ?\n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2233 (= (point) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2234 (not (or term-pager-count
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2235 term-kill-echo-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2236 term-scroll-with-delete)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2237 (insert ?\n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2238 (term-adjust-current-row-cache 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2239 (setq term-start-line-column 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2240 (setq term-current-column 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2241 (setq i temp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2242 (t ;; Not followed by LF or can't optimize:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2243 (term-vertical-motion 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2244 (setq term-current-column 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2245 ((eq char ?\n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2246 (if (not (and term-kill-echo-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2247 (term-check-kill-echo-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2248 (term-down 1 t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2249 ((eq char ?\b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2250 (term-move-columns -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2251 ((eq char ?\033) ; Escape
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2252 (setq term-terminal-state 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2253 ((eq char 0)) ; NUL: Do nothing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2254 ((eq char ?\016)) ; Shift Out - ignored
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2255 ((eq char ?\017)) ; Shift In - ignored
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2256 ((eq char ?\^G)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2257 (beep t)) ; Bell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2258 ((eq char ?\032)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2259 (let ((end (string-match "\n" str i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2260 (if end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2261 (progn (funcall term-command-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2262 (substring str (1+ i) (1- end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2263 (setq i end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2264 (setq term-terminal-parameter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2265 (substring str i))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2266 (setq term-terminal-state 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2267 (setq i str-length))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2268 (t ; insert char FIXME: Should never happen
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2269 (term-move-columns 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2270 (backward-delete-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2271 (insert char))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2272 ((eq term-terminal-state 2) ; Seen Esc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2273 (cond ((eq char ?\133) ;; ?\133 = ?[
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2274 (make-local-variable 'term-terminal-parameter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2275 (make-local-variable 'term-terminal-previous-parameter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2276 (setq term-terminal-parameter 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2277 (setq term-terminal-previous-parameter 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2278 (setq term-terminal-state 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2279 ((eq char ?D) ;; scroll forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2280 (term-handle-deferred-scroll)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2281 (term-down 1 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2282 (setq term-terminal-state 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2283 ((eq char ?M) ;; scroll reversed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2284 (term-insert-lines 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2285 (setq term-terminal-state 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2286 ((eq char ?7) ;; Save cursor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2287 (term-handle-deferred-scroll)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2288 (setq term-saved-cursor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2289 (cons (term-current-row)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2290 (term-horizontal-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2291 (setq term-terminal-state 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2292 ((eq char ?8) ;; Restore cursor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2293 (if term-saved-cursor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2294 (term-goto (car term-saved-cursor)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2295 (cdr term-saved-cursor)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2296 (setq term-terminal-state 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2297 ((setq term-terminal-state 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2298 ((eq term-terminal-state 3) ; Seen Esc [
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2299 (cond ((and (>= char ?0) (<= char ?9))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2300 (setq term-terminal-parameter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2301 (+ (* 10 term-terminal-parameter) (- char ?0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2302 ((eq char ?\073 ) ; ?;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2303 (setq term-terminal-previous-parameter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2304 term-terminal-parameter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2305 (setq term-terminal-parameter 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2306 ((eq char ??)) ; Ignore ?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2307 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2308 (term-handle-ansi-escape proc char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2309 (setq term-terminal-state 0)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2310 (if (term-handling-pager)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2311 ;; Finish stuff to get ready to handle PAGER.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2312 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2313 (if (> (% (current-column) term-width) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2314 (setq term-terminal-parameter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2315 (substring str i))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2316 ;; We're at column 0. Goto end of buffer; to compensate,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2317 ;; prepend a ?\r for later. This looks more consistent.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2318 (if (zerop i)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2319 (setq term-terminal-parameter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2320 (concat "\r" (substring str i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2321 (setq term-terminal-parameter (substring str (1- i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2322 (aset term-terminal-parameter 0 ?\r))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2323 (goto-char (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2324 (setq term-terminal-state 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2325 (make-local-variable 'term-pager-old-filter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2326 (setq term-pager-old-filter (process-filter proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2327 (set-process-filter proc term-pager-filter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2328 (setq i str-length)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2329 (setq i (1+ i))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2330
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2331 (if (>= (term-current-row) term-height)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2332 (term-handle-deferred-scroll))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2333
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2334 (set-marker (process-mark proc) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2335 (if save-point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2336 (progn (goto-char save-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2337 (set-marker save-point nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2338
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2339 ;; Check for a pending filename-and-line number to display.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2340 ;; We do this before scrolling, because we might create a new window.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2341 (if (and term-pending-frame
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2342 (eq (window-buffer selected) (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2343 (progn (term-display-line (car term-pending-frame)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2344 (cdr term-pending-frame))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2345 (setq term-pending-frame nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2346 ;; We have created a new window, so check the window size.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2347 (term-check-size proc)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2348
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2349 ;; Scroll each window displaying the buffer but (by default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2350 ;; only if the point matches the process-mark we started with.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2351 (setq win selected)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2352 (while (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2353 (setq win (next-window win nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2354 (if (eq (window-buffer win) (process-buffer proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2355 (let ((scroll term-scroll-to-bottom-on-output))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2356 (select-window win)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2357 (if (or (= (point) save-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2358 (eq scroll t) (eq scroll 'all)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2359 ;; Maybe user wants point to jump to the end.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2360 (and (eq selected win)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2361 (or (eq scroll 'this) (not save-point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2362 (and (eq scroll 'others)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2363 (not (eq selected win))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2364 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2365 (goto-char term-home-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2366 (recenter 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2367 (goto-char (process-mark proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2368 (if (not (pos-visible-in-window-p (point) win))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2369 (recenter -1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2370 ;; Optionally scroll so that the text
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2371 ;; ends at the bottom of the window.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2372 (if (and term-scroll-show-maximum-output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2373 (>= (point) (process-mark proc)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2374 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2375 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2376 (recenter -1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2377 (not (eq win selected))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2378
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2379 (set-marker save-marker nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2380 ;; unwind-protect cleanup-forms follow:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2381 (set-buffer previous-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2382 (select-window selected))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2383
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2384 (defun term-handle-deferred-scroll ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2385 (let ((count (- (term-current-row) term-height)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2386 (if (> count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2387 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2388 (goto-char term-home-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2389 (term-vertical-motion count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2390 (set-marker term-home-marker (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2391 (setq term-current-row (1- term-height))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2392
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2393 ;;; Handle a character assuming (eq terminal-state 2) -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2394 ;;; i.e. we have previousely seen Escape followed by ?[.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2395
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2396 (defun term-handle-ansi-escape (proc char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2397 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2398 ((eq char ?H) ; cursor motion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2399 (if (<= term-terminal-parameter 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2400 (setq term-terminal-parameter 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2401 (if (<= term-terminal-previous-parameter 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2402 (setq term-terminal-previous-parameter 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2403 (if (> term-terminal-previous-parameter term-height)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2404 (setq term-terminal-previous-parameter term-height))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2405 (if (> term-terminal-parameter term-width)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2406 (setq term-terminal-parameter term-width))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2407 (term-goto
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2408 (1- term-terminal-previous-parameter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2409 (1- term-terminal-parameter)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2410 ;; \E[A - cursor up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2411 ((eq char ?A)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2412 (term-handle-deferred-scroll)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2413 (term-down (- (max 1 term-terminal-parameter)) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2414 ;; \E[B - cursor down
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2415 ((eq char ?B)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2416 (term-down (max 1 term-terminal-parameter) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2417 ;; \E[C - cursor right
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2418 ((eq char ?C)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2419 (term-move-columns (max 1 term-terminal-parameter)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2420 ;; \E[D - cursor left
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2421 ((eq char ?D)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2422 (term-move-columns (- (max 1 term-terminal-parameter))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2423 ;; \E[J - clear to end of screen
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2424 ((eq char ?J)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2425 (term-erase-in-display term-terminal-parameter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2426 ;; \E[K - clear to end of line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2427 ((eq char ?K)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2428 (term-erase-in-line term-terminal-parameter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2429 ;; \E[L - insert lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2430 ((eq char ?L)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2431 (term-insert-lines (max 1 term-terminal-parameter)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2432 ;; \E[M - delete lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2433 ((eq char ?M)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2434 (term-delete-lines (max 1 term-terminal-parameter)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2435 ;; \E[P - delete chars
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2436 ((eq char ?P)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2437 (term-delete-chars (max 1 term-terminal-parameter)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2438 ;; \E[@ - insert spaces
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2439 ((eq char ?@)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2440 (term-insert-spaces (max 1 term-terminal-parameter)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2441 ;; \E[?h - DEC Private Mode Set
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2442 ((eq char ?h)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2443 (cond ((eq term-terminal-parameter 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2444 (setq term-insert-mode t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2445 ((eq term-terminal-parameter 47)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2446 (term-switch-to-alternate-sub-buffer t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2447 ;; \E[?l - DEC Private Mode Reset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2448 ((eq char ?l)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2449 (cond ((eq term-terminal-parameter 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2450 (setq term-insert-mode nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2451 ((eq term-terminal-parameter 47)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2452 (term-switch-to-alternate-sub-buffer nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2453 ;; \E[m - Set/reset standard mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2454 ((eq char ?m)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2455 (cond ((eq term-terminal-parameter 7)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2456 (setq term-current-face 'highlight))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2457 ((eq term-terminal-parameter 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2458 (setq term-current-face 'term-underline-face))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2459 ((eq term-terminal-parameter 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2460 (setq term-current-face 'bold))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2461 (t (setq term-current-face 'default))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2462 ;; \E[6n - Report cursor position
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2463 ((eq char ?n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2464 (term-handle-deferred-scroll)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2465 (process-send-string proc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2466 (format "\e[%s;%sR"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2467 (1+ (term-current-row))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2468 (1+ (term-horizontal-column)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2469 ;; \E[r - Set scrolling region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2470 ((eq char ?r)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2471 (term-scroll-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2472 (1- term-terminal-previous-parameter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2473 term-terminal-parameter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2474 (t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2475
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2476 (defun term-scroll-region (top bottom)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2477 "Set scrolling region.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2478 TOP is the top-most line (inclusive) of the new scrolling region,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2479 while BOTTOM is the line folling the new scrolling region (e.g. exclusive).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2480 The top-most line is line 0."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2481 (setq term-scroll-start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2482 (if (or (< top 0) (>= top term-height))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2483 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2484 top))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2485 (setq term-scroll-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2486 (if (or (<= bottom term-scroll-start) (> bottom term-height))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2487 term-height
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2488 bottom))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2489 (setq term-scroll-with-delete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2490 (or (term-using-alternate-sub-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2491 (not (and (= term-scroll-start 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2492 (= term-scroll-end term-height))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2493
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2494 (defun term-switch-to-alternate-sub-buffer (set)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2495 ;; If asked to switch to (from) the alternate sub-buffer, and already (not)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2496 ;; using it, do nothing. This test is needed for some programs (including
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2497 ;; emacs) that emit the ti termcap string twice, for unknown reason.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2498 (term-handle-deferred-scroll)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2499 (if (eq set (not (term-using-alternate-sub-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2500 (let ((row (term-current-row))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2501 (col (term-horizontal-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2502 (cond (set
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2503 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2504 (if (not (eq (preceding-char) ?\n))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2505 (term-insert-char ?\n 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2506 (setq term-scroll-with-delete t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2507 (setq term-saved-home-marker (copy-marker term-home-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2508 (set-marker term-home-marker (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2509 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2510 (setq term-scroll-with-delete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2511 (not (and (= term-scroll-start 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2512 (= term-scroll-end term-height))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2513 (set-marker term-home-marker term-saved-home-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2514 (set-marker term-saved-home-marker nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2515 (setq term-saved-home-marker nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2516 (goto-char term-home-marker)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2517 (setq term-current-column nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2518 (setq term-current-row 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2519 (term-goto row col))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2520
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2521 ;; Default value for the symbol term-command-hook.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2522
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2523 (defun term-command-hook (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2524 (cond ((= (aref string 0) ?\032)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2525 ;; gdb (when invoked with -fullname) prints:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2526 ;; \032\032FULLFILENAME:LINENUMBER:CHARPOS:BEG_OR_MIDDLE:PC\n
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2527 (let* ((first-colon (string-match ":" string 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2528 (second-colon
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2529 (string-match ":" string (1+ first-colon)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2530 (filename (substring string 1 first-colon))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2531 (fileline (string-to-int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2532 (substring string (1+ first-colon) second-colon))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2533 (setq term-pending-frame (cons filename fileline))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2534 ((= (aref string 0) ?/)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2535 (cd (substring string 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2536 ;; Allowing the inferior to call functions in emacs is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2537 ;; probably too big a security hole.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2538 ;; ((= (aref string 0) ?!)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2539 ;; (eval (car (read-from-string string 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2540 (t)));; Otherwise ignore it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2541
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2542 ;; Make sure the file named TRUE-FILE is in a buffer that appears on the screen
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2543 ;; and that its line LINE is visible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2544 ;; Put the overlay-arrow on the line LINE in that buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2545 ;; This is mainly used by gdb.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2546
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2547 (defun term-display-line (true-file line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2548 (term-display-buffer-line (find-file-noselect true-file) line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2549
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2550 (defun term-display-buffer-line (buffer line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2551 (let* ((window (display-buffer buffer t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2552 (pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2553 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2554 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2555 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2556 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2557 (goto-line line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2558 (setq pos (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2559 (setq overlay-arrow-string "=>")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2560 (or overlay-arrow-position
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2561 (setq overlay-arrow-position (make-marker)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2562 (set-marker overlay-arrow-position (point) (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2563 (cond ((or (< pos (point-min)) (> pos (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2564 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2565 (goto-char pos))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2566 (set-window-point window overlay-arrow-position)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2567
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2568 ;;; The buffer-local marker term-home-marker defines the "home position"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2569 ;;; (in terms of cursor motion). However, we move the term-home-marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2570 ;;; "down" as needed so that is no more that a window-full above (point-max).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2571
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2572 (defun term-goto-home ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2573 (term-handle-deferred-scroll)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2574 (goto-char term-home-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2575 (setq term-current-row 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2576 (setq term-current-column (current-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2577 (setq term-start-line-column term-current-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2578
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2579 (defun term-goto (row col)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2580 (term-handle-deferred-scroll)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2581 (cond ((and term-current-row (>= row term-current-row))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2582 ;; I assume this is a worthwhile optimization.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2583 (term-vertical-motion 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2584 (setq term-current-column term-start-line-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2585 (setq row (- row term-current-row)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2586 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2587 (term-goto-home)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2588 (term-down row)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2589 (term-move-columns col))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2590
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2591 ; The page is full, so enter "pager" mode, and wait for input.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2592
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2593 (defun term-process-pager ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2594 (if (not term-pager-break-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2595 (let* ((map (make-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2596 (i 0) tmp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2597 ; (while (< i 128)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2598 ; (define-key map (make-string 1 i) 'term-send-raw)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2599 ; (setq i (1+ i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2600 (define-key map "\e"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2601 (lookup-key (current-global-map) "\e"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2602 (define-key map "\C-x"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2603 (lookup-key (current-global-map) "\C-x"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2604 (define-key map "\C-u"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2605 (lookup-key (current-global-map) "\C-u"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2606 (define-key map " " 'term-pager-page)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2607 (define-key map "\r" 'term-pager-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2608 (define-key map "?" 'term-pager-help)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2609 (define-key map "h" 'term-pager-help)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2610 (define-key map "b" 'term-pager-back-page)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2611 (define-key map "\177" 'term-pager-back-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2612 (define-key map "q" 'term-pager-discard)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2613 (define-key map "D" 'term-pager-disable)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2614 (define-key map "<" 'term-pager-bob)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2615 (define-key map ">" 'term-pager-eob)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2616
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2617 ;; Add menu bar.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2618 (term-if-emacs19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2619 (term-ifnot-xemacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2620 (define-key map [menu-bar terminal] term-terminal-menu)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2621 (define-key map [menu-bar signals] term-signals-menu)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2622 (setq tmp (make-sparse-keymap "More pages?"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2623 (define-key tmp [help] '("Help" . term-pager-help))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2624 (define-key tmp [disable]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2625 '("Diable paging" . term-fake-pager-disable))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2626 (define-key tmp [discard]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2627 '("Discard remaining output" . term-pager-discard))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2628 (define-key tmp [eob] '("Goto to end" . term-pager-eob))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2629 (define-key tmp [bob] '("Goto to beginning" . term-pager-bob))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2630 (define-key tmp [line] '("1 line forwards" . term-pager-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2631 (define-key tmp [bline] '("1 line backwards" . term-pager-back-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2632 (define-key tmp [back] '("1 page backwards" . term-pager-back-page))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2633 (define-key tmp [page] '("1 page forwards" . term-pager-page))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2634 (define-key map [menu-bar page] (cons "More pages?" tmp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2635 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2636
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2637 (setq term-pager-break-map map)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2638 ; (let ((process (get-buffer-process (current-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2639 ; (stop-process process))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2640 (setq term-pager-old-local-map (current-local-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2641 (use-local-map term-pager-break-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2642 (make-local-variable 'term-old-mode-line-format)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2643 (setq term-old-mode-line-format mode-line-format)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2644 (setq mode-line-format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2645 (list "-- **MORE** "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2646 mode-line-buffer-identification
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2647 " [Type ? for help] "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2648 "%-"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2649 (set-buffer-modified-p (buffer-modified-p))) ;;No-op, but updates mode line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2650
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2651 (defun term-pager-line (lines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2652 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2653 (let* ((moved (vertical-motion (1+ lines)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2654 (deficit (- lines moved)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2655 (if (> moved lines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2656 (backward-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2657 (cond ((<= deficit 0) ;; OK, had enough in the buffer for request.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2658 (recenter (1- term-height)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2659 ((term-pager-continue deficit)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2660
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2661 (defun term-pager-page (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2662 "Proceed past the **MORE** break, allowing the next page of output to appear"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2663 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2664 (term-pager-line (* arg term-height)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2665
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2666 ; Pager mode command to go to beginning of buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2667 (defun term-pager-bob ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2668 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2669 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2670 (if (= (vertical-motion term-height) term-height)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2671 (backward-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2672 (recenter (1- term-height)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2673
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2674 ; pager mode command to go to end of buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2675 (defun term-pager-eob ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2676 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2677 (goto-char term-home-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2678 (recenter 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2679 (goto-char (process-mark (get-buffer-process (current-buffer)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2680
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2681 (defun term-pager-back-line (lines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2682 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2683 (vertical-motion (- 1 lines))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2684 (if (not (bobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2685 (backward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2686 (beep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2687 ;; Move cursor to end of window.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2688 (vertical-motion term-height)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2689 (backward-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2690 (recenter (1- term-height)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2691
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2692 (defun term-pager-back-page (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2693 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2694 (term-pager-back-line (* arg term-height)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2695
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2696 (defun term-pager-discard ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2697 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2698 (setq term-terminal-parameter "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2699 (interrupt-process nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2700 (term-pager-continue term-height))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2701
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2702 ; Disable pager processing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2703 ; Only callable while in pager mode. (Contrast term-disable-pager.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2704 (defun term-pager-disable ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2705 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2706 (if (term-handling-pager)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2707 (term-pager-continue nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2708 (setq term-pager-count nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2709 (term-update-mode-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2710
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2711 ; Enable pager processing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2712 (defun term-pager-enable ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2713 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2714 (or (term-pager-enabled)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2715 (setq term-pager-count 0)) ;; Or maybe set to (term-current-row) ??
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2716 (term-update-mode-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2717
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2718 (defun term-pager-toggle ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2719 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2720 (if (term-pager-enabled) (term-pager-disable) (term-pager-enable)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2721
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2722 (term-ifnot-xemacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2723 (defalias 'term-fake-pager-enable 'term-pager-toggle)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2724 (defalias 'term-fake-pager-disable 'term-pager-toggle)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2725 (put 'term-char-mode 'menu-enable '(term-in-line-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2726 (put 'term-line-mode 'menu-enable '(term-in-char-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2727 (put 'term-fake-pager-enable 'menu-enable '(not term-pager-count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2728 (put 'term-fake-pager-disable 'menu-enable 'term-pager-count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2729
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2730 (defun term-pager-help ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2731 "Provide help on commands available in a terminal-emulator **MORE** break"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2732 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2733 (message "Terminal-emulator pager break help...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2734 (sit-for 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2735 (with-electric-help
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2736 (function (lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2737 (princ (substitute-command-keys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2738 "\\<term-pager-break-map>\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2739 Terminal-emulator MORE break.\n\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2740 Type one of the following keys:\n\n\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2741 \\[term-pager-page]\t\tMove forward one page.\n\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2742 \\[term-pager-line]\t\tMove forward one line.\n\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2743 \\[universal-argument] N \\[term-pager-page]\tMove N pages forward.\n\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2744 \\[universal-argument] N \\[term-pager-line]\tMove N lines forward.\n\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2745 \\[universal-argument] N \\[term-pager-back-line]\tMove N lines back.\n\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2746 \\[universal-argument] N \\[term-pager-back-page]\t\tMove N pages back.\n\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2747 \\[term-pager-bob]\t\tMove to the beginning of the buffer.\n\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2748 \\[term-pager-eob]\t\tMove to the end of the buffer.\n\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2749 \\[term-pager-discard]\t\tKill pending output and kill process.\n\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2750 \\[term-pager-disable]\t\tDisable PAGER handling.\n\n\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2751 \\{term-pager-break-map}\n\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2752 Any other key is passed through to the program
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2753 running under the terminal emulator and disables pager processing until
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2754 all pending output has been dealt with."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2755 nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2756
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2757 (defun term-pager-continue (new-count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2758 (let ((process (get-buffer-process (current-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2759 (use-local-map term-pager-old-local-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2760 (setq term-pager-old-local-map nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2761 (setq mode-line-format term-old-mode-line-format)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2762 (set-buffer-modified-p (buffer-modified-p)) ;; Updates mode line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2763 (setq term-pager-count new-count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2764 (set-process-filter process term-pager-old-filter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2765 (funcall term-pager-old-filter process "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2766 (continue-process process)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2767
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2768 ;; Make sure there are DOWN blank lines below the current one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2769 ;; Return 0 if we're unable (because of PAGER handling), else return DOWN.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2770
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2771 (defun term-handle-scroll (down)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2772 (let ((scroll-needed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2773 (- (+ (term-current-row) down 1) term-scroll-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2774 (if (> scroll-needed 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2775 (let ((save-point (copy-marker (point))) (save-top))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2776 (goto-char term-home-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2777 (cond (term-scroll-with-delete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2778 ;; delete scroll-needed lines at term-scroll-start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2779 (term-vertical-motion term-scroll-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2780 (setq save-top (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2781 (term-vertical-motion scroll-needed)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2782 (delete-region save-top (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2783 (goto-char save-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2784 (term-vertical-motion down)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2785 (term-adjust-current-row-cache (- scroll-needed))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2786 (setq term-current-column nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2787 (term-insert-char ?\n scroll-needed))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2788 ((and (numberp term-pager-count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2789 (< (setq term-pager-count (- term-pager-count down))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2790 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2791 (setq down 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2792 (term-process-pager))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2793 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2794 (term-adjust-current-row-cache (- scroll-needed))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2795 (term-vertical-motion scroll-needed)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2796 (set-marker term-home-marker (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2797 (goto-char save-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2798 (set-marker save-point nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2799 down)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2800
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2801 (defun term-down (down &optional check-for-scroll)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2802 "Move down DOWN screen lines vertically."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2803 (let ((start-column (term-horizontal-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2804 (if (and check-for-scroll (or term-scroll-with-delete term-pager-count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2805 (setq down (term-handle-scroll down)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2806 (term-adjust-current-row-cache down)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2807 (if (/= (point) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2808 (setq down (- down (term-vertical-motion down))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2809 ;; Extend buffer with extra blank lines if needed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2810 (cond ((> down 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2811 (term-insert-char ?\n down)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2812 (setq term-current-column 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2813 (setq term-start-line-column 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2814 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2815 (setq term-current-column nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2816 (setq term-start-line-column (current-column))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2817 (if start-column
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2818 (term-move-columns start-column))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2819
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2820 ;; Assuming point is at the beginning of a screen line,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2821 ;; if the line above point wraps around, add a ?\n to undo the wrapping.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2822 ;; FIXME: Probably should be called more than it is.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2823 (defun term-unwrap-line ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2824 (if (not (bolp)) (insert-before-markers ?\n)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2825
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2826 (defun term-erase-in-line (kind)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2827 (if (> kind 1) ;; erase left of point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2828 (let ((cols (term-horizontal-column)) (saved-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2829 (term-vertical-motion 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2830 (delete-region (point) saved-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2831 (term-insert-char ?\n cols)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2832 (if (not (eq kind 1)) ;; erase right of point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2833 (let ((saved-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2834 (wrapped (and (zerop (term-horizontal-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2835 (not (zerop (term-current-column))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2836 (term-vertical-motion 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2837 (delete-region saved-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2838 ;; wrapped is true if we're at the beginning of screen line,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2839 ;; but not a buffer line. If we delete the current screen line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2840 ;; that will make the previous line no longer wrap, and (because
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2841 ;; of the way emacs display works) point will be at the end of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2842 ;; the previous screen line rather then the beginning of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2843 ;; current one. To avoid that, we make sure that current line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2844 ;; contain a space, to force the previous line to continue to wrap.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2845 ;; We could do this always, but it seems preferable to not add the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2846 ;; extra space when wrapped is false.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2847 (if wrapped
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2848 (insert ? ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2849 (insert ?\n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2850 (put-text-property saved-point (point) 'face 'default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2851 (goto-char saved-point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2852
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2853 (defun term-erase-in-display (kind)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2854 "Erases (that is blanks out) part of the window.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2855 If KIND is 0, erase from (point) to (point-max);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2856 if KIND is 1, erase from home to point; else erase from home to point-max.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2857 Should only be called when point is at the start of a screen line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2858 (term-handle-deferred-scroll)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2859 (cond ((eq term-terminal-parameter 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2860 (delete-region (point) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2861 (term-unwrap-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2862 ((let ((row (term-current-row))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2863 (col (term-horizontal-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2864 (start-region term-home-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2865 (end-region (if (eq kind 1) (point) (point-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2866 (delete-region start-region end-region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2867 (term-unwrap-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2868 (if (eq kind 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2869 (term-insert-char ?\n row))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2870 (setq term-current-column nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2871 (setq term-current-row nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2872 (term-goto row col)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2873
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2874 (defun term-delete-chars (count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2875 (let ((save-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2876 (term-vertical-motion 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2877 (term-unwrap-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2878 (goto-char save-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2879 (move-to-column (+ (term-current-column) count) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2880 (delete-region save-point (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2881
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2882 ;;; Insert COUNT spaces after point, but do not change any of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2883 ;;; following screen lines. Hence we may have to delete characters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2884 ;;; at teh end of this screen line to make room.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2885
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2886 (defun term-insert-spaces (count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2887 (let ((save-point (point)) (save-eol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2888 (term-vertical-motion 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2889 (if (bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2890 (backward-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2891 (setq save-eol (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2892 (move-to-column (+ (term-start-line-column) (- term-width count)) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2893 (if (> save-eol (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2894 (delete-region (point) save-eol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2895 (goto-char save-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2896 (term-insert-char ? count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2897 (goto-char save-point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2898
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2899 (defun term-delete-lines (lines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2900 (let ((start (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2901 (save-current-column term-current-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2902 (save-start-line-column term-start-line-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2903 (save-current-row (term-current-row)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2904 (term-down lines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2905 (delete-region start (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2906 (term-down (- term-scroll-end save-current-row lines))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2907 (term-insert-char ?\n lines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2908 (setq term-current-column save-current-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2909 (setq term-start-line-column save-start-line-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2910 (setq term-current-row save-current-row)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2911 (goto-char start)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2912
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2913 (defun term-insert-lines (lines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2914 (let ((start (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2915 (start-deleted)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2916 (save-current-column term-current-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2917 (save-start-line-column term-start-line-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2918 (save-current-row (term-current-row)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2919 (term-down (- term-scroll-end save-current-row lines))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2920 (setq start-deleted (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2921 (term-down lines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2922 (delete-region start-deleted (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2923 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2924 (setq term-current-column save-current-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2925 (setq term-start-line-column save-start-line-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2926 (setq term-current-row save-current-row)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2927 (term-insert-char ?\n lines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2928 (goto-char start)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2929
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2930 (defun term-set-output-log (name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2931 "Record raw inferior process output in a buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2932 (interactive (list (if term-log-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2933 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2934 (read-buffer "Record output in buffer: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2935 (format "%s output-log"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2936 (buffer-name (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2937 nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2938 (if (or (null name) (equal name ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2939 (progn (setq term-log-buffer nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2940 (message "Output logging off."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2941 (if (get-buffer name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2942 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2943 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2944 (set-buffer (get-buffer-create name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2945 (fundamental-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2946 (buffer-disable-undo (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2947 (erase-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2948 (setq term-log-buffer (get-buffer name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2949 (message "Recording terminal emulator output into buffer \"%s\""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2950 (buffer-name term-log-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2951
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2952 (defun term-stop-photo ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2953 "Discontinue raw inferior process logging."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2954 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2955 (term-set-output-log nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2956
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2957 (defun term-show-maximum-output ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2958 "Put the end of the buffer at the bottom of the window."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2959 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2960 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2961 (recenter -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2962
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2963 ;;; Do the user's customisation...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2964
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2965 (defvar term-load-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2966 "This hook is run when term is loaded in.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2967 This is a good place to put keybindings.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2968
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2969 (run-hooks 'term-load-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2970
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2971
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2972 ;;; Filename/command/history completion in a buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2973 ;;; ===========================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2974 ;;; Useful completion functions, courtesy of the Ergo group.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2975
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2976 ;;; Six commands:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2977 ;;; term-dynamic-complete Complete or expand command, filename,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2978 ;;; history at point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2979 ;;; term-dynamic-complete-filename Complete filename at point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2980 ;;; term-dynamic-list-filename-completions List completions in help buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2981 ;;; term-replace-by-expanded-filename Expand and complete filename at point;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2982 ;;; replace with expanded/completed name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2983 ;;; term-dynamic-simple-complete Complete stub given candidates.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2984
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2985 ;;; These are not installed in the term-mode keymap. But they are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2986 ;;; available for people who want them. Shell-mode installs them:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2987 ;;; (define-key shell-mode-map "\t" 'term-dynamic-complete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2988 ;;; (define-key shell-mode-map "\M-?"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2989 ;;; 'term-dynamic-list-filename-completions)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2990 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2991 ;;; Commands like this are fine things to put in load hooks if you
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2992 ;;; want them present in specific modes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2993
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2994 (defvar term-completion-autolist nil
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 76
diff changeset
2995 "*If non-nil, automatically list possibilities on partial completion.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2996 This mirrors the optional behavior of tcsh.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2997
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2998 (defvar term-completion-addsuffix t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2999 "*If non-nil, add a `/' to completed directories, ` ' to file names.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3000 This mirrors the optional behavior of tcsh.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3001
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3002 (defvar term-completion-recexact nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3003 "*If non-nil, use shortest completion if characters cannot be added.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3004 This mirrors the optional behavior of tcsh.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3005
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3006 A non-nil value is useful if `term-completion-autolist' is non-nil too.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3007
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3008 (defvar term-completion-fignore nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3009 "*List of suffixes to be disregarded during file completion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3010 This mirrors the optional behavior of bash and tcsh.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3011
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3012 Note that this applies to `term-dynamic-complete-filename' only.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3013
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3014 (defvar term-file-name-prefix ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3015 "Prefix prepended to absolute file names taken from process input.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3016 This is used by term's and shell's completion functions, and by shell's
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3017 directory tracking functions.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3018
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3019
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3020 (defun term-directory (directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3021 ;; Return expanded DIRECTORY, with `term-file-name-prefix' if absolute.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3022 (expand-file-name (if (file-name-absolute-p directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3023 (concat term-file-name-prefix directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3024 directory)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3025
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3026
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3027 (defun term-word (word-chars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3028 "Return the word of WORD-CHARS at point, or nil if non is found.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3029 Word constituents are considered to be those in WORD-CHARS, which is like the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3030 inside of a \"[...]\" (see `skip-chars-forward')."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3031 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3032 (let ((limit (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3033 (word (concat "[" word-chars "]"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3034 (non-word (concat "[^" word-chars "]")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3035 (if (re-search-backward non-word nil 'move)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3036 (forward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3037 ;; Anchor the search forwards.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3038 (if (or (eolp) (looking-at non-word))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3039 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3040 (re-search-forward (concat word "+") limit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3041 (buffer-substring (match-beginning 0) (match-end 0))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3042
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3043
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3044 (defun term-match-partial-filename ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3045 "Return the filename at point, or nil if non is found.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3046 Environment variables are substituted. See `term-word'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3047 (let ((filename (term-word "~/A-Za-z0-9+@:_.$#,={}-")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3048 (and filename (substitute-in-file-name filename))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3049
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3050
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3051 (defun term-dynamic-complete ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3052 "Dynamically perform completion at point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3053 Calls the functions in `term-dynamic-complete-functions' to perform
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3054 completion until a function returns non-nil, at which point completion is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3055 assumed to have occurred."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3056 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3057 (let ((functions term-dynamic-complete-functions))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3058 (while (and functions (null (funcall (car functions))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3059 (setq functions (cdr functions)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3060
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3061
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3062 (defun term-dynamic-complete-filename ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3063 "Dynamically complete the filename at point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3064 Completes if after a filename. See `term-match-partial-filename' and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3065 `term-dynamic-complete-as-filename'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3066 This function is similar to `term-replace-by-expanded-filename', except that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3067 it won't change parts of the filename already entered in the buffer; it just
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3068 adds completion characters to the end of the filename. A completions listing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3069 may be shown in a help buffer if completion is ambiguous.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3070
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3071 Completion is dependent on the value of `term-completion-addsuffix',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3072 `term-completion-recexact' and `term-completion-fignore', and the timing of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3073 completions listing is dependent on the value of `term-completion-autolist'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3074
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3075 Returns t if successful."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3076 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3077 (if (term-match-partial-filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3078 (prog2 (or (eq (selected-window) (minibuffer-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3079 (message "Completing file name..."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3080 (term-dynamic-complete-as-filename))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3081
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3082 (defun term-dynamic-complete-as-filename ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3083 "Dynamically complete at point as a filename.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3084 See `term-dynamic-complete-filename'. Returns t if successful."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3085 (let* ((completion-ignore-case nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3086 (completion-ignored-extensions term-completion-fignore)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3087 (success t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3088 (filename (or (term-match-partial-filename) ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3089 (pathdir (file-name-directory filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3090 (pathnondir (file-name-nondirectory filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3091 (directory (if pathdir (term-directory pathdir) default-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3092 (completion (file-name-completion pathnondir directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3093 (mini-flag (eq (selected-window) (minibuffer-window))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3094 (cond ((null completion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3095 (message "No completions of %s" filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3096 (setq success nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3097 ((eq completion t) ; Means already completed "file".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3098 (if term-completion-addsuffix (insert " "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3099 (or mini-flag (message "Sole completion")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3100 ((string-equal completion "") ; Means completion on "directory/".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3101 (term-dynamic-list-filename-completions))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3102 (t ; Completion string returned.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3103 (let ((file (concat (file-name-as-directory directory) completion)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3104 (insert (substring (directory-file-name completion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3105 (length pathnondir)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3106 (cond ((symbolp (file-name-completion completion directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3107 ;; We inserted a unique completion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3108 (if term-completion-addsuffix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3109 (insert (if (file-directory-p file) "/" " ")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3110 (or mini-flag (message "Completed")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3111 ((and term-completion-recexact term-completion-addsuffix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3112 (string-equal pathnondir completion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3113 (file-exists-p file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3114 ;; It's not unique, but user wants shortest match.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3115 (insert (if (file-directory-p file) "/" " "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3116 (or mini-flag (message "Completed shortest")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3117 ((or term-completion-autolist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3118 (string-equal pathnondir completion))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3119 ;; It's not unique, list possible completions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3120 (term-dynamic-list-filename-completions))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3121 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3122 (or mini-flag (message "Partially completed")))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3123 success))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3124
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3125
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3126 (defun term-replace-by-expanded-filename ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3127 "Dynamically expand and complete the filename at point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3128 Replace the filename with an expanded, canonicalised and completed replacement.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3129 \"Expanded\" means environment variables (e.g., $HOME) and `~'s are replaced
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3130 with the corresponding directories. \"Canonicalised\" means `..' and `.' are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3131 removed, and the filename is made absolute instead of relative. For expansion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3132 see `expand-file-name' and `substitute-in-file-name'. For completion see
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3133 `term-dynamic-complete-filename'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3134 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3135 (replace-match (expand-file-name (term-match-partial-filename)) t t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3136 (term-dynamic-complete-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3137
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3138
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3139 (defun term-dynamic-simple-complete (stub candidates)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3140 "Dynamically complete STUB from CANDIDATES list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3141 This function inserts completion characters at point by completing STUB from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3142 the strings in CANDIDATES. A completions listing may be shown in a help buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3143 if completion is ambiguous.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3144
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3145 Returns nil if no completion was inserted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3146 Returns `sole' if completed with the only completion match.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3147 Returns `shortest' if completed with the shortest of the completion matches.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3148 Returns `partial' if completed as far as possible with the completion matches.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3149 Returns `listed' if a completion listing was shown.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3150
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3151 See also `term-dynamic-complete-filename'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3152 (let* ((completion-ignore-case nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3153 (candidates (mapcar (function (lambda (x) (list x))) candidates))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3154 (completions (all-completions stub candidates)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3155 (cond ((null completions)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3156 (message "No completions of %s" stub)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3157 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3158 ((= 1 (length completions)) ; Gotcha!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3159 (let ((completion (car completions)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3160 (if (string-equal completion stub)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3161 (message "Sole completion")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3162 (insert (substring completion (length stub)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3163 (message "Completed"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3164 (if term-completion-addsuffix (insert " "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3165 'sole))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3166 (t ; There's no unique completion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3167 (let ((completion (try-completion stub candidates)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3168 ;; Insert the longest substring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3169 (insert (substring completion (length stub)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3170 (cond ((and term-completion-recexact term-completion-addsuffix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3171 (string-equal stub completion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3172 (member completion completions))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3173 ;; It's not unique, but user wants shortest match.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3174 (insert " ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3175 (message "Completed shortest")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3176 'shortest)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3177 ((or term-completion-autolist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3178 (string-equal stub completion))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3179 ;; It's not unique, list possible completions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3180 (term-dynamic-list-completions completions)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3181 'listed)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3182 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3183 (message "Partially completed")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3184 'partial)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3185
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3186
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3187 (defun term-dynamic-list-filename-completions ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3188 "List in help buffer possible completions of the filename at point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3189 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3190 (let* ((completion-ignore-case nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3191 (filename (or (term-match-partial-filename) ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3192 (pathdir (file-name-directory filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3193 (pathnondir (file-name-nondirectory filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3194 (directory (if pathdir (term-directory pathdir) default-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3195 (completions (file-name-all-completions pathnondir directory)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3196 (if completions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3197 (term-dynamic-list-completions completions)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3198 (message "No completions of %s" filename))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3199
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3200
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3201 (defun term-dynamic-list-completions (completions)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3202 "List in help buffer sorted COMPLETIONS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3203 Typing SPC flushes the help buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3204 (let ((conf (current-window-configuration)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3205 (with-output-to-temp-buffer "*Completions*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3206 (display-completion-list (sort completions 'string-lessp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3207 (message "Hit space to flush")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3208 (let (key first)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3209 (if (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3210 (set-buffer (get-buffer "*Completions*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3211 (setq key (read-key-sequence nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3212 first (aref key 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3213 (and (consp first)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3214 (eq (window-buffer (posn-window (event-start first)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3215 (get-buffer "*Completions*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3216 (eq (key-binding key) 'mouse-choose-completion)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3217 ;; If the user does mouse-choose-completion with the mouse,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3218 ;; execute the command, then delete the completion window.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3219 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3220 (mouse-choose-completion first)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3221 (set-window-configuration conf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3222 (if (eq first ?\ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3223 (set-window-configuration conf)
76
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 70
diff changeset
3224 (setq unread-command-events (append key nil)))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3225
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3226 ;;; Converting process modes to use term mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3227 ;;; ===========================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3228 ;;; Renaming variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3229 ;;; Most of the work is renaming variables and functions. These are the common
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3230 ;;; ones:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3231 ;;; Local variables:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3232 ;;; last-input-start term-last-input-start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3233 ;;; last-input-end term-last-input-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3234 ;;; shell-prompt-pattern term-prompt-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3235 ;;; shell-set-directory-error-hook <no equivalent>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3236 ;;; Miscellaneous:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3237 ;;; shell-set-directory <unnecessary>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3238 ;;; shell-mode-map term-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3239 ;;; Commands:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3240 ;;; shell-send-input term-send-input
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3241 ;;; shell-send-eof term-delchar-or-maybe-eof
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3242 ;;; kill-shell-input term-kill-input
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3243 ;;; interrupt-shell-subjob term-interrupt-subjob
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3244 ;;; stop-shell-subjob term-stop-subjob
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3245 ;;; quit-shell-subjob term-quit-subjob
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3246 ;;; kill-shell-subjob term-kill-subjob
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3247 ;;; kill-output-from-shell term-kill-output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3248 ;;; show-output-from-shell term-show-output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3249 ;;; copy-last-shell-input Use term-previous-input/term-next-input
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3250 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3251 ;;; SHELL-SET-DIRECTORY is gone, its functionality taken over by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3252 ;;; SHELL-DIRECTORY-TRACKER, the shell mode's term-input-filter-functions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3253 ;;; Term mode does not provide functionality equivalent to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3254 ;;; shell-set-directory-error-hook; it is gone.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3255 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3256 ;;; term-last-input-start is provided for modes which want to munge
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3257 ;;; the buffer after input is sent, perhaps because the inferior
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3258 ;;; insists on echoing the input. The LAST-INPUT-START variable in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3259 ;;; the old shell package was used to implement a history mechanism,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3260 ;;; but you should think twice before using term-last-input-start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3261 ;;; for this; the input history ring often does the job better.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3262 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3263 ;;; If you are implementing some process-in-a-buffer mode, called foo-mode, do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3264 ;;; *not* create the term-mode local variables in your foo-mode function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3265 ;;; This is not modular. Instead, call term-mode, and let *it* create the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3266 ;;; necessary term-specific local variables. Then create the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3267 ;;; foo-mode-specific local variables in foo-mode. Set the buffer's keymap to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3268 ;;; be foo-mode-map, and its mode to be foo-mode. Set the term-mode hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3269 ;;; (term-{prompt-regexp, input-filter, input-filter-functions,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3270 ;;; get-old-input) that need to be different from the defaults. Call
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3271 ;;; foo-mode-hook, and you're done. Don't run the term-mode hook yourself;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3272 ;;; term-mode will take care of it. The following example, from shell.el,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3273 ;;; is typical:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3274 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3275 ;;; (defvar shell-mode-map '())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3276 ;;; (cond ((not shell-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3277 ;;; (setq shell-mode-map (copy-keymap term-mode-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3278 ;;; (define-key shell-mode-map "\C-c\C-f" 'shell-forward-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3279 ;;; (define-key shell-mode-map "\C-c\C-b" 'shell-backward-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3280 ;;; (define-key shell-mode-map "\t" 'term-dynamic-complete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3281 ;;; (define-key shell-mode-map "\M-?"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3282 ;;; 'term-dynamic-list-filename-completions)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3283 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3284 ;;; (defun shell-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3285 ;;; (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3286 ;;; (term-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3287 ;;; (setq term-prompt-regexp shell-prompt-pattern)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3288 ;;; (setq major-mode 'shell-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3289 ;;; (setq mode-name "Shell")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3290 ;;; (use-local-map shell-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3291 ;;; (make-local-variable 'shell-directory-stack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3292 ;;; (setq shell-directory-stack nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3293 ;;; (add-hook 'term-input-filter-functions 'shell-directory-tracker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3294 ;;; (run-hooks 'shell-mode-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3295 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3296 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3297 ;;; Note that make-term is different from make-shell in that it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3298 ;;; doesn't have a default program argument. If you give make-shell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3299 ;;; a program name of NIL, it cleverly chooses one of explicit-shell-name,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3300 ;;; $ESHELL, $SHELL, or /bin/sh. If you give make-term a program argument
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3301 ;;; of NIL, it barfs. Adjust your code accordingly...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3302 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3303 ;;; Completion for term-mode users
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3304 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3305 ;;; For modes that use term-mode, term-dynamic-complete-functions is the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3306 ;;; hook to add completion functions to. Functions on this list should return
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3307 ;;; non-nil if completion occurs (i.e., further completion should not occur).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3308 ;;; You could use term-dynamic-simple-complete to do the bulk of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3309 ;;; completion job.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3310
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3311 (provide 'term)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3312
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3313 ;;; term.el ends here