9front - general discussion about 9front
 help / color / mirror / Atom feed
From: ori@eigenstate.org
To: iru.muzgo@gmail.com, ori@eigenstate.org
Cc: 9front@9front.org
Subject: Re: [9front] vt plumbing: empty selection
Date: Thu, 9 Apr 2020 06:23:03 -0700	[thread overview]
Message-ID: <118155DD32BF65C43B0104476ED419FE@eigenstate.org> (raw)
In-Reply-To: <CABJnqBTVE6F0Fg7SsfCEqhC+JSWG43uQO6nSqfbvPL0K-Dr=Zw@mail.gmail.com>

> 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 */



  reply	other threads:[~2020-04-09 13:23 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-09  4:14 ori
2020-04-09  6:58 ` [9front] " Iruatã Souza
2020-04-09  6:59   ` Iruatã Souza
2020-04-09 13:06     ` ori
2020-04-09 13:17       ` Iruatã Souza
2020-04-09 13:23         ` ori [this message]
2020-04-09 15:12           ` Iruatã Souza
2020-04-10 16:01             ` cinap_lenrek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=118155DD32BF65C43B0104476ED419FE@eigenstate.org \
    --to=ori@eigenstate.org \
    --cc=9front@9front.org \
    --cc=iru.muzgo@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).