1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

Be more efficient when buffering output in Eshell

This makes the built-in 'eshell/cat' 5-10x faster on large files in my
(somewhat limited) tests.  In addition, this change periodically
redisplays when using the Eshell buffered output so that users can see
some progress.

* lisp/eshell/esh-io.el (eshell-print-queue-size, eshell-print-queue,
eshell-print-queue-count): Make obsolete in favor of...
(eshell-buffered-print-size, eshell--buffered-print-queue)
(eshell--buffered-print-current-size): ... these.
(eshell-buffered-print-redisplay-throttle): New user option.
(eshell--buffered-print-next-redisplay): New variable.
(eshell-init-print-buffer): Make obsolete.
(eshell-flush): Add new REDISPLAY-NOW argument in favor of CLEAR (which
only 'eshell-init-print-buffer' should have used).
(eshell-buffered-print): Compare queued output length to
'eshell--buffered-print-current-size'.
(eshell-with-buffered-print): New macro.

* lisp/eshell/esh-var.el (eshell/env):
* lisp/eshell/em-dirs.el (eshell/cd):
* lisp/eshell/em-hist.el (eshell/history):
* lisp/eshell/em-unix.el (eshell/cat):
* lisp/eshell/em-ls.el (eshell/ls): Use 'eshell-with-buffered-print'.
(flush-func): Remove.
(eshell-ls--insert-directory, eshell-do-ls): Remove 'flush-func'.

* test/lisp/eshell/em-unix-tests.el (em-unix-test/compile/interactive)
(em-unix-test/compile/pipeline, em-unix-test/compile/subcommand): Fix
indentation.
(em-unix-test/cat/file-output): New test.

* etc/NEWS: Announce these improvements.
This commit is contained in:
Jim Porter 2024-06-03 22:01:48 -07:00
parent c69c822c59
commit 2fac71255f
8 changed files with 143 additions and 77 deletions

View file

@ -26,10 +26,12 @@
(require 'ert)
(require 'em-unix)
(eval-and-compile
(defvar this-directory (file-name-directory
(or load-file-name default-directory))))
(require 'eshell-tests-helpers
(expand-file-name "eshell-tests-helpers"
(file-name-directory (or load-file-name
default-directory))))
(expand-file-name "eshell-tests-helpers" this-directory))
;;; Tests:
@ -37,11 +39,11 @@
"Check that `eshell/compile' opens a compilation buffer interactively."
(skip-unless (executable-find "echo"))
(with-temp-eshell
(eshell-match-command-output "compile echo hello"
"#<buffer \\*compilation\\*>")
(with-current-buffer "*compilation*"
(forward-line 3)
(should (looking-at "echo hello")))))
(eshell-match-command-output "compile echo hello"
"#<buffer \\*compilation\\*>")
(with-current-buffer "*compilation*"
(forward-line 3)
(should (looking-at "echo hello")))))
(ert-deftest em-unix-test/compile/noninteractive ()
"Check that `eshell/compile' writes to stdout noninteractively."
@ -54,15 +56,26 @@
(skip-unless (and (executable-find "echo")
(executable-find "cat")))
(with-temp-eshell
(eshell-match-command-output "compile echo hello | *cat"
"\\`hello\n")))
(eshell-match-command-output "compile echo hello | *cat"
"\\`hello\n")))
(ert-deftest em-unix-test/compile/subcommand ()
"Check that `eshell/compile' writes to stdout from a subcommand."
(skip-unless (and (executable-find "echo")
(executable-find "cat")))
(with-temp-eshell
(eshell-match-command-output "echo ${compile echo hello}"
"\\`hello\n")))
(eshell-match-command-output "echo ${compile echo hello}"
"\\`hello\n")))
(ert-deftest em-unix-test/cat/file-output ()
"Check that `eshell/cat' can print a file's contents."
(with-temp-eshell
(let* ((this-file (expand-file-name "em-unix-tests.el" this-directory))
(contents (save-current-buffer
(find-file this-file)
(buffer-string))))
(eshell-match-command-output
(format "cat '%s'" (string-replace "'" "''" this-file))
(concat (regexp-quote contents))))))
;; em-unix-tests.el ends here