Mercurial > emacs
annotate lisp/eshell/em-term.el @ 112214:40a246eebab9
* lisp/emacs-lisp/easymenu.el: Add :enable, and obey :label. Require CL.
(easy-menu-create-menu, easy-menu-convert-item-1):
Use :label rather than nil for labels. Use `case'.
Add :enable as alias for :active.
(easy-menu-binding): Obey :label.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Thu, 13 Jan 2011 21:12:43 -0500 |
parents | f57f72bb4757 |
children | 417b1e4d63cd |
rev | line source |
---|---|
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
32526
diff
changeset
|
1 ;;; em-term.el --- running visual commands |
29876 | 2 |
95152
ad5d26b1d5d1
Use eshell-defgroup rather than defgroup.
Glenn Morris <rgm@gnu.org>
parents:
94661
diff
changeset
|
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, |
106815 | 4 ;; 2008, 2009, 2010 Free Software Foundation, Inc. |
29876 | 5 |
32526 | 6 ;; Author: John Wiegley <johnw@gnu.org> |
7 | |
29876 | 8 ;; This file is part of GNU Emacs. |
9 | |
94661
b5b0801a7637
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
10 ;; GNU Emacs is free software: you can redistribute it and/or modify |
29876 | 11 ;; it under the terms of the GNU General Public License as published by |
94661
b5b0801a7637
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
12 ;; the Free Software Foundation, either version 3 of the License, or |
b5b0801a7637
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
13 ;; (at your option) any later version. |
29876 | 14 |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
94661
b5b0801a7637
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
29876 | 22 |
23 ;;; Commentary: | |
24 | |
25 ;; At the moment, eshell is stream-based in its interactive input and | |
26 ;; output. This means that full-screen commands, such as "vi" or | |
27 ;; "lynx", will not display correctly. These are therefore thought of | |
28 ;; as "visual" programs. In order to run these progrem under Emacs, | |
29 ;; Eshell uses the term.el package, and invokes them in a separate | |
30 ;; buffer, giving the illusion that Eshell itself is allowing these | |
31 ;; visual processes to execute. | |
32 | |
87075
e8d46c0f12e6
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
33 ;;; Code: |
e8d46c0f12e6
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
34 |
e8d46c0f12e6
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
35 (eval-when-compile (require 'eshell)) |
29876 | 36 (require 'term) |
37 | |
95152
ad5d26b1d5d1
Use eshell-defgroup rather than defgroup.
Glenn Morris <rgm@gnu.org>
parents:
94661
diff
changeset
|
38 ;;;###autoload |
ad5d26b1d5d1
Use eshell-defgroup rather than defgroup.
Glenn Morris <rgm@gnu.org>
parents:
94661
diff
changeset
|
39 (eshell-defgroup eshell-term nil |
87075
e8d46c0f12e6
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
40 "This module causes visual commands (e.g., 'vi') to be executed by |
e8d46c0f12e6
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
41 the `term' package, which comes with Emacs. This package handles most |
e8d46c0f12e6
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
42 of the ANSI control codes, allowing curses-based applications to run |
e8d46c0f12e6
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
43 within an Emacs window. The variable `eshell-visual-commands' defines |
e8d46c0f12e6
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
44 which commands are considered visual in nature." |
e8d46c0f12e6
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
45 :tag "Running visual commands" |
e8d46c0f12e6
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
46 :group 'eshell-module) |
e8d46c0f12e6
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
47 |
29876 | 48 ;;; User Variables: |
49 | |
50 (defcustom eshell-term-load-hook '(eshell-term-initialize) | |
110580
f57f72bb4757
Cosmetic doc fixes for eshell.
Glenn Morris <rgm@gnu.org>
parents:
110148
diff
changeset
|
51 "A list of functions to call when loading `eshell-term'." |
29876 | 52 :type 'hook |
53 :group 'eshell-term) | |
54 | |
55 (defcustom eshell-visual-commands | |
56 '("vi" ; what is going on?? | |
57 "screen" "top" ; ok, a valid program... | |
58 "less" "more" ; M-x view-file | |
59 "lynx" "ncftp" ; w3.el, ange-ftp | |
60 "pine" "tin" "trn" "elm") ; GNUS!! | |
110580
f57f72bb4757
Cosmetic doc fixes for eshell.
Glenn Morris <rgm@gnu.org>
parents:
110148
diff
changeset
|
61 "A list of commands that present their output in a visual fashion." |
29876 | 62 :type '(repeat string) |
63 :group 'eshell-term) | |
64 | |
65 (defcustom eshell-term-name "eterm" | |
110580
f57f72bb4757
Cosmetic doc fixes for eshell.
Glenn Morris <rgm@gnu.org>
parents:
110148
diff
changeset
|
66 "Name to use for the TERM variable when running visual commands. |
29876 | 67 See `term-term-name' in term.el for more information on how this is |
68 used." | |
69 :type 'string | |
70 :group 'eshell-term) | |
71 | |
72 (defcustom eshell-escape-control-x t | |
110580
f57f72bb4757
Cosmetic doc fixes for eshell.
Glenn Morris <rgm@gnu.org>
parents:
110148
diff
changeset
|
73 "If non-nil, allow <C-x> to be handled by Emacs key in visual buffers. |
29876 | 74 See the variable `eshell-visual-commands'. If this variable is set to |
75 nil, <C-x> will send that control character to the invoked process." | |
76 :type 'boolean | |
77 :group 'eshell-term) | |
78 | |
79 ;;; Internal Variables: | |
80 | |
81 (defvar eshell-parent-buffer) | |
82 | |
83 ;;; Functions: | |
84 | |
85 (defun eshell-term-initialize () | |
86 "Initialize the `term' interface code." | |
87 (make-local-variable 'eshell-interpreter-alist) | |
88 (setq eshell-interpreter-alist | |
89 (cons (cons (function | |
90 (lambda (command) | |
91 (member (file-name-nondirectory command) | |
92 eshell-visual-commands))) | |
93 'eshell-exec-visual) | |
94 eshell-interpreter-alist))) | |
95 | |
96 (defun eshell-exec-visual (&rest args) | |
97 "Run the specified PROGRAM in a terminal emulation buffer. | |
98 ARGS are passed to the program. At the moment, no piping of input is | |
99 allowed." | |
100 (let* (eshell-interpreter-alist | |
101 (interp (eshell-find-interpreter (car args))) | |
102 (program (car interp)) | |
103 (args (eshell-flatten-list | |
104 (eshell-stringify-list (append (cdr interp) | |
105 (cdr args))))) | |
106 (term-buf | |
107 (generate-new-buffer | |
108 (concat "*" (file-name-nondirectory program) "*"))) | |
109 (eshell-buf (current-buffer))) | |
110 (save-current-buffer | |
111 (switch-to-buffer term-buf) | |
112 (term-mode) | |
113 (set (make-local-variable 'term-term-name) eshell-term-name) | |
114 (make-local-variable 'eshell-parent-buffer) | |
115 (setq eshell-parent-buffer eshell-buf) | |
116 (term-exec term-buf program program nil args) | |
117 (let ((proc (get-buffer-process term-buf))) | |
118 (if (and proc (eq 'run (process-status proc))) | |
119 (set-process-sentinel proc 'eshell-term-sentinel) | |
120 (error "Failed to invoke visual command"))) | |
121 (term-char-mode) | |
122 (if eshell-escape-control-x | |
123 (term-set-escape-char ?\C-x)))) | |
124 nil) | |
125 | |
126 (defun eshell-term-sentinel (proc string) | |
127 "Destroy the buffer visiting PROC." | |
128 (let ((proc-buf (process-buffer proc))) | |
129 (when (and proc-buf (buffer-live-p proc-buf) | |
130 (not (eq 'run (process-status proc))) | |
131 (= (process-exit-status proc) 0)) | |
132 (if (eq (current-buffer) proc-buf) | |
133 (let ((buf (and (boundp 'eshell-parent-buffer) | |
134 eshell-parent-buffer | |
135 (buffer-live-p eshell-parent-buffer) | |
136 eshell-parent-buffer))) | |
137 (if buf | |
138 (switch-to-buffer buf)))) | |
139 (kill-buffer proc-buf)))) | |
140 | |
141 ;; jww (1999-09-17): The code below will allow Eshell to send input | |
142 ;; characters directly to the currently running interactive process. | |
143 ;; However, since this would introduce other problems that would need | |
144 ;; solutions, I'm going to let it wait until after 2.1. | |
145 | |
146 ; (defvar eshell-term-raw-map nil | |
147 ; "Keyboard map for sending characters directly to the inferior process.") | |
148 ; (defvar eshell-term-escape-char nil | |
149 ; "Escape character for char-sub-mode of term mode. | |
150 ; Do not change it directly; use term-set-escape-char instead.") | |
151 ; (defvar eshell-term-raw-escape-map nil) | |
152 | |
153 ; (defun eshell-term-send-raw-string (chars) | |
154 ; (goto-char eshell-last-output-end) | |
155 ; (process-send-string (eshell-interactive-process) chars)) | |
156 | |
157 ; (defun eshell-term-send-raw () | |
158 ; "Send the last character typed through the terminal-emulator | |
159 ; without any interpretation." | |
160 ; (interactive) | |
161 ; ;; Convert `return' to C-m, etc. | |
101012
eadf79f14b29
Comment (replace last-input-char with last-input-event).
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
162 ; (if (and (symbolp last-input-event) |
eadf79f14b29
Comment (replace last-input-char with last-input-event).
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
163 ; (get last-input-event 'ascii-character)) |
eadf79f14b29
Comment (replace last-input-char with last-input-event).
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
164 ; (setq last-input-event (get last-input-event 'ascii-character))) |
eadf79f14b29
Comment (replace last-input-char with last-input-event).
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
165 ; (eshell-term-send-raw-string (make-string 1 last-input-event))) |
29876 | 166 |
167 ; (defun eshell-term-send-raw-meta () | |
168 ; (interactive) | |
101012
eadf79f14b29
Comment (replace last-input-char with last-input-event).
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
169 ; (if (symbolp last-input-event) |
29876 | 170 ; ;; Convert `return' to C-m, etc. |
101012
eadf79f14b29
Comment (replace last-input-char with last-input-event).
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
171 ; (let ((tmp (get last-input-event 'event-symbol-elements))) |
29876 | 172 ; (if tmp |
101012
eadf79f14b29
Comment (replace last-input-char with last-input-event).
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
173 ; (setq last-input-event (car tmp))) |
eadf79f14b29
Comment (replace last-input-char with last-input-event).
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
174 ; (if (symbolp last-input-event) |
29876 | 175 ; (progn |
101012
eadf79f14b29
Comment (replace last-input-char with last-input-event).
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
176 ; (setq tmp (get last-input-event 'ascii-character)) |
eadf79f14b29
Comment (replace last-input-char with last-input-event).
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
177 ; (if tmp (setq last-input-event tmp)))))) |
eadf79f14b29
Comment (replace last-input-char with last-input-event).
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
178 ; (eshell-term-send-raw-string (if (and (numberp last-input-event) |
eadf79f14b29
Comment (replace last-input-char with last-input-event).
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
179 ; (> last-input-event 127) |
eadf79f14b29
Comment (replace last-input-char with last-input-event).
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
180 ; (< last-input-event 256)) |
eadf79f14b29
Comment (replace last-input-char with last-input-event).
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
181 ; (make-string 1 last-input-event) |
eadf79f14b29
Comment (replace last-input-char with last-input-event).
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
182 ; (format "\e%c" last-input-event)))) |
29876 | 183 |
184 ; (defun eshell-term-mouse-paste (click arg) | |
185 ; "Insert the last stretch of killed text at the position clicked on." | |
186 ; (interactive "e\nP") | |
187 ; (if (boundp 'xemacs-logo) | |
188 ; (eshell-term-send-raw-string | |
189 ; (or (condition-case () (x-get-selection) (error ())) | |
110148
bcc7c00e9ef4
Remove cut buffer from documentation.
Jan D. <jan.h.d@swipnet.se>
parents:
106815
diff
changeset
|
190 ; (error "No selection available"))) |
29876 | 191 ; ;; Give temporary modes such as isearch a chance to turn off. |
192 ; (run-hooks 'mouse-leave-buffer-hook) | |
193 ; (setq this-command 'yank) | |
194 ; (eshell-term-send-raw-string | |
195 ; (current-kill (cond ((listp arg) 0) | |
196 ; ((eq arg '-) -1) | |
197 ; (t (1- arg))))))) | |
198 | |
199 ; ;; Which would be better: "\e[A" or "\eOA"? readline accepts either. | |
200 ; ;; For my configuration it's definitely better \eOA but YMMV. -mm | |
201 ; ;; For example: vi works with \eOA while elm wants \e[A ... | |
202 ; (defun eshell-term-send-up () (interactive) (eshell-term-send-raw-string "\eOA")) | |
203 ; (defun eshell-term-send-down () (interactive) (eshell-term-send-raw-string "\eOB")) | |
204 ; (defun eshell-term-send-right () (interactive) (eshell-term-send-raw-string "\eOC")) | |
205 ; (defun eshell-term-send-left () (interactive) (eshell-term-send-raw-string "\eOD")) | |
206 ; (defun eshell-term-send-home () (interactive) (eshell-term-send-raw-string "\e[1~")) | |
207 ; (defun eshell-term-send-end () (interactive) (eshell-term-send-raw-string "\e[4~")) | |
208 ; (defun eshell-term-send-prior () (interactive) (eshell-term-send-raw-string "\e[5~")) | |
209 ; (defun eshell-term-send-next () (interactive) (eshell-term-send-raw-string "\e[6~")) | |
210 ; (defun eshell-term-send-del () (interactive) (eshell-term-send-raw-string "\C-?")) | |
211 ; (defun eshell-term-send-backspace () (interactive) (eshell-term-send-raw-string "\C-H")) | |
212 | |
213 ; (defun eshell-term-set-escape-char (c) | |
214 ; "Change term-escape-char and keymaps that depend on it." | |
215 ; (if eshell-term-escape-char | |
216 ; (define-key eshell-term-raw-map eshell-term-escape-char 'eshell-term-send-raw)) | |
217 ; (setq c (make-string 1 c)) | |
218 ; (define-key eshell-term-raw-map c eshell-term-raw-escape-map) | |
219 ; ;; Define standard bindings in eshell-term-raw-escape-map | |
220 ; (define-key eshell-term-raw-escape-map "\C-x" | |
221 ; (lookup-key (current-global-map) "\C-x")) | |
222 ; (define-key eshell-term-raw-escape-map "\C-v" | |
223 ; (lookup-key (current-global-map) "\C-v")) | |
224 ; (define-key eshell-term-raw-escape-map "\C-u" | |
225 ; (lookup-key (current-global-map) "\C-u")) | |
226 ; (define-key eshell-term-raw-escape-map c 'eshell-term-send-raw)) | |
227 | |
228 ; (defun eshell-term-char-mode () | |
229 ; "Switch to char (\"raw\") sub-mode of term mode. | |
230 ; Each character you type is sent directly to the inferior without | |
231 ; intervention from Emacs, except for the escape character (usually C-c)." | |
232 ; (interactive) | |
233 ; (if (not eshell-term-raw-map) | |
234 ; (let* ((map (make-keymap)) | |
235 ; (esc-map (make-keymap)) | |
236 ; (i 0)) | |
237 ; (while (< i 128) | |
238 ; (define-key map (make-string 1 i) 'eshell-term-send-raw) | |
239 ; (define-key esc-map (make-string 1 i) 'eshell-term-send-raw-meta) | |
240 ; (setq i (1+ i))) | |
241 ; (define-key map "\e" esc-map) | |
242 ; (setq eshell-term-raw-map map) | |
243 ; (setq eshell-term-raw-escape-map | |
244 ; (copy-keymap (lookup-key (current-global-map) "\C-x"))) | |
245 ; (if (boundp 'xemacs-logo) | |
246 ; (define-key eshell-term-raw-map [button2] 'eshell-term-mouse-paste) | |
247 ; (define-key eshell-term-raw-map [mouse-2] 'eshell-term-mouse-paste)) | |
248 ; (define-key eshell-term-raw-map [up] 'eshell-term-send-up) | |
249 ; (define-key eshell-term-raw-map [down] 'eshell-term-send-down) | |
250 ; (define-key eshell-term-raw-map [right] 'eshell-term-send-right) | |
251 ; (define-key eshell-term-raw-map [left] 'eshell-term-send-left) | |
252 ; (define-key eshell-term-raw-map [delete] 'eshell-term-send-del) | |
253 ; (define-key eshell-term-raw-map [backspace] 'eshell-term-send-backspace) | |
254 ; (define-key eshell-term-raw-map [home] 'eshell-term-send-home) | |
255 ; (define-key eshell-term-raw-map [end] 'eshell-term-send-end) | |
256 ; (define-key eshell-term-raw-map [prior] 'eshell-term-send-prior) | |
257 ; (define-key eshell-term-raw-map [next] 'eshell-term-send-next) | |
258 ; (eshell-term-set-escape-char ?\C-c)))) | |
259 | |
260 ; (defun eshell-term-line-mode () | |
261 ; "Switch to line (\"cooked\") sub-mode of eshell-term mode." | |
262 ; (use-local-map term-old-mode-map)) | |
263 | |
87075
e8d46c0f12e6
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
264 (provide 'em-term) |
29876 | 265 |
95152
ad5d26b1d5d1
Use eshell-defgroup rather than defgroup.
Glenn Morris <rgm@gnu.org>
parents:
94661
diff
changeset
|
266 ;; Local Variables: |
ad5d26b1d5d1
Use eshell-defgroup rather than defgroup.
Glenn Morris <rgm@gnu.org>
parents:
94661
diff
changeset
|
267 ;; generated-autoload-file: "esh-groups.el" |
ad5d26b1d5d1
Use eshell-defgroup rather than defgroup.
Glenn Morris <rgm@gnu.org>
parents:
94661
diff
changeset
|
268 ;; End: |
ad5d26b1d5d1
Use eshell-defgroup rather than defgroup.
Glenn Morris <rgm@gnu.org>
parents:
94661
diff
changeset
|
269 |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
270 ;; arch-tag: ab7c8fe4-3101-4257-925b-1354c6b2fe9d |
29876 | 271 ;;; em-term.el ends here |