Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: (backward-)kill-argument
- X-seq: zsh-workers 16839
- From: "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxx
- Subject: Re: (backward-)kill-argument
- Date: Fri, 15 Mar 2002 15:31:46 +0000
- In-reply-to: <15505.46831.979708.369781@xxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- References: <m2zo1cxvvl.fsf@xxxxxxxxxxxxxxxxxxxxx> 	<15505.46831.979708.369781@xxxxxxxxxxxxxxxxxx>
On Mar 15,  9:55am, Sven Wischnowsky wrote:
}
} > i want to:
} >   * kill filenames w/  spaces: e.g.    this\ is\ file.txt
} 
} Write yourself a little widget. As a starting point:
} 
}   kill-with-spaces() {
}     local words
}     words="${(z)BUFFER}"
}     BUFFER="${BUFFER%${words[-1]}[ 	]#}"
}   }
That's a nice function, Sven, but I think I'd call it something like
`backward-kill-shell-word', and it ought to test $LBUFFER, not $BUFFER.
If you throw in `setopt localoptions extendedglob', we could even put
it in the distribution,
} (There's a space and a TAB inside that [ ].)
You can write that as [[:space:]] now, I think?
} >   * maybe even the bracketed part:
} >         find  { -name '*.h' }
} > 
} > Is it possible in Zsh?
} 
} Using the above you could check if $words[-1] is one of the closing
} braces and if it is, search back in the array for the matching opening
} brace. When found, you can delete the end of $BUFFER up to that
} matching brace by using a pattern of the form:
} 
}   ${words[-n]}[ 	]##...[ 	]##${words[-1]}[ 	]#
Hmm, I think I'd just do a loop killing words until the open-brace was
missing from $LBUFFER.  So, putting it all together,
    backward-kill-shell-expression() {
        setopt localoptions extendedglob
        local words
        words="${(z)LBUFFER}"
        LBUFFER="${LBUFFER%${words[-1]}[[:space:]]#}"
        if [[ "$words[-1]" == '}' ]]
        then
            words="${(z)LBUFFER}"
            while [[ "${${(@M)words:#[\{\}]}[-1]}" == '{' ]]
            do
                LBUFFER="${LBUFFER%${words[-1]}[[:space:]]#}"
                words="${(z)LBUFFER}"
            done
        fi
    }
This could be extended to handle `( ... )', `[[ ... ]]', etc., and we
could of course also write a forward- version.
-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com
Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   
Messages sorted by:
Reverse Date,
Date,
Thread,
Author