]> git.eshelyaron.com Git - emacs.git/commitdiff
Support 'comint-pager' in Eshell
authorJim Porter <jporterbugs@gmail.com>
Wed, 23 Aug 2023 20:29:19 +0000 (13:29 -0700)
committerJim Porter <jporterbugs@gmail.com>
Wed, 23 Aug 2023 23:46:25 +0000 (16:46 -0700)
* lisp/eshell/esh-var.el (eshell-variable-aliases-list): Add "PAGER".
(eshell-var-initialize): Make 'comint-pager' buffer-local and bind it
in subcommands so that we can temporarily set it as necessary.

* test/lisp/eshell/esh-var-tests.el (esh-var-test/pager-var/default)
(esh-var-test/pager-var/set, esh-var-test/pager-var/unset)
(esh-var-test/pager-var/set-locally): New tests.

* doc/misc/eshell.texi (Variables): Document this (bug#63778).

Co-authored-by: Morgan Smith <Morgan.J.Smith@outlook.com>
doc/misc/eshell.texi
lisp/eshell/esh-var.el
test/lisp/eshell/esh-var-tests.el

index 4897b410b760d582f0d563b2509afd543bc885fe..f8f60bae13a4dc2a5b804989c9df8c23b2617fb0 100644 (file)
@@ -1094,6 +1094,13 @@ necessary.  By default, its value is
 @code{@var{emacs-version},eshell}.  Other parts of Emacs, such as
 Tramp, may add extra information to this value.
 
+@vindex $PAGER
+@item $PAGER
+This variable indicates the pager that commands should use when they
+wish to paginate long output.  Its value is that of
+@code{comint-pager} if non-@code{nil}; otherwise, it uses the value of
+@code{$PAGER} from the @code{process-environment}.
+
 @end table
 
 @xref{Aliases}, for the built-in variables @samp{$*}, @samp{$1},
index c7c0a21d2a9a6dab7781a58eddfba2f51a9fd03a..711c35f85273a5e56b518a2a38cb5dd032bb1b02 100644 (file)
@@ -162,6 +162,13 @@ if they are quoted with a backslash."
     ("COLUMNS" ,(lambda () (window-body-width nil 'remap)) t t)
     ("LINES" ,(lambda () (window-body-height nil 'remap)) t t)
     ("INSIDE_EMACS" eshell-inside-emacs t)
+    ("PAGER" (,(lambda () (or comint-pager (getenv "PAGER")))
+              . ,(lambda (_ value)
+                   ;; When unsetting PAGER, be sure to clear its value
+                   ;; from `process-environment' too.
+                   (unless value (setenv "PAGER"))
+                   (setq comint-pager value)))
+     t t)
     ("UID" ,(lambda () (file-user-uid)) nil t)
     ("GID" ,(lambda () (file-group-gid)) nil t)
 
@@ -262,11 +269,13 @@ copied (a.k.a. \"exported\") to the environment of created subprocesses."
   ;; changing a variable will affect all of Emacs.
   (unless eshell-modify-global-environment
     (setq-local process-environment (eshell-copy-environment)))
+  (make-local-variable 'comint-pager)
   (setq-local eshell-subcommand-bindings
               (append
                '((process-environment (eshell-copy-environment))
                  (eshell-variable-aliases-list eshell-variable-aliases-list)
-                 (eshell-path-env-list eshell-path-env-list))
+                 (eshell-path-env-list eshell-path-env-list)
+                 (comint-pager comint-pager))
                eshell-subcommand-bindings))
 
   (setq-local eshell-special-chars-inside-quoting
index 3e58fe749ddc2eff5f2844f499e35d428ed077c6..ff646f5f9778669bf066e746e9581084c4837bdd 100644 (file)
@@ -766,6 +766,52 @@ it, since the setter is nil."
    (eshell-match-command-output "echo $INSIDE_EMACS[, 1]"
                                 "eshell")))
 
+(ert-deftest esh-var-test/pager-var/default ()
+  "Test that retrieving the default value of $PAGER works.
+This should be the value of `comint-pager' if non-nil, otherwise
+the value of the $PAGER env var."
+  (let ((comint-pager nil)
+        (process-environment (cons "PAGER=cat" process-environment)))
+    (eshell-command-result-equal "echo $PAGER" "cat")
+    (setq comint-pager "less")
+    (eshell-command-result-equal "echo $PAGER" "less")))
+
+(ert-deftest esh-var-test/pager-var/set ()
+  "Test that setting $PAGER in Eshell overrides the default value."
+  (let ((comint-pager nil)
+        (process-environment (cons "PAGER=cat" process-environment)))
+    (with-temp-eshell
+     (eshell-match-command-output "set PAGER bat" "bat")
+     (eshell-match-command-output "echo $PAGER" "bat"))
+    (setq comint-pager "less")
+    (with-temp-eshell
+     (eshell-match-command-output "set PAGER bat" "bat")
+     (eshell-match-command-output "echo $PAGER" "bat"))))
+
+(ert-deftest esh-var-test/pager-var/unset ()
+  "Test that unsetting $PAGER in Eshell overrides the default value."
+  (let ((comint-pager nil)
+        (process-environment (cons "PAGER=cat" process-environment)))
+    (with-temp-eshell
+     (eshell-insert-command "unset PAGER")
+     (eshell-match-command-output "echo $PAGER" "\\`\\'"))
+    (setq comint-pager "less")
+    (with-temp-eshell
+     (eshell-insert-command "unset PAGER")
+     (eshell-match-command-output "echo $PAGER" "\\`\\'"))))
+
+(ert-deftest esh-var-test/pager-var/set-locally ()
+  "Test setting $PAGER temporarily for a single command."
+  (let ((comint-pager nil)
+        (process-environment (cons "PAGER=cat" process-environment)))
+    (with-temp-eshell
+     (eshell-match-command-output "PAGER=bat env" "PAGER=bat\n")
+     (eshell-match-command-output "echo $PAGER" "cat"))
+    (setq comint-pager "less")
+    (with-temp-eshell
+     (eshell-match-command-output "PAGER=bat env" "PAGER=bat\n")
+     (eshell-match-command-output "echo $PAGER" "less"))))
+
 (ert-deftest esh-var-test/path-var/local-directory ()
   "Test using $PATH in a local directory."
   (let ((expected-path (string-join (eshell-get-path t) (path-separator))))