zsh-workers
 help / color / mirror / code / Atom feed
* This widget implementation feels a bit clunky (edit-quoted-word)
@ 2015-06-20  9:16 Mikael Magnusson
  2015-06-20 17:06 ` Peter Stephenson
  2015-06-20 17:21 ` This widget implementation feels a bit clunky (edit-quoted-word) Bart Schaefer
  0 siblings, 2 replies; 19+ messages in thread
From: Mikael Magnusson @ 2015-06-20  9:16 UTC (permalink / raw)
  To: zsh workers

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


^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2015-08-18  7:05 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-20  9:16 This widget implementation feels a bit clunky (edit-quoted-word) Mikael Magnusson
2015-06-20 17:06 ` Peter Stephenson
2015-06-21  7:09   ` Mikael Magnusson
2015-06-21 17:17     ` Peter Stephenson
2015-06-22  2:26       ` Mikael Magnusson
2015-06-22  0:18     ` PATCH: Document narrow-to-region -l and -r Mikael Magnusson
2015-06-20 17:21 ` This widget implementation feels a bit clunky (edit-quoted-word) Bart Schaefer
2015-07-18 23:42   ` PATCH: narrow-to-region (was Re: This widget implementation feels a bit clunky) Bart Schaefer
2015-07-19  3:55     ` Oliver Kiddle
2015-07-19  8:23       ` Bart Schaefer
2015-07-20  9:19         ` Oliver Kiddle
2015-07-20 16:29           ` Bart Schaefer
2015-07-23  5:41           ` Undo and narrow-to-region (was Re: PATCH: narrow-to-region (was ...)) Bart Schaefer
2015-07-27 15:44             ` Oliver Kiddle
2015-08-12 17:00               ` PATCH: Re: Undo and narrow-to-region (was ...) Oliver Kiddle
2015-08-17 21:15                 ` Daniel Hahler
2015-08-17 21:58                   ` Bart Schaefer
2015-08-18  3:43                     ` Bart Schaefer
2015-08-18  7:05                   ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).