unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#8340: 23.2; recompile does not retain compilation-environment needed by vc-git-grep
@ 2011-03-24 18:45 Trevor Spiteri
  2011-09-05  9:10 ` Juri Linkov
  0 siblings, 1 reply; 7+ messages in thread
From: Trevor Spiteri @ 2011-03-24 18:45 UTC (permalink / raw)
  To: 8340

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))






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

* bug#8340: 23.2; recompile does not retain compilation-environment needed by vc-git-grep
  2011-03-24 18:45 bug#8340: 23.2; recompile does not retain compilation-environment needed by vc-git-grep Trevor Spiteri
@ 2011-09-05  9:10 ` Juri Linkov
  2011-09-06  9:27   ` Juri Linkov
  0 siblings, 1 reply; 7+ messages in thread
From: Juri Linkov @ 2011-09-05  9:10 UTC (permalink / raw)
  To: Trevor Spiteri; +Cc: 8340

> 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))))





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

* bug#8340: 23.2; recompile does not retain compilation-environment needed by vc-git-grep
  2011-09-05  9:10 ` Juri Linkov
@ 2011-09-06  9:27   ` Juri Linkov
  2011-09-06 18:39     ` Stefan Monnier
  0 siblings, 1 reply; 7+ messages in thread
From: Juri Linkov @ 2011-09-06  9:27 UTC (permalink / raw)
  To: Trevor Spiteri; +Cc: 8340

> 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))






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

* bug#8340: 23.2; recompile does not retain compilation-environment needed by vc-git-grep
  2011-09-06  9:27   ` Juri Linkov
@ 2011-09-06 18:39     ` Stefan Monnier
  2011-09-07 12:19       ` Juri Linkov
  0 siblings, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2011-09-06 18:39 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 8340, Trevor Spiteri

> -(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





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

* bug#8340: 23.2; recompile does not retain compilation-environment needed by vc-git-grep
  2011-09-06 18:39     ` Stefan Monnier
@ 2011-09-07 12:19       ` Juri Linkov
  2011-09-07 13:36         ` Stefan Monnier
  0 siblings, 1 reply; 7+ messages in thread
From: Juri Linkov @ 2011-09-07 12:19 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 8340, Trevor Spiteri

> 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





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

* bug#8340: 23.2; recompile does not retain compilation-environment needed by vc-git-grep
  2011-09-07 12:19       ` Juri Linkov
@ 2011-09-07 13:36         ` Stefan Monnier
  2011-09-08 12:12           ` Juri Linkov
  0 siblings, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2011-09-07 13:36 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 8340, Trevor Spiteri

>> 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





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

* bug#8340: 23.2; recompile does not retain compilation-environment needed by vc-git-grep
  2011-09-07 13:36         ` Stefan Monnier
@ 2011-09-08 12:12           ` Juri Linkov
  0 siblings, 0 replies; 7+ messages in thread
From: Juri Linkov @ 2011-09-08 12:12 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 8340-done, Trevor Spiteri

>>> 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.





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

end of thread, other threads:[~2011-09-08 12:12 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-24 18:45 bug#8340: 23.2; recompile does not retain compilation-environment needed by vc-git-grep Trevor Spiteri
2011-09-05  9:10 ` Juri Linkov
2011-09-06  9:27   ` Juri Linkov
2011-09-06 18:39     ` Stefan Monnier
2011-09-07 12:19       ` Juri Linkov
2011-09-07 13:36         ` Stefan Monnier
2011-09-08 12:12           ` Juri Linkov

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).