From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24805 invoked by alias); 20 Jun 2015 09:16:26 -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: 35542 Received: (qmail 4748 invoked from network); 20 Jun 2015 09:16:23 -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:date:message-id:subject:from:to:content-type; bh=6VZx6vUwdtmQBQPdcmjug6Rl56h6eamVPTE+0xnY1G4=; b=dhKjxtNsaziMX9t81V+rQpfjl/ZkZEElpQIhbATqzLXIhZdLaKET6CJXvtgSu8T74p UNYbRD6qBvoaC7lWyNsSi34SjOj0s8nviqpMzQ2kjOT5I+nikeewhRcbODhKeculmtsv cNs08abccGjAkDUw+sRtPJq2l+RtGe8nLBQvrZdN8tb1XFO5Io/VzdDpwV4jlOwWNeMY OfIFo1d3o58HWpV/vkjnz1Aenbf2gnm5Hl78TgolUtJbidz/VtE5Nw1xJVWIw896zSeE hFxEyDWYEYBeZx5e/xpsNQM+KsnoDiTUWJjLhkFaWBCy3AudfW7YYqh3YAYctLiRGgoX RAXg== MIME-Version: 1.0 X-Received: by 10.107.163.146 with SMTP id m140mr27721053ioe.85.1434791780975; Sat, 20 Jun 2015 02:16:20 -0700 (PDT) Date: Sat, 20 Jun 2015 11:16:20 +0200 Message-ID: Subject: This widget implementation feels a bit clunky (edit-quoted-word) From: Mikael Magnusson To: zsh workers Content-Type: text/plain; charset=UTF-8 autoload -U narrow-to-region function _narrow_to_region_marked() { #I had this function since before local right local left local OLDMARK=MARK local wasregion=1 if ((REGION_ACTIVE == 0)); then MARK=CURSOR wasregion=0 fi REGION_ACTIVE=0 if ((MARK < CURSOR)); then left="$LBUFFER[0,$((MARK-CURSOR-1))]" right="$RBUFFER" else left="$LBUFFER" right="$BUFFER[$((MARK+1)),-1]" fi narrow-to-region -p "$left>>|" -P "|<<$right" _line_redraw #update highlight stuff doesn't happen here otherwise MARK=OLDMARK if ((wasregion)); then REGION_ACTIVE=1 fi } function _edit_quoted_word() { local -a reply local REPLY REPLY2 len _split_shell_arguments_intuitive local STARTPOS ENDPOS local OLDCURSOR=$CURSOR OLDMARK=$MARK wasregion=$REGION_ACTIVE STARTPOS=${#${(j::)reply[1,REPLY-1]}} reply[REPLY]=${(Q)reply[REPLY]} ENDPOS=${#${(j::)reply[1,REPLY]}} CURSOR=$STARTPOS MARK=$ENDPOS REGION_ACTIVE=1 BUFFER=${(j::)reply} len=$#BUFFER _narrow_to_region_marked CURSOR=$STARTPOS MARK=$((ENDPOS+$#BUFFER-len)) zle quote-region #the following line is also my quote-unquote-word widget modify-current-argument '${(q-)${(Q)ARG}}' CURSOR=$OLDCURSOR MARK=$OLDMARK REGION_ACTIVE=$wasregion } zle -N edit-quoted-word _edit_quoted_word bindkey '^_q' edit-quoted-word autoload -U modify-current-argument autoload -U split-shell-arguments function _split_shell_arguments_intuitive() { #Had this since before too split-shell-arguments #have to duplicate some of modify-current-argument to get the word #_under_ the cursor, not after. setopt localoptions noksharrays multibyte if (( REPLY > 1 )); then if (( REPLY & 1 )); then (( REPLY-- )) fi fi } I'm not exactly sure how often I would use this, but I had the thought and set off on an adventure. This lets you be on a thing like % echo I\''d (like) to "have\" some better example?' turns into % echo >>|I'd (like) to "have\" some better example?|<< which is then somewhat easier to edit, then you maybe type this instead % echo >>|I'd (like) to "have\" '${(q-)${(Q)ARG}}' some better example?|<< after pressing enter, it turns back into % echo I\''d (like) to "have\" ''${(q-)${(Q)ARG}}'' some better example?' I feel like it's unnecessarily hard to get the resulting text from a narrow-to-region session. It would be nice if quote-region let you specify the type of quoting. Urk? -- Mikael Magnusson