From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lj1-f177.google.com ([209.85.208.177]) by ewsd; Thu Apr 9 11:12:52 EDT 2020 Received: by mail-lj1-f177.google.com with SMTP id q22so63568ljg.0 for <9front@9front.org>; Thu, 09 Apr 2020 08:12:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=76rKsTc1e34iRNG05HqsbfhU9VgLSu/HVFeYYDubS50=; b=PXbgovnpPHPqs187CObTW2bvgPm9FbcyoQnj6fJJ9oKXlXsVypi5C+pEu6c2czeHIU VcaVj5wq/MKjiwqiPt7AtdzK283N7FfP2u1jrZ9ODL25dG0+Po35HaGSJBM1P7tEsAxT 5Dkn5G+B4kWPgtxltkPUQUDm1PKPDQhM5C6jrqSXKz3rcRjrdlWKZ1V5AzWUHR2t75gq lCnLLIeeyTokHhd3a7m0sk3NiEFJaxTyyT7Fx9sXbswZmfaG2dqdpTZRYYMm7kw2n9eS 93PWJaS7RYKV8+tcvs0WCjmvAaOA+fb689sWHPZAG2QMQVPZoeSTltLKIOoPY6ik/1ln hkVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=76rKsTc1e34iRNG05HqsbfhU9VgLSu/HVFeYYDubS50=; b=hf7Sl9wxfpXEYUgGcPY76nSUl5qsfYym6MCgB1YUQFPYWKGzug46u/Kys4ngR1DMxF RM91K9bdItK8/NfsXfIXh8bbngODnnSOUSg4JlwJ+Xmkw0ZhkZbvDohM20sLBP6wxse5 yuCrccQF4r+HQnC6uv4KC+Dm2469AFqnMhQcnyxF1Q5biUEjaXZ+YIVuI1kNcz6EC+wj lwpE4XaybMcGCycALENFowT2LiGRU9vPFmG6rkrPw/gg7Qd23d8f6aQC+7+Ja6/KwQa9 oAhtFhCTC7OmO2fKSua4wvcxk+UM3aFhmIaRzuK7lrGrVcl7YBj9BPV1EqTNmIde6PvB 8sXw== X-Gm-Message-State: AGi0PubdTIe7IuQn/i1XRORjurhkD8rBtaEdiac6OGwTksEb3bm2mMm+ ozq2riFPwz4e2Z0p8WsRCqzDwLsO7ZzvuM/2+CFocg== X-Google-Smtp-Source: APiQypKrZAgLVcA0QtjfwXoKjHPFvDZCk1eyRxShFbFRokmDPDTRnm4/kGrDIcdqqURkrHeb5Ad96zDXeptMN3zddmM= X-Received: by 2002:a2e:b4f1:: with SMTP id s17mr126141ljm.283.1586445167102; Thu, 09 Apr 2020 08:12:47 -0700 (PDT) MIME-Version: 1.0 References: <118155DD32BF65C43B0104476ED419FE@eigenstate.org> In-Reply-To: <118155DD32BF65C43B0104476ED419FE@eigenstate.org> From: =?UTF-8?Q?Iruat=C3=A3_Souza?= Date: Thu, 9 Apr 2020 17:12:35 +0200 Message-ID: Subject: Re: [9front] vt plumbing: empty selection To: ori@eigenstate.org Cc: 9front@9front.org Content-Type: text/plain; charset="UTF-8" List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: map/reduce HTTP over AJAX just-in-time-oriented cloud general-purpose control Looks good to me! On Thu, Apr 9, 2020 at 3:23 PM wrote: > > > why not > > > > if (x0 == x1) > > return nil; > > > > s = malloc((x1 - x0 + 1)*UTFmax); > > if (s == nil) > > return nil; > > > > Mostly because my coffee hasn't metabolized. Done. > > diff -r 3bcb5998f222 sys/src/cmd/vt/main.c > --- a/sys/src/cmd/vt/main.c Wed Apr 08 23:48:09 2020 +0200 > +++ b/sys/src/cmd/vt/main.c Thu Apr 09 06:22:30 2020 -0700 > @@ -170,7 +170,7 @@ > void escapedump(int,uchar *,int); > void paste(void); > void snarfsel(void); > -void plumbsel(void); > +void plumbsel(Point); > > static Channel *pidchan; > > @@ -982,13 +982,47 @@ > free(s); > } > > +/* > + * Grabs the non-whitespace text around a character > + * cell, matching the behavior in rio for plumbing. > + * Does not modify the selection. > + */ > +char* > +surrounding(Point p) > +{ > + int c, x0, x1; > + char *s, *e; > + > + for(x0 = p.x; x0 > 0; x0--){ > + c = *onscreenr(x0 - 1, p.y); > + if(c == 0 || c == ' ' || c == '\t' || c == '\n') > + break; > + } > + for(x1 = p.x; x1 <= xmax; x1++){ > + c = *onscreenr(x1 + 1, p.y); > + if(c == 0 || c == ' ' || c == '\t' || c == '\n') > + break; > + } > + if(x0 == x1) > + return nil; > + s = malloc((x1 - x0 + 1)*UTFmax); > + if(s == nil) > + return nil; > + e = selrange(s, x0, p.y, x1, p.y); > + *e = 0; > + return s; > +} > + > void > -plumbsel(void) > +plumbsel(Point p) > { > char *s, wdir[1024]; > int plumb; > > - if((s = selection()) == nil) > + s = selection(); > + if(s == nil || *s == 0) > + s = surrounding(p); > + if(s == nil) > return; > if(getwd(wdir, sizeof wdir) == nil){ > free(s); > @@ -1116,6 +1150,9 @@ > void > readmenu(void) > { > + Point p; > + > + p = pos(mc->xy); > if(button3()) { > menu3.item[1] = ttystate[cs->raw].crnl ? "cr" : "crnl"; > menu3.item[2] = ttystate[cs->raw].nlcr ? "nl" : "nlcr"; > @@ -1173,7 +1210,7 @@ > return; > > case Mplumb: > - plumbsel(); > + plumbsel(p); > return; > > case Mpage: /* pause and clear at end of screen */ >