@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},
("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)
;; 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
(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))))