Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[PATCH] _fc: allow the user to limit the number of events



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



Messages sorted by: Reverse Date, Date, Thread, Author