Mercurial > emacs
annotate lisp/eshell/esh-mode.el @ 84948:3977b897d1a1
*** empty log message ***
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Thu, 27 Sep 2007 11:55:06 +0000 |
parents | ef255e3b79f5 |
children | c0cc9997f433 59ee4068f60b bdb3fe0ba9fa |
rev | line source |
---|---|
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
38111
diff
changeset
|
1 ;;; esh-mode.el --- user interface |
29870 | 2 |
64701
34bd8e434dd7
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64085
diff
changeset
|
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, |
75346 | 4 ;; 2005, 2006, 2007 Free Software Foundation, Inc. |
29870 | 5 |
32526 | 6 ;; Author: John Wiegley <johnw@gnu.org> |
7 | |
29870 | 8 ;; This file is part of GNU Emacs. |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
78220
a1e8300d3c55
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
76468
diff
changeset
|
12 ;; the Free Software Foundation; either version 3, or (at your option) |
29870 | 13 ;; any later version. |
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 | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
64085 | 22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
23 ;; Boston, MA 02110-1301, USA. | |
29870 | 24 |
25 (provide 'esh-mode) | |
26 | |
27 (eval-when-compile (require 'esh-maint)) | |
28 | |
29 (defgroup eshell-mode nil | |
30 "This module contains code for handling input from the user." | |
31 :tag "User interface" | |
32 :group 'eshell) | |
33 | |
34 ;;; Commentary: | |
35 | |
36 ;; Basically, Eshell is used just like shell mode (<M-x shell>). The | |
37 ;; keystrokes for navigating the buffer, and accessing the command | |
38 ;; history, are identical. Unlike shell mode, however, Eshell mode's | |
39 ;; governing process is Emacs itself. With shell mode, an inferior | |
40 ;; shell process is executed that communicates with Emacs via comint | |
41 ;; -- a mode for handling sub-process interaction. Eshell mode, on | |
42 ;; the other hand, is a truly native Emacs shell. No subprocess are | |
43 ;; invoked except the ones requested by the user at the prompt. | |
44 ;; | |
45 ;; After entering a command, use <RET> to invoke it ([Command | |
46 ;; invocation]) . If there is a command on disk, it will be executed | |
47 ;; as in a normal shell. If there is no command by that name on disk, | |
48 ;; but a Lisp function with that name is defined, the Lisp function | |
49 ;; will be called, using the arguments passed on the command line. | |
50 ;; | |
51 ;; Some of the other features of the command interaction mode are: | |
52 ;; | |
53 ;; @ <M-RET> can be used to accumulate further commands while a | |
54 ;; command is currently running. Since all input is passed to the | |
55 ;; subprocess being executed, there is no automatic input queueing | |
56 ;; as there is with other shells. | |
57 ;; | |
58 ;; @ <C-c C-t> can be used to truncate the buffer if it grows too | |
59 ;; large. | |
60 ;; | |
61 ;; @ <C-c C-r> will move point to the beginning of the output of the | |
62 ;; last command. With a prefix argument, it will narrow to view | |
63 ;; only that output. | |
64 ;; | |
65 ;; @ <C-c C-o> will delete the output from the last command. | |
66 ;; | |
67 ;; @ <C-c C-f> will move forward a complete shell argument. | |
68 ;; | |
69 ;; @ <C-c C-b> will move backward a complete shell argument. | |
70 | |
71 (require 'esh-module) | |
72 (require 'esh-cmd) | |
73 (require 'esh-io) | |
74 (require 'esh-var) | |
75 | |
76 ;;; User Variables: | |
77 | |
78 (defcustom eshell-mode-unload-hook nil | |
79 "*A hook that gets run when `eshell-mode' is unloaded." | |
80 :type 'hook | |
81 :group 'eshell-mode) | |
82 | |
83 (defcustom eshell-mode-hook nil | |
84 "*A hook that gets run when `eshell-mode' is entered." | |
85 :type 'hook | |
86 :group 'eshell-mode) | |
87 | |
88 (defcustom eshell-first-time-mode-hook nil | |
89 "*A hook that gets run the first time `eshell-mode' is entered. | |
90 That is to say, the first time during an Emacs session." | |
91 :type 'hook | |
92 :group 'eshell-mode) | |
93 | |
94 (defcustom eshell-exit-hook '(eshell-query-kill-processes) | |
95 "*A hook that is run whenever `eshell' is exited. | |
96 This hook is only run if exiting actually kills the buffer." | |
97 :type 'hook | |
98 :group 'eshell-mode) | |
99 | |
100 (defcustom eshell-kill-on-exit t | |
101 "*If non-nil, kill the Eshell buffer on the `exit' command. | |
102 Otherwise, the buffer will simply be buried." | |
103 :type 'boolean | |
104 :group 'eshell-mode) | |
105 | |
106 (defcustom eshell-input-filter-functions nil | |
107 "*Functions to call before input is processed. | |
108 The input is contained in the region from `eshell-last-input-start' to | |
109 `eshell-last-input-end'." | |
110 :type 'hook | |
111 :group 'eshell-mode) | |
112 | |
31326 | 113 (defcustom eshell-send-direct-to-subprocesses nil |
114 "*If t, send any input immediately to a subprocess." | |
115 :type 'boolean | |
116 :group 'eshell-mode) | |
117 | |
29870 | 118 (defcustom eshell-expand-input-functions nil |
119 "*Functions to call before input is parsed. | |
120 Each function is passed two arguments, which bounds the region of the | |
121 current input text." | |
122 :type 'hook | |
123 :group 'eshell-mode) | |
124 | |
125 (defcustom eshell-scroll-to-bottom-on-input nil | |
126 "*Controls whether input to interpreter causes window to scroll. | |
127 If nil, then do not scroll. If t or `all', scroll all windows showing | |
128 buffer. If `this', scroll only the selected window. | |
129 | |
130 See `eshell-preinput-scroll-to-bottom'." | |
131 :type '(radio (const :tag "Do not scroll Eshell windows" nil) | |
132 (const :tag "Scroll all windows showing the buffer" all) | |
133 (const :tag "Scroll only the selected window" this)) | |
134 :group 'eshell-mode) | |
135 | |
136 (defcustom eshell-scroll-to-bottom-on-output nil | |
137 "*Controls whether interpreter output causes window to scroll. | |
138 If nil, then do not scroll. If t or `all', scroll all windows showing | |
139 buffer. If `this', scroll only the selected window. If `others', | |
140 scroll only those that are not the selected window. | |
141 | |
142 See variable `eshell-scroll-show-maximum-output' and function | |
143 `eshell-postoutput-scroll-to-bottom'." | |
144 :type '(radio (const :tag "Do not scroll Eshell windows" nil) | |
145 (const :tag "Scroll all windows showing the buffer" all) | |
146 (const :tag "Scroll only the selected window" this) | |
147 (const :tag "Scroll all windows other than selected" this)) | |
148 :group 'eshell-mode) | |
149 | |
150 (defcustom eshell-scroll-show-maximum-output t | |
151 "*Controls how interpreter output causes window to scroll. | |
152 If non-nil, then show the maximum output when the window is scrolled. | |
153 | |
154 See variable `eshell-scroll-to-bottom-on-output' and function | |
155 `eshell-postoutput-scroll-to-bottom'." | |
156 :type 'boolean | |
157 :group 'eshell-mode) | |
158 | |
159 (defcustom eshell-buffer-maximum-lines 1024 | |
160 "*The maximum size in lines for eshell buffers. | |
161 Eshell buffers are truncated from the top to be no greater than this | |
162 number, if the function `eshell-truncate-buffer' is on | |
163 `eshell-output-filter-functions'." | |
164 :type 'integer | |
165 :group 'eshell-mode) | |
166 | |
167 (defcustom eshell-output-filter-functions | |
84710
ef255e3b79f5
(eshell-output-filter-functions): Add eshell-postoutput-scroll-to-bottom.
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
168 '(eshell-postoutput-scroll-to-bottom |
ef255e3b79f5
(eshell-output-filter-functions): Add eshell-postoutput-scroll-to-bottom.
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
169 eshell-handle-control-codes |
29870 | 170 eshell-watch-for-password-prompt) |
171 "*Functions to call before output is displayed. | |
172 These functions are only called for output that is displayed | |
173 interactively, and not for output which is redirected." | |
174 :type 'hook | |
175 :group 'eshell-mode) | |
176 | |
177 (defcustom eshell-preoutput-filter-functions nil | |
178 "*Functions to call before output is inserted into the buffer. | |
179 These functions get one argument, a string containing the text to be | |
180 inserted. They return the string as it should be inserted." | |
181 :type 'hook | |
182 :group 'eshell-mode) | |
183 | |
184 (defcustom eshell-password-prompt-regexp | |
33020 | 185 "[Pp]ass\\(word\\|phrase\\).*:\\s *\\'" |
29870 | 186 "*Regexp matching prompts for passwords in the inferior process. |
187 This is used by `eshell-watch-for-password-prompt'." | |
188 :type 'regexp | |
189 :group 'eshell-mode) | |
190 | |
191 (defcustom eshell-skip-prompt-function nil | |
192 "*A function called from beginning of line to skip the prompt." | |
35974
0faaf71003ac
(eshell-skip-prompt-function): Fix :type.
Dave Love <fx@gnu.org>
parents:
33020
diff
changeset
|
193 :type '(choice (const nil) function) |
29870 | 194 :group 'eshell-mode) |
195 | |
196 (defcustom eshell-status-in-modeline t | |
197 "*If non-nil, let the user know a command is running in the modeline." | |
198 :type 'boolean | |
199 :group 'eshell-mode) | |
200 | |
201 (defvar eshell-first-time-p t | |
202 "A variable which is non-nil the first time Eshell is loaded.") | |
203 | |
204 ;; Internal Variables: | |
205 | |
206 ;; these are only set to `nil' initially for the sake of the | |
207 ;; byte-compiler, when compiling other files which `require' this one | |
208 (defvar eshell-mode nil) | |
209 (defvar eshell-mode-map nil) | |
210 (defvar eshell-command-running-string "--") | |
211 (defvar eshell-command-map nil) | |
212 (defvar eshell-command-prefix nil) | |
213 (defvar eshell-last-input-start nil) | |
214 (defvar eshell-last-input-end nil) | |
215 (defvar eshell-last-output-start nil) | |
216 (defvar eshell-last-output-block-begin nil) | |
217 (defvar eshell-last-output-end nil) | |
218 | |
219 (defvar eshell-currently-handling-window nil) | |
220 (defvar eshell-mode-syntax-table nil) | |
221 (defvar eshell-mode-abbrev-table nil) | |
222 | |
223 (define-abbrev-table 'eshell-mode-abbrev-table ()) | |
224 | |
225 (eval-when-compile | |
226 (unless (eshell-under-xemacs-p) | |
227 (defalias 'characterp 'ignore) | |
228 (defalias 'char-int 'ignore))) | |
229 | |
230 (if (not eshell-mode-syntax-table) | |
231 (let ((i 0)) | |
232 (setq eshell-mode-syntax-table (make-syntax-table)) | |
233 (while (< i ?0) | |
234 (modify-syntax-entry i "_ " eshell-mode-syntax-table) | |
235 (setq i (1+ i))) | |
236 (setq i (1+ ?9)) | |
237 (while (< i ?A) | |
238 (modify-syntax-entry i "_ " eshell-mode-syntax-table) | |
239 (setq i (1+ i))) | |
240 (setq i (1+ ?Z)) | |
241 (while (< i ?a) | |
242 (modify-syntax-entry i "_ " eshell-mode-syntax-table) | |
243 (setq i (1+ i))) | |
244 (setq i (1+ ?z)) | |
245 (while (< i 128) | |
246 (modify-syntax-entry i "_ " eshell-mode-syntax-table) | |
247 (setq i (1+ i))) | |
248 (modify-syntax-entry ? " " eshell-mode-syntax-table) | |
249 (modify-syntax-entry ?\t " " eshell-mode-syntax-table) | |
250 (modify-syntax-entry ?\f " " eshell-mode-syntax-table) | |
251 (modify-syntax-entry ?\n "> " eshell-mode-syntax-table) | |
252 ;; Give CR the same syntax as newline, for selective-display. | |
253 (modify-syntax-entry ?\^m "> " eshell-mode-syntax-table) | |
254 ;;; (modify-syntax-entry ?\; "< " eshell-mode-syntax-table) | |
255 (modify-syntax-entry ?` "' " eshell-mode-syntax-table) | |
256 (modify-syntax-entry ?' "' " eshell-mode-syntax-table) | |
257 (modify-syntax-entry ?, "' " eshell-mode-syntax-table) | |
258 ;; Used to be singlequote; changed for flonums. | |
259 (modify-syntax-entry ?. "_ " eshell-mode-syntax-table) | |
260 (modify-syntax-entry ?- "_ " eshell-mode-syntax-table) | |
261 (modify-syntax-entry ?| ". " eshell-mode-syntax-table) | |
262 (modify-syntax-entry ?# "' " eshell-mode-syntax-table) | |
263 (modify-syntax-entry ?\" "\" " eshell-mode-syntax-table) | |
264 (modify-syntax-entry ?\\ "/ " eshell-mode-syntax-table) | |
265 (modify-syntax-entry ?\( "() " eshell-mode-syntax-table) | |
266 (modify-syntax-entry ?\) ")( " eshell-mode-syntax-table) | |
267 (modify-syntax-entry ?\{ "(} " eshell-mode-syntax-table) | |
268 (modify-syntax-entry ?\} "){ " eshell-mode-syntax-table) | |
269 (modify-syntax-entry ?\[ "(] " eshell-mode-syntax-table) | |
270 (modify-syntax-entry ?\] ")[ " eshell-mode-syntax-table) | |
271 ;; All non-word multibyte characters should be `symbol'. | |
272 (if (eshell-under-xemacs-p) | |
273 (map-char-table | |
274 (function | |
275 (lambda (key val) | |
276 (and (characterp key) | |
277 (>= (char-int key) 256) | |
278 (/= (char-syntax key) ?w) | |
279 (modify-syntax-entry key "_ " | |
280 eshell-mode-syntax-table)))) | |
281 (standard-syntax-table)) | |
282 (map-char-table | |
283 (function | |
284 (lambda (key val) | |
285 (and (>= key 256) | |
286 (/= (char-syntax key) ?w) | |
287 (modify-syntax-entry key "_ " | |
288 eshell-mode-syntax-table)))) | |
289 (standard-syntax-table))))) | |
290 | |
291 ;;; User Functions: | |
292 | |
293 ;;;###autoload | |
294 (defun eshell-mode () | |
295 "Emacs shell interactive mode. | |
296 | |
297 \\{eshell-mode-map}" | |
298 (kill-all-local-variables) | |
299 | |
300 (setq major-mode 'eshell-mode) | |
301 (setq mode-name "EShell") | |
302 (set (make-local-variable 'eshell-mode) t) | |
303 | |
304 (make-local-variable 'eshell-mode-map) | |
305 (setq eshell-mode-map (make-sparse-keymap)) | |
306 (use-local-map eshell-mode-map) | |
307 | |
308 (when eshell-status-in-modeline | |
309 (make-local-variable 'eshell-command-running-string) | |
45735
642c25258945
(eshell-mode, eshell-mode): Use copy-sequence.
Richard M. Stallman <rms@gnu.org>
parents:
43338
diff
changeset
|
310 (let ((fmt (copy-sequence mode-line-format))) |
29870 | 311 (make-local-variable 'mode-line-format) |
312 (setq mode-line-format fmt)) | |
313 (let ((modeline (memq 'mode-line-modified mode-line-format))) | |
314 (if modeline | |
315 (setcar modeline 'eshell-command-running-string)))) | |
316 | |
317 (define-key eshell-mode-map [return] 'eshell-send-input) | |
318 (define-key eshell-mode-map [(control ?m)] 'eshell-send-input) | |
319 (define-key eshell-mode-map [(control ?j)] 'eshell-send-input) | |
320 (define-key eshell-mode-map [(meta return)] 'eshell-queue-input) | |
321 (define-key eshell-mode-map [(meta control ?m)] 'eshell-queue-input) | |
322 (define-key eshell-mode-map [(meta control ?l)] 'eshell-show-output) | |
323 | |
324 (set (make-local-variable 'eshell-command-prefix) | |
325 (make-symbol "eshell-command-prefix")) | |
326 (fset eshell-command-prefix (make-sparse-keymap)) | |
327 (set (make-local-variable 'eshell-command-map) | |
328 (symbol-function eshell-command-prefix)) | |
329 (define-key eshell-mode-map [(control ?c)] eshell-command-prefix) | |
330 | |
31240 | 331 ;; without this, find-tag complains about read-only text being |
332 ;; modified | |
333 (if (eq (key-binding [(meta ?.)]) 'find-tag) | |
334 (define-key eshell-mode-map [(meta ?.)] 'eshell-find-tag)) | |
29870 | 335 (define-key eshell-command-map [(meta ?o)] 'eshell-mark-output) |
31326 | 336 (define-key eshell-command-map [(meta ?d)] 'eshell-toggle-direct-send) |
29870 | 337 |
338 (define-key eshell-command-map [(control ?a)] 'eshell-bol) | |
339 (define-key eshell-command-map [(control ?b)] 'eshell-backward-argument) | |
340 (define-key eshell-command-map [(control ?e)] 'eshell-show-maximum-output) | |
341 (define-key eshell-command-map [(control ?f)] 'eshell-forward-argument) | |
342 (define-key eshell-command-map [return] 'eshell-copy-old-input) | |
343 (define-key eshell-command-map [(control ?m)] 'eshell-copy-old-input) | |
344 (define-key eshell-command-map [(control ?o)] 'eshell-kill-output) | |
345 (define-key eshell-command-map [(control ?r)] 'eshell-show-output) | |
346 (define-key eshell-command-map [(control ?t)] 'eshell-truncate-buffer) | |
347 (define-key eshell-command-map [(control ?u)] 'eshell-kill-input) | |
348 (define-key eshell-command-map [(control ?w)] 'backward-kill-word) | |
31240 | 349 (define-key eshell-command-map [(control ?y)] 'eshell-repeat-argument) |
29870 | 350 |
351 (setq local-abbrev-table eshell-mode-abbrev-table) | |
352 (set-syntax-table eshell-mode-syntax-table) | |
353 | |
354 (set (make-local-variable 'dired-directory) default-directory) | |
355 (set (make-local-variable 'list-buffers-directory) | |
356 (expand-file-name default-directory)) | |
357 | |
358 ;; always set the tab width to 8 in Eshell buffers, since external | |
359 ;; commands which do their own formatting almost always expect this | |
360 (set (make-local-variable 'tab-width) 8) | |
361 | |
31240 | 362 ;; don't ever use auto-fill in Eshell buffers |
363 (setq auto-fill-function nil) | |
364 | |
29870 | 365 ;; always display everything from a return value |
366 (if (boundp 'print-length) | |
367 (set (make-local-variable 'print-length) nil)) | |
368 (if (boundp 'print-level) | |
369 (set (make-local-variable 'print-level) nil)) | |
370 | |
371 ;; set require-final-newline to nil; otherwise, all redirected | |
372 ;; output will end with a newline, whether or not the source | |
373 ;; indicated it! | |
374 (set (make-local-variable 'require-final-newline) nil) | |
375 | |
376 (set (make-local-variable 'max-lisp-eval-depth) | |
377 (max 3000 max-lisp-eval-depth)) | |
378 (set (make-local-variable 'max-specpdl-size) | |
379 (max 6000 max-lisp-eval-depth)) | |
380 | |
381 (set (make-local-variable 'eshell-last-input-start) (point-marker)) | |
382 (set (make-local-variable 'eshell-last-input-end) (point-marker)) | |
383 (set (make-local-variable 'eshell-last-output-start) (point-marker)) | |
384 (set (make-local-variable 'eshell-last-output-end) (point-marker)) | |
385 (set (make-local-variable 'eshell-last-output-block-begin) (point)) | |
386 | |
45735
642c25258945
(eshell-mode, eshell-mode): Use copy-sequence.
Richard M. Stallman <rms@gnu.org>
parents:
43338
diff
changeset
|
387 (let ((modules-list (copy-sequence eshell-modules-list))) |
29870 | 388 (make-local-variable 'eshell-modules-list) |
389 (setq eshell-modules-list modules-list)) | |
390 | |
391 ;; load extension modules into memory. This will cause any global | |
392 ;; variables they define to be visible, since some of the core | |
393 ;; modules sometimes take advantage of their functionality if used. | |
394 (eshell-for module eshell-modules-list | |
395 (let ((module-fullname (symbol-name module)) | |
396 module-shortname) | |
397 (if (string-match "^eshell-\\(.*\\)" module-fullname) | |
398 (setq module-shortname | |
399 (concat "em-" (match-string 1 module-fullname)))) | |
400 (unless module-shortname | |
401 (error "Invalid Eshell module name: %s" module-fullname)) | |
402 (unless (featurep (intern module-shortname)) | |
403 (load module-shortname)))) | |
404 | |
405 (unless (file-exists-p eshell-directory-name) | |
406 (eshell-make-private-directory eshell-directory-name t)) | |
407 | |
408 ;; load core Eshell modules for this session | |
409 (eshell-for module (eshell-subgroups 'eshell) | |
410 (run-hooks (intern-soft (concat (symbol-name module) | |
411 "-load-hook")))) | |
412 | |
413 ;; load extension modules for this session | |
414 (eshell-for module eshell-modules-list | |
415 (let ((load-hook (intern-soft (concat (symbol-name module) | |
416 "-load-hook")))) | |
417 (if (and load-hook (boundp load-hook)) | |
418 (run-hooks load-hook)))) | |
419 | |
31326 | 420 (if eshell-send-direct-to-subprocesses |
421 (add-hook 'pre-command-hook 'eshell-intercept-commands t t)) | |
422 | |
423 (if eshell-scroll-to-bottom-on-input | |
424 (add-hook 'pre-command-hook 'eshell-preinput-scroll-to-bottom t t)) | |
29870 | 425 |
426 (when eshell-scroll-show-maximum-output | |
427 (set (make-local-variable 'scroll-conservatively) 1000)) | |
428 | |
429 (when eshell-status-in-modeline | |
430 (add-hook 'eshell-pre-command-hook 'eshell-command-started nil t) | |
431 (add-hook 'eshell-post-command-hook 'eshell-command-finished nil t)) | |
432 | |
433 (add-hook 'kill-buffer-hook | |
434 (function | |
435 (lambda () | |
436 (run-hooks 'eshell-exit-hook))) t t) | |
437 | |
438 (if eshell-first-time-p | |
439 (run-hooks 'eshell-first-time-mode-hook)) | |
62760
8cd0894899dc
(eshell-mode): Use run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62332
diff
changeset
|
440 (run-mode-hooks 'eshell-mode-hook) |
29870 | 441 (run-hooks 'eshell-post-command-hook)) |
442 | |
443 (put 'eshell-mode 'mode-class 'special) | |
444 | |
445 (eshell-deftest mode major-mode | |
446 "Major mode is correct" | |
447 (eq major-mode 'eshell-mode)) | |
448 | |
449 (eshell-deftest mode eshell-mode-variable | |
450 "`eshell-mode' is true" | |
451 (eq eshell-mode t)) | |
452 | |
453 (eshell-deftest var window-height | |
454 "LINES equals window height" | |
33020 | 455 (let ((eshell-stringify-t t)) |
456 (eshell-command-result-p "= $LINES (window-height)" "t\n"))) | |
29870 | 457 |
458 (defun eshell-command-started () | |
459 "Indicate in the modeline that a command has started." | |
460 (setq eshell-command-running-string "**") | |
461 (force-mode-line-update)) | |
462 | |
463 (defun eshell-command-finished () | |
464 "Indicate in the modeline that a command has finished." | |
465 (setq eshell-command-running-string "--") | |
466 (force-mode-line-update)) | |
467 | |
468 (eshell-deftest mode command-running-p | |
469 "Modeline shows no command running" | |
470 (or (eshell-under-xemacs-p) | |
471 (not eshell-status-in-modeline) | |
472 (and (memq 'eshell-command-running-string mode-line-format) | |
473 (equal eshell-command-running-string "--")))) | |
474 | |
475 ;;; Internal Functions: | |
476 | |
31326 | 477 (defun eshell-toggle-direct-send () |
478 (interactive) | |
479 (if eshell-send-direct-to-subprocesses | |
480 (progn | |
481 (setq eshell-send-direct-to-subprocesses nil) | |
482 (remove-hook 'pre-command-hook 'eshell-intercept-commands t) | |
483 (message "Sending subprocess input on RET")) | |
484 (setq eshell-send-direct-to-subprocesses t) | |
485 (add-hook 'pre-command-hook 'eshell-intercept-commands t t) | |
486 (message "Sending subprocess input directly"))) | |
487 | |
488 (defun eshell-self-insert-command (N) | |
489 (interactive "i") | |
490 (process-send-string | |
491 (eshell-interactive-process) | |
492 (char-to-string (if (symbolp last-command-char) | |
493 (get last-command-char 'ascii-character) | |
494 last-command-char)))) | |
495 | |
496 (defun eshell-intercept-commands () | |
497 (when (and (eshell-interactive-process) | |
498 (not (and (integerp last-input-event) | |
499 (memq last-input-event '(?\C-x ?\C-c))))) | |
500 (let ((possible-events (where-is-internal this-command)) | |
501 (name (symbol-name this-command)) | |
502 (intercept t)) | |
503 ;; Assume that any multikey combination which does NOT target an | |
504 ;; Eshell command, is a combo the user wants invoked rather than | |
505 ;; sent to the underlying subprocess. | |
506 (unless (and (> (length name) 7) | |
507 (equal (substring name 0 7) "eshell-")) | |
508 (while possible-events | |
509 (if (> (length (car possible-events)) 1) | |
510 (setq intercept nil possible-events nil) | |
511 (setq possible-events (cdr possible-events))))) | |
512 (if intercept | |
513 (setq this-command 'eshell-self-insert-command))))) | |
514 | |
31240 | 515 (defun eshell-find-tag (&optional tagname next-p regexp-p) |
516 "A special version of `find-tag' that ignores read-onlyness." | |
517 (interactive) | |
31241 | 518 (require 'etags) |
31240 | 519 (let ((inhibit-read-only t) |
32446
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31326
diff
changeset
|
520 (no-default (eobp)) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31326
diff
changeset
|
521 (find-tag-default-function 'ignore)) |
62332
18090a2d479a
(eshell-find-tag): Use with-no-warnings.
Richard M. Stallman <rms@gnu.org>
parents:
62262
diff
changeset
|
522 (with-no-warnings |
18090a2d479a
(eshell-find-tag): Use with-no-warnings.
Richard M. Stallman <rms@gnu.org>
parents:
62262
diff
changeset
|
523 (setq tagname (car (find-tag-interactive "Find tag: ")))) |
31240 | 524 (find-tag tagname next-p regexp-p))) |
525 | |
29870 | 526 (defun eshell-move-argument (limit func property arg) |
527 "Move forward ARG arguments." | |
528 (catch 'eshell-incomplete | |
529 (eshell-parse-arguments (save-excursion (eshell-bol) (point)) | |
530 (line-end-position))) | |
31240 | 531 (let ((pos (save-excursion |
532 (funcall func 1) | |
533 (while (and (> arg 0) (/= (point) limit)) | |
534 (if (get-text-property (point) property) | |
535 (setq arg (1- arg))) | |
536 (if (> arg 0) | |
537 (funcall func 1))) | |
538 (point)))) | |
29870 | 539 (goto-char pos) |
540 (if (and (eq func 'forward-char) | |
541 (= (1+ pos) limit)) | |
542 (forward-char 1)))) | |
543 | |
544 (eshell-deftest arg forward-arg | |
545 "Move across command arguments" | |
546 (eshell-insert-command "echo $(+ 1 (- 4 3)) \"alpha beta\" file" 'ignore) | |
547 (let ((here (point)) begin valid) | |
548 (eshell-bol) | |
549 (setq begin (point)) | |
550 (eshell-forward-argument 4) | |
551 (setq valid (= here (point))) | |
552 (eshell-backward-argument 4) | |
553 (prog1 | |
554 (and valid (= begin (point))) | |
555 (eshell-bol) | |
556 (delete-region (point) (point-max))))) | |
557 | |
558 (defun eshell-forward-argument (&optional arg) | |
559 "Move forward ARG arguments." | |
560 (interactive "p") | |
561 (eshell-move-argument (point-max) 'forward-char 'arg-end arg)) | |
562 | |
563 (defun eshell-backward-argument (&optional arg) | |
564 "Move backward ARG arguments." | |
565 (interactive "p") | |
566 (eshell-move-argument (point-min) 'backward-char 'arg-begin arg)) | |
567 | |
31240 | 568 (defun eshell-repeat-argument (&optional arg) |
569 (interactive "p") | |
570 (let ((begin (save-excursion | |
571 (eshell-backward-argument arg) | |
572 (point)))) | |
573 (kill-ring-save begin (point)) | |
574 (yank))) | |
575 | |
29870 | 576 (defun eshell-bol () |
577 "Goes to the beginning of line, then skips past the prompt, if any." | |
578 (interactive) | |
579 (beginning-of-line) | |
580 (and eshell-skip-prompt-function | |
581 (funcall eshell-skip-prompt-function))) | |
582 | |
583 (defsubst eshell-push-command-mark () | |
584 "Push a mark at the end of the last input text." | |
585 (push-mark (1- eshell-last-input-end) t)) | |
586 | |
587 (custom-add-option 'eshell-pre-command-hook 'eshell-push-command-mark) | |
588 | |
589 (defsubst eshell-goto-input-start () | |
590 "Goto the start of the last command input. | |
591 Putting this function on `eshell-pre-command-hook' will mimic Plan 9's | |
592 9term behavior." | |
593 (goto-char eshell-last-input-start)) | |
594 | |
595 (custom-add-option 'eshell-pre-command-hook 'eshell-push-command-mark) | |
596 | |
597 (defsubst eshell-interactive-print (string) | |
598 "Print STRING to the eshell display buffer." | |
599 (eshell-output-filter nil string)) | |
600 | |
601 (defsubst eshell-begin-on-new-line () | |
602 "This function outputs a newline if not at beginning of line." | |
603 (save-excursion | |
604 (goto-char eshell-last-output-end) | |
605 (or (bolp) | |
606 (eshell-interactive-print "\n")))) | |
607 | |
608 (defsubst eshell-reset (&optional no-hooks) | |
609 "Output a prompt on a new line, aborting any current input. | |
610 If NO-HOOKS is non-nil, then `eshell-post-command-hook' won't be run." | |
611 (goto-char (point-max)) | |
612 (setq eshell-last-input-start (point-marker) | |
613 eshell-last-input-end (point-marker) | |
614 eshell-last-output-start (point-marker) | |
615 eshell-last-output-block-begin (point) | |
616 eshell-last-output-end (point-marker)) | |
617 (eshell-begin-on-new-line) | |
618 (unless no-hooks | |
619 (run-hooks 'eshell-post-command-hook) | |
620 (goto-char (point-max)))) | |
621 | |
622 (defun eshell-parse-command-input (beg end &optional args) | |
623 "Parse the command input from BEG to END. | |
624 The difference is that `eshell-parse-command' expects a complete | |
625 command string (and will error if it doesn't get one), whereas this | |
626 function will inform the caller whether more input is required. | |
627 | |
628 If nil is returned, more input is necessary (probably because a | |
629 multi-line input string wasn't terminated properly). Otherwise, it | |
630 will return the parsed command." | |
31240 | 631 (let (delim command) |
632 (if (setq delim | |
633 (catch 'eshell-incomplete | |
634 (ignore | |
635 (setq command (eshell-parse-command (cons beg end) | |
636 args t))))) | |
637 (ignore | |
638 (message "Expecting completion of delimeter %c ..." | |
639 (if (listp delim) | |
640 (car delim) | |
641 delim))) | |
29870 | 642 command))) |
643 | |
644 (defun eshell-update-markers (pmark) | |
645 "Update the input and output markers relative to point and PMARK." | |
646 (set-marker eshell-last-input-start pmark) | |
647 (set-marker eshell-last-input-end (point)) | |
648 (set-marker eshell-last-output-end (point))) | |
649 | |
650 (defun eshell-queue-input (&optional use-region) | |
651 "Queue the current input text for execution by Eshell. | |
652 Particularly, don't send the text to the current process, even if it's | |
653 waiting for input." | |
654 (interactive "P") | |
655 (eshell-send-input use-region t)) | |
656 | |
657 (eshell-deftest mode queue-input | |
658 "Queue command input" | |
659 (eshell-insert-command "sleep 2") | |
660 (eshell-insert-command "echo alpha" 'eshell-queue-input) | |
661 (let ((count 10)) | |
662 (while (and eshell-current-command | |
663 (> count 0)) | |
664 (sit-for 1 0) | |
665 (setq count (1- count)))) | |
666 (eshell-match-result "alpha\n")) | |
667 | |
668 (defun eshell-send-input (&optional use-region queue-p no-newline) | |
62262
9e498efab42b
(eshell-send-input): Doc fix.
Andreas Schwab <schwab@suse.de>
parents:
57929
diff
changeset
|
669 "Send the input received to Eshell for parsing and processing. |
29870 | 670 After `eshell-last-output-end', sends all text from that marker to |
671 point as input. Before that marker, calls `eshell-get-old-input' to | |
672 retrieve old input, copies it to the end of the buffer, and sends it. | |
673 | |
674 If USE-REGION is non-nil, the current region (between point and mark) | |
675 will be used as input. | |
676 | |
677 If QUEUE-P is non-nil, input will be queued until the next prompt, | |
678 rather than sent to the currently active process. If no process, the | |
679 input is processed immediately. | |
680 | |
681 If NO-NEWLINE is non-nil, the input is sent without an implied final | |
682 newline." | |
683 (interactive "P") | |
684 ;; Note that the input string does not include its terminal newline. | |
685 (let ((proc-running-p (and (eshell-interactive-process) | |
686 (not queue-p))) | |
687 (inhibit-point-motion-hooks t) | |
688 after-change-functions) | |
689 (unless (and proc-running-p | |
690 (not (eq (process-status | |
691 (eshell-interactive-process)) 'run))) | |
692 (if (or proc-running-p | |
693 (>= (point) eshell-last-output-end)) | |
694 (goto-char (point-max)) | |
695 (let ((copy (eshell-get-old-input use-region))) | |
696 (goto-char eshell-last-output-end) | |
697 (insert-and-inherit copy))) | |
31326 | 698 (unless (or no-newline |
699 (and eshell-send-direct-to-subprocesses | |
700 proc-running-p)) | |
29870 | 701 (insert-before-markers-and-inherit ?\n)) |
702 (if proc-running-p | |
703 (progn | |
704 (eshell-update-markers eshell-last-output-end) | |
31326 | 705 (if (or eshell-send-direct-to-subprocesses |
706 (= eshell-last-input-start eshell-last-input-end)) | |
29870 | 707 (unless no-newline |
708 (process-send-string (eshell-interactive-process) "\n")) | |
709 (process-send-region (eshell-interactive-process) | |
710 eshell-last-input-start | |
711 eshell-last-input-end))) | |
712 (if (= eshell-last-output-end (point)) | |
713 (run-hooks 'eshell-post-command-hook) | |
714 (let (input) | |
715 (eshell-condition-case err | |
716 (progn | |
717 (setq input (buffer-substring-no-properties | |
718 eshell-last-output-end (1- (point)))) | |
719 (run-hook-with-args 'eshell-expand-input-functions | |
720 eshell-last-output-end (1- (point))) | |
721 (let ((cmd (eshell-parse-command-input | |
722 eshell-last-output-end (1- (point))))) | |
723 (when cmd | |
724 (eshell-update-markers eshell-last-output-end) | |
725 (setq input (buffer-substring-no-properties | |
726 eshell-last-input-start | |
727 (1- eshell-last-input-end))) | |
728 (run-hooks 'eshell-input-filter-functions) | |
729 (and (catch 'eshell-terminal | |
730 (ignore | |
33020 | 731 (if (eshell-invoke-directly cmd input) |
732 (eval cmd) | |
733 (eshell-eval-command cmd input)))) | |
29870 | 734 (eshell-life-is-too-much))))) |
735 (quit | |
736 (eshell-reset t) | |
737 (run-hooks 'eshell-post-command-hook) | |
738 (signal 'quit nil)) | |
739 (error | |
740 (eshell-reset t) | |
741 (eshell-interactive-print | |
742 (concat (error-message-string err) "\n")) | |
743 (run-hooks 'eshell-post-command-hook) | |
744 (insert-and-inherit input))))))))) | |
745 | |
38111
737e1a913c78
Disabled a test that often yields false failures.
John Wiegley <johnw@newartisans.com>
parents:
37435
diff
changeset
|
746 ; (eshell-deftest proc send-to-subprocess |
737e1a913c78
Disabled a test that often yields false failures.
John Wiegley <johnw@newartisans.com>
parents:
37435
diff
changeset
|
747 ; "Send input to a subprocess" |
737e1a913c78
Disabled a test that often yields false failures.
John Wiegley <johnw@newartisans.com>
parents:
37435
diff
changeset
|
748 ; ;; jww (1999-12-06): what about when bc is unavailable? |
737e1a913c78
Disabled a test that often yields false failures.
John Wiegley <johnw@newartisans.com>
parents:
37435
diff
changeset
|
749 ; (if (not (eshell-search-path "bc")) |
737e1a913c78
Disabled a test that often yields false failures.
John Wiegley <johnw@newartisans.com>
parents:
37435
diff
changeset
|
750 ; t |
737e1a913c78
Disabled a test that often yields false failures.
John Wiegley <johnw@newartisans.com>
parents:
37435
diff
changeset
|
751 ; (eshell-insert-command "bc") |
737e1a913c78
Disabled a test that often yields false failures.
John Wiegley <johnw@newartisans.com>
parents:
37435
diff
changeset
|
752 ; (eshell-insert-command "1 + 2") |
737e1a913c78
Disabled a test that often yields false failures.
John Wiegley <johnw@newartisans.com>
parents:
37435
diff
changeset
|
753 ; (sit-for 1 0) |
737e1a913c78
Disabled a test that often yields false failures.
John Wiegley <johnw@newartisans.com>
parents:
37435
diff
changeset
|
754 ; (forward-line -1) |
737e1a913c78
Disabled a test that often yields false failures.
John Wiegley <johnw@newartisans.com>
parents:
37435
diff
changeset
|
755 ; (prog1 |
737e1a913c78
Disabled a test that often yields false failures.
John Wiegley <johnw@newartisans.com>
parents:
37435
diff
changeset
|
756 ; (looking-at "3\n") |
737e1a913c78
Disabled a test that often yields false failures.
John Wiegley <johnw@newartisans.com>
parents:
37435
diff
changeset
|
757 ; (eshell-insert-command "quit") |
737e1a913c78
Disabled a test that often yields false failures.
John Wiegley <johnw@newartisans.com>
parents:
37435
diff
changeset
|
758 ; (sit-for 1 0)))) |
29870 | 759 |
760 (defsubst eshell-kill-new () | |
761 "Add the last input text to the kill ring." | |
762 (kill-ring-save eshell-last-input-start eshell-last-input-end)) | |
763 | |
764 (custom-add-option 'eshell-input-filter-functions 'eshell-kill-new) | |
765 | |
766 (defun eshell-output-filter (process string) | |
767 "Send the output from PROCESS (STRING) to the interactive display. | |
768 This is done after all necessary filtering has been done." | |
769 (let ((oprocbuf (if process (process-buffer process) | |
770 (current-buffer))) | |
771 (inhibit-point-motion-hooks t) | |
772 after-change-functions) | |
773 (let ((functions eshell-preoutput-filter-functions)) | |
774 (while (and functions string) | |
775 (setq string (funcall (car functions) string)) | |
776 (setq functions (cdr functions)))) | |
777 (if (and string oprocbuf (buffer-name oprocbuf)) | |
778 (let ((obuf (current-buffer)) | |
779 opoint obeg oend) | |
780 (set-buffer oprocbuf) | |
781 (setq opoint (point)) | |
782 (setq obeg (point-min)) | |
783 (setq oend (point-max)) | |
784 (let ((buffer-read-only nil) | |
785 (nchars (length string)) | |
786 (ostart nil)) | |
787 (widen) | |
788 (goto-char eshell-last-output-end) | |
789 (setq ostart (point)) | |
790 (if (<= (point) opoint) | |
791 (setq opoint (+ opoint nchars))) | |
792 (if (< (point) obeg) | |
793 (setq obeg (+ obeg nchars))) | |
794 (if (<= (point) oend) | |
795 (setq oend (+ oend nchars))) | |
796 (insert-before-markers string) | |
797 (if (= (window-start (selected-window)) (point)) | |
798 (set-window-start (selected-window) | |
799 (- (point) nchars))) | |
800 (if (= (point) eshell-last-input-end) | |
801 (set-marker eshell-last-input-end | |
802 (- eshell-last-input-end nchars))) | |
803 (set-marker eshell-last-output-start ostart) | |
804 (set-marker eshell-last-output-end (point)) | |
805 (force-mode-line-update)) | |
806 (narrow-to-region obeg oend) | |
807 (goto-char opoint) | |
808 (eshell-run-output-filters) | |
809 (set-buffer obuf))))) | |
810 | |
811 (defun eshell-run-output-filters () | |
812 "Run the `eshell-output-filter-functions' on the current output." | |
813 (save-current-buffer | |
814 (run-hooks 'eshell-output-filter-functions)) | |
815 (setq eshell-last-output-block-begin | |
816 (marker-position eshell-last-output-end))) | |
817 | |
818 ;;; jww (1999-10-23): this needs testing | |
819 (defun eshell-preinput-scroll-to-bottom () | |
820 "Go to the end of buffer in all windows showing it. | |
821 Movement occurs if point in the selected window is not after the | |
822 process mark, and `this-command' is an insertion command. Insertion | |
63513
3a1ff24e79ba
(eshell-preinput-scroll-to-bottom): Fix spelling in docstrings.
Juanma Barranquero <lekktu@gmail.com>
parents:
62760
diff
changeset
|
823 commands recognized are `self-insert-command', `yank', and |
29870 | 824 `hilit-yank'. Depends on the value of |
825 `eshell-scroll-to-bottom-on-input'. | |
826 | |
827 This function should be a pre-command hook." | |
828 (if (memq this-command '(self-insert-command yank hilit-yank)) | |
829 (let* ((selected (selected-window)) | |
830 (current (current-buffer)) | |
831 (scroll eshell-scroll-to-bottom-on-input)) | |
832 (if (< (point) eshell-last-output-end) | |
833 (if (eq scroll 'this) | |
834 (goto-char (point-max)) | |
835 (walk-windows | |
836 (function | |
837 (lambda (window) | |
838 (when (and (eq (window-buffer window) current) | |
839 (or (eq scroll t) (eq scroll 'all))) | |
840 (select-window window) | |
841 (goto-char (point-max)) | |
842 (select-window selected)))) | |
843 nil t)))))) | |
844 | |
845 ;;; jww (1999-10-23): this needs testing | |
846 (defun eshell-postoutput-scroll-to-bottom () | |
847 "Go to the end of buffer in all windows showing it. | |
848 Does not scroll if the current line is the last line in the buffer. | |
849 Depends on the value of `eshell-scroll-to-bottom-on-output' and | |
850 `eshell-scroll-show-maximum-output'. | |
851 | |
852 This function should be in the list `eshell-output-filter-functions'." | |
853 (let* ((selected (selected-window)) | |
854 (current (current-buffer)) | |
855 (scroll eshell-scroll-to-bottom-on-output)) | |
856 (unwind-protect | |
857 (walk-windows | |
858 (function | |
859 (lambda (window) | |
860 (if (eq (window-buffer window) current) | |
861 (progn | |
862 (select-window window) | |
863 (if (and (< (point) eshell-last-output-end) | |
864 (or (eq scroll t) (eq scroll 'all) | |
865 ;; Maybe user wants point to jump to end. | |
866 (and (eq scroll 'this) | |
867 (eq selected window)) | |
868 (and (eq scroll 'others) | |
869 (not (eq selected window))) | |
870 ;; If point was at the end, keep it at end. | |
871 (>= (point) eshell-last-output-start))) | |
872 (goto-char eshell-last-output-end)) | |
873 ;; Optionally scroll so that the text | |
874 ;; ends at the bottom of the window. | |
875 (if (and eshell-scroll-show-maximum-output | |
876 (>= (point) eshell-last-output-end)) | |
877 (save-excursion | |
878 (goto-char (point-max)) | |
879 (recenter -1))) | |
880 (select-window selected))))) | |
881 nil t) | |
882 (set-buffer current)))) | |
883 | |
884 (defun eshell-beginning-of-input () | |
885 "Return the location of the start of the previous input." | |
886 eshell-last-input-start) | |
887 | |
888 (defun eshell-beginning-of-output () | |
889 "Return the location of the end of the previous output block." | |
890 eshell-last-input-end) | |
891 | |
892 (defun eshell-end-of-output () | |
893 "Return the location of the end of the previous output block." | |
894 (if (eshell-using-module 'eshell-prompt) | |
895 eshell-last-output-start | |
896 eshell-last-output-end)) | |
897 | |
898 (defun eshell-kill-output () | |
899 "Kill all output from interpreter since last input. | |
900 Does not delete the prompt." | |
901 (interactive) | |
902 (save-excursion | |
903 (goto-char (eshell-beginning-of-output)) | |
904 (insert "*** output flushed ***\n") | |
905 (delete-region (point) (eshell-end-of-output)))) | |
906 | |
907 (eshell-deftest io flush-output | |
908 "Flush previous output" | |
909 (eshell-insert-command "echo alpha") | |
910 (eshell-kill-output) | |
911 (and (eshell-match-result (regexp-quote "*** output flushed ***\n")) | |
912 (forward-line) | |
913 (= (point) eshell-last-output-start))) | |
914 | |
915 (defun eshell-show-output (&optional arg) | |
916 "Display start of this batch of interpreter output at top of window. | |
917 Sets mark to the value of point when this command is run. | |
918 With a prefix argument, narrows region to last command output." | |
919 (interactive "P") | |
920 (goto-char (eshell-beginning-of-output)) | |
921 (set-window-start (selected-window) | |
922 (save-excursion | |
923 (goto-char (eshell-beginning-of-input)) | |
924 (line-beginning-position))) | |
925 (if arg | |
926 (narrow-to-region (eshell-beginning-of-output) | |
927 (eshell-end-of-output))) | |
928 (eshell-end-of-output)) | |
929 | |
930 (defun eshell-mark-output (&optional arg) | |
931 "Display start of this batch of interpreter output at top of window. | |
932 Sets mark to the value of point when this command is run. | |
933 With a prefix argument, narrows region to last command output." | |
934 (interactive "P") | |
935 (push-mark (eshell-show-output arg))) | |
936 | |
937 (defun eshell-kill-input () | |
938 "Kill all text from last stuff output by interpreter to point." | |
939 (interactive) | |
940 (if (> (point) eshell-last-output-end) | |
941 (kill-region eshell-last-output-end (point)) | |
942 (let ((here (point))) | |
943 (eshell-bol) | |
944 (kill-region (point) here)))) | |
945 | |
57929
7cab04dc2b65
(eshell-show-maximum-output): Don't use interactive-p.
Richard M. Stallman <rms@gnu.org>
parents:
53870
diff
changeset
|
946 (defun eshell-show-maximum-output (&optional interactive) |
7cab04dc2b65
(eshell-show-maximum-output): Don't use interactive-p.
Richard M. Stallman <rms@gnu.org>
parents:
53870
diff
changeset
|
947 "Put the end of the buffer at the bottom of the window. |
7cab04dc2b65
(eshell-show-maximum-output): Don't use interactive-p.
Richard M. Stallman <rms@gnu.org>
parents:
53870
diff
changeset
|
948 When run interactively, widen the buffer first." |
7cab04dc2b65
(eshell-show-maximum-output): Don't use interactive-p.
Richard M. Stallman <rms@gnu.org>
parents:
53870
diff
changeset
|
949 (interactive "p") |
7cab04dc2b65
(eshell-show-maximum-output): Don't use interactive-p.
Richard M. Stallman <rms@gnu.org>
parents:
53870
diff
changeset
|
950 (if interactive |
29870 | 951 (widen)) |
952 (goto-char (point-max)) | |
953 (recenter -1)) | |
954 | |
955 (defun eshell-get-old-input (&optional use-current-region) | |
956 "Return the command input on the current line." | |
957 (if use-current-region | |
958 (buffer-substring (min (point) (mark)) | |
959 (max (point) (mark))) | |
960 (save-excursion | |
961 (beginning-of-line) | |
962 (and eshell-skip-prompt-function | |
963 (funcall eshell-skip-prompt-function)) | |
964 (let ((beg (point))) | |
965 (end-of-line) | |
966 (buffer-substring beg (point)))))) | |
967 | |
968 (defun eshell-copy-old-input () | |
969 "Insert after prompt old input at point as new input to be edited." | |
970 (interactive) | |
971 (let ((input (eshell-get-old-input))) | |
972 (goto-char eshell-last-output-end) | |
973 (insert-and-inherit input))) | |
974 | |
975 (eshell-deftest mode run-old-command | |
976 "Re-run an old command" | |
977 (eshell-insert-command "echo alpha") | |
978 (goto-char eshell-last-input-start) | |
979 (string= (eshell-get-old-input) "echo alpha")) | |
980 | |
981 (defun eshell/exit () | |
982 "Leave or kill the Eshell buffer, depending on `eshell-kill-on-exit'." | |
983 (throw 'eshell-terminal t)) | |
984 | |
985 (defun eshell-life-is-too-much () | |
986 "Kill the current buffer (or bury it). Good-bye Eshell." | |
987 (interactive) | |
988 (if (not eshell-kill-on-exit) | |
989 (bury-buffer) | |
990 (kill-buffer (current-buffer)))) | |
991 | |
992 (defun eshell-truncate-buffer () | |
993 "Truncate the buffer to `eshell-buffer-maximum-lines'. | |
994 This function could be on `eshell-output-filter-functions' or bound to | |
995 a key." | |
996 (interactive) | |
997 (save-excursion | |
998 (goto-char eshell-last-output-end) | |
999 (let ((lines (count-lines 1 (point))) | |
1000 (inhibit-read-only t)) | |
1001 (forward-line (- eshell-buffer-maximum-lines)) | |
1002 (beginning-of-line) | |
1003 (let ((pos (point))) | |
1004 (if (bobp) | |
1005 (if (interactive-p) | |
57929
7cab04dc2b65
(eshell-show-maximum-output): Don't use interactive-p.
Richard M. Stallman <rms@gnu.org>
parents:
53870
diff
changeset
|
1006 (message "Buffer too short to truncate")) |
29870 | 1007 (delete-region (point-min) (point)) |
1008 (if (interactive-p) | |
1009 (message "Truncated buffer from %d to %d lines (%.1fk freed)" | |
1010 lines eshell-buffer-maximum-lines | |
1011 (/ pos 1024.0)))))))) | |
1012 | |
1013 (custom-add-option 'eshell-output-filter-functions | |
1014 'eshell-truncate-buffer) | |
1015 | |
38438
7b528c6c17a3
(eshell-send-invisible): Renamed from
Gerd Moellmann <gerd@gnu.org>
parents:
38414
diff
changeset
|
1016 (defun eshell-send-invisible (str) |
29870 | 1017 "Read a string without echoing. |
1018 Then send it to the process running in the current buffer." | |
1019 (interactive "P") ; Defeat snooping via C-x ESC ESC | |
1020 (let ((str (read-passwd | |
53870
94735a7620dd
(eshell-send-invisible): Fix format string.
Andreas Schwab <schwab@suse.de>
parents:
52401
diff
changeset
|
1021 (format "%s Password: " |
29870 | 1022 (process-name (eshell-interactive-process)))))) |
1023 (if (stringp str) | |
1024 (process-send-string (eshell-interactive-process) | |
1025 (concat str "\n")) | |
1026 (message "Warning: text will be echoed")))) | |
1027 | |
1028 (defun eshell-watch-for-password-prompt () | |
1029 "Prompt in the minibuffer for password and send without echoing. | |
38438
7b528c6c17a3
(eshell-send-invisible): Renamed from
Gerd Moellmann <gerd@gnu.org>
parents:
38414
diff
changeset
|
1030 This function uses `eshell-send-invisible' to read and send a password to the |
29870 | 1031 buffer's process if STRING contains a password prompt defined by |
1032 `eshell-password-prompt-regexp'. | |
1033 | |
1034 This function could be in the list `eshell-output-filter-functions'." | |
1035 (when (eshell-interactive-process) | |
1036 (save-excursion | |
1037 (goto-char eshell-last-output-block-begin) | |
1038 (beginning-of-line) | |
1039 (if (re-search-forward eshell-password-prompt-regexp | |
1040 eshell-last-output-end t) | |
38438
7b528c6c17a3
(eshell-send-invisible): Renamed from
Gerd Moellmann <gerd@gnu.org>
parents:
38414
diff
changeset
|
1041 (eshell-send-invisible nil))))) |
29870 | 1042 |
1043 (custom-add-option 'eshell-output-filter-functions | |
1044 'eshell-watch-for-password-prompt) | |
1045 | |
1046 (defun eshell-handle-control-codes () | |
1047 "Act properly when certain control codes are seen." | |
1048 (save-excursion | |
1049 (let ((orig (point))) | |
1050 (goto-char eshell-last-output-block-begin) | |
1051 (unless (eolp) | |
1052 (beginning-of-line)) | |
1053 (while (< (point) eshell-last-output-end) | |
1054 (let ((char (char-after))) | |
1055 (cond | |
1056 ((eq char ?\r) | |
1057 (if (< (1+ (point)) eshell-last-output-end) | |
1058 (if (memq (char-after (1+ (point))) | |
1059 '(?\n ?\r)) | |
1060 (delete-char 1) | |
1061 (let ((end (1+ (point)))) | |
1062 (beginning-of-line) | |
1063 (delete-region (point) end))) | |
1064 (add-text-properties (point) (1+ (point)) | |
1065 '(invisible t)) | |
1066 (forward-char))) | |
1067 ((eq char ?\a) | |
1068 (delete-char 1) | |
1069 (beep)) | |
1070 ((eq char ?\C-h) | |
1071 (delete-backward-char 1) | |
1072 (delete-char 1)) | |
1073 (t | |
1074 (forward-char)))))))) | |
1075 | |
1076 (custom-add-option 'eshell-output-filter-functions | |
1077 'eshell-handle-control-codes) | |
1078 | |
76468
b32293a2b36f
eshell ansi-color hook
Mark A. Hershberger <mah@everybody.org>
parents:
75346
diff
changeset
|
1079 (defun eshell-handle-ansi-color () |
b32293a2b36f
eshell ansi-color hook
Mark A. Hershberger <mah@everybody.org>
parents:
75346
diff
changeset
|
1080 "Handle ANSI color codes." |
b32293a2b36f
eshell ansi-color hook
Mark A. Hershberger <mah@everybody.org>
parents:
75346
diff
changeset
|
1081 (require 'ansi-color) |
b32293a2b36f
eshell ansi-color hook
Mark A. Hershberger <mah@everybody.org>
parents:
75346
diff
changeset
|
1082 (ansi-color-apply-on-region eshell-last-output-start |
b32293a2b36f
eshell ansi-color hook
Mark A. Hershberger <mah@everybody.org>
parents:
75346
diff
changeset
|
1083 eshell-last-output-end)) |
b32293a2b36f
eshell ansi-color hook
Mark A. Hershberger <mah@everybody.org>
parents:
75346
diff
changeset
|
1084 |
b32293a2b36f
eshell ansi-color hook
Mark A. Hershberger <mah@everybody.org>
parents:
75346
diff
changeset
|
1085 (custom-add-option 'eshell-output-filter-functions |
b32293a2b36f
eshell ansi-color hook
Mark A. Hershberger <mah@everybody.org>
parents:
75346
diff
changeset
|
1086 'eshell-handle-ansi-color) |
b32293a2b36f
eshell ansi-color hook
Mark A. Hershberger <mah@everybody.org>
parents:
75346
diff
changeset
|
1087 |
29870 | 1088 ;;; Code: |
1089 | |
52401 | 1090 ;;; arch-tag: ec65bc2b-da14-4547-81d3-a32af3a4dc57 |
29870 | 1091 ;;; esh-mode.el ends here |