Re: [9fans] A few more questions about sam

2021-08-05 Thread fwrm via 9fans
4) In ed/awk/grep/etc... regexp is used to "select" *the lines containing it* 
and do stuff, in sam however it's used to describe the shape of string(s) 
themselves you want to "select" (with x and y commands). It doesn't have the 
concept of a line. Your selection can be less than a line, or you can select 
multiple strings that happen to be in different lines. Or multiple lines.

For example, consider this string:
hello "test" bye
"hello" again

The command ,x/".+"/ would select every string that begins with a double quote, 
has one character or more after that, and ends with a double quote. If we 
wanted to select only the characters inside double quotes, we could reject the 
double quote character by adding the command y/"/ to the previous one. Or we 
can also only select the quotes by adding x/"/ instead, if we wanted to change 
double quotes (that surround one or more characters) to single quotes we could 
do: ,x/".+"/ x/"/ c/'/ or to capitalize all letters inside quotes (with the 
unix tool tr(1)) we could do: ,x/".+"/ y/"/ | tr [:lower:] [:upper:]

You can do interesting things with x and y when you combine them with the 
conditionals: g and v.
--
9fans: 9fans
Permalink: 
https://9fans.topicbox.com/groups/9fans/T3107cd3bc536dc63-M6657add7fd6d31ba8f447d79
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription


Re: [9fans] A few more questions about sam

2021-08-05 Thread umbraticus
> Is there a way to customise the starting layout of sam?

I have this patch, which changes the starting geometry of
cmd window and opens files fullscreen immediately instead of
having to sweep a rect:

diff -u /sys/src/cmd/samterm/main.c ./main.c
--- /sys/src/cmd/samterm/main.c Thu Apr 30 10:24:09 2020
+++ ./main.cSat Jan 16 16:08:33 2021
@@ -43,7 +43,7 @@
scratch = alloc(100*RUNESIZE);
nscralloc = 100;
r = screen->r;
-   r.max.y = r.min.y+Dy(r)/5;
+   r.min.x = r.max.x-Dx(r)/4;
flstart(screen->clipr);
rinit();
flnew([0], gettext, 1, );
diff -u /sys/src/cmd/samterm/menu.c ./menu.c
--- /sys/src/cmd/samterm/menu.c Wed Jan 18 13:12:54 2012
+++ ./menu.cMon Jun 21 21:53:12 2021
@@ -205,7 +205,8 @@
Rectangle r;
Text *t;
 
