Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
This widget implementation feels a bit clunky (edit-quoted-word)
- X-seq: zsh-workers 35542
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: zsh workers <zsh-workers@xxxxxxx>
- Subject: This widget implementation feels a bit clunky (edit-quoted-word)
- Date: Sat, 20 Jun 2015 11:16:20 +0200
- 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==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author