zsh-workers
 help / color / mirror / code / Atom feed
* backward-kill-shell-word widget
@ 2016-01-01  0:37 Daniel Shahaf
  2016-01-10  7:42 ` Sebastian Gniazdowski
                   ` (4 more replies)
  0 siblings, 5 replies; 25+ messages in thread
From: Daniel Shahaf @ 2016-01-01  0:37 UTC (permalink / raw)
  To: zsh-workers

[ I mentioned this to IRC some weeks ago and Valodim told me about
select-word-style so I didn't post this to the list; but now, I'll post it
anyway in case there's a subtle difference that I'm overlooking.
Perhaps the interactive_comments test is such a difference? ]

This widget is like ^W but for "shell words" rather than
whitespace-separated words, so

    % echo foo "bar baz" <CURSOR>^W
    becomes
    % echo foo <CURSOR>

If you use zsh 5.1.1 or older, comment the 'zle -f' line.  (Without that
line, using this widget followed by another kill followed by a yank
won't include the text this widget killed in the yank.)

---

backward-kill-shell-word() {
  local MATCH; integer MBEGIN MEND
  integer start end_of_word end_of_cut=$CURSOR

  # Walk backwards to an end-of-word
  [[ $LBUFFER =~ '[[:space:]]*$' ]] || : # sets $MATCH
  (( end_of_word = CURSOR - $#MATCH ))

  # Find the start of the shell word ending at $BUFFER[end_of_word]
  () {
    local l="$PREBUFFER$LBUFFER[1,end_of_word]"
    local -a a
    if [[ -o interactive_comments ]]; then
      a=( ${(zZ+c+)l} )
    else
      a=( ${(z)l} )
    fi
    (( start = end_of_word - ${#a[-1]} + 1 ))
  }

  # Standard kill-widget behaviour
  zle -f 'kill'
  if [[ $LASTWIDGET == *'kill'* ]]; then
    CUTBUFFER=${BUFFER[start,end_of_cut]}$CUTBUFFER
  else
    zle copy-region-as-kill -- "${BUFFER[start,end_of_cut]}"
  fi

  # Delete the last shell word from $LBUFFER
  LBUFFER[start,end_of_cut]=""
}
zle -N backward-kill-shell-word
bindkey '^T' backward-kill-shell-word


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

end of thread, other threads:[~2016-07-08 14:24 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-01  0:37 backward-kill-shell-word widget Daniel Shahaf
2016-01-10  7:42 ` Sebastian Gniazdowski
2016-01-10  7:54   ` Sebastian Gniazdowski
2016-01-10 20:13   ` Daniel Shahaf
2016-01-10 13:37 ` Sebastian Gniazdowski
2016-01-10 19:59   ` Daniel Shahaf
2016-01-10 21:06     ` Bart Schaefer
2016-01-12  8:23   ` Bart Schaefer
2016-01-10 15:50 ` Sebastian Gniazdowski
2016-01-10 20:19   ` Daniel Shahaf
2016-01-11  8:05     ` Sebastian Gniazdowski
2016-01-12 10:36       ` Sebastian Gniazdowski
2016-01-13  1:18       ` Daniel Shahaf
2016-01-13  8:38         ` Sebastian Gniazdowski
2016-01-14  0:13           ` Daniel Shahaf
2016-01-14  6:54             ` Bart Schaefer
2016-01-15  6:26               ` Daniel Shahaf
2016-01-10 17:17 ` Bart Schaefer
2016-01-10 19:53   ` Daniel Shahaf
2016-01-12  7:54     ` Bart Schaefer
2016-04-14 16:21   ` Bart Schaefer
2016-07-08 14:19   ` Oliver Kiddle
2016-01-11 11:53 ` Sebastian Gniazdowski
2016-01-12  6:59   ` Bart Schaefer
2016-01-12  7:49     ` Sebastian Gniazdowski

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).