Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm
Precedence: bulk
X-No-Archive: yes
List-Id: Zsh Workers List <zsh-workers.zsh.org>
List-Post: <mailto:zsh-workers@zsh.org>
List-Help: <mailto:zsh-workers-help@zsh.org>
X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM
	autolearn=ham autolearn_force=no version=3.4.1
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,  4 Jul 2016 17:32:59 -0400
Message-Id: <1467667979-31193-1-git-send-email-llua@gmx.com>
X-Mailer: git-send-email 2.6.6
X-Provags-ID: V03:K0:q7g8MDDDcNLGLzy+Yx2KSsh2EFpQI/V60zJAyZZIskV0ro8CpbA
 xgK7FbCRvxDKICKcfn2ofENWe3sl5TS8zkWDR+wlR+3mqYrsE/X2D0SFq4dpyzSSPO7vPWq
 ObbKHuOGmR0v9Ww+n8KB2Rz/uc0+JHilMu+8Zx0eU8dBmd40LD70PjxL20wWT+bQhMDZ8X/
 sNvo4O1779UN42DxTftpA==
X-UI-Out-Filterresults: notjunk:1;V01:K0:ADYltlGaOd4=:vAqUxMzm+XxC//oTGyr3IK
 3EiahF8Pn+hWQeU2BQaAV9f69zQ1JlCPyiKRIR8OYhqJdE+enUVw98RY/Ie0Bg3T7TaCBm/qQ
 thjCAgUUMIoT6iQrMeOtAr4UBEWN8uBOCGQlX4LBRgqnRybwkt1VR4DY3QjwoWboyq5TTfArc
 mP+ggQP0IP6aeqDP2sj7Vut7idg1HzJ06vSUqm+3i7v5JDZKnjyzM7ugpYs+ktH1eY9ksGSJ/
 bhhTfAByBFVoQOXDm5rG+RTT4AEZ8r7T+zkGtpBQakkVL2rOLQDo0+SD9YYMwrYo1pNDp6CoZ
 kdTSmzjVOs9ljUq/toEXEbGHZpPXpYft6JkuxG7AUgdVJTSXDH04oW8eTgGB+TKH+ogpZ8Y/5
 9qhB9Jepn1bcYyG5Hlr83/+LGxh1UOy7OuU1dYBaSESB2Swfz0JuDV+7Uhmyh8WdZ3rEB1hqc
 o5DzbStPvWxf2iCLYnvpTr0rcRR18klYb4+HDa9BaYjIMNeBx6/CQwM/U3EIgVus/XhX7TOCy
 WvIRRK8uZY43MPAunq24PjvTpWL1VgUmbHhAZJ7pB5DHNZ5FcE3BsnwGIzCh4/VcZ/E/60qdF
 d1oKwYazI99+lvqyfCxf1Y5KYxhgKQXnMk6pqID3frHBcFngMJOl0cCL7+6gKHg2SMpg2lcOb
 mulNHrLpZ8B1sIVv5F1IjCUttw9g1WWh2gvAEMPseg1nTujr5TyzT2eagdH/3TfMe5PixI7RM
 Qyzk4S6n6BzDifHITol9Z0jjBtCvILbzvx+ijTob051jy8VyMgCVJ+hsaqA=
X-Seq: zsh-workers 38787

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