-   if(getr() && (t = malloc(sizeof(Text{
+   r = screen->r;
+   if(t = malloc(sizeof(Text))){
memset((void*)t, 0, sizeof(Text));
current((Flayer *)0);
flnew(>l[0], gettext, 0, (char *)t);

kvik also has some window placement hacks:

https://git.sr.ht/~kvik/ham

There was a video demo somewhere.

To understand sam's automatic window placement around the
cmd window, resize cmd to a square in the centre and
experiment with creating new windows by clicking in various
regions around the square.  There is afaik no way to save &
reproduce window geometry; as mentioned above, I just open
everything fullscreen.

> http://runjimmyrunrunyoufuckerrun.com/rc/s

I wrote this (improvements welcomed) but it relies on the ^
command and $% and $%dot variables which may not exist in
your version of sam.  I believe it was brought to your attention
for these functions, which load a previous editing session:

# ^d [file] # save unwritten changes and dump sam state to file
fn d{
rfork e
switch($#*){
case 0
dump = /tmp/sam.dump
case 1
dump = $1
case *
echo !u d
exit
}
d = `{pwd}
echo 'X/^''/w'
echo !rm -f $dump
echo 'Y/^..\./!echo `{cleanname -d' $d 
'$%}^'':#''^$%dot(2)^'',#''^$%dot(3) >>' $dump
echo 'X/^..\./!echo `{cleanname -d' $d 
'$%}^'':#''^$%dot(2)^'',#''^$%dot(3) >>' $dump
}

# !l [file] # load dump file
fn l{
switch($#*){
case 0
xargs -n1 plumb  Can someone point me to a specific resource that explains
> these expressions in more detail than does the sam man and
> sam tut?

http://sam.cat-v.org/ has a cheat sheet & some other
resources.  What is sam_tut.pdf missing that you would like
to understand?

umbraticus

--
9fans: 9fans
Permalink: 
https://9fans.topicbox.com/groups/9fans/T3107cd3bc536dc63-M51c4690187627a0d4fc416e0
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription


Re: [9fans] [PATCH] Spaceindent mode for acme

2021-08-05 Thread Rodrigo G . López
hi,

9front's had this for a long time (last time i used acme it already
did, back in 2017).
maybe you could try to import those changes instead of rolling your own?


best,

-rodri

On Thu, Aug 5, 2021 at 6:59 PM binarycat  wrote:
> 
> I do prefer tabs over spaces, but sometimes you have to use spaces.
> For example, zig doesn't even allow the tab charachter in its source
> code.
> 
> So, I put together a simple patch that adds a command `Spaceindent`.
> This command works similar to `Indent`, but changing whether to insert
> tabs or spaces. there is also the `-s` option to enable it on startup.
> 
> The number of spaces to insert is the same as the tab width,
> controlled by `Tab`.
> 
> My implementation may be a bit awkward, I haven't tried modifying acme
> to this extent before.
> --
> binarycat 

--
9fans: 9fans
Permalink: 
https://9fans.topicbox.com/groups/9fans/Td96032ea2eda50a5-M4c0bddcfef55e476f27d69d3
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription


[9fans] [PATCH] Spaceindent mode for acme

2021-08-05 Thread binarycat
I do prefer tabs over spaces, but sometimes you have to use spaces.
For example, zig doesn't even allow the tab charachter in its source
code.

So, I put together a simple patch that adds a command `Spaceindent`.
This command works similar to `Indent`, but changing whether to insert
tabs or spaces. there is also the `-s` option to enable it on startup.

The number of spaces to insert is the same as the tab width,
controlled by `Tab`.

My implementation may be a bit awkward, I haven't tried modifying acme
to this extent before.
-- 
binarycat 

--
9fans: 9fans
Permalink: 
https://9fans.topicbox.com/groups/9fans/Td96032ea2eda50a5-M4893eb0b25b35bb71504e5b3
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription
From c60b2b2a0dc502e61ab7d80b3ef5d0aa8b37690b Mon Sep 17 00:00:00 2001
From: binarycat 
Date: Thu, 5 Aug 2021 12:48:08 -0400
Subject: [PATCH] spaceindent

---
 acme.c |  5 -
 dat.h  |  2 ++
 exec.c | 55 ++-
 text.c |  7 +++
 wind.c |  1 +
 5 files changed, 64 insertions(+), 6 deletions(-)

diff --git a/acme.c b/acme.c
index d001a2a..d0c1772 100644
--- a/acme.c
+++ b/acme.c
@@ -114,6 +114,9 @@ threadmain(int argc, char *argv[])
 	case 'r':
 		swapscrollbuttons = TRUE;
 		break;
+	case 's':
+		globalspaceindent = TRUE;
+		break;
 	case 'W':
 		winsize = ARGF();
 		if(winsize == nil)
@@ -121,7 +124,7 @@ threadmain(int argc, char *argv[])
 		break;
 	default:
 	Usage:
-		fprint(2, "usage: acme -a -c ncol -f fontname -F fixedwidthfontname -l loadfile -W winsize\n");
+		fprint(2, "usage: acme -as -c ncol -f fontname -F fixedwidthfontname -l loadfile -W winsize\n");
 		threadexitsall("usage");
 	}ARGEND
 
diff --git a/dat.h b/dat.h
index 8a81c97..90a3794 100644
--- a/dat.h
+++ b/dat.h
@@ -241,6 +241,7 @@ struct Window
 	uchar	filemenu;
 	uchar	dirty;
 	uchar	autoindent;
+	uchar	spaceindent;
 	uchar	showdel;
 	int		id;
 	Range	addr;
@@ -553,6 +554,7 @@ int			editing;
 int			erroutfd;
 int			messagesize;		/* negotiated in 9P version setup */
 int			globalautoindent;
+int			globalspaceindent;
 int			dodollarsigns;
 char*		mtpt;
 
diff --git a/exec.c b/exec.c
index be7936a..547e988 100644
--- a/exec.c
+++ b/exec.c
@@ -55,6 +55,7 @@ void	sendx(Text*, Text*, Text*, int, int, Rune*, int);
 void	sort(Text*, Text*, Text*, int, int, Rune*, int);
 void	tab(Text*, Text*, Text*, int, int, Rune*, int);
 void	zeroxx(Text*, Text*, Text*, int, int, Rune*, int);
+void spaceindent(Text*, Text*, Text*, int, int, Rune*, int);
 
 typedef struct Exectab Exectab;
 struct Exectab
@@ -95,6 +96,8 @@ static Rune LSort[] = { 'S', 'o', 'r', 't', 0 };
 static Rune LTab[] = { 'T', 'a', 'b', 0 };
 static Rune LUndo[] = { 'U', 'n', 'd', 'o', 0 };
 static Rune LZerox[] = { 'Z', 'e', 'r', 'o', 'x', 0 };
+static Rune LSpaceindent[] = { 'S', 'p', 'a', 'c', 'e', 'i', 'n', 'd', 'e', 'n', 't', 0 };
+
 
 Exectab exectab[] = {
 	{ LAbort,		doabort,	FALSE,	XXX,		XXX,		},
@@ -110,6 +113,7 @@ Exectab exectab[] = {
 	{ LID,		id,		FALSE,	XXX,		XXX		},
 	{ LIncl,		incl,		FALSE,	XXX,		XXX		},
 	{ LIndent,		indent,	FALSE,	XXX,		XXX		},
+	{ LSpaceindent,	spaceindent,	FALSE,	XXX,	XXX	},
 	{ LKill,		xkill,		FALSE,	XXX,		XXX		},
 	{ LLoad,		dump,	FALSE,	FALSE,	XXX		},
 	{ LLocal,		local,	FALSE,	XXX,		XXX		},
@@ -1395,29 +1399,37 @@ enum {
 	Ioff = 1
 };
 
+
+
 static int
-indentval(Rune *s, int n)
+onoffval(Rune *s, int n, int *global)
 {
 	if(n < 2)
 		return IError;
 	if(runestrncmp(s, LON, n) == 0){
-		globalautoindent = TRUE;
-		warning(nil, "Indent ON\n");
+		*global = TRUE;
+		//warning(nil, "Indent ON\n");
 		return IGlobal;
 	}
 	if(runestrncmp(s, LOFF, n) == 0){
-		globalautoindent = FALSE;
-		warning(nil, "Indent OFF\n");
+		*global = FALSE;
+		//warning(nil, "Indent OFF\n");
 		return IGlobal;
 	}
 	return runestrncmp(s, Lon, n) == 0;
 }
 
+static int
+indentval(Rune *s, int n) {
+	return onoffval(s, n, );
+}
+
 static void
 fixindent(Window *w, void *arg)
 {
 	USED(arg);
 	w->autoindent = globalautoindent;
+	w->spaceindent = globalspaceindent;
 }
 
 void
@@ -1426,6 +1438,8 @@ indent(Text *et, Text *_0, Text *argt, int _1, int _2, Rune *arg, int narg)
 	Rune *a, *r;
 	Window *w;
 	int na, len, autoindent;
+	
+	
 
 	USED(_0);
 	USED(_1);
@@ -1449,6 +1463,37 @@ indent(Text *et, Text *_0, Text *argt, int _1, int _2, Rune *arg, int narg)
 		w->autoindent = autoindent;
 }
 
+void
+spaceindent(Text *et, Text *_0, Text *argt, int _1, int _2, Rune *arg, int narg)
+{
+	Rune *a, *r;
+	Window *w;
+	int na, len, spindent;
+	
+	
+
+	USED(_0);
+	USED(_1);
+	USED(_2);
+
+	w = nil;
+	if(et!=nil && et->w!=nil)
+		w = et->w;
+	spindent = IError;
+	getarg(argt, FALSE, TRUE, , );
+	if(r!=nil && len>0)
+		spindent = onoffval(r, len, );
+	else{ /* I'm not really sure what this does */
+		a = findbl(arg, narg, );
+		if(a != arg)
+			spindent = onoffval(arg, narg-na, );
+	}
+	if(spindent == IGlobal)
+		allwindows(fixindent, nil);
+	else if(w != nil && spindent >= 

[9fans] A learners sam cheat sheet

2021-08-05 Thread revcomninos
Below is my learners cheat sheet of sam commands which I am enclosing should 
find it helpful. I welcome any suggestions and/or corrections. These have been 
put together mostly from the standard resources, but there are gaps in my 
knowledge. 

$ - end of line/file
$-/vi/ -- search from end of the file backwards
0,$ t "peter.c" 0 -- copy dot from 1 file to another
0  send dot to stdin of command
,|sort -- sort the file
, > spell -- check spelling
# substitute #'th tagged pattern
,t "junk.c" 0 -- copy current file to start of junk.c
|tr a-z A-Z -- change case
,| uniq -- delete juxtaposed duplicates blank lines
/vi/+- m 0 moves the line containing "vi" to the top of the file
/vi/ or +/vi/ -- search forward
/vi/+- t 0 copies the next line with vi to the top of the file
/vi/+/vi/ -- search for the second occurrence of "vi" following dot
v/regexp/ command -- If dot does not contain, run command
,>wc -l -- count lines in file
,>wc -- word count of current document
w writes the whole file to disk or parts of a file
x/$^/!# -- comment a line
,x/ +$/d
.x/'+$/i/ --color-auto/
x/$^/!# ,x/^$\n/d
x/$^/!# ,x/[0-9]/d
x/^/.,/0d -- strip C comments from selection
,x/^/a/ / -- indents blocks of text with a tab stop.
,x/[a-zA-Z0-9]+/-#0;+#1| tr a-z A-Z -- capitalise every word (slow)
,x/[‘‘’’“”‘’]/c/"
X/\.c$/ ,x/variable/+-p -- find all uses of a variable in the C source files
,x/‘‘|’’/c/"/ -- change smart quotes to curly
x cmd - set dot and run command on each matching line
,x/  +/d
,x/\*/d
,x/^ +/d
,x/\*/d -- delete all asterisks
,x/^ /d -- deletes the indents
X D -- remove out all up to date files
,x/^ +/d -- Remove the space at the beginning of the line
,x g/^$\n/d -- delete blank lines
,x/good/ c/bad/
,x g/vi/p - idem
,x/^http.[^,]*?/d
,x/^http.[^,]*?/d -- search for "http...," and delete
,x/\n+/a/\n/ -- finds every occurrence of 1 or more (+) newlines (\n) and 
appends a new line.
,x/.*\n/ g/ed/ v/red/ p -- find ed but not red
,x/(.+\n)+/ g/It was the best of times/ p
,x /.*\n/ g/vi/ p - break file into lines, if lines contain "vi, print
,x/\n\n\n+/c/\n -- idem
.x/Peter/d -- search dot for 'Peter' and delete 'Peter'
X/regex/b -- switch to a loaded file with a regex
X/regexp/ command -- Run command on files whose menu line matches
x/regexp/command - set dot and run command on each match
X/\.sam$/,x/the/+-p -- search multiple files for text and print the results
.x s/.*/echo "&."/
,x s/good/bad/
,x s/\.\.\n/g -- break sentences into new lines
,x s/\\p/\n\n/g
,x s/\\s/\n\n/g
,x//|tr a-z A-Z
x/^/d -- remove 1 tab of indent from selection
,x/teh/c/the/
,x/^TODAY$//d -- strip  from all files
X ,x/(.+\n)+/ g/account/p
,y/best/ x/(.+\n)+/g/It was the best of times/p
Y/regexp/ command -- As X but select unmatched files
y/regexp/ command -- as x but select unmatched text

,x[a-zA-Z]+/{
g/fred/ v/./ c/jim/
g/jim/ v// c/fred/
} -- swap fred for jim in file
,x/Emacs|vi/{
g/Emacs/ c/vi/
g/vi/ c/Emacs/
}
Go from search results in sam window to document:
,x g//{
p
}

,| ssam -f your_script
As for comments in scripts, if you use ssam(1) to run them the easiest way
would be starting the lines you want to be ignored with a character
that isn't a sam command - this will work because ssam sends stderr to 
/dev/null.

--
9fans: 9fans
Permalink: 
https://9fans.topicbox.com/groups/9fans/Tc2ebea6bfef26073-M5318338af59b6b616cd4210c
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription


[9fans] A few more questions about sam

2021-08-05 Thread revcomninos
I am running sam as a standalone on Debian 10:
https://9fans.github.io/plan9port/
I have found this version to be stable and would not like to change it.
I also like the visual display. 
I start up sam from the terminal with a single option:
font=/mnt/font/GoMono/14/font sam
In this scenario, i.e. not running sam on plan9 itself, does

- (plumb) perform any useful action?
- Is there a way to customise the starting layout of sam? Someone recommended 
this link:
http://runjimmyrunrunyoufuckerrun.com/rc/s
However, I have had difficulty running this script in my setup.
- Does sam have any such a thing as a customisation file, such as .emacs or 
.vimrc? If so, where can I find any documentation on it? 
- sam's regex seem to lie somewhere between ed and more recent structural 
regular expressions, yet is not synonymous with either. Can someone point me to 
a specific resource that explains these expressions in more detail than does 
the sam man and sam tut?

--
9fans: 9fans
Permalink: 
https://9fans.topicbox.com/groups/9fans/T3107cd3bc536dc63-Ma0f414dace5fd771de173b2e
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription