all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Unexpected behavior of grep-use-null-device in non-interactive mode
@ 2021-02-22 23:00 david.chappaz
  2021-02-23 17:24 ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: david.chappaz @ 2021-02-22 23:00 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,

 

I'm using emacs 27.1.

 

Here is a simple experiment in interactive mode:

 

1/ Start emacs with --no-init

2/ I can check that grep-use-null-device is set to 'auto-detect'

3/ Run interactively M-x grep, something. The command that's echoed in the
grep buffer is:

grep --color -nH --null -e something

4/ I can check that grep-use-null-device has been set to nil

 

So far so good. Now consider the non-interactive variant:

 

1/ Start emacs with --no-init

2/ I can check that grep-use-null-device is set to 'auto-detect'

3/ Now I execute non- interactively (grep "grep --color -nH --null -e
something") . The command that's echoed in the grep buffer is:

grep --color -nH --null -e something /dev/null

4/ I can check that grep-use-null-device has been set to nil

5/ If I execute non- interactively the same (grep "grep --color -nH --null
-e something"), the command that's echoed in the grep buffer now is:

grep --color -nH --null -e something

 

Why is /dev/null added to the command at step 3 ?

Is this a bug ? Or perhaps my expectations are not quite right ?

 

Thanks !

David



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

* Re: Unexpected behavior of grep-use-null-device in non-interactive mode
  2021-02-22 23:00 Unexpected behavior of grep-use-null-device in non-interactive mode david.chappaz
@ 2021-02-23 17:24 ` Eli Zaretskii
  0 siblings, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2021-02-23 17:24 UTC (permalink / raw)
  To: help-gnu-emacs

> From: <david.chappaz@free.fr>
> Date: Mon, 22 Feb 2021 15:00:24 -0800
> 
> Why is /dev/null added to the command at step 3 ?
> 
> Is this a bug ? Or perhaps my expectations are not quite right ?

The function that auto-detects null-device support is only called when
you invoke the command interactively.  And the doc string actually
says so:

  (defcustom grep-use-null-device 'auto-detect
    "If t, append the value of `null-device' to `grep' commands.
  This is done to ensure that the output of grep includes the filename of
  any match in the case where only a single file is searched, and is not
  necessary if the grep program used supports the `-H' option.

  In interactive usage, the actual value of this variable is set up
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  by `grep-compute-defaults'
  ^^^^^^^^^^^^^^^^^^^^^^^^^

Why do you need to call 'grep' noninteractively, and still want it to
show the hits as if it were an interactive call?



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

* Re: Unexpected behavior of grep-use-null-device in non-interactive mode
@ 2021-02-24  2:47 david.chappaz
  2021-02-24 16:53 ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: david.chappaz @ 2021-02-24  2:47 UTC (permalink / raw)
  To: help-gnu-emacs

 

> The function that auto-detects null-device support is only called when

> you invoke the command interactively.  And the doc string actually

> says so:

 

Thanks for pointing that out, it makes sense !

 

In my non-interactive variant though, 'grep' is not called interactively at
any point.

*         The result from step 3 doesn't contradict the fact that
auto-detection for the null-device support only takes place when you invoke
the command interactively.

*         However, the transition from step 3 to step 4 shows that
grep-use-null-device is changed (to nil) from 'auto-detect', so some kind of
auto-detection seems to have taken place

*         Furthermore, results from step 5 (in contrast to the results from
step 3) clearly show that auto-detection has taken place, despite the
absence of any interactive invocation.

 

In a few words, if I read the documentation correctly, I would expect
grep-use-null-device to be changed from 'auto-detect' on the first
*interactive* invocation, but never before that. Am I right ?

 

> Why do you need to call 'grep' noninteractively, and still want it to

> show the hits as if it were an interactive call?

 

Although I love emacs, I'm very inexperienced in elisp and there is no doubt
many people would scream when looking at my very obscure elisp functions.

In this particular case, I'm building a wrapper around 'grep', very much
inspired by this:

 

https://ideoplex.com/2014/08/03/emacs-windows-and-ack/

 

The only difference is that my own wrapper has some interactive steps at the
beginning, e.g. to ask for the pattern to search, to ask for the folder
where to search from, etc... Eventually it builds a command and calls 'grep'
non-interactively.

 

David

 



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

* Re: Unexpected behavior of grep-use-null-device in non-interactive mode
  2021-02-24  2:47 david.chappaz
@ 2021-02-24 16:53 ` Eli Zaretskii
  0 siblings, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2021-02-24 16:53 UTC (permalink / raw)
  To: help-gnu-emacs

> From: <david.chappaz@free.fr>
> Date: Tue, 23 Feb 2021 18:47:45 -0800
> 
> In a few words, if I read the documentation correctly, I would expect
> grep-use-null-device to be changed from 'auto-detect' on the first
> *interactive* invocation, but never before that. Am I right ?

If you think there's a bug here, please use "M-x report-emacs-bug RET"
to report it with all the details.

Thanks.



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

end of thread, other threads:[~2021-02-24 16:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-02-22 23:00 Unexpected behavior of grep-use-null-device in non-interactive mode david.chappaz
2021-02-23 17:24 ` Eli Zaretskii
  -- strict thread matches above, loose matches on Subject: below --
2021-02-24  2:47 david.chappaz
2021-02-24 16:53 ` Eli Zaretskii

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.