zsh-workers
 help / color / Atom feed
* PATCH: Update the description of S flag in the completion
@ 2019-12-02  0:31 Sebastian Gniazdowski
  2019-12-02  0:46 ` Sebastian Gniazdowski
  0 siblings, 1 reply; 6+ messages in thread
From: Sebastian Gniazdowski @ 2019-12-02  0:31 UTC (permalink / raw)
  To: Zsh hackers list

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

Hi,
the current description is:
S  -- search substrings in #, %, / expressions

which:
- is counter the manual and usage-proof, as the flag affects / and //
substitutions only in the non-greedy way.

The patch changes the description to:
S -- match non-greedy in /, // or search substrings in % and # expressions

(the referenced manual fragment is:
       S      Search substrings as well as beginnings or  ends;  with
#  start  from  the
              beginning and with  % start from the end of the string.
With substitution
              via ${.../...} or ${...//...}, specifies non-greedy
matching, i.e. that  the
              shortest instead of the longest match should be replaced.)

-- 
Sebastian Gniazdowski
News: https://twitter.com/ZdharmaI
IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin
Blog: http://zdharma.org

[-- Attachment #2: 0001-_brace_parameter-Update-the-description-of-S-flag.patch.2.txt --]
[-- Type: text/plain, Size: 1089 bytes --]

From c0f421ae9988cb125243845eb3acc59847f818b7 Mon Sep 17 00:00:00 2001
From: Sebastian Gniazdowski <sgniazdowski@gmail.com>
Date: Mon, 2 Dec 2019 01:16:03 +0100
Subject: [PATCH] _brace_parameter: Update the description of S flag

---
 Completion/Zsh/Context/_brace_parameter | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Completion/Zsh/Context/_brace_parameter b/Completion/Zsh/Context/_brace_parameter
index a9ab44efd..c6e74bf7b 100644
--- a/Completion/Zsh/Context/_brace_parameter
+++ b/Completion/Zsh/Context/_brace_parameter
@@ -177,7 +177,7 @@ if [[ $PREFIX = *'${('[^\)]# ]]; then
     "s:split words on specified string"
     "Z:split words as if zsh command line (with options)"
     # "_:extended flags, for future expansion"
-    "S:search substrings in #, %, / expressions"
+    "S:match non-greedy in /, // or search substrings in % and # expressions"
     "I:search <argument>th match in #, %, / expressions"
     "B:include index of beginning of match in #, % expressions"
     "E:include index of one past end of match in #, % expressions"
-- 
2.21.0


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

* Re: PATCH: Update the description of S flag in the completion
  2019-12-02  0:31 PATCH: Update the description of S flag in the completion Sebastian Gniazdowski
@ 2019-12-02  0:46 ` Sebastian Gniazdowski
  2019-12-03  5:16   ` Sebastian Gniazdowski
  2019-12-03 10:39   ` Oliver Kiddle
  0 siblings, 2 replies; 6+ messages in thread
From: Sebastian Gniazdowski @ 2019-12-02  0:46 UTC (permalink / raw)
  To: Zsh hackers list

On that occasion, isn't this a bug?:

❯ str="ab##c#d"; print ${(S)str##\#}
ab#c#d
❯ str="ab##c#d"; print ${(S)str##\##}
ab##c#d

Why no match at all in the second case?

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

* Re: PATCH: Update the description of S flag in the completion
  2019-12-02  0:46 ` Sebastian Gniazdowski
@ 2019-12-03  5:16   ` Sebastian Gniazdowski
  2019-12-03  9:42     ` Peter Stephenson
  2019-12-03 10:39   ` Oliver Kiddle
  1 sibling, 1 reply; 6+ messages in thread
From: Sebastian Gniazdowski @ 2019-12-03  5:16 UTC (permalink / raw)
  To: Zsh hackers list

On Mon, 2 Dec 2019 at 01:46, Sebastian Gniazdowski
<sgniazdowski@gmail.com> wrote:
>
> On that occasion, isn't this a bug?:
>
> ❯ str="ab##c#d"; print ${(S)str##\#}
> ab#c#d
> ❯ str="ab##c#d"; print ${(S)str##\##}
> ab##c#d
>
> Why no match at all in the second case?

Any update on this? It would be good that the rarely-used flags are reliable.

-- 
Sebastian Gniazdowski
News: https://twitter.com/ZdharmaI
IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin
Blog: http://zdharma.org

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

* Re: PATCH: Update the description of S flag in the completion
  2019-12-03  5:16   ` Sebastian Gniazdowski
@ 2019-12-03  9:42     ` Peter Stephenson
  2019-12-03 14:45       ` Sebastian Gniazdowski
  0 siblings, 1 reply; 6+ messages in thread
From: Peter Stephenson @ 2019-12-03  9:42 UTC (permalink / raw)
  To: zsh-workers

On Tue, 2019-12-03 at 06:16 +0100, Sebastian Gniazdowski wrote:
> On Mon, 2 Dec 2019 at 01:46, Sebastian Gniazdowski
> <sgniazdowski@gmail.com> wrote:
> > 
> > 
> > On that occasion, isn't this a bug?:
> > 
> > ❯ str="ab##c#d"; print ${(S)str##\#}
> > ab#c#d
> > ❯ str="ab##c#d"; print ${(S)str##\##}
> > ab##c#d
> > 
> > Why no match at all in the second case?
> Any update on this? It would be good that the rarely-used flags are reliable.
> 

You've got an expression which can match an empty string which you're
also telling to match a substring so it can match an empty string
anywhere.  The order in which it tries to match will be crucial so this
is not a useful thing to attempt.  What are you actually trying to do?

pws


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

* Re: PATCH: Update the description of S flag in the completion
  2019-12-02  0:46 ` Sebastian Gniazdowski
  2019-12-03  5:16   ` Sebastian Gniazdowski
@ 2019-12-03 10:39   ` Oliver Kiddle
  1 sibling, 0 replies; 6+ messages in thread
From: Oliver Kiddle @ 2019-12-03 10:39 UTC (permalink / raw)
  To: Sebastian Gniazdowski; +Cc: Zsh hackers list

Sebastian Gniazdowski wrote:
> On that occasion, isn't this a bug?:
>
> ❯ str="ab##c#d"; print ${(S)str##\#}
> ab#c#d
> ❯ str="ab##c#d"; print ${(S)str##\##}
> ab##c#d
>
> Why no match at all in the second case?

It does not exhaustively find the longest match. It takes the first
possible match but matches that one greedily. The first possible match
is the empty string at the beginning of the string.

I think the following demonstrates how this works more clearly:

  % str="aXXbXXXXXXXXc"; print ${(S)str##X##}
  abXXXXXXXXc

This matches the shorter block of Xs between a and b and the greedyness
means that both Xs were matched. ${(S)str#X##} returns aXbXXXXXXXXc.

Oliver

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

* Re: PATCH: Update the description of S flag in the completion
  2019-12-03  9:42     ` Peter Stephenson
@ 2019-12-03 14:45       ` Sebastian Gniazdowski
  0 siblings, 0 replies; 6+ messages in thread
From: Sebastian Gniazdowski @ 2019-12-03 14:45 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Zsh hackers list

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

wt., 3 gru 2019, 10:43 użytkownik Peter Stephenson <p.stephenson@samsung.com>
napisał:

> On Tue, 2019-12-03 at 06:16 +0100, Sebastian Gniazdowski wrote:
> > On Mon, 2 Dec 2019 at 01:46, Sebastian Gniazdowski
> > <sgniazdowski@gmail.com> wrote:
> > >
> > >
> > > On that occasion, isn't this a bug?:
> > >
> > > ❯ str="ab##c#d"; print ${(S)str##\#}
> > > ab#c#d
> > > ❯ str="ab##c#d"; print ${(S)str##\##}
> > > ab##c#d
> > >
> > > Why no match at all in the second case?
> > Any update on this? It would be good that the rarely-used flags are
> reliable.
> >
>
> You've got an expression which can match an empty string which you're
> also telling to match a substring so it can match an empty string
> anywhere.  The order in which it tries to match will be crucial so this
> is not a useful thing to attempt.  What are you actually trying to do?
>

I was expecting that it'll do a greedy match. Turns out, as Oliver writes,
that there's something like "nonexhaustive" greedy match which seems to
work like (|\###) so this pretty much explains it. I wasn't doing anything
particular, just testing the flags before updating the description.

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

end of thread, back to index

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-02  0:31 PATCH: Update the description of S flag in the completion Sebastian Gniazdowski
2019-12-02  0:46 ` Sebastian Gniazdowski
2019-12-03  5:16   ` Sebastian Gniazdowski
2019-12-03  9:42     ` Peter Stephenson
2019-12-03 14:45       ` Sebastian Gniazdowski
2019-12-03 10:39   ` Oliver Kiddle

zsh-workers

Archives are clonable: git clone --mirror http://inbox.vuxu.org/zsh-workers

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.workers


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git