Subject: Re: bug#72426: 29.2.50; comint-pager doesn't affect async-shell-command

From: Spencer Baugh <[email-masked]>
Date: Tue, 06 Aug 2024 12:42:09 -0400

Eli Zaretskii <[email-masked]> writes:

>> From: Spencer Baugh <[email-masked]>
>> Cc: Eli Zaretskii <[email-masked]>,  [email-masked]
>> Date: Tue, 06 Aug 2024 11:31:06 -0400
>> 
>> Jim Porter <[email-masked]> writes:
>> 
>> > Perhaps we should be setting the pager in a similar way to how TERM is
>> > set in startup.el?
>> >
>> >     ;; Subprocesses of Emacs do not have direct access to the terminal, so
>> >     ;; unless told otherwise they should only assume a dumb terminal.
>> >     ;; We are careful to do it late (after term-setup-hook), although the
>> >     ;; new multi-tty code does not use $TERM any more there anyway.
>> >     (setenv "TERM" "dumb")
>> >
>> > I think the reasoning in that comment applies to PAGER as well: unless
>> > told otherwise, subprocesses probably shouldn't use pager like "less";
>> > it's very unlikely to work correctly.
>> >
>> > In that case, would it make sense to add something along these lines
>> > to startup.el?
>> >
>> >     (when (executable-find "cat")
>> >       (setenv "PAGER" "cat"))
>> 
>> Yes, I'd be very in favor of that.  Fixing this is exactly my
>> motivation.
>
> We could perhaps try this on master.  If it doesn't cause trouble,
> maybe this is the right way, indeed.

Here's a patch which does this, for master.

(Everyone please feel free to CC me on any bugs or emacs-devel
discussions about this; I will try hard to fix any issues that crop up.)

>From 14db307fd53a6c5b13a09ef3e023b0ba299d61a8 Mon Sep 17 00:00:00 2001
From: Spencer Baugh <[email-masked]>
Date: Tue, 6 Aug 2024 12:39:37 -0400
Subject: [PATCH] Stop subprocesses from using inherited or default PAGER

At startup, set PAGER to cat so that any inherited or default
value of PAGER does not affect subprocesses of Emacs.  Pagers
generally won't work when a subprocess runs under Emacs.

A user can use comint-pager (or other customizations) to tell
subprocesses to use a different specific pager.

* lisp/startup.el (normal-top-level): Set PAGER to cat, if cat
is available. (bug#72426)
---
 lisp/startup.el | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lisp/startup.el b/lisp/startup.el
index f18795ae6ac..324f3aeee60 100644
--- a/lisp/startup.el
+++ b/lisp/startup.el
@@ -854,6 +854,10 @@ normal-top-level
     ;; We are careful to do it late (after term-setup-hook), although the
     ;; new multi-tty code does not use $TERM any more there anyway.
     (setenv "TERM" "dumb")
+    ;; Likewise, subprocesses should not use a pager unless told
+    ;; otherwise, since it generally won't work.
+    (when (executable-find "cat")
+      (setenv "PAGER" "cat"))
     ;; Remove DISPLAY from the process-environment as well.  This allows
     ;; `callproc.c' to give it a useful adaptive default which is either
     ;; the value of the `display' frame-parameter or the DISPLAY value
-- 
2.39.3