From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7297 invoked by alias); 30 Jan 2016 20:41:22 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 21211 Received: (qmail 12101 invoked from network); 30 Jan 2016 20:41:21 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version:content-type; bh=KD8XZPcge0H2BER2/+kN71UaUBZ1lHE/q+0SZuU2tCQ=; b=Cjx+9KvNnuU/A8Uh8qkK1gzqYvjl4hFCRXaTFM+t5fL0kl7eW1kiFhYyLU39Om3mza 1hsbWOnHdubBNOqyMtkOrVdtLf8UDUUX9Q6mA1XuZPhF7vO8DrMKZtsbRsGT9rRO4pnr GhJNICNCRooLOFcXg/Qbdnty0viW5NVrpFcYChV+7ZIqWpq8Gyue/0SlSqD2V9WtMUaH kaO+FaeNL6vXKoZs4cD6LoeuWVImwyuKb8EZU4wXr9qT4I6Sn5+PLzR5Hg+E5EuIk3Mr miR+9JNgygs82k+W2ZVK4jUESpCjZaBv41zoL7l/IENlFv8Dh6Kt83LsxSpMUo261kdS gGfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version:content-type; bh=KD8XZPcge0H2BER2/+kN71UaUBZ1lHE/q+0SZuU2tCQ=; b=hNKnVdXGyHIhaiF7fsBL2AjU7PpJ+76hErupxvLBez8PFTcGEuSH1qgBqk/uYNDZqr D/ZAudMjtAYSMNL6zEqWhuGF8Krsw6b3ju0y3A+/Pi1+kyzHIDRj/Cdxve8KqJ7/oVec pH8xo4mq8PRF+Kf+JEfkgyl4THAwUy4RiaptQ4Rc1uNqJbJ05VWmMJfOAT+1jA9lFIUc 6UOm89Wp9Up3Tzc0iIOf5NzNfIYrEVn52qeWunH+HVmGhumJRqou85cJSqk3JEsWzI4T tc8g9VjGSfXagKO8uGOx4j07vkfUza9OUygQbYGEkNlIfB0DM2TncSVW6zOa2RuN8OVF 4GkQ== X-Gm-Message-State: AG10YOSq/Cff7ZbxIuPFfz5oaymT0JSNP610cSsMWtA8tzA+olKUdG6MzkMxfmxB0r4e8g== X-Received: by 10.66.102.97 with SMTP id fn1mr25278232pab.131.1454186479584; Sat, 30 Jan 2016 12:41:19 -0800 (PST) From: Bart Schaefer Message-Id: <160130124209.ZM10392@torch.brasslantern.com> Date: Sat, 30 Jan 2016 12:42:09 -0800 In-Reply-To: <160130085456.ZM9730@torch.brasslantern.com> Comments: In reply to Bart Schaefer "Re: Feature request (@M):# with context matches" (Jan 30, 8:54am) References: <160130085456.ZM9730@torch.brasslantern.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: Zsh Users Subject: Re: Feature request (@M):# with context matches MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Jan 30, 8:54am, Bart Schaefer wrote: } } while (( ( hit = $list[(i)*$search_pattern*] ) < $#list )) } do } print -r -- $list[hit-3,hit+3] } shift $hit list } done } } with some appropriate checking that (hit-3) doesn't become negative and } wrap around to the other end of the array, and other foo to manage the } possiblity of overlapping contexts. If you don't care about multiple hits or merging overlapping contexts, you can even mash this down to a single statement. E.g. torch% declare S=path # Searching in $path torch% integer hit=0 C=2 # Context is 2 elements torch% print -rl ${${(P)S}[$(( mathsubst> (hit = ${${(P)S}[(i)*local*]}) > C mathsubst> ? hit < $#path mathsubst> ? hit-C mathsubst> : hit mathsubst> : 1 mathsubst> )),$(( mathsubst> hit < $#path mathsubst> ? hit+C mathsubst> : hit mathsubst> ))]} /home/schaefer/bin /usr/local/bin /bin /usr/bin (Math parsing permits embedded newlines, subscript parsing does not, thus the placement of "[$((" and ")),$((" and "))]".) Note the ?: ternary tests would be different if using (I) to search from right to left.