all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* grep-command: Ignore case if case-fold-search is non-nil
@ 2016-09-18  9:31 Tino Calancha
  2016-09-18  9:57 ` Dmitry Gutov
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Tino Calancha @ 2016-09-18  9:31 UTC (permalink / raw)
  To: Emacs developers; +Cc: tino.calancha


Hi,

Do you think `grep-compute-defaults' should add '-i', i.e., ignore case,
in the default `grep-command' when `case-fold-search' is non-nil?
Option '-i' is specified by POSIX, do we need to check if `grep-program'
support it?

Regards,
Tino
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
From 5220d4858475f0825c01926456a8932079e3d0d7 Mon Sep 17 00:00:00 2001
From: Tino Calancha <tino.calancha@gmail.com>
Date: Sun, 18 Sep 2016 18:19:52 +0900
Subject: [PATCH] grep-compute-defaults: Ignore case if case-fold-search is
  non-nil

* lisp/progmodes/grep.el (grep-compute-defaults): Use option '-i'.
---
  lisp/progmodes/grep.el | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el
index f7f097b..ac871a1 100644
--- a/lisp/progmodes/grep.el
+++ b/lisp/progmodes/grep.el
@@ -590,7 +590,8 @@ grep-compute-defaults
      (unless (and grep-command grep-find-command
  		 grep-template grep-find-template)
        (let ((grep-options
-	     (concat (if grep-use-null-device "-n" "-nH")
+	     (concat (if grep-use-null-device "-n"
+                       (if case-fold-search "-nHi" "-nH"))
  		     (if (grep-probe grep-program
  				     `(nil nil nil "-e" "foo" 
,null-device)
  				     nil 1)
-- 
2.9.3

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



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

* Re: grep-command: Ignore case if case-fold-search is non-nil
  2016-09-18  9:31 grep-command: Ignore case if case-fold-search is non-nil Tino Calancha
@ 2016-09-18  9:57 ` Dmitry Gutov
  2016-09-18 10:30   ` Tino Calancha
  2016-09-18 14:45 ` Eli Zaretskii
  2016-09-18 15:05 ` Drew Adams
  2 siblings, 1 reply; 16+ messages in thread
From: Dmitry Gutov @ 2016-09-18  9:57 UTC (permalink / raw)
  To: Tino Calancha, Emacs developers

On 18.09.2016 12:31, Tino Calancha wrote:

> Do you think `grep-compute-defaults' should add '-i', i.e., ignore case,
> in the default `grep-command' when `case-fold-search' is non-nil?
> Option '-i' is specified by POSIX, do we need to check if `grep-program'
> support it?

I don't think so. At least not the way your patch is written.

grep-options is used in both grep-template and grep-find-template.

And they both get "-i" inserted into later, in grep-expand-template.



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

* Re: grep-command: Ignore case if case-fold-search is non-nil
  2016-09-18  9:57 ` Dmitry Gutov
@ 2016-09-18 10:30   ` Tino Calancha
  2016-09-18 10:52     ` Richard Copley
  0 siblings, 1 reply; 16+ messages in thread
From: Tino Calancha @ 2016-09-18 10:30 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: Emacs developers, Tino Calancha



On Sun, 18 Sep 2016, Dmitry Gutov wrote:

> On 18.09.2016 12:31, Tino Calancha wrote:
>
>> Do you think `grep-compute-defaults' should add '-i', i.e., ignore case,
>> in the default `grep-command' when `case-fold-search' is non-nil?
>> Option '-i' is specified by POSIX, do we need to check if `grep-program'
>> support it?
>
> grep-options is used in both grep-template and grep-find-template.
>
> And they both get "-i" inserted into later, in grep-expand-template.
Thank you.
Tha's right: `rgrep' and `lgrep' default to case _insensitive_ search; 
but `grep-find' defaults to case _sensitive_ search.

emacs -Q
M-: (dired (concat source-directory "/lisp")) RET
M-x: lgrep RET undid RET replace.el RET RET
;; Found a match (same for rgrep)
M-x: grep-find RET
;; show a case sensitive default command as follows:
find . -type f -exec grep --color -nH -e  \{\} +

I would suggest to be instead:
find . -type f -exec grep --color -nHi -e  \{\} +

that would be consistent with defaults for `rgrep' and `lgrep'.
What do you think?

Tino



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

