Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Identify "active" region?
- X-seq: zsh-workers 24906
- From: "Mikael Magnusson" <mikachu@xxxxxxxxx>
- To: zsh-workers@xxxxxxxxxx
- Subject: Re: Identify "active" region?
- Date: Sun, 4 May 2008 09:16:07 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=4QPsyU8oD19XPTKudVCtSuo2tlKh3VokzwnNCsPNv2Y=; b=VduywGYDI9P1yZ+haarHLHU6EMafFtVCa7AGUkFCyQ9xWNohVf789KCL7O7FwyRKjX/3l0Tr0m2zIZBE6dsjBigstpFA/jXrXw+yTnE3YYUk+ufCbRVJFLiwW0WM5a76Qr7KwKEu9zES5HF9lFFXzsmba1JUgJbc1J7bLBFM6wY=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=QFAIXriUN2WQstD6XDVsSuMnMxeMkfUZ0ZvW+/88/811h9NheaKc6TchTd8jPXmKlNUUFqcMNhOm+cP9g4SJLuOzEvOMg7NKhzdU/pmraef0X8/avCZNwvD8UTB165JCw/IOYYUPD/KdLLSYQve37n4IuNg8bKGKEtghbT48RZE=
- In-reply-to: <080503175219.ZM11801@xxxxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- References: <080503175219.ZM11801@xxxxxxxxxxxxxxxxxxxxxx>
2008/5/4 Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>:
> I'd like to write a widget that does
>
> if [[ there is an active region ]]
> then zle kill-region
> else zle backward-kill-word
> fi
>
> (In fact, I'm tempted to write it in C and make it the default binding
> for ^W, but that's somewhat beside the point of this message.)
>
> There doesn't seem to be any way to determine that there's an active
> region except to override set-mark-command and exchange-point-and-mark
> to stash something in a global variable. Have I missed something?
>
> (I thought perhaps I could peek into $region_highlight in the latest
> from CVS, but that doesn't update on the fly.)
>
> Opinions on usefulness going forward of detecting the active region?
> A distinguished value of MARK appears too problematic, so it'd have to
> be another zle variable, or ...?
>
> For the time being I'm using the less-than-satisfactory
> (( MARK > 0 && MARK != CURSOR ))
> which isn't *that* bad since if I meant to kill all the way to the
> beginning of the line I'd probably use kill-whole-line, and at worst
> I just have to do exchange-point-and-mark first.
fwiw, i'd like to second this, i've been meaning to ask it for a while
but didn't get around to it. My widget looks like this:
autoload -U narrow-to-region
function _narrow_to_region_marked()
{
local right
local left
if ((MARK == 0)); then
zle set-mark-command
fi
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"
}
I'd like to replace the "MARK == 0" with "is there an active region?".
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author