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