* Re: grep-command: Ignore case if case-fold-search is non-nil
  2016-09-18 10:30   ` Tino Calancha
@ 2016-09-18 10:52     ` Richard Copley
  2016-09-18 11:09       ` Tino Calancha
  0 siblings, 1 reply; 16+ messages in thread
From: Richard Copley @ 2016-09-18 10:52 UTC (permalink / raw)
  To: Tino Calancha; +Cc: Emacs developers, Dmitry Gutov

On 18 September 2016 at 11:30, Tino Calancha <tino.calancha@gmail.com> wrote:
>
>
> On Sun, 18 Sep 2016, Dmitry Gutov wrote:
>
>> On 18.09.2016 12:31, Tino Calancha wrote:
>>
>>> Do you think `grep-compute-defaults' should add '-i', i.e., ignore case,
>>> in the default `grep-command' when `case-fold-search' is non-nil?
>>> Option '-i' is specified by POSIX, do we need to check if `grep-program'
>>> support it?
>>
>>
>> grep-options is used in both grep-template and grep-find-template.
>>
>> And they both get "-i" inserted into later, in grep-expand-template.
>
> Thank you.
> Tha's right: `rgrep' and `lgrep' default to case _insensitive_ search; but
> `grep-find' defaults to case _sensitive_ search.
>
> emacs -Q
> M-: (dired (concat source-directory "/lisp")) RET
> M-x: lgrep RET undid RET replace.el RET RET
> ;; Found a match (same for rgrep)
> M-x: grep-find RET
> ;; show a case sensitive default command as follows:
> find . -type f -exec grep --color -nH -e  \{\} +
>
> I would suggest to be instead:
> find . -type f -exec grep --color -nHi -e  \{\} +
>
> that would be consistent with defaults for `rgrep' and `lgrep'.
> What do you think?

What if the user toggles case-fold-search between invocations of
grep-find? Will the argument be updated?

If not, and if the user doesn't know about `grep-compute-defaults' (an
undocumented non-interactive function) then the argument depends on
the state of case-fold-search at the time of the first use of
grep-find, which seems awkward.

If so, on the other hand, doesn't that turn toggle-case-fold-search
into quite a heavyweight operation?

Or what am I missing?
Thanks.



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

* Re: grep-command: Ignore case if case-fold-search is non-nil
  2016-09-18 10:52     ` Richard Copley
@ 2016-09-18 11:09       ` Tino Calancha
  2016-09-18 11:55         ` Dmitry Gutov
  0 siblings, 1 reply; 16+ messages in thread
From: Tino Calancha @ 2016-09-18 11:09 UTC (permalink / raw)
  To: Richard Copley; +Cc: Dmitry Gutov, Emacs developers, Tino Calancha



On Sun, 18 Sep 2016, Richard Copley wrote:

> On 18 September 2016 at 11:30, Tino Calancha <tino.calancha@gmail.com> wrote:
>>
>>
>> On Sun, 18 Sep 2016, Dmitry Gutov wrote:
>>
>>> On 18.09.2016 12:31, Tino Calancha wrote:
>>>
>>>> Do you think `grep-compute-defaults' should add '-i', i.e., ignore case,
>>>> in the default `grep-command' when `case-fold-search' is non-nil?
>>>> Option '-i' is specified by POSIX, do we need to check if `grep-program'
>>>> support it?
>>>
>>>
>>> grep-options is used in both grep-template and grep-find-template.
>>>
>>> And they both get "-i" inserted into later, in grep-expand-template.
>>
>> Thank you.
>> Tha's right: `rgrep' and `lgrep' default to case _insensitive_ search; but
>> `grep-find' defaults to case _sensitive_ search.
>>
>> emacs -Q
>> M-: (dired (concat source-directory "/lisp")) RET
>> M-x: lgrep RET undid RET replace.el RET RET
>> ;; Found a match (same for rgrep)
>> M-x: grep-find RET
>> ;; show a case sensitive default command as follows:
>> find . -type f -exec grep --color -nH -e  \{\} +
>>
>> I would suggest to be instead:
>> find . -type f -exec grep --color -nHi -e  \{\} +
>>
>> that would be consistent with defaults for `rgrep' and `lgrep'.
>> What do you think?

