zsh-workers
 help / color / mirror / code / Atom feed
* Documentation error
@ 2011-12-10 17:09 gi1242+zsh
  2011-12-10 17:37 ` Mikael Magnusson
  0 siblings, 1 reply; 11+ messages in thread
From: gi1242+zsh @ 2011-12-10 17:09 UTC (permalink / raw)
  To: zsh-workers

Hi All,

Is the following an error in the documentation from man zshcompsys:

      _example_caching_policy () {
	     # rebuild if cache is more than a week old
	     local -a oldp
	     oldp=( "$1"(Nmw+1) )
	     (( $#oldp ))
	 }

Technically won't this rebuild the cache if it's more than TWO weeks
old? "$1"(Nmw+0) seems to do one week old for me,

GI

-- 
A gossip is someone with a great sense of rumor.


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

* Re: Documentation error
  2011-12-10 17:09 Documentation error gi1242+zsh
@ 2011-12-10 17:37 ` Mikael Magnusson
  2011-12-10 17:44   ` gi1242+zsh
  0 siblings, 1 reply; 11+ messages in thread
From: Mikael Magnusson @ 2011-12-10 17:37 UTC (permalink / raw)
  To: gi1242+zsh, zsh-workers

On 10 December 2011 18:09,  <gi1242+zsh@gmail.com> wrote:
> Hi All,
>
> Is the following an error in the documentation from man zshcompsys:
>
>      _example_caching_policy () {
>             # rebuild if cache is more than a week old
>             local -a oldp
>             oldp=( "$1"(Nmw+1) )
>             (( $#oldp ))
>         }
>
> Technically won't this rebuild the cache if it's more than TWO weeks
> old? "$1"(Nmw+0) seems to do one week old for me,

It depends on what you mean by more than one week. The way it works in
zsh is that -, +, and no sign are disjunct sets, so mw-1, mw1, mw+1
don't have any overlap. mw1 is any files that are one week old, which
is 7-13 days, so more than that is 14 days old (two weeks).

-- 
Mikael Magnusson


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

* Re: Documentation error
  2011-12-10 17:37 ` Mikael Magnusson
@ 2011-12-10 17:44   ` gi1242+zsh
  2011-12-10 18:29     ` Peter Stephenson
  0 siblings, 1 reply; 11+ messages in thread
From: gi1242+zsh @ 2011-12-10 17:44 UTC (permalink / raw)
  To: zsh-workers

On Sat, Dec 10, 2011 at 06:37:04PM +0100, Mikael Magnusson wrote:

