| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 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 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
(require 'esh-module) |
|---|
| 72 |
(require 'esh-cmd) |
|---|
| 73 |
(require 'esh-io) |
|---|
| 74 |
(require 'esh-var) |
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 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 |
|---|
| 168 |
'(eshell-postoutput-scroll-to-bottom |
|---|
| 169 |
eshell-handle-control-codes |
|---|
| 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 |
|---|
| 185 |
"[Pp]ass\\(word\\|phrase\\).*:\\s *\\'" |
|---|
| 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." |
|---|
| 193 |
:type '(choice (const nil) function) |
|---|
| 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 |
|
|---|
| 205 |
|
|---|
| 206 |
|
|---|
| 207 |
|
|---|
| 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 |
|
|---|
| 253 |
(modify-syntax-entry ?\^m "> " eshell-mode-syntax-table) |
|---|
| 254 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 292 |
|
|---|
| 293 |
|
|---|
| 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) |
|---|
| 310 |
(let ((fmt (copy-sequence mode-line-format))) |
|---|
| 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 |
|
|---|
| 331 |
|
|---|
| 332 |
|
|---|
| 333 |
(if (eq (key-binding [(meta ?.)]) 'find-tag) |
|---|
| 334 |
(define-key eshell-mode-map [(meta ?.)] 'eshell-find-tag)) |
|---|
| 335 |
(define-key eshell-command-map [(meta ?o)] 'eshell-mark-output) |
|---|
| 336 |
(define-key eshell-command-map [(meta ?d)] 'eshell-toggle-direct-send) |
|---|
| 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) |
|---|
| 349 |
(define-key eshell-command-map [(control ?y)] 'eshell-repeat-argument) |
|---|
| 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 |
|
|---|
| 359 |
|
|---|
| 360 |
(set (make-local-variable 'tab-width) 8) |
|---|
| 361 |
|
|---|
| 362 |
|
|---|
| 363 |
(setq auto-fill-function nil) |
|---|
| 364 |
|
|---|
| 365 |
|
|---|
| 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 |
|
|---|
| 372 |
|
|---|
| 373 |
|
|---|
| 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 |
|
|---|
| 387 |
(let ((modules-list (copy-sequence eshell-modules-list))) |
|---|
| 388 |
(make-local-variable 'eshell-modules-list) |
|---|
| 389 |
(setq eshell-modules-list modules-list)) |
|---|
| 390 |
|
|---|
| 391 |
|
|---|
| 392 |
|
|---|
| 393 |
|
|---|
| 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 |
|
|---|
| 409 |
(eshell-for module (eshell-subgroups 'eshell) |
|---|
| 410 |
(run-hooks (intern-soft (concat (symbol-name module) |
|---|
| 411 |
"-load-hook")))) |
|---|
| 412 |
|
|---|
| 413 |
|
|---|
| 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 |
|
|---|
| 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)) |
|---|
| 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)) |
|---|
| 440 |
(run-mode-hooks 'eshell-mode-hook) |
|---|
| 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" |
|---|
| 455 |
(let ((eshell-stringify-t t)) |
|---|
| 456 |
(eshell-command-result-p "= $LINES (window-height)" "t\n"))) |
|---|
| 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 |
|
|---|
| 476 |
|
|---|
| 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 |
|
|---|
| 504 |
|
|---|
| 505 |
|
|---|
| 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 |
|
|---|
| 515 |
(defun eshell-find-tag (&optional tagname next-p regexp-p) |
|---|
| 516 |
"A special version of `find-tag' that ignores read-onlyness." |
|---|
| 517 |
(interactive) |
|---|
| 518 |
(require 'etags) |
|---|
| 519 |
(let ((inhibit-read-only t) |
|---|
| 520 |
(no-default (eobp)) |
|---|
| 521 |
(find-tag-default-function 'ignore)) |
|---|
| 522 |
(with-no-warnings |
|---|
| 523 |
(setq tagname (car (find-tag-interactive "Find tag: ")))) |
|---|
| 524 |
(find-tag tagname next-p regexp-p))) |
|---|
| 525 |
|
|---|
| 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))) |
|---|
| 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)))) |
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 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." |
|---|
| 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))) |
|---|
| 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) |
|---|
| 669 |
"Send the input received to Eshell for parsing and processing. |
|---|
| 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 |
|
|---|
| 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))) |
|---|
| 698 |
(unless (or no-newline |
|---|
| 699 |
(and eshell-send-direct-to-subprocesses |
|---|
| 700 |
proc-running-p)) |
|---|
| 701 |
(insert-before-markers-and-inherit ?\n)) |
|---|
| 702 |
(if proc-running-p |
|---|
| 703 |
(progn |
|---|
| 704 |
(eshell-update-markers eshell-last-output-end) |
|---|
| 705 |
(if (or eshell-send-direct-to-subprocesses |
|---|
| 706 |
(= eshell-last-input-start eshell-last-input-end)) |
|---|
| 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 |
|---|
| 731 |
(if (eshell-invoke-directly cmd input) |
|---|
| 732 |
(eval cmd) |
|---|
| 733 |
(eshell-eval-command cmd input)))) |
|---|
| 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 |
|
|---|
| 746 |
|
|---|
| 747 |
|
|---|
| 748 |
|
|---|
| 749 |
|
|---|
| 750 |
|
|---|
| 751 |
|
|---|
| 752 |
|
|---|
| 753 |
|
|---|
| 754 |
|
|---|
| 755 |
|
|---|
| 756 |
|
|---|
| 757 |
|
|---|
| 758 |
|
|---|
| 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 (opoint obeg oend) |
|---|
| 779 |
(with-current-buffer oprocbuf |
|---|
| 780 |
(setq opoint (point)) |
|---|
| 781 |
(setq obeg (point-min)) |
|---|
| 782 |
(setq oend (point-max)) |
|---|
| 783 |
(let ((buffer-read-only nil) |
|---|
| 784 |
(nchars (length string)) |
|---|
| 785 |
(ostart nil)) |
|---|
| 786 |
(widen) |
|---|
| 787 |
(goto-char eshell-last-output-end) |
|---|
| 788 |
(setq ostart (point)) |
|---|
| 789 |
(if (<= (point) opoint) |
|---|
| 790 |
(setq opoint (+ opoint nchars))) |
|---|
| 791 |
(if (< (point) obeg) |
|---|
| 792 |
(setq obeg (+ obeg nchars))) |
|---|
| 793 |
(if (<= (point) oend) |
|---|
| 794 |
(setq oend (+ oend nchars))) |
|---|
| 795 |
(insert-before-markers string) |
|---|
| 796 |
(if (= (window-start (selected-window)) (point)) |
|---|
| 797 |
(set-window-start (selected-window) |
|---|
| 798 |
(- (point) nchars))) |
|---|
| 799 |
(if (= (point) eshell-last-input-end) |
|---|
| 800 |
(set-marker eshell-last-input-end |
|---|
| 801 |
(- eshell-last-input-end nchars))) |
|---|
| 802 |
(set-marker eshell-last-output-start ostart) |
|---|
| 803 |
(set-marker eshell-last-output-end (point)) |
|---|
| 804 |
(force-mode-line-update)) |
|---|
| 805 |
(narrow-to-region obeg oend) |
|---|
| 806 |
(goto-char opoint) |
|---|
| 807 |
(eshell-run-output-filters)))))) |
|---|
| 808 |
|
|---|
| 809 |
(defun eshell-run-output-filters () |
|---|
| 810 |
"Run the `eshell-output-filter-functions' on the current output." |
|---|
| 811 |
(save-current-buffer |
|---|
| 812 |
(run-hooks 'eshell-output-filter-functions)) |
|---|
| 813 |
(setq eshell-last-output-block-begin |
|---|
| 814 |
(marker-position eshell-last-output-end))) |
|---|
| 815 |
|
|---|
| 816 |
|
|---|
| 817 |
(defun eshell-preinput-scroll-to-bottom () |
|---|
| 818 |
"Go to the end of buffer in all windows showing it. |
|---|
| 819 |
Movement occurs if point in the selected window is not after the |
|---|
| 820 |
process mark, and `this-command' is an insertion command. Insertion |
|---|
| 821 |
commands recognized are `self-insert-command', `yank', and |
|---|
| 822 |
`hilit-yank'. Depends on the value of |
|---|
| 823 |
`eshell-scroll-to-bottom-on-input'. |
|---|
| 824 |
|
|---|
| 825 |
This function should be a pre-command hook." |
|---|
| 826 |
(if (memq this-command '(self-insert-command yank hilit-yank)) |
|---|
| 827 |
(let* ((selected (selected-window)) |
|---|
| 828 |
(current (current-buffer)) |
|---|
| 829 |
(scroll eshell-scroll-to-bottom-on-input)) |
|---|
| 830 |
(if (< (point) eshell-last-output-end) |
|---|
| 831 |
(if (eq scroll 'this) |
|---|
| 832 |
(goto-char (point-max)) |
|---|
| 833 |
(walk-windows |
|---|
| 834 |
(function |
|---|
| 835 |
(lambda (window) |
|---|
| 836 |
(when (and (eq (window-buffer window) current) |
|---|
| 837 |
(or (eq scroll t) (eq scroll 'all))) |
|---|
| 838 |
(select-window window) |
|---|
| 839 |
(goto-char (point-max)) |
|---|
| 840 |
(select-window selected)))) |
|---|
| 841 |
nil t)))))) |
|---|
| 842 |
|
|---|
| 843 |
|
|---|
| 844 |
(defun eshell-postoutput-scroll-to-bottom () |
|---|
| 845 |
"Go to the end of buffer in all windows showing it. |
|---|
| 846 |
Does not scroll if the current line is the last line in the buffer. |
|---|
| 847 |
Depends on the value of `eshell-scroll-to-bottom-on-output' and |
|---|
| 848 |
`eshell-scroll-show-maximum-output'. |
|---|
| 849 |
|
|---|
| 850 |
This function should be in the list `eshell-output-filter-functions'." |
|---|
| 851 |
(let* ((selected (selected-window)) |
|---|
| 852 |
(current (current-buffer)) |
|---|
| 853 |
(scroll eshell-scroll-to-bottom-on-output)) |
|---|
| 854 |
(unwind-protect |
|---|
| 855 |
(walk-windows |
|---|
| 856 |
(function |
|---|
| 857 |
(lambda (window) |
|---|
| 858 |
(if (eq (window-buffer window) current) |
|---|
| 859 |
(progn |
|---|
| 860 |
(select-window window) |
|---|
| 861 |
(if (and (< (point) eshell-last-output-end) |
|---|
| 862 |
(or (eq scroll t) (eq scroll 'all) |
|---|
| 863 |
|
|---|
| 864 |
(and (eq scroll 'this) |
|---|
| 865 |
(eq selected window)) |
|---|
| 866 |
(and (eq scroll 'others) |
|---|
| 867 |
(not (eq selected window))) |
|---|
| 868 |
|
|---|
|