* [9front] sam = cmd
@ 2022-04-16 5:49 umbraticus
2022-04-16 6:53 ` umbraticus
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: umbraticus @ 2022-04-16 5:49 UTC (permalink / raw)
To: 9front
This patch makes sam's = cmd output what seems to me a more
useful (plumbable) format: /full/path/to/file:addr , where
addr is line(s) under = and rune(s) under =#. I don't
really see how one even could depend on the original format
(maybe some complicated sam -d script?) but am open to
thoughts & opinions.
umbraticus
diff f84cf1e60427675514fb056cc1723e45da01e043 uncommitted
--- a/sys/man/1/sam
+++ b/sys/man/1/sam
@@ -403,10 +403,10 @@
Set dot.
.TP
.B =
-Print the line address and character address of the range.
+Print the file name and line address of the range.
.TP
.B =#
-Print just the character address of the range.
+Print the file name and character address of the range.
.PD
.SS File commands
.PD 0
--- a/sys/src/cmd/sam/sam.c
+++ b/sys/src/cmd/sam/sam.c
@@ -688,11 +688,25 @@
}
void
-printposn(File *f, int charsonly)
+printposn(File *f, int chars)
{
Posn l1, l2;
+ char *s;
- if(!charsonly){
+ if(f->name.s[0]){
+ getcurwd();
+ s = Strtoc(&curwd);
+ dprint("%s", s);
+ free(s);
+ s = Strtoc(&f->name);
+ dprint("%s:", s);
+ free(s);
+ }
+ if(chars){
+ dprint("#%lud", addr.r.p1);
+ if(addr.r.p2 != addr.r.p1)
+ dprint(",#%lud", addr.r.p2);
+ }else{
l1 = 1+nlcount(f, (Posn)0, addr.r.p1);
l2 = l1+nlcount(f, addr.r.p1, addr.r.p2);
/* check if addr ends with '\n' */
@@ -701,11 +715,7 @@
dprint("%lud", l1);
if(l2 != l1)
dprint(",%lud", l2);
- dprint("; ");
}
- dprint("#%lud", addr.r.p1);
- if(addr.r.p2 != addr.r.p1)
- dprint(",#%lud", addr.r.p2);
dprint("\n");
}
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [9front] sam = cmd
2022-04-16 5:49 [9front] sam = cmd umbraticus
@ 2022-04-16 6:53 ` umbraticus
2022-04-27 23:41 ` qwx
2022-04-16 14:42 ` Philip Silva
2022-04-16 18:22 ` ori
2 siblings, 1 reply; 7+ messages in thread
From: umbraticus @ 2022-04-16 6:53 UTC (permalink / raw)
To: 9front
and of course I press send and immediately notice a mistake
(ml is a lot more responsive lately!) better patch follows:
diff f84cf1e60427675514fb056cc1723e45da01e043 uncommitted
--- a/sys/man/1/sam
+++ b/sys/man/1/sam
@@ -403,10 +403,10 @@
Set dot.
.TP
.B =
-Print the line address and character address of the range.
+Print the file name and line address of the range.
.TP
.B =#
-Print just the character address of the range.
+Print the file name and character address of the range.
.PD
.SS File commands
.PD 0
--- a/sys/src/cmd/sam/sam.c
+++ b/sys/src/cmd/sam/sam.c
@@ -688,11 +688,27 @@
}
void
-printposn(File *f, int charsonly)
+printposn(File *f, int chars)
{
Posn l1, l2;
+ char *s;
- if(!charsonly){
+ if(f->name.s[0]){
+ if(f->name.s[0]!='/'){
+ getcurwd();
+ s = Strtoc(&curwd);
+ dprint("%s", s);
+ free(s);
+ }
+ s = Strtoc(&f->name);
+ dprint("%s:", s);
+ free(s);
+ }
+ if(chars){
+ dprint("#%lud", addr.r.p1);
+ if(addr.r.p2 != addr.r.p1)
+ dprint(",#%lud", addr.r.p2);
+ }else{
l1 = 1+nlcount(f, (Posn)0, addr.r.p1);
l2 = l1+nlcount(f, addr.r.p1, addr.r.p2);
/* check if addr ends with '\n' */
@@ -701,11 +717,7 @@
dprint("%lud", l1);
if(l2 != l1)
dprint(",%lud", l2);
- dprint("; ");
}
- dprint("#%lud", addr.r.p1);
- if(addr.r.p2 != addr.r.p1)
- dprint(",#%lud", addr.r.p2);
dprint("\n");
}
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [9front] sam = cmd
2022-04-16 5:49 [9front] sam = cmd umbraticus
2022-04-16 6:53 ` umbraticus
@ 2022-04-16 14:42 ` Philip Silva
2022-04-16 18:22 ` ori
2 siblings, 0 replies; 7+ messages in thread
From: Philip Silva @ 2022-04-16 14:42 UTC (permalink / raw)
To: 9front
I wonder, at least it's possible to use in regexes, e.g.
2; #9/foo/
3; #9/foo/
to search in line 2 or 3 (Although I use acme anyway :D)
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [9front] sam = cmd
2022-04-16 5:49 [9front] sam = cmd umbraticus
2022-04-16 6:53 ` umbraticus
2022-04-16 14:42 ` Philip Silva
@ 2022-04-16 18:22 ` ori
2022-04-16 20:58 ` Steve Simon
2022-04-27 1:05 ` qwx
2 siblings, 2 replies; 7+ messages in thread
From: ori @ 2022-04-16 18:22 UTC (permalink / raw)
To: 9front
Quoth umbraticus@prosimetrum.com:
> This patch makes sam's = cmd output what seems to me a more
> useful (plumbable) format: /full/path/to/file:addr , where
> addr is line(s) under = and rune(s) under =#. I don't
> really see how one even could depend on the original format
> (maybe some complicated sam -d script?) but am open to
> thoughts & opinions.
>
I like it. Most of the time, I use = to get some address
that I can point people at, and having it plumbable is
very nice for this.
The rest of the time, I use it for "bookmarking" where
I am, and just plumbing the output to select the address
will do for that.
I think the output format at the moment is an artifact
of sam predating the plumber, and changing it makes
sense to me.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [9front] sam = cmd
2022-04-16 18:22 ` ori
@ 2022-04-16 20:58 ` Steve Simon
2022-04-27 1:05 ` qwx
1 sibling, 0 replies; 7+ messages in thread
From: Steve Simon @ 2022-04-16 20:58 UTC (permalink / raw)
To: 9front
great idea
begs the question why no-one ever did this before.
-Steve
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [9front] sam = cmd
2022-04-16 18:22 ` ori
2022-04-16 20:58 ` Steve Simon
@ 2022-04-27 1:05 ` qwx
1 sibling, 0 replies; 7+ messages in thread
From: qwx @ 2022-04-27 1:05 UTC (permalink / raw)
To: 9front
Quoth umbraticus@prosimetrum.com:
> This patch makes sam's = cmd output what seems to me a more
> useful (plumbable) format: /full/path/to/file:addr , where
> addr is line(s) under = and rune(s) under =#. I don't
> really see how one even could depend on the original format
> (maybe some complicated sam -d script?) but am open to
> thoughts & opinions.
Hello,
Unless there are any late objections, I think that this should be
merged (the updated patch in a follow-up mail).
Cheers,
qwx
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [9front] sam = cmd
2022-04-16 6:53 ` umbraticus
@ 2022-04-27 23:41 ` qwx
0 siblings, 0 replies; 7+ messages in thread
From: qwx @ 2022-04-27 23:41 UTC (permalink / raw)
To: 9front
Pushed. Thanks!
Cheers,
qwx
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-04-27 23:43 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-16 5:49 [9front] sam = cmd umbraticus
2022-04-16 6:53 ` umbraticus
2022-04-27 23:41 ` qwx
2022-04-16 14:42 ` Philip Silva
2022-04-16 18:22 ` ori
2022-04-16 20:58 ` Steve Simon
2022-04-27 1:05 ` qwx
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).