zsh-workers
 help / color / mirror / code / Atom feed
* Re: [PATCH] _fc: allow the user to limit the number of events
       [not found] <812932212.4222957.1467756469555.JavaMail.yahoo.ref@mail.yahoo.com>
@ 2016-07-05 22:07 ` Oliver Kiddle
  2016-07-11 19:55 ` Eric Cook
  1 sibling, 0 replies; 5+ messages in thread
From: Oliver Kiddle @ 2016-07-05 22:07 UTC (permalink / raw)
  To: zsh-workers

Eric Cook wrote:
> +    zstyle -s ":completion:${curcontext}:history-events" history-events _histno

The actual matches are added with just 'events' as the tag so the tag component of this style should be consistent with that.

I'd also agree that the style should have a more generic name. _dates has a max-matches-length style which does the same thing (apart from also allowing a percentage). You might also consider copying the special _next_tags handling from _dates.

> +++ b/Completion/Linux/Command/_sysstat
> @@ -1,4 +1,4 @@
> -#compdef -P mpstat (|cifs)iostat isag sadf sar pidstat
> +#compdef -P mpstat cifsiostat isag sadf sar pidstat

If you remove the pattern, the -P option is not needed here anymore.

Oliver


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

* [PATCH] _fc: allow the user to limit the number of events
       [not found] <812932212.4222957.1467756469555.JavaMail.yahoo.ref@mail.yahoo.com>
  2016-07-05 22:07 ` [PATCH] _fc: allow the user to limit the number of events Oliver Kiddle
@ 2016-07-11 19:55 ` Eric Cook
  1 sibling, 0 replies; 5+ messages in thread
From: Eric Cook @ 2016-07-11 19:55 UTC (permalink / raw)
  To: zsh-workers

What about `max-matches'? I did like `max-matches-length' until i read
what `max-matches-width' does. Knowing that, i would personally expect
m-m-length to do something related to m-m-width.

I fixed _dates to allow single digit percentages too.

I also don't know understand what the _next_tags stuff in _dates is doing
So i didn't cargo cult it, do you mind explaining?
---
diff --git a/Completion/Unix/Type/_dates b/Completion/Unix/Type/_dates
index e4fa62e..64a1833 100644
--- a/Completion/Unix/Type/_dates
+++ b/Completion/Unix/Type/_dates
@@ -27,7 +27,7 @@ format=${userformat:-${format[2]:-%F}}
 
 zstyle -a ':completion:$curcontext:dates' max-matches-length r
 for ri in $r; do
-  [[ $ri = [0-9]##% ]] && (( ri = LINES * .${ri%%%} ))
+  [[ $ri = [0-9]##% ]] && (( ri = LINES * .${(l:2::0:)ri%%%} ))
   (( ri < rows )) && (( rows=ri ))
 done
 (( rows = rows / 8 ))
diff --git a/Completion/Zsh/Command/_fc b/Completion/Zsh/Command/_fc
index 68456cc..046cad2 100644
--- a/Completion/Zsh/Command/_fc
+++ b/Completion/Zsh/Command/_fc
@@ -1,7 +1,7 @@
 #compdef fc history r
 
 local curcontext="$curcontext" state state_descr line ret=1
-local events num cmd sep
+local events num cmd sep _histno _histi
 typeset -A opt_args
 local fc_common fc_hist fc_r
 
@@ -75,7 +75,15 @@ if [[ -n $state ]]; then
     _wanted -2V events expl "$state_descr" compadd -M "B:0=" -ld events - \
         "${events[@]%% *}"
   elif [[ -prefix - ]]; then
+    zstyle -s ":completion:${curcontext}:events" max-matches _histno
+    if [[ $_histno = <->% ]]; then
+      (( _histno = HISTNO * .${(l:2::0:)_histno%%%} ))
+    elif ! [[ $_histno = <-> ]]; then
+      _histno=$((HISTNO+1))
+    fi
+
     for num cmd in "${(kv@)history}"; do
+      (( ++_histi < _histno )) || break
       (( num=num - HISTNO ))
       events+=( "${(r.1+$#HISTNO.)num} $sep $cmd" )
     done
diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo
index 8792324..9c23bb5 100644
--- a/Doc/Zsh/compsys.yo
+++ b/Doc/Zsh/compsys.yo
@@ -2123,6 +2123,12 @@ performed.
 
 The default value for this style is `tt(2 numeric)'.
 )
+kindex(max-matches, completion style)
+item(tt(max-matches))(
+If this is set to an integer or percentage, it is used to limit the number
+of matches for commands that support it. tt(fc) and tt(history) are two examples
+that use it due to possibly generating a large number of matches.
+)
 kindex(max-matches-width, completion style)
 item(tt(max-matches-width))(
 This style is used to determine the trade off between the width of the


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

* Re: [PATCH] _fc: allow the user to limit the number of events
  2016-07-05  4:57 ` Daniel Shahaf
@ 2016-07-05 14:58   ` Mikael Magnusson
  0 siblings, 0 replies; 5+ messages in thread
From: Mikael Magnusson @ 2016-07-05 14:58 UTC (permalink / raw)
  To: Daniel Shahaf; +Cc: Eric Cook, zsh workers

On Tue, Jul 5, 2016 at 6:57 AM, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> Eric Cook wrote on Mon, Jul 04, 2016 at 17:32:59 -0400:
>> I am open to a better style name if someone can think of one.
>
>> +kindex(history-events, completion style)
>> +item(tt(history-events))(
>> +If this is set to a number, it is used to limit the number of history
>> +events when completing tt(fc) or tt(history).
>> +)
>
> How about calling the style `limit`?  That name is more generic so other
> places could use it too.  (Example: __git_reflog_entries)

The _history completer uses "range", but the format of that is
slightly different.

-- 
Mikael Magnusson


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

* Re: [PATCH] _fc: allow the user to limit the number of events
  2016-07-04 21:32 Eric Cook
@ 2016-07-05  4:57 ` Daniel Shahaf
  2016-07-05 14:58   ` Mikael Magnusson
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel Shahaf @ 2016-07-05  4:57 UTC (permalink / raw)
  To: Eric Cook; +Cc: zsh-workers

Eric Cook wrote on Mon, Jul 04, 2016 at 17:32:59 -0400:
> I am open to a better style name if someone can think of one.

> +kindex(history-events, completion style)
> +item(tt(history-events))(
> +If this is set to a number, it is used to limit the number of history
> +events when completing tt(fc) or tt(history).
> +)

How about calling the style `limit`?  That name is more generic so other
places could use it too.  (Example: __git_reflog_entries)


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

* [PATCH] _fc: allow the user to limit the number of events
@ 2016-07-04 21:32 Eric Cook
  2016-07-05  4:57 ` Daniel Shahaf
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Cook @ 2016-07-04 21:32 UTC (permalink / raw)
  To: zsh-workers

Which can be useful when someone has an very large HISTFILE.
I am open to a better style name if someone can think of one.

---
 Completion/Zsh/Command/_fc | 5 ++++-
 Doc/Zsh/compsys.yo         | 5 +++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/Completion/Zsh/Command/_fc b/Completion/Zsh/Command/_fc
index 68456cc..5044451 100644
--- a/Completion/Zsh/Command/_fc
+++ b/Completion/Zsh/Command/_fc
@@ -1,7 +1,7 @@
 #compdef fc history r
 
 local curcontext="$curcontext" state state_descr line ret=1
-local events num cmd sep
+local events num cmd sep _histno _histi
 typeset -A opt_args
 local fc_common fc_hist fc_r
 
@@ -75,7 +75,10 @@ if [[ -n $state ]]; then
     _wanted -2V events expl "$state_descr" compadd -M "B:0=" -ld events - \
         "${events[@]%% *}"
   elif [[ -prefix - ]]; then
+    zstyle -s ":completion:${curcontext}:history-events" history-events _histno
+    _histno=${_histno%%:<->}; [[ $_histno = <-> ]] || _histno=$((HISTNO+1))
     for num cmd in "${(kv@)history}"; do
+      (( ++_histi < _histno )) || break
       (( num=num - HISTNO ))
       events+=( "${(r.1+$#HISTNO.)num} $sep $cmd" )
     done
diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo
index fb0abce..fa20b6b 100644
--- a/Doc/Zsh/compsys.yo
+++ b/Doc/Zsh/compsys.yo
@@ -1691,6 +1691,11 @@ in the list.  To avoid having matches considered as possible
 completions at all, the tt(tag-order) style can be modified as described
 below.
 )
+kindex(history-events, completion style)
+item(tt(history-events))(
+If this is set to a number, it is used to limit the number of history
+events when completing tt(fc) or tt(history).
+)
 kindex(hosts, completion style)
 item(tt(hosts))(
 A list of names of hosts that should be completed.  If this is not set,
-- 
2.6.6


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

end of thread, other threads:[~2016-07-11 20:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <812932212.4222957.1467756469555.JavaMail.yahoo.ref@mail.yahoo.com>
2016-07-05 22:07 ` [PATCH] _fc: allow the user to limit the number of events Oliver Kiddle
2016-07-11 19:55 ` Eric Cook
2016-07-04 21:32 Eric Cook
2016-07-05  4:57 ` Daniel Shahaf
2016-07-05 14:58   ` Mikael Magnusson

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