Hi Richard,
> What if the user toggles case-fold-search between invocations of
> grep-find? Will the argument be updated?
>
> If not, and if the user doesn't know about `grep-compute-defaults' (an
> undocumented non-interactive function) then the argument depends on
> the state of case-fold-search at the time of the first use of
> grep-find, which seems awkward.
AFICT, if the user changes case-fold-search, `rgrep' and `lgrep' 
will follow that change, but `grep-find' seems keep unchanged.
I guess the behaviour of `grep-find' should be similar as the other
2 commands.  Then, if a user want to keep his/her `grep-command' constant,
s?he just need to customize it.



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

* Re: grep-command: Ignore case if case-fold-search is non-nil
  2016-09-18 11:09       ` Tino Calancha
@ 2016-09-18 11:55         ` Dmitry Gutov
  0 siblings, 0 replies; 16+ messages in thread
From: Dmitry Gutov @ 2016-09-18 11:55 UTC (permalink / raw)
  To: Tino Calancha, Richard Copley; +Cc: Emacs developers

On 18.09.2016 14:09, Tino Calancha wrote:

> AFICT, if the user changes case-fold-search, `rgrep' and `lgrep' will
> follow that change, but `grep-find' seems keep unchanged.
> I guess the behaviour of `grep-find' should be similar as the other
> 2 commands.

Agreed. Maybe ideally, we get rid of both grep-command and 
grep-find-command, and generate both dynamically when required.

> Then, if a user want to keep his/her `grep-command' constant,
> s?he just need to customize it.

That would also be fine, but I don't know when or why would the users 
want that.



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

* Re: grep-command: Ignore case if case-fold-search is non-nil
  2016-09-18  9:31 grep-command: Ignore case if case-fold-search is non-nil Tino Calancha
  2016-09-18  9:57 ` Dmitry Gutov
@ 2016-09-18 14:45 ` Eli Zaretskii
  2016-09-18 15:10   ` Tino Calancha
  2016-09-18 18:03   ` Paul Eggert
  2016-09-18 15:05 ` Drew Adams
  2 siblings, 2 replies; 16+ messages in thread
From: Eli Zaretskii @ 2016-09-18 14:45 UTC (permalink / raw)
  To: Tino Calancha; +Cc: emacs-devel

> From: Tino Calancha <tino.calancha@gmail.com>
> Date: Sun, 18 Sep 2016 18:31:03 +0900 (JST)
> Cc: tino.calancha@gmail.com
> 
> Do you think `grep-compute-defaults' should add '-i', i.e., ignore case,
> in the default `grep-command' when `case-fold-search' is non-nil?

case-fold-search defaults to non-nil, so this would make "M-x grep"
case-insensitive for many users.  I'm not sure they will like it.

More generally, it is not clear to me that a the connection between
the buffer from which "M-x grep" is invoked and the search is strong
enough to make the Grep search "inherit" the case-sensitivity of
buffer searches.



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

* RE: grep-command: Ignore case if case-fold-search is non-nil
  2016-09-18  9:31 grep-command: Ignore case if case-fold-search is non-nil Tino Calancha
  2016-09-18  9:57 ` Dmitry Gutov
  2016-09-18 14:45 ` Eli Zaretskii
@ 2016-09-18 15:05 ` Drew Adams
  2016-09-18 15:14   ` Tino Calancha
  2 siblings, 1 reply; 16+ messages in thread
From: Drew Adams @ 2016-09-18 15:05 UTC (permalink / raw)
  To: Tino Calancha, Emacs developers

> Do you think `grep-compute-defaults' should add '-i', i.e., ignore case,
> in the default `grep-command' when `case-fold-search' is non-nil?

No.

Just because you might want to search the current buffer
case-(in)sensitively, that in no way implies that you want to
search a set of files somewhere the same way.

`grep' is an external command.  It is not about acting (e.g.,
searching) buffers within Emacs.



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

* Re: grep-command: Ignore case if case-fold-search is non-nil
  2016-09-18 14:45 ` Eli Zaretskii
@ 2016-09-18 15:10   ` Tino Calancha
  2016-09-18 16:52     ` Andreas Schwab
  2016-09-18 18:03   ` Paul Eggert
  1 sibling, 1 reply; 16+ messages in thread
From: Tino Calancha @ 2016-09-18 15:10 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel, Tino Calancha



On Sun, 18 Sep 2016, Eli Zaretskii wrote:

>> From: Tino Calancha <tino.calancha@gmail.com>
>> Date: Sun, 18 Sep 2016 18:31:03 +0900 (JST)
>> Cc: tino.calancha@gmail.com
>>
>> Do you think `grep-compute-defaults' should add '-i', i.e., ignore case,
>> in the default `grep-command' when `case-fold-search' is non-nil?
>
> case-fold-search defaults to non-nil, so this would make "M-x grep"
> case-insensitive for many users.  I'm not sure they will like it.
case-insensitive searches is a great default: it maximize the search 
space, no worries to missing a match.

