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

From: Spencer Baugh <[email-masked]>
Date: Fri, 02 Aug 2024 14:39:41 -0400

Patch fixing this:

>From 2af83cd922b34e1cde4ab4973e07fdb283acd26a Mon Sep 17 00:00:00 2001
From: Spencer Baugh <[email-masked]>
Date: Fri, 2 Aug 2024 14:39:08 -0400
Subject: [PATCH] Respect comint-pager in async-shell-command

comint-pager now also affects async-shell-command.

As a side benefit, this also allows it to be configured with
connection-local variables.

* lisp/comint.el (comint-exec-1): Remove check on comint-pager.
(comint-term-environment): Add check on comint-pager. (bug#72426)
---
 lisp/comint.el | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/lisp/comint.el b/lisp/comint.el
index c7cd22d840a..4f28ddc3165 100644
--- a/lisp/comint.el
+++ b/lisp/comint.el
@@ -893,10 +893,6 @@ comint-exec-1
 	 (nconc
           (comint-term-environment)
 	  (list (format "INSIDE_EMACS=%s,comint" emacs-version))
-          (when comint-pager
-            (if (stringp comint-pager)
-                (list (format "PAGER=%s" comint-pager))
-              (error "comint-pager should be a string: %s" comint-pager)))
 	  process-environment))
 	(default-directory
 	  (if (file-accessible-directory-p default-directory)
@@ -925,7 +921,9 @@ comint-exec-1
     proc))
 
 (defun comint-term-environment ()
-  "Return an environment variable list for terminal configuration."
+  "Return an environment variable list for terminal configuration.
+
+Includes a value for PAGER based on `comint-pager'."
   ;; If using termcap, we specify `emacs' as the terminal type
   ;; because that lets us specify a width.
   ;; If using terminfo, we default to `dumb' because that is
@@ -934,12 +932,17 @@ comint-term-environment
   ;; Some programs that use terminfo get very confused
   ;; if TERM is not a valid terminal type.
   (with-connection-local-variables
-   (if system-uses-terminfo
-       (list (format "TERM=%s" comint-terminfo-terminal)
-             "TERMCAP="
-             (format "COLUMNS=%d" (window-width)))
-     (list "TERM=emacs"
-           (format "TERMCAP=emacs:co#%d:tc=unknown:" (window-width))))))
+   (nconc
+    (when comint-pager
+      (if (stringp comint-pager)
+          (list (format "PAGER=%s" comint-pager))
+        (error "comint-pager should be a string: %s" comint-pager)))
+    (if system-uses-terminfo
+        (list (format "TERM=%s" comint-terminfo-terminal)
+              "TERMCAP="
+              (format "COLUMNS=%d" (window-width)))
+      (list "TERM=emacs"
+            (format "TERMCAP=emacs:co#%d:tc=unknown:" (window-width)))))))
 
 (defun comint-nonblank-p (str)
   "Return non-nil if STR contains non-whitespace syntax."
-- 
2.39.3