From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13227 invoked by alias); 22 Jun 2015 02:26:11 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 35559 Received: (qmail 20655 invoked from network); 22 Jun 2015 02:26:10 -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=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=OCcb0FzOcfVXL+1c2A+mUNwTU73kdtusT28zPEMvtHE=; b=sa0pysKIXMqkRZEFuLOcfvq1bsvnlGQwT/AoIykoZo6JV4HJ1lqPM+gPHW/+KFAo8E W5J7xzuOtW8RT8PLh1p3peuSdePtr+7PpUH4DMRO79hoeLHN2eo9WypK38VQ8wibdbtI YI/EB3LqieN+VGHcGoM9QXj04Gi7rRO7j3pFYYJCsw7X+VHabAjNtolq/oBhBFUZ6skE bf1NkSbddX5YKETtehufWHb3skjGY+ABlztSuEchWBpS0Syi65xr+0UuRC3GuYG06845 WLHJ8Rg4PGGPdakOS9YZ53s5ou7DXpTCrpdBPnYUBcwziLcvkOWs6iVtxUXTVWb+Hcb6 0K9w== MIME-Version: 1.0 X-Received: by 10.107.4.6 with SMTP id 6mr26914420ioe.49.1434939967128; Sun, 21 Jun 2015 19:26:07 -0700 (PDT) In-Reply-To: <20150621181740.522742c8@ntlworld.com> References: <20150620180659.735a6cc6@ntlworld.com> <20150621181740.522742c8@ntlworld.com> Date: Mon, 22 Jun 2015 04:26:07 +0200 Message-ID: Subject: Re: This widget implementation feels a bit clunky (edit-quoted-word) From: Mikael Magnusson To: Peter Stephenson Cc: zsh workers Content-Type: text/plain; charset=UTF-8 On Sun, Jun 21, 2015 at 7:17 PM, Peter Stephenson wrote: > On Sun, 21 Jun 2015 09:09:29 +0200 > Mikael Magnusson wrote: >> On Sat, Jun 20, 2015 at 7:06 PM, Peter Stephenson >> wrote: >> > On Sat, 20 Jun 2015 11:16:20 +0200 >> > Mikael Magnusson wrote: >> >> I feel like it's unnecessarily hard to get the resulting text from a >> >> narrow-to-region session. >> > >> > Would you want something like this? >> >> That does look very promising, yeah. :) >> I suppose I should volunteer for writing the doc patch for this. > > I've remembered to commit it on the master branch. This feels more reasonable now (some of the improvements might be applied to the previous version too, so not an entirely fair comparison), (the business with the :+ is because if you delete the whole string, ${(q-)lbuf} when lbuf is empty results in '', and so does rbuf, thus concatenated to '''' which with rc_quotes enabled leaves a single ' that should not be there). function _edit_quoted_word() { local -a reply local REPLY REPLY2 len left right lbuf rbuf _split_shell_arguments_intuitive left=${(j::)reply[1,REPLY-1]} right=${(j::)reply[REPLY+1,-1]} (( CURSOR-=$#left )) BUFFER=${(Q)reply[REPLY]} REGION_ACTIVE=0 narrow-to-region -l lbuf -r rbuf -p "$left>>|" -P "|<<$right" 0 $#BUFFER LBUFFER=$left${lbuf:+${(q-)lbuf}} RBUFFER=${rbuf:+${(q-)rbuf}}$right } zle -N _edit_quoted_word bindkey '^_q' _edit_quoted_word autoload -U split-shell-arguments function _split_shell_arguments_intuitive() { split-shell-arguments # borrowed logic from modify-current-argument to get word under cursor (( REPLY > 1 && REPLY & 1 )) && (( REPLY-- )) } -- Mikael Magnusson