annotate lisp/eterm/term.el @ 152:4c132ee2d62b

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