> More generally, it is not clear to me that a the connection between
> the buffer from which "M-x grep" is invoked and the search is strong
> enough to make the Grep search "inherit" the case-sensitivity of
> buffer searches.
It's not totally clear to me either, but it's not lacking of some logic;
and if one user want 100% control s?he can customize `grep-command':  I do
it in order to pass the flag -I.  I prefer to ignore the binary files.




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

* RE: grep-command: Ignore case if case-fold-search is non-nil
  2016-09-18 15:05 ` Drew Adams
@ 2016-09-18 15:14   ` Tino Calancha
  2016-09-18 15:39     ` Eli Zaretskii
  2016-09-18 17:55     ` Drew Adams
  0 siblings, 2 replies; 16+ messages in thread
From: Tino Calancha @ 2016-09-18 15:14 UTC (permalink / raw)
  To: Drew Adams; +Cc: Emacs developers, Tino Calancha



On Sun, 18 Sep 2016, Drew Adams wrote:

>> Do you think `grep-compute-defaults' should add '-i', i.e., ignore case,
>> in the default `grep-command' when `case-fold-search' is non-nil?
>
> No.
>
> Just because you might want to search the current buffer
> case-(in)sensitively, that in no way implies that you want to
> search a set of files somewhere the same way.
>
> `grep' is an external command.  It is not about acting (e.g.,
> searching) buffers within Emacs.
Ok, let me change my question.

Should `grep' family of commands in Emacs pass '-i' as default,
regardless of the `case-fold-search' value in current buffer,
if the user didn't customize `grep-command'?





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

* Re: grep-command: Ignore case if case-fold-search is non-nil
  2016-09-18 15:14   ` Tino Calancha
@ 2016-09-18 15:39     ` Eli Zaretskii
  2016-09-18 17:55     ` Drew Adams
  1 sibling, 0 replies; 16+ messages in thread
From: Eli Zaretskii @ 2016-09-18 15:39 UTC (permalink / raw)
  To: Tino Calancha; +Cc: drew.adams, emacs-devel

> From: Tino Calancha <tino.calancha@gmail.com>
> Date: Mon, 19 Sep 2016 00:14:27 +0900 (JST)
> Cc: Emacs developers <emacs-devel@gnu.org>,
> 	Tino Calancha <tino.calancha@gmail.com>
> 
> Should `grep' family of commands in Emacs pass '-i' as default,
> regardless of the `case-fold-search' value in current buffer,
> if the user didn't customize `grep-command'?

Like I said, I don't think many users will like that, as it's not the
default behavior of Grep.  It is easy to add that if one wants it, so
no need to change a long-standing default, IMO.



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

* Re: grep-command: Ignore case if case-fold-search is non-nil
  2016-09-18 15:10   ` Tino Calancha
@ 2016-09-18 16:52     ` Andreas Schwab
  0 siblings, 0 replies; 16+ messages in thread
From: Andreas Schwab @ 2016-09-18 16:52 UTC (permalink / raw)
  To: Tino Calancha; +Cc: Eli Zaretskii, emacs-devel

On Sep 19 2016, Tino Calancha <tino.calancha@gmail.com> wrote:

> case-insensitive searches is a great default: it maximize the search
> space, no worries to missing a match.

It also maximised the false hits.  Unlike Emacs, grep doesn't revert
back to case sensitive matching if the search term contains upper case
letters.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



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

* RE: grep-command: Ignore case if case-fold-search is non-nil
  2016-09-18 15:14   ` Tino Calancha
  2016-09-18 15:39     ` Eli Zaretskii
@ 2016-09-18 17:55     ` Drew Adams
  2016-09-18 18:05       ` Tino Calancha
  1 sibling, 1 reply; 16+ messages in thread
From: Drew Adams @ 2016-09-18 17:55 UTC (permalink / raw)
  To: Tino Calancha; +Cc: Emacs developers

> > Just because you might want to search the current buffer
> > case-(in)sensitively, that in no way implies that you want to
> > search a set of files somewhere the same way.
> >
> > `grep' is an external command.  It is not about acting (e.g.,
> > searching) buffers within Emacs.
> Ok, let me change my question.
> 
> Should `grep' family of commands in Emacs pass '-i' as default,
> regardless of the `case-fold-search' value in current buffer,
> if the user didn't customize `grep-command'?

That's a better question.  I don't see why it should, but
it's a fair question.

The real point, I think, is that users can get their
preferred default behavior by customizing `grep-command'.
What the default value of that option is, is a secondary
consideration.  What's the argument for changing to -i
for the default?



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

* Re: grep-command: Ignore case if case-fold-search is non-nil
  2016-09-18 14:45 ` Eli Zaretskii
  2016-09-18 15:10   ` Tino Calancha
@ 2016-09-18 18:03   ` Paul Eggert
  1 sibling, 0 replies; 16+ messages in thread
From: Paul Eggert @ 2016-09-18 18:03 UTC (permalink / raw)
  To: Eli Zaretskii, Tino Calancha; +Cc: emacs-devel

Eli Zaretskii wrote:
> case-fold-search defaults to non-nil, so this would make "M-x grep"
> case-insensitive for many users.  I'm not sure they will like it.

Similarly for M-x grep-find and find's -i option, and for M-x vc-git-grep, and 
for M-x diff and diff's --ignore-case and --ignore-file-name-case options, and 
probably for other stuff.

It might be OK to add a new variable, which would have the effect of setting 
case-fold-search and all the other stuff, for users who want case-folding to be 
the default everywhere. But where would it stop? Would the new setting also have 
the effect of setting font-lock-keywords-case-fold-search, say?



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

* RE: grep-command: Ignore case if case-fold-search is non-nil
  2016-09-18 17:55     ` Drew Adams
@ 2016-09-18 18:05       ` Tino Calancha
  2016-09-18 18:16         ` Drew Adams
  0 siblings, 1 reply; 16+ messages in thread
From: Tino Calancha @ 2016-09-18 18:05 UTC (permalink / raw)
  To: Drew Adams; +Cc: Emacs developers, Tino Calancha



On Sun, 18 Sep 2016, Drew Adams wrote:

>>> Just because you might want to search the current buffer
>>> case-(in)sensitively, that in no way implies that you want to
>>> search a set of files somewhere the same way.
>>>
>>> `grep' is an external command.  It is not about acting (e.g.,
>>> searching) buffers within Emacs.
>> Ok, let me change my question.
>>
>> Should `grep' family of commands in Emacs pass '-i' as default,
>> regardless of the `case-fold-search' value in current buffer,
>> if the user didn't customize `grep-command'?
>
> That's a better question.  I don't see why it should, but
> it's a fair question.
>
> The real point, I think, is that users can get their
> preferred default behavior by customizing `grep-command'.
> What the default value of that option is, is a secondary
> consideration.  What's the argument for changing to -i
> for the default?
After Eli answers, i agree is not good idea changing a long
standing default value.  I actually customize `grep-command' to
do what i like to do, and i keep it case insensitive.
My only concern now i that `rgrep', `lgrep' follow case-fold-search
but `grep-find' do not.  It's a minor thing, though.



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

* RE: grep-command: Ignore case if case-fold-search is non-nil
  2016-09-18 18:05       ` Tino Calancha
@ 2016-09-18 18:16         ` Drew Adams
  0 siblings, 0 replies; 16+ messages in thread
From: Drew Adams @ 2016-09-18 18:16 UTC (permalink / raw)
  To: Tino Calancha; +Cc: Emacs developers

> My only concern now i that `rgrep', `lgrep' follow
> case-fold-search but `grep-find' do not.

I wonder why they do?  They were introduced in Emacs 22,
IIRC.  Perhaps their design was not as well thought-out
as it should be?



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

end of thread, other threads:[~2016-09-18 18:16 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-18  9:31 grep-command: Ignore case if case-fold-search is non-nil Tino Calancha
2016-09-18  9:57 ` Dmitry Gutov
2016-09-18 10:30   ` Tino Calancha
2016-09-18 10:52     ` Richard Copley
2016-09-18 11:09       ` Tino Calancha
2016-09-18 11:55         ` Dmitry Gutov
2016-09-18 14:45 ` Eli Zaretskii
2016-09-18 15:10   ` Tino Calancha
2016-09-18 16:52     ` Andreas Schwab
2016-09-18 18:03   ` Paul Eggert
2016-09-18 15:05 ` Drew Adams
2016-09-18 15:14   ` Tino Calancha
2016-09-18 15:39     ` Eli Zaretskii
2016-09-18 17:55     ` Drew Adams
2016-09-18 18:05       ` Tino Calancha
2016-09-18 18:16         ` Drew Adams

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.