From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15078 invoked from network); 4 May 2008 07:16:25 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.4 (2008-01-01) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.4 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 4 May 2008 07:16:25 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 26972 invoked from network); 4 May 2008 07:16:17 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 4 May 2008 07:16:17 -0000 Received: (qmail 24351 invoked by alias); 4 May 2008 07:16:13 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 24906 Received: (qmail 24333 invoked from network); 4 May 2008 07:16:13 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 4 May 2008 07:16:13 -0000 Received: from rv-out-0506.google.com (rv-out-0506.google.com [209.85.198.235]) by bifrost.dotsrc.org (Postfix) with ESMTP id 2951080ED172 for ; Sun, 4 May 2008 09:16:08 +0200 (CEST) Received: by rv-out-0506.google.com with SMTP id g37so1144811rvb.21 for ; Sun, 04 May 2008 00:16:07 -0700 (PDT) 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= Received: by 10.140.207.2 with SMTP id e2mr2194938rvg.104.1209885367457; Sun, 04 May 2008 00:16:07 -0700 (PDT) Received: by 10.140.127.7 with HTTP; Sun, 4 May 2008 00:16:07 -0700 (PDT) Message-ID: <237967ef0805040016v5ceaaa89sfddf41e14567c719@mail.gmail.com> Date: Sun, 4 May 2008 09:16:07 +0200 From: "Mikael Magnusson" To: zsh-workers@sunsite.dk Subject: Re: Identify "active" region? In-Reply-To: <080503175219.ZM11801@torch.brasslantern.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <080503175219.ZM11801@torch.brasslantern.com> X-Virus-Scanned: ClamAV 0.91.2/7019/Sun May 4 04:17:43 2008 on bifrost X-Virus-Status: Clean 2008/5/4 Bart Schaefer : > 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