unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#50607: 28.0.50; 'M-x compile' misbehaves if 'process-environment' is buffer-local
@ 2021-09-15 18:08 Augusto Stoffel
  2021-09-16 14:06 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 2+ messages in thread
From: Augusto Stoffel @ 2021-09-15 18:08 UTC (permalink / raw)
  To: 50607

[-- Attachment #1: Type: text/plain, Size: 756 bytes --]

This has already been discussed on email-devel but didn't come to a
conclusion.  I don't want to linger on it, but I would like the problem
to get assigned a bug number, so it has a chance of being addressed in
the future.

A summary of the problem: suppose buffer A has a buffer-local value of
'process-environment' containing an extra directory in the PATH, and
that a given 'program' is only available on that directory.  Then 'M-x
compile RET program RET' will not find 'program', because the
*compilation* buffer will not "inherit" the PATH from A.

For the reasons why one would want/need such a setup, see
https://lists.gnu.org/archive/html/emacs-devel/2021-08/msg01380.html
and other messages in that thread.

Finally, I attach my proposed patch.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Make-compile-respect-buffer-local-process-environmen.patch --]
[-- Type: text/x-patch, Size: 1630 bytes --]

From a104e1eae100f01585587df30f49866f3b038785 Mon Sep 17 00:00:00 2001
From: Augusto Stoffel <arstoffel@gmail.com>
Date: Thu, 29 Apr 2021 12:45:04 +0200
Subject: [PATCH] Make 'compile' respect buffer-local process environment

* lisp/progmodes/compile.el (compilation-start): Use
`process-environment' from original buffer in the compilation process.
---
 lisp/progmodes/compile.el | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/lisp/progmodes/compile.el b/lisp/progmodes/compile.el
index af7b8292b7..bdf20a3f51 100644
--- a/lisp/progmodes/compile.el
+++ b/lisp/progmodes/compile.el
@@ -1783,6 +1783,8 @@ compilation-start
 	    (replace-regexp-in-string "-mode\\'" "" (symbol-name mode))))
 	 (thisdir default-directory)
 	 (thisenv compilation-environment)
+         (bufferpath (when (local-variable-p 'exec-path) exec-path))
+         (bufferenv (when (local-variable-p 'process-environment) process-environment))
 	 outwin outbuf)
     (with-current-buffer
 	(setq outbuf
@@ -1850,6 +1852,12 @@ compilation-start
         ;; NB: must be done after (funcall mode) as that resets local variables
         (setq-local compilation-directory thisdir)
         (setq-local compilation-environment thisenv)
+        (if bufferpath
+            (setq-local exec-path bufferpath)
+          (kill-local-variable 'exec-path))
+        (if bufferenv
+            (setq-local process-environment bufferenv)
+          (kill-local-variable 'process-environment))
 	(if highlight-regexp
             (setq-local compilation-highlight-regexp highlight-regexp))
         (if (or compilation-auto-jump-to-first-error
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* bug#50607: 28.0.50; 'M-x compile' misbehaves if 'process-environment' is buffer-local
  2021-09-15 18:08 bug#50607: 28.0.50; 'M-x compile' misbehaves if 'process-environment' is buffer-local Augusto Stoffel
@ 2021-09-16 14:06 ` Lars Ingebrigtsen
  0 siblings, 0 replies; 2+ messages in thread
From: Lars Ingebrigtsen @ 2021-09-16 14:06 UTC (permalink / raw)
  To: Augusto Stoffel; +Cc: 50607

Augusto Stoffel <arstoffel@gmail.com> writes:

> Finally, I attach my proposed patch.

Makes sense to me, so I've pushed this to Emacs 28 (with some minor
stylistic changes).

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-09-16 14:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-15 18:08 bug#50607: 28.0.50; 'M-x compile' misbehaves if 'process-environment' is buffer-local Augusto Stoffel
2021-09-16 14:06 ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).