zsh-workers
 help / color / mirror / code / Atom feed
From: Eric Cook <llua@gmx.com>
To: zsh-workers@zsh.org
Subject: [PATCH] _fc: allow the user to limit the number of events
Date: Mon, 11 Jul 2016 15:55:48 -0400	[thread overview]
Message-ID: <1468266948-9318-1-git-send-email-llua@gmx.com> (raw)
In-Reply-To: <812932212.4222957.1467756469555.JavaMail.yahoo.ref@mail.yahoo.com>

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


  parent reply	other threads:[~2016-07-11 20:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [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 [this message]
2016-07-04 21:32 Eric Cook
2016-07-05  4:57 ` Daniel Shahaf
2016-07-05 14:58   ` Mikael Magnusson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1468266948-9318-1-git-send-email-llua@gmx.com \
    --to=llua@gmx.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).