Mercurial > emacs
annotate lisp/eshell/em-smart.el @ 32889:673e3ef1f7f6
(where_is_cache, where_is_cache_keymaps): New vars.
(Fset_keymap_parent, store_in_keymap): Flush the where-is cache.
(where_is_internal): Renamed from Fwhere_is_internal.
Don't DEFUN any more. Arg `xkeymap' replaced by `keymaps'.
(Fwhere_is_internal): New function wrapping where_is_internal.
(where_is_internal_1): Handle the case where we're filling the cache.
(syms_of_keymap): Init and gcpro the where_is_cache(|_keymaps).
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Wed, 25 Oct 2000 23:35:21 +0000 |
parents | 8e57189d61b4 |
children | e21feeab77fb |
rev | line source |
---|---|
29876 | 1 ;;; em-smart --- smart display of output |
2 | |
29934
34b1ab9d583d
Change spelling of the Free Software Foundation.
Gerd Moellmann <gerd@gnu.org>
parents:
29876
diff
changeset
|
3 ;; Copyright (C) 1999, 2000 Free Software Foundation |
29876 | 4 |
32526 | 5 ;; Author: John Wiegley <johnw@gnu.org> |
6 | |
29876 | 7 ;; This file is part of GNU Emacs. |
8 | |
9 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
10 ;; it under the terms of the GNU General Public License as published by | |
11 ;; the Free Software Foundation; either version 2, or (at your option) | |
12 ;; any later version. | |
13 | |
14 ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
22 ;; Boston, MA 02111-1307, USA. | |
23 | |
24 (provide 'em-smart) | |
25 | |
26 (eval-when-compile (require 'esh-maint)) | |
27 | |
28 (defgroup eshell-smart nil | |
29 "This module combines the facility of normal, modern shells with | |
30 some of the edit/review concepts inherent in the design of Plan 9's | |
31 9term. See the docs for more details. | |
32 | |
33 Most likely you will have to turn this option on and play around with | |
34 it to get a real sense of how it works." | |
35 :tag "Smart display of output" | |
30273
dad74ad87ac2
(eshell-smart): Replace links to eshell.info with
Eli Zaretskii <eliz@gnu.org>
parents:
29934
diff
changeset
|
36 :link '(info-link "(eshell)Smart display of output") |
29876 | 37 :group 'eshell-module) |
38 | |
39 ;;; Commentary: | |
40 | |
41 ;; The best way to get a sense of what this code is trying to do is by | |
42 ;; using it. Basically, the philosophy represents a blend between the | |
43 ;; ease of use of modern day shells, and the review-before-you-proceed | |
44 ;; mentality of Plan 9's 9term. | |
45 ;; | |
46 ;; @ When you invoke a command, it is assumed that you want to read | |
47 ;; the output of that command. | |
48 ;; | |
49 ;; @ If the output is not what you wanted, it is assumed that you will | |
50 ;; want to edit, and then resubmit a refined version of that | |
51 ;; command. | |
52 ;; | |
53 ;; @ If the output is valid, pressing any self-inserting character key | |
54 ;; will jump to end of the buffer and insert that character, in | |
55 ;; order to begin entry of a new command. | |
56 ;; | |
57 ;; @ If you show an intention to edit the previous command -- by | |
58 ;; moving around within it -- then the next self-inserting | |
59 ;; characters will insert *there*, instead of at the bottom of the | |
60 ;; buffer. | |
61 ;; | |
62 ;; @ If you show an intention to review old commands, such as M-p or | |
63 ;; M-r, point will jump to the bottom of the buffer before invoking | |
64 ;; that command. | |
65 ;; | |
66 ;; @ If none of the above has happened yet (i.e., your point is just | |
67 ;; sitting on the previous command), you can use SPACE and BACKSPACE | |
68 ;; (or DELETE) to page forward and backward *through the output of | |
69 ;; the last command only*. It will constrain the movement of the | |
70 ;; point and window so that the maximum amount of output is always | |
71 ;; displayed at all times. | |
72 ;; | |
73 ;; @ While output is being generated from a command, the window will | |
74 ;; be constantly reconfigured (until it would otherwise make no | |
75 ;; difference) in order to always show you the most output from the | |
76 ;; command possible. This happens if you change window sizes, | |
77 ;; scroll, etc. | |
78 ;; | |
79 ;; @ Like I said, it's not really comprehensible until you try it! ;) | |
80 | |
81 ;;; User Variables: | |
82 | |
83 (defcustom eshell-smart-load-hook '(eshell-smart-initialize) | |
84 "*A list of functions to call when loading `eshell-smart'." | |
85 :type 'hook | |
86 :group 'eshell-smart) | |
87 | |
88 (defcustom eshell-smart-unload-hook | |
89 (list | |
90 (function | |
91 (lambda () | |
92 (remove-hook 'window-configuration-change-hook | |
93 'eshell-refresh-windows)))) | |
94 "*A hook that gets run when `eshell-smart' is unloaded." | |
95 :type 'hook | |
96 :group 'eshell-smart) | |
97 | |
98 (defcustom eshell-review-quick-commands nil | |
31240 | 99 "*If t, always review commands. |
100 Reviewing means keeping point on the text of the command that was just | |
101 invoked, to allow corrections to be made easily. | |
102 | |
103 If set to nil, quick commands won't be reviewed. A quick command is a | |
104 command that produces no output, and exits successfully. | |
105 | |
106 If set to `not-even-short-output', then the definition of \"quick | |
107 command\" is extended to include commands that produce output, iff | |
108 that output can be presented in its entirely in the Eshell window." | |
109 :type '(choice (const :tag "No" nil) | |
110 (const :tag "Yes" t) | |
111 (const :tag "Not even short output" | |
112 not-even-short-output)) | |
29876 | 113 :group 'eshell-smart) |
114 | |
115 (defcustom eshell-smart-display-navigate-list | |
116 '(insert-parentheses | |
117 mouse-yank-at-click | |
118 mouse-yank-secondary | |
119 yank-pop | |
120 yank-rectangle | |
121 yank) | |
122 "*A list of commands which cause Eshell to jump to the end of buffer." | |
123 :type '(repeat function) | |
124 :group 'eshell-smart) | |
125 | |
126 (defcustom eshell-smart-space-goes-to-end t | |
127 "*If non-nil, space will go to end of buffer when point-max is visible. | |
128 That is, if a command is running and the user presses SPACE at a time | |
129 when the end of the buffer is visible, point will go to the end of the | |
130 buffer and smart-display will be turned off (that is, subsequently | |
131 pressing backspace will not cause the buffer to scroll down). | |
132 | |
133 This feature is provided to make it very easy to watch the output of a | |
134 long-running command, such as make, where it's more desirable to see | |
135 the output go by than to review it afterward. | |
136 | |
137 Setting this variable to nil means that space and backspace will | |
138 always have a consistent behavior, which is to move back and forth | |
139 through displayed output. But it also means that enabling output | |
140 tracking requires the user to manually move point to the end of the | |
141 buffer using \\[end-of-buffer]." | |
142 :type 'boolean | |
143 :group 'eshell-smart) | |
144 | |
145 (defcustom eshell-where-to-jump 'begin | |
146 "*This variable indicates where point should jump to after a command. | |
147 The options are `begin', `after' or `end'." | |
148 :type '(radio (const :tag "Beginning of command" begin) | |
149 (const :tag "After command word" after) | |
150 (const :tag "End of command" end)) | |
151 :group 'eshell-smart) | |
152 | |
153 ;;; Internal Variables: | |
154 | |
155 (defvar eshell-smart-displayed nil) | |
156 (defvar eshell-smart-command-done nil) | |
157 | |
158 ;;; Functions: | |
159 | |
160 (defun eshell-smart-initialize () | |
161 "Setup Eshell smart display." | |
162 (unless eshell-non-interactive-p | |
163 ;; override a few variables, since they would interfere with the | |
164 ;; smart display functionality. | |
165 (set (make-local-variable 'eshell-scroll-to-bottom-on-output) nil) | |
166 (set (make-local-variable 'eshell-scroll-to-bottom-on-input) nil) | |
167 (set (make-local-variable 'eshell-scroll-show-maximum-output) t) | |
168 | |
169 (make-local-hook 'window-scroll-functions) | |
170 (add-hook 'window-scroll-functions 'eshell-smart-scroll-window nil t) | |
171 (add-hook 'window-configuration-change-hook 'eshell-refresh-windows) | |
172 | |
173 (make-local-hook 'eshell-output-filter-functions) | |
174 (add-hook 'eshell-output-filter-functions 'eshell-refresh-windows t t) | |
175 | |
176 (make-local-hook 'pre-command-hook) | |
177 (make-local-hook 'after-change-functions) | |
178 (add-hook 'after-change-functions | |
179 'eshell-disable-after-change nil t) | |
180 | |
181 (make-local-hook 'eshell-input-filter-functions) | |
182 (add-hook 'eshell-input-filter-functions | |
183 'eshell-smart-display-setup nil t) | |
184 | |
185 (make-local-variable 'eshell-smart-command-done) | |
186 (make-local-hook 'eshell-post-command-hook) | |
187 (add-hook 'eshell-post-command-hook | |
188 (function | |
189 (lambda () | |
190 (setq eshell-smart-command-done t))) t t) | |
191 | |
31240 | 192 (unless (eq eshell-review-quick-commands t) |
29876 | 193 (add-hook 'eshell-post-command-hook |
194 'eshell-smart-maybe-jump-to-end nil t)))) | |
195 | |
196 (defun eshell-smart-scroll-window (wind start) | |
197 "Scroll the given Eshell window accordingly." | |
198 (unless eshell-currently-handling-window | |
199 (let ((inhibit-point-motion-hooks t) | |
200 (eshell-currently-handling-window t)) | |
201 (save-current-buffer | |
202 (save-selected-window | |
203 (select-window wind) | |
204 (eshell-smart-redisplay)))))) | |
205 | |
206 (defun eshell-refresh-windows (&optional frame) | |
207 "Refresh all visible Eshell buffers." | |
208 (let (affected) | |
209 (walk-windows | |
210 (function | |
211 (lambda (wind) | |
212 (with-current-buffer (window-buffer wind) | |
213 (when eshell-mode | |
214 (let (window-scroll-functions) | |
215 (eshell-smart-scroll-window wind (window-start)) | |
216 (setq affected t)))))) | |
217 0 frame) | |
218 (if affected | |
219 (let (window-scroll-functions) | |
220 (eshell-redisplay))))) | |
221 | |
222 (defun eshell-smart-display-setup () | |
223 "Set the point to somewhere in the beginning of the last command." | |
224 (cond | |
225 ((eq eshell-where-to-jump 'begin) | |
226 (goto-char eshell-last-input-start)) | |
227 ((eq eshell-where-to-jump 'after) | |
228 (goto-char (next-single-property-change | |
229 eshell-last-input-start 'arg-end)) | |
230 (if (= (point) (- eshell-last-input-end 2)) | |
231 (forward-char))) | |
232 ((eq eshell-where-to-jump 'end) | |
233 (goto-char (1- eshell-last-input-end))) | |
234 (t | |
235 (error "Invalid value for `eshell-where-to-jump'"))) | |
236 (setq eshell-smart-command-done nil) | |
237 (add-hook 'pre-command-hook 'eshell-smart-display-move nil t) | |
238 (eshell-refresh-windows)) | |
239 | |
240 (defun eshell-disable-after-change (b e l) | |
241 "Disable smart display mode if the buffer changes in any way." | |
242 (when eshell-smart-command-done | |
243 (remove-hook 'pre-command-hook 'eshell-smart-display-move t) | |
244 (setq eshell-smart-command-done nil))) | |
245 | |
246 (defun eshell-smart-maybe-jump-to-end () | |
247 "Jump to the end of the input buffer. | |
31240 | 248 This is done whenever a command exits sucessfully and both the command |
249 and the end of the buffer are still visible." | |
29876 | 250 (when (and (= eshell-last-command-status 0) |
31240 | 251 (if (eq eshell-review-quick-commands 'not-even-short-output) |
252 (and (pos-visible-in-window-p (point-max)) | |
253 (pos-visible-in-window-p eshell-last-input-start)) | |
254 (= (count-lines eshell-last-input-end | |
255 eshell-last-output-end) 0))) | |
29876 | 256 (goto-char (point-max)) |
257 (remove-hook 'pre-command-hook 'eshell-smart-display-move t))) | |
258 | |
259 (defun eshell-smart-redisplay () | |
260 "Display as much output as possible, smartly." | |
261 (if (eobp) | |
262 (recenter -1) | |
31241 | 263 (let ((top-point (point))) |
264 (and (memq 'eshell-smart-display-move pre-command-hook) | |
265 (>= (point) eshell-last-input-start) | |
266 (< (point) eshell-last-input-end) | |
267 (set-window-start (selected-window) | |
268 (line-beginning-position) t)) | |
269 (if (pos-visible-in-window-p (point-max)) | |
270 (save-excursion | |
271 (goto-char (point-max)) | |
272 (recenter -1) | |
273 (unless (pos-visible-in-window-p top-point) | |
274 (goto-char top-point) | |
275 (set-window-start (selected-window) | |
276 (line-beginning-position) t))))))) | |
29876 | 277 |
278 (defun eshell-smart-goto-end () | |
279 "Like `end-of-buffer', but do not push a mark." | |
280 (interactive) | |
281 (goto-char (point-max))) | |
282 | |
283 (defun eshell-smart-display-move () | |
284 "Handle self-inserting or movement commands intelligently." | |
285 (let (clear) | |
286 (if (or current-prefix-arg | |
287 (and (> (point) eshell-last-input-start) | |
288 (< (point) eshell-last-input-end)) | |
289 (>= (point) eshell-last-output-end)) | |
290 (setq clear t) | |
291 (cond | |
292 ((eq this-command 'self-insert-command) | |
293 (if (eq last-command-char ? ) | |
294 (if (and eshell-smart-space-goes-to-end | |
295 eshell-current-command) | |
296 (if (not (pos-visible-in-window-p (point-max))) | |
297 (setq this-command 'scroll-up) | |
298 (setq this-command 'eshell-smart-goto-end)) | |
299 (setq this-command 'scroll-up)) | |
300 (setq clear t) | |
301 (goto-char (point-max)))) | |
302 ((eq this-command 'delete-backward-char) | |
303 (setq this-command 'ignore) | |
304 (if (< (point) eshell-last-input-start) | |
305 (eshell-show-output) | |
306 (if (pos-visible-in-window-p eshell-last-input-start) | |
307 (progn | |
308 (ignore-errors | |
309 (scroll-down)) | |
310 (eshell-show-output)) | |
311 (scroll-down) | |
312 (if (pos-visible-in-window-p eshell-last-input-end) | |
313 (eshell-show-output))))) | |
314 ((or (memq this-command eshell-smart-display-navigate-list) | |
315 (and (eq this-command 'eshell-send-input) | |
316 (not (and (>= (point) eshell-last-input-start) | |
317 (< (point) eshell-last-input-end))))) | |
318 (setq clear t) | |
319 (goto-char (point-max))))) | |
320 (if clear | |
321 (remove-hook 'pre-command-hook 'eshell-smart-display-move t)))) | |
322 | |
323 ;;; Code: | |
324 | |
325 ;;; em-smart.el ends here |