>> Hi All,
>>
>> Is the following an error in the documentation from man zshcompsys:
>>
>>      _example_caching_policy () {
>>             # rebuild if cache is more than a week old
>>             local -a oldp
>>             oldp=( "$1"(Nmw+1) )
>>             (( $#oldp ))
>>         }
>>
>> Technically won't this rebuild the cache if it's more than TWO weeks
>> old? "$1"(Nmw+0) seems to do one week old for me,
> 
> It depends on what you mean by more than one week. The way it works in
> zsh is that -, +, and no sign are disjunct sets, so mw-1, mw1, mw+1
> don't have any overlap. mw1 is any files that are one week old, which
> is 7-13 days, so more than that is 14 days old (two weeks).

Hmm. mw+1 gave me false for a 13 day old file, and true for a 15 day old
file. But mw+0 gave me true for all files more than a week old. 

Reading the comment in the ZSH man page (included above), I'd guess it
means that the cache will be rebuilt if it's more than 7 days old.
However, it appears to only be rebuilt if it's more than 14 days old?

Perhaps the comment above (or example above) should be changed to match
up? [I'm of course not advocating any change in ZSH behaviour.]

GI

-- 
Chemicals: Noxious substances from which modern foods are made.


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

* Re: Documentation error
  2011-12-10 17:44   ` gi1242+zsh
@ 2011-12-10 18:29     ` Peter Stephenson
  2011-12-10 18:54       ` Mikael Magnusson
  0 siblings, 1 reply; 11+ messages in thread
From: Peter Stephenson @ 2011-12-10 18:29 UTC (permalink / raw)
  To: zsh-workers

On Sat, 10 Dec 2011 12:44:11 -0500
gi1242+zsh@gmail.com wrote:
> >>...
> >>             # rebuild if cache is more than a week old
> >>             local -a oldp
> >>             oldp=( "$1"(Nmw+1) )
> >>...
> >> Technically won't this rebuild the cache if it's more than TWO weeks
> >> old? "$1"(Nmw+0) seems to do one week old for me,
> > 
> > It depends on what you mean by more than one week. The way it works in
> > zsh is that -, +, and no sign are disjunct sets, so mw-1, mw1, mw+1
> > don't have any overlap. mw1 is any files that are one week old, which
> > is 7-13 days, so more than that is 14 days old (two weeks).
> 
> Hmm. mw+1 gave me false for a 13 day old file, and true for a 15 day old
> file. But mw+0 gave me true for all files more than a week old. 
> 
> Reading the comment in the ZSH man page (included above), I'd guess it
> means that the cache will be rebuilt if it's more than 7 days old.
> However, it appears to only be rebuilt if it's more than 14 days old?
> 
> Perhaps the comment above (or example above) should be changed to match
> up? [I'm of course not advocating any change in ZSH behaviour.]

It does seem to violate the principle of least surprise --- the
documentation for globbing qualifiers now has a long spiel about
ignoring the fraction part of the difference in times to try to explain.
Maybe +7 (days) is better?  Of course there's still the same oddity at
the level of a day but that's a good deal easier to sweep under the
carpet.

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


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

* Re: Documentation error
  2011-12-10 18:29     ` Peter Stephenson
@ 2011-12-10 18:54       ` Mikael Magnusson
  2011-12-10 19:26         ` Peter Stephenson
  0 siblings, 1 reply; 11+ messages in thread
From: Mikael Magnusson @ 2011-12-10 18:54 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zsh-workers

On 10 December 2011 19:29, Peter Stephenson <p.w.stephenson@ntlworld.com> wrote:
> On Sat, 10 Dec 2011 12:44:11 -0500
> gi1242+zsh@gmail.com wrote:
>> >>...
>> >>             # rebuild if cache is more than a week old
>> >>             local -a oldp
>> >>             oldp=( "$1"(Nmw+1) )
>> >>...
>> >> Technically won't this rebuild the cache if it's more than TWO weeks
>> >> old? "$1"(Nmw+0) seems to do one week old for me,
>> >
>> > It depends on what you mean by more than one week. The way it works in
>> > zsh is that -, +, and no sign are disjunct sets, so mw-1, mw1, mw+1
>> > don't have any overlap. mw1 is any files that are one week old, which
>> > is 7-13 days, so more than that is 14 days old (two weeks).
>>
>> Hmm. mw+1 gave me false for a 13 day old file, and true for a 15 day old
>> file. But mw+0 gave me true for all files more than a week old.
>>
>> Reading the comment in the ZSH man page (included above), I'd guess it
>> means that the cache will be rebuilt if it's more than 7 days old.
>> However, it appears to only be rebuilt if it's more than 14 days old?
>>
>> Perhaps the comment above (or example above) should be changed to match
>> up? [I'm of course not advocating any change in ZSH behaviour.]
>
> It does seem to violate the principle of least surprise --- the
> documentation for globbing qualifiers now has a long spiel about
> ignoring the fraction part of the difference in times to try to explain.
> Maybe +7 (days) is better?  Of course there's still the same oddity at
> the level of a day but that's a good deal easier to sweep under the
> carpet.

There's no day modifier :).

-- 
Mikael Magnusson


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

* Re: Documentation error
  2011-12-10 18:54       ` Mikael Magnusson
@ 2011-12-10 19:26         ` Peter Stephenson
  2011-12-10 20:02           ` PATCH: _globquals: Say what the digit is when completing modification time qualifiers Mikael Magnusson
  2011-12-10 20:13           ` Documentation error Peter Stephenson
  0 siblings, 2 replies; 11+ messages in thread
From: Peter Stephenson @ 2011-12-10 19:26 UTC (permalink / raw)
  To: zsh-workers

On Sat, 10 Dec 2011 19:54:02 +0100
Mikael Magnusson <mikachu@gmail.com> wrote:
> There's no day modifier :).

It's the default, *(m+7) does it.

(There could be perfectly well be a "d" modifier, too, to avoid suprises,
however.  I seem to remember it's caught me in the past.)

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


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

* PATCH: _globquals: Say what the digit is when completing modification time qualifiers
  2011-12-10 19:26         ` Peter Stephenson
@ 2011-12-10 20:02           ` Mikael Magnusson
  2011-12-13 19:23             ` PATCH: _globquals: Say what the digit is when completing time qualifiers, add d Mikael Magnusson
  2011-12-10 20:13           ` Documentation error Peter Stephenson
  1 sibling, 1 reply; 11+ messages in thread
From: Mikael Magnusson @ 2011-12-10 20:02 UTC (permalink / raw)
  To: zsh-workers

How about something like this too? It changes the completion output to
say what the digit means.

% *(m<tab>
=== time specifier
M  -- months
h  -- hours
m  -- minutes
s  -- seconds
w  -- weeks
=== sense
+  -- more than
-  -- less than
=== digit (days)

% *(mM<tab>
=== digit (months)


---
 Completion/Zsh/Type/_globquals |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/Completion/Zsh/Type/_globquals b/Completion/Zsh/Type/_globquals
index 778dfa8..b47a34d 100644
--- a/Completion/Zsh/Type/_globquals
+++ b/Completion/Zsh/Type/_globquals
@@ -114,6 +114,10 @@ while [[ -n $PREFIX ]]; do
     if ! compset -P '([Mwhms]|)([-+]|)<->'; then
       # complete/skip relative time spec
       alts=()
+      () {
+      local timespec=$PREFIX[1]
+      local -A specmap
+      specmap=( M months w weeks h hours m minutes s seconds '' days )
       if ! compset -P '[Mwhms]' && [[ -z $PREFIX ]]; then
         alts+=(
           "time-specifiers:time specifier:\
@@ -122,7 +126,8 @@ while [[ -n $PREFIX ]]; do
       if ! compset -P '[-+]' && [[ -z $PREFIX ]]; then
         alts+=("senses:sense:((-\:less\ than +\:more\ than))")
       fi
-      alts+=('digits:digit: ')
+      alts+=('digits:digit ('${${specmap[$timespec]}:-invalid time specifier}'): ')
+      }
       _alternative $alts
       return
     fi
-- 
1.7.5.4


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

* Re: Documentation error
  2011-12-10 19:26         ` Peter Stephenson
  2011-12-10 20:02           ` PATCH: _globquals: Say what the digit is when completing modification time qualifiers Mikael Magnusson
@ 2011-12-10 20:13           ` Peter Stephenson
  2011-12-11  2:22             ` gi1242+zsh
  1 sibling, 1 reply; 11+ messages in thread
From: Peter Stephenson @ 2011-12-10 20:13 UTC (permalink / raw)
  To: zsh-workers

On Sat, 10 Dec 2011 19:26:47 +0000
Peter Stephenson <p.w.stephenson@ntlworld.com> wrote:
> (There could be perfectly well be a "d" modifier, too, to avoid suprises,
> however.  I seem to remember it's caught me in the past.)

Can't see any harm; there's no clash with other syntax, since at least
the number is mandatory.

Index: Doc/Zsh/expn.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/expn.yo,v
retrieving revision 1.140
diff -p -u -r1.140 expn.yo
--- Doc/Zsh/expn.yo	28 Aug 2011 16:38:28 -0000	1.140
+++ Doc/Zsh/expn.yo	10 Dec 2011 20:11:50 -0000
@@ -2430,7 +2430,8 @@ Files accessed more than var(n) days ago
 value (tt(PLUS())var(n)).  Optional unit specifiers `tt(M)', `tt(w)',
 `tt(h)', `tt(m)' or `tt(s)' (e.g. `tt(ah5)') cause the check to be
 performed with months (of 30 days), weeks, hours, minutes or seconds
-instead of days, respectively.
+instead of days, respectively.  An explicit `tt(d)' for days is also
+allowed.
 
 Any fractional part of the difference between the access time and the
 current part in the appropriate units is ignored in the comparison.  For
Index: Src/glob.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/glob.c,v
retrieving revision 1.78
diff -p -u -r1.78 glob.c
--- Src/glob.c	7 Dec 2011 01:31:21 -0000	1.78
+++ Src/glob.c	10 Dec 2011 20:11:50 -0000
@@ -1530,6 +1530,8 @@ zglob(LinkList list, LinkNode np, int no
 			    g_units = TT_MONTHS, ++s;
 			else if (*s == 's')
 			    g_units = TT_SECONDS, ++s;
+			else if (*s == 'd')
+			    ++s;
 		    }
 		    /* See if it's greater than, equal to, or less than */
 		    if ((g_range = *s == '+' ? 1 : *s == '-' ? -1 : 0))

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


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

* Re: Documentation error
  2011-12-10 20:13           ` Documentation error Peter Stephenson
@ 2011-12-11  2:22             ` gi1242+zsh
  0 siblings, 0 replies; 11+ messages in thread
From: gi1242+zsh @ 2011-12-11  2:22 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zsh-workers

On Sat, Dec 10, 2011 at 08:13:50PM +0000, Peter Stephenson wrote:

>> (There could be perfectly well be a "d" modifier, too, to avoid suprises,
>> however.  I seem to remember it's caught me in the past.)
> 
> Can't see any harm; there's no clash with other syntax, since at least
> the number is mandatory.

Great! I first tried replacing mw+1 with md+7, got caught and removed
the d. Accepting a "d" modifier reduces surprise.

About the completion documentation, what was the verdict? If you just
change

    oldp=( "$1"(Nmw+1) )

to 

    oldp=( "$1"(Nmw+0) )

in the zshcompsys man page (in the cache_invalid example), it will
surprise novices much less. Not the end of the world if you don't change
it though...

Best,

GI

-- 
TEN SURE SIGNS THE RECESSION HAS HIT REALLY HARD
5. McDonald's is selling the 1/4 ouncer.


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

* PATCH: _globquals: Say what the digit is when completing time qualifiers, add d
  2011-12-10 20:02           ` PATCH: _globquals: Say what the digit is when completing modification time qualifiers Mikael Magnusson
@ 2011-12-13 19:23             ` Mikael Magnusson
  2011-12-13 21:27               ` Peter Stephenson
  0 siblings, 1 reply; 11+ messages in thread
From: Mikael Magnusson @ 2011-12-13 19:23 UTC (permalink / raw)
  To: zsh-workers

Added the d flag, and moved locals to top to get rid of anon function.
It seems the scoping conflicts with compset -P somehow. I didn't notice
at first that with my previous patch, *(mM<tab> would no longer output
the +- hints, as you can see in the previous mail. Now it works:

% *(mM<tab>
=== sense
+  -- more than
-  -- less than
=== digit (months)


---
 Completion/Zsh/Type/_globquals |   16 +++++++++-------
 1 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/Completion/Zsh/Type/_globquals b/Completion/Zsh/Type/_globquals
index 778dfa8..9de7742 100644
--- a/Completion/Zsh/Type/_globquals
+++ b/Completion/Zsh/Type/_globquals
@@ -1,7 +1,8 @@
 #autoload
 
-local state=qual expl char delim
+local state=qual expl char delim timespec
 local -a alts
+local -A specmap
 
 while [[ -n $PREFIX ]]; do
   char=$PREFIX[1]
@@ -111,18 +112,19 @@ while [[ -n $PREFIX ]]; do
     ;;
 
     ([amc])
-    if ! compset -P '([Mwhms]|)([-+]|)<->'; then
+    if ! compset -P '([Mwhmsd]|)([-+]|)<->'; then
       # complete/skip relative time spec
       alts=()
-      if ! compset -P '[Mwhms]' && [[ -z $PREFIX ]]; then
-        alts+=(
-          "time-specifiers:time specifier:\
-((M\:months w\:weeks h\:hours m:\minutes s\:seconds))")
+      timespec=$PREFIX[1]
+      if ! compset -P '[Mwhmsd]' && [[ -z $PREFIX ]]; then
+        alts+=("time-specifiers:time specifier:\
+((M\:months w\:weeks h\:hours m:\minutes s\:seconds d\:days))")
       fi
       if ! compset -P '[-+]' && [[ -z $PREFIX ]]; then
         alts+=("senses:sense:((-\:less\ than +\:more\ than))")
       fi
-      alts+=('digits:digit: ')
+      specmap=( M months w weeks h hours m minutes s seconds '(|+|-|d)' days)
+      alts+=('digits:digit ('${${specmap[(K)$timespec]}:-invalid time specifier}'):' )
       _alternative $alts
       return
     fi
-- 
1.7.5.4


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

* Re: PATCH: _globquals: Say what the digit is when completing time qualifiers, add d
  2011-12-13 19:23             ` PATCH: _globquals: Say what the digit is when completing time qualifiers, add d Mikael Magnusson
@ 2011-12-13 21:27               ` Peter Stephenson
  0 siblings, 0 replies; 11+ messages in thread
From: Peter Stephenson @ 2011-12-13 21:27 UTC (permalink / raw)
  To: zsh-workers

On Tue, 13 Dec 2011 20:23:26 +0100
Mikael Magnusson <mikachu@gmail.com> wrote:
> Added the d flag, and moved locals to top to get rid of anon function.
> It seems the scoping conflicts with compset -P somehow.

There are hooks to restore state after function calls in the completion
system so you can use a different function to complete something else
without too much work.  Anonymous functions have the same effect as any
other.

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


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

end of thread, other threads:[~2011-12-13 21:27 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-10 17:09 Documentation error gi1242+zsh
2011-12-10 17:37 ` Mikael Magnusson
2011-12-10 17:44   ` gi1242+zsh
2011-12-10 18:29     ` Peter Stephenson
2011-12-10 18:54       ` Mikael Magnusson
2011-12-10 19:26         ` Peter Stephenson
2011-12-10 20:02           ` PATCH: _globquals: Say what the digit is when completing modification time qualifiers Mikael Magnusson
2011-12-13 19:23             ` PATCH: _globquals: Say what the digit is when completing time qualifiers, add d Mikael Magnusson
2011-12-13 21:27               ` Peter Stephenson
2011-12-10 20:13           ` Documentation error Peter Stephenson
2011-12-11  2:22             ` gi1242+zsh

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

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 NNTP newsgroup(s).