GNU bug report logs - #8340
23.2; recompile does not retain compilation-environment needed by vc-git-grep

Previous Next

Package: emacs;

Reported by: Trevor Spiteri <tspiteri <at> ieee.org>

Date: Thu, 24 Mar 2011 19:11:02 UTC

Severity: normal

Found in version 23.2

Done: Juri Linkov <juri <at> jurta.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 8340 in the body.
You can then email your comments to 8340 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#8340; Package emacs. (Thu, 24 Mar 2011 19:11:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Trevor Spiteri <tspiteri <at> ieee.org>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Thu, 24 Mar 2011 19:11:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Trevor Spiteri <tspiteri <at> ieee.org>
To: bug-gnu-emacs <at> gnu.org
Subject: 23.2; recompile does not retain compilation-environment needed by
	vc-git-grep
Date: Thu, 24 Mar 2011 18:45:12 +0000
Version 23.2.

In the function vc-git-grep inside vc-git.el, the compilation 
environment is set as

    (compilation-environment '("PAGER="))

because git grep needs that. If I use M-x recompile in the *grep* buffer 
after using M-x vc-git-grep, compilation-environment is not set, and a 
warning that the "terminal is not fully functional" is displayed, one 
page of results is shown, and git grep blocks waiting on standard input, 
since it is using more as a pager.

To fix this, I applied the following patch to compile.el that stores 
compile-environment in a similar way to default-directory. It works for 
me, but I do not really know elisp.

--- a/compile.el    2011-03-24 18:24:01.000000000 +0000
+++ b/compile.el    2011-03-24 18:27:44.000000000 +0000
@@ -511,6 +511,9 @@
 (defvar compilation-directory nil
   "Directory to restore to when doing `recompile'.")

+(defvar recompilation-environment nil
+  "Environment to restore when doing `recompile'.")
+
 (defvar compilation-directory-matcher
   '("\\(?:Entering\\|Leavin\\(g\\)\\) directory `\\(.+\\)'$" (2 . 1))
   "A list for tracking when directories are entered or left.
@@ -1106,7 +1109,8 @@
 If the optional argument `edit-command' is non-nil, the command can be 
edited."
   (interactive "P")
   (save-some-buffers (not compilation-ask-about-save) nil)
-  (let ((default-directory (or compilation-directory default-directory)))
+  (let ((default-directory (or compilation-directory default-directory))
+        (compilation-environment (or recompilation-environment 
compilation-environment)))
     (when edit-command
       (setcar compilation-arguments
               (compilation-read-command (car compilation-arguments))))
@@ -1236,6 +1240,7 @@
         ;; affected by the special handling of "cd ...;".
         ;; NB: must be fone after (funcall mode) as that resets local 
variables
         (set (make-local-variable 'compilation-directory) thisdir)
+        (set (make-local-variable 'recompilation-environment) 
compilation-environment)
     (if highlight-regexp
         (set (make-local-variable 'compilation-highlight-regexp)
          highlight-regexp))





Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#8340; Package emacs. (Mon, 05 Sep 2011 09:19:01 GMT) Full text and rfc822 format available.

Message #8 received at 8340 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> jurta.org>
To: Trevor Spiteri <tspiteri <at> ieee.org>
Cc: 8340 <at> debbugs.gnu.org
Subject: Re: 23.2; recompile does not retain compilation-environment needed by
	vc-git-grep
Date: Mon, 05 Sep 2011 12:10:05 +0300
> In the function vc-git-grep inside vc-git.el, the compilation environment
> is set as
>
>     (compilation-environment '("PAGER="))
>
> because git grep needs that. If I use M-x recompile in the *grep* buffer
> after using M-x vc-git-grep, compilation-environment is not set, and
> a warning that the "terminal is not fully functional" is displayed, one
> page of results is shown, and git grep blocks waiting on standard input,
> since it is using more as a pager.
>
> To fix this, I applied the following patch to compile.el that stores
> compile-environment in a similar way to default-directory. It works for me,
> but I do not really know elisp.

Generally it would be better to reuse `compilation-environment' and set
it buffer-locally in the *compilation* buffer, but there is another problem.
Some users might want to set `compilation-environment' in .emacs like:

  (add-hook 'compilation-mode-hook
            (lambda ()
              (setq compilation-environment '("LANG=C"))))

See more in http://thread.gmane.org/gmane.emacs.devel/108353

But then let-binding (let ((compilation-environment '("PAGER="))))
in `vc-git-grep' is ineffective because `compilation-mode-hook'
overrides it.  So `compilation-environment' should be defcustom
to avoid this problem.

I don't know whether it's good for defcustom to be buffer-local.  But this
should fix both problems when `vc-git-grep' will add "PAGER=" to the
default or customized value of `compilation-environment' like
(let ((compilation-environment (cons "PAGER=" compilation-environment))))




Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#8340; Package emacs. (Tue, 06 Sep 2011 09:40:02 GMT) Full text and rfc822 format available.

Message #11 received at 8340 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> jurta.org>
To: Trevor Spiteri <tspiteri <at> ieee.org>
Cc: 8340 <at> debbugs.gnu.org
Subject: Re: bug#8340: 23.2;
	recompile does not retain compilation-environment needed by
	vc-git-grep
Date: Tue, 06 Sep 2011 12:27:19 +0300
> Generally it would be better to reuse `compilation-environment' and set
> it buffer-locally in the *compilation* buffer, but there is another problem.
> Some users might want to set `compilation-environment' in .emacs like:
>
>   (add-hook 'compilation-mode-hook
>             (lambda ()
>               (setq compilation-environment '("LANG=C"))))
>
> See more in http://thread.gmane.org/gmane.emacs.devel/108353
>
> But then let-binding (let ((compilation-environment '("PAGER="))))
> in `vc-git-grep' is ineffective because `compilation-mode-hook'
> overrides it.  So `compilation-environment' should be defcustom
> to avoid this problem.

The following patch fixed all these problems:

=== modified file 'lisp/progmodes/compile.el'
--- lisp/progmodes/compile.el	2011-09-02 16:38:40 +0000
+++ lisp/progmodes/compile.el	2011-09-06 09:23:31 +0000
@@ -637,11 +637,15 @@ (defvar compilation-exit-message-functio
 and exit message; it returns a cons (MESSAGE . MODELINE) of the strings to
 write into the compilation buffer, and to put in its mode line.")
 
-(defvar compilation-environment nil
-  "*List of environment variables for compilation to inherit.
+(defcustom compilation-environment nil
+  "List of environment variables for compilation to inherit.
 Each element should be a string of the form ENVVARNAME=VALUE.
 This list is temporarily prepended to `process-environment' prior to
-starting the compilation process.")
+starting the compilation process."
+  :type '(repeat (string :tag "ENVVARNAME=VALUE"))
+  :options '(("LANG=C"))
+  :group 'compilation
+  :version "24.1")
 
 ;; History of compile commands.
 (defvar compile-history nil)
@@ -1482,6 +1491,7 @@ (defun compilation-start (command &optio
 	      "compilation"
 	    (replace-regexp-in-string "-mode\\'" "" (symbol-name mode))))
 	 (thisdir default-directory)
+	 (thisenv compilation-environment)
 	 outwin outbuf)
     (with-current-buffer
 	(setq outbuf
@@ -1530,6 +1541,7 @@ (defun compilation-start (command &optio
         ;; affected by the special handling of "cd ...;".
         ;; NB: must be fone after (funcall mode) as that resets local variables
         (set (make-local-variable 'compilation-directory) thisdir)
+	(set (make-local-variable 'compilation-environment) thisenv)
 	(if highlight-regexp
 	    (set (make-local-variable 'compilation-highlight-regexp)
 		 highlight-regexp))

=== modified file 'lisp/vc/vc-git.el'
--- lisp/vc/vc-git.el	2011-09-01 07:29:56 +0000
+++ lisp/vc/vc-git.el	2011-09-06 09:19:48 +0000
@@ -998,7 +998,7 @@ (defun vc-git-grep (regexp &optional fil
 	    (add-to-history 'grep-history command))))
       (when command
 	(let ((default-directory dir)
-	      (compilation-environment '("PAGER=")))
+	      (compilation-environment (cons "PAGER=" compilation-environment)))
 	  ;; Setting process-setup-function makes exit-message-function work
 	  ;; even when async processes aren't supported.
 	  (compilation-start command 'grep-mode))





Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#8340; Package emacs. (Tue, 06 Sep 2011 18:44:02 GMT) Full text and rfc822 format available.

Message #14 received at 8340 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: Juri Linkov <juri <at> jurta.org>
Cc: 8340 <at> debbugs.gnu.org, Trevor Spiteri <tspiteri <at> ieee.org>
Subject: Re: bug#8340: 23.2;
	recompile does not retain compilation-environment needed by
	vc-git-grep
Date: Tue, 06 Sep 2011 14:39:58 -0400
> -(defvar compilation-environment nil
> -  "*List of environment variables for compilation to inherit.
> +(defcustom compilation-environment nil
> +  "List of environment variables for compilation to inherit.
>  Each element should be a string of the form ENVVARNAME=VALUE.
>  This list is temporarily prepended to `process-environment' prior to
> -starting the compilation process.")
> +starting the compilation process."
> +  :type '(repeat (string :tag "ENVVARNAME=VALUE"))
> +  :options '(("LANG=C"))
> +  :group 'compilation
> +  :version "24.1")

What is this supposed to fix?

>  ;; History of compile commands.
>  (defvar compile-history nil)
> @@ -1482,6 +1491,7 @@ (defun compilation-start (command &optio
>  	      "compilation"
>  	    (replace-regexp-in-string "-mode\\'" "" (symbol-name mode))))
>  	 (thisdir default-directory)
> +	 (thisenv compilation-environment)
>  	 outwin outbuf)
>      (with-current-buffer
>  	(setq outbuf
> @@ -1530,6 +1541,7 @@ (defun compilation-start (command &optio
>          ;; affected by the special handling of "cd ...;".
>          ;; NB: must be fone after (funcall mode) as that resets local variables
>          (set (make-local-variable 'compilation-directory) thisdir)
> +	(set (make-local-variable 'compilation-environment) thisenv)
>  	(if highlight-regexp
>  	    (set (make-local-variable 'compilation-highlight-regexp)
>  		 highlight-regexp))

> === modified file 'lisp/vc/vc-git.el'
> --- lisp/vc/vc-git.el	2011-09-01 07:29:56 +0000
> +++ lisp/vc/vc-git.el	2011-09-06 09:19:48 +0000
> @@ -998,7 +998,7 @@ (defun vc-git-grep (regexp &optional fil
>  	    (add-to-history 'grep-history command))))
>        (when command
>  	(let ((default-directory dir)
> -	      (compilation-environment '("PAGER=")))
> +	      (compilation-environment (cons "PAGER=" compilation-environment)))
>  	  ;; Setting process-setup-function makes exit-message-function work
>  	  ;; even when async processes aren't supported.
>  	  (compilation-start command 'grep-mode))

Mixing defcustom+bufferlocal+letbinding is really asking for trouble,
although I think in this case it might just fall within the limits of
what does work.
The vc-git.el patch looks perfectly good and so does the (set...thisenv).
But I'd prefer to refrain from making compilation-environment a defcustom
for now, until we find a really good use for it.


        Stefan




Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#8340; Package emacs. (Wed, 07 Sep 2011 12:48:02 GMT) Full text and rfc822 format available.

Message #17 received at 8340 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> jurta.org>
To: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Cc: 8340 <at> debbugs.gnu.org, Trevor Spiteri <tspiteri <at> ieee.org>
Subject: Re: bug#8340: 23.2;
	recompile does not retain compilation-environment needed by
	vc-git-grep
Date: Wed, 07 Sep 2011 15:19:33 +0300
> Mixing defcustom+bufferlocal+letbinding is really asking for trouble,
> although I think in this case it might just fall within the limits of
> what does work.
>
> The vc-git.el patch looks perfectly good and so does the (set...thisenv).

Installed.

> But I'd prefer to refrain from making compilation-environment a defcustom
> for now, until we find a really good use for it.

There have been requests to make it a defcustom, and you even agreed to that ;-)
http://lists.gnu.org/archive/html/emacs-devel/2009-02/msg00118.html

It will allow the users to find and change it more easily in cases like this:
http://lists.gnu.org/archive/html/help-gnu-emacs/2011-02/msg00338.html




Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#8340; Package emacs. (Wed, 07 Sep 2011 13:41:01 GMT) Full text and rfc822 format available.

Message #20 received at 8340 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Juri Linkov <juri <at> jurta.org>
Cc: 8340 <at> debbugs.gnu.org, Trevor Spiteri <tspiteri <at> ieee.org>
Subject: Re: bug#8340: 23.2;
	recompile does not retain compilation-environment needed by
	vc-git-grep
Date: Wed, 07 Sep 2011 09:36:42 -0400
>> But I'd prefer to refrain from making compilation-environment a defcustom
>> for now, until we find a really good use for it.
> There have been requests to make it a defcustom, and you even agreed
> to that ;-)
> http://lists.gnu.org/archive/html/emacs-devel/2009-02/msg00118.html
> It will allow the users to find and change it more easily in cases like this:
> http://lists.gnu.org/archive/html/help-gnu-emacs/2011-02/msg00338.html

OK, sounds fine, go ahead,


        Stefan




Reply sent to Juri Linkov <juri <at> jurta.org>:
You have taken responsibility. (Thu, 08 Sep 2011 12:19:02 GMT) Full text and rfc822 format available.

Notification sent to Trevor Spiteri <tspiteri <at> ieee.org>:
bug acknowledged by developer. (Thu, 08 Sep 2011 12:19:03 GMT) Full text and rfc822 format available.

Message #25 received at 8340-done <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> jurta.org>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 8340-done <at> debbugs.gnu.org, Trevor Spiteri <tspiteri <at> ieee.org>
Subject: Re: bug#8340: 23.2;
	recompile does not retain compilation-environment needed by
	vc-git-grep
Date: Thu, 08 Sep 2011 15:12:41 +0300
>>> But I'd prefer to refrain from making compilation-environment a defcustom
>>> for now, until we find a really good use for it.
>> There have been requests to make it a defcustom, and you even agreed
>> to that ;-)
>> http://lists.gnu.org/archive/html/emacs-devel/2009-02/msg00118.html
>> It will allow the users to find and change it more easily in cases like this:
>> http://lists.gnu.org/archive/html/help-gnu-emacs/2011-02/msg00338.html
>
> OK, sounds fine, go ahead,

Done.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 07 Oct 2011 11:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 12 years and 198 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.