Re: [9fans] ed regular expressions in sam

2021-07-20 Thread Silas
In sam, g has two uses - either as a guard or after an s command where all 
substitutions are made

Quoting sam(1) (available at )
after an s command:
> If the command is followed by a g, as in
>    s/x/y/g, all matches in the range are substituted.
as a guard:
> g/regexp/ command
> v/regexp/ command
>    If the range contains (g) or does not contain (v) a
>    match for the expression, set dot to the range and run
>    the command.

--
9fans: 9fans
Permalink: 
https://9fans.topicbox.com/groups/9fans/Te7fcdc06a68bb777-Md69f4d24cf42efd3c4ceca26
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription


Re: [9fans] Autoexpand in sam

2021-09-25 Thread Silas
Your error mean spell's  output is too large to fit within sam's command window.

I don't have much experience with spell but I'd suggest correcting some of the 
typos found and running again or opening via B /tmp/sam.err and examining the 
typos found.

Silas
--
9fans: 9fans
Permalink: 
https://9fans.topicbox.com/groups/9fans/T0e2541a723ce90e5-M00c1d332035ddbd98d76091f
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription


[9fans] Re: Making multiple changes to dot using sam -d

2022-05-11 Thread Silas
Hi, 

Yep, seems you can combine changes with 

,x {
x/sam/c/sam -d/
x/teh/c/the/
}

Adding an optional guard before the opening brace. Note the changes must be 
correct way round otherwise you get the error "?changes not in sequence"

Silas
--
9fans: 9fans
Permalink: 
https://9fans.topicbox.com/groups/9fans/T06c9db1e30f71346-M9ed1425bee373a09dc2b0985
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription


Re: [9fans] p9f mention of 9front

2021-06-24 Thread silas poulson
What’s Dorren continent referencing?

Silas

On 24 Jun 2021, at 22:25, Wes Kussmaul 
mailto:w...@reliableid.com>> wrote:



All versions of Plan9, Inferno, derivatives, forks, et al are welcome on the 
Glenda continent.







9fans<https://9fans.topicbox.com/latest> / 9fans / see 
discussions<https://9fans.topicbox.com/groups/9fans> + 
participants<https://9fans.topicbox.com/groups/9fans/members> + delivery 
options<https://9fans.topicbox.com/groups/9fans/subscription> 
Permalink<https://9fans.topicbox.com/groups/9fans/T523d6e906a17a7cc-Ma32a526a9ee3953b55afcc24>


--
9fans: 9fans
Permalink: 
https://9fans.topicbox.com/groups/9fans/T523d6e906a17a7cc-M7b4febdc7dfcb5246fa8f366
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription


[9fans] Sam arena allocators

2021-06-28 Thread silas poulson
Hi,

Recently discovered a blog post[1] stating Sam used to have arena
based allocators.

Having difficulty finding more about this - does anyone know what the
allocator looked like and why the source returned to using the
standard allocators.

Silas

[1]https://jeremywsherman.com/2012/02/28/memory-allocation-in-sam/


--
9fans: 9fans
Permalink: 
https://9fans.topicbox.com/groups/9fans/Tf83e4250af593565-M69cd9bb1a4303e77810a75e6
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription


Re: [9fans] Sam arena allocators

2021-06-28 Thread silas poulson
> On 28 Jun 2021, at 23:29, Rob Pike  wrote:
> After Acme was written, I replaced most of the buffer management code in Sam
> with that from Acme, which was more efficient 

Right, that makes sense.

> It's possible the old code used an arena allocator, I don't remember,
> but it's possible you're referring to the code in samterm, which grew up
> on the Blit and likely had some compacting arena management code in
> it to keep the memory footprint small.

Possibly, I’m still exploring the code.

Re-reading Sam paper though, memory management section seems to imply
custom allocator, ran on both terminal and host to efficiently hold strings in 
memory 
via variable length arrays.

> As always, though, my memory may be faulty; it compacts too often.

Ha

Silas
--
9fans: 9fans
Permalink: 
https://9fans.topicbox.com/groups/9fans/Tf83e4250af593565-M2eda808e9e8fed8b9d6abce0
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription


Re: [9fans] Sam arena allocators

2021-06-29 Thread silas poulson
On 30 Jun 2021, at 00:44, noel.h...@gmail.com<mailto:noel.h...@gmail.com> wrote:
The source file in question is 'gcalloc.c' and it seems to be in sam
source as late as 10th Edition. From a perusal of research source, it
seems to have been used in jim, sam, pads, mux amongst others.

Right, thank you for that - forgot sources were available via list.

Will examine closely

Silas

--
9fans: 9fans
Permalink: 
https://9fans.topicbox.com/groups/9fans/Tf83e4250af593565-M282bbf82ea9329be71eff119
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription


Re: [9fans] Sam tricks (was: Alternative to fine-grained mouse usage?)

2021-07-01 Thread Silas McCroskey
> often switching files, Sam's menus are practically worse than Acme
> The weakest point in sam -d is still switching files, you have to type
> whole filenames

X/pathregex/b

sam will dump a warning about an expected blank, but it'll otherwise
do what you hope for (switch to the open file matching the regex).

> Loading a rc file with a bunch of "fn ...  {" simplifies things quite a lot 
> in general

Seconded on ^ and _ (though I rarely use the latter). I use "bind -b
lib/sam /bin" within sam, though, as I prefer separate files so I can
organize stuff by language and such (e.g. ^c/ind indents . with tabs,
^py/ind indents . with spaces, and language-specific poor-man's
parsing for stuff like selecting the entire body of the function
you're in). Also nice: a lot of my "scripts" just use "#!/bin/sed 1d"
or "#!/bin/sed /^#/d" so they don't need to mess with shell evaluation
at all, e.g.:

mystia% cat lib/sam/d
#!/bin/sed /^#/d
,> diff -c $% /fd/0

(outputs the diff between the buffer and the file -- mostly ends up in
/tmp/sam.err)

mystia% cat lib/sam/gd
#!/bin/sed /^#/d
!@{cd `{basename -d $%} && git/diff `{basename $%}}

(outputs the git diff of the current file -- mostly ends up in /tmp/sam.err)

- sam-d

--
9fans: 9fans
Permalink: 
https://9fans.topicbox.com/groups/9fans/T274bbf3037e0edb1-Mb6b866d13c89e6a36656b2e3
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription


Re: [9fans] Alternative to fine-grained mouse usage?

2021-07-02 Thread silas poulson
On 1 Jul 2021, at 18:48, Ethan Gardener 
mailto:eeke...@fastmail.fm>> wrote:
sam -d can't display line numbers

You can sort of display them via

,x {
p
}

Though it’s ugly and annoyingly can’t apply sam’s regex to remove the character 
locations.

Silas

--
9fans: 9fans
Permalink: 
https://9fans.topicbox.com/groups/9fans/T716c5aa0e2aa8a27-M379705a7f19743c3d79dfbb2
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription


Re: [9fans] Alternative to fine-grained mouse usage?

2021-07-02 Thread Silas McCroskey
> In any case, Plan 9's ed has a nice "browse" command which sam can't match. I 
> used to issue "0bn", then just "b" once per page. Or, if you don't want line 
> numbers, leave out the "n".

"+,+20p" does it. Doesn't work near the end of the file, though; not
sure if that can be improved within the same expression or you just
have to know to "+,$p" instead.

I agree with the camp that considers using line numbers (other than 0)
in sam (and ed, for that matter) to be something of an anti-pattern,
so I stopped letting the lack of 'n' bother me a long time ago. I'm
sure that's not much help for someone who's admitted to giving up on
regex though; you've got me curious how difficult it'd be to add it.

- sam-d

--
9fans: 9fans
Permalink: 
https://9fans.topicbox.com/groups/9fans/T716c5aa0e2aa8a27-Mceaed1e19b5399da7fe7634c
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription


Re: [9fans] Alternative to fine-grained mouse usage?

2021-07-03 Thread silas poulson

On 2 Jul 2021, at 19:06, Ethan Gardener 
mailto:eeke...@fastmail.fm>> wrote:

This reminds me why I switched to Forth: I can program my editor properly

Could you expand on this point?

Vaguely aware of Forth, but no experience with forth editors

Silas

--
9fans: 9fans
Permalink: 
https://9fans.topicbox.com/groups/9fans/T716c5aa0e2aa8a27-Mdb55b296d66f40a958396d89
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription


Re: [9fans] ed regular expressions in sam

2021-07-20 Thread Silas McCroskey
> I have yet gotten to this usage of "g" after "s".

The key difference here is not in the behavior of suffixed 'g', but in
how selections are made and operated on in the first place.

Ed's "selection" (aka dot, as you can reference it with '.') is always
a full, single line. It can *iterate* over multiple lines with
prefixed 'g', but each command (e.g. 's') will be run against only one
line at a time. As a result, suffixed 'g' always means "allow multiple
edits within this line" (alternatively, *not* suffixing with 'g' means
"only edit the first occurence of each line").

Sam's "selection" is more arbitrary -- it can be (and frequently is)
less than a line or multiple lines at once. In this case 'g' takes on
a different meaning -- "allow multiple edits within this selection" --
meaning if you *don't* pass 'g', and you're working with a multi-line
selection, only the first match in the entire selection will be
changed by the 's', regardless of whether other matches occurred on
separate lines.

As rob pointed out, interposing an 'x' without a regex will split the
selection into lines and iterate over each, getting you back to the
line-at-a-time behavior that is often easier to reason about.

--
9fans: 9fans
Permalink: 
https://9fans.topicbox.com/groups/9fans/Te7fcdc06a68bb777-M4fb1e908c2fdeb00adbda077
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription


Re: [9fans] Help with a sam cleanup script

2021-07-21 Thread Silas McCroskey
# is, for better or for worse, an address in sam:

  #n   The empty string after character n; #0 is the beginning
   of the file.

If you're talking about running the script with ^, it's just an
executable. You can put whatever you want in the shebang line; I tend
to use the following:

#!/bin/sed '/^#/d'
# this line is ignored
,x/\*|^ +| +$/d
# this line is also ignored
,x/  +//c/
,x/[‘‘’’“”‘’]/c/"
,x/\\p|\\b/c/\n\n\n
,x/\n\n+/c/\n

Running this as a script outputs only the lines in the file not
beginning with # for interpretation by sam.

To use it with ssam -f, you'd have to use the output rather than the
file directly.

In rc: ssam -f <{script}
In bash: ssam -f <(script)

both send the output to a temporary fd and then return a virtual file
path to that fd for commands like this that expect a file path.

If you really want comments within the sam language itself, the best I
came up with after 5 minutes of thinking was:

x/$^/!#

i.e. run a commented out shell command when an impossible pattern is
matched. The x// is needed to avoid actually launching the shell, and
the !# is needed to avoid interpreting the characters following as
another sam command (even if it's one that would never be run).

- Silas

--
9fans: 9fans
Permalink: 
https://9fans.topicbox.com/groups/9fans/T10b1d559ae7d981e-Mafc9e9d330eaec6c6ad1fe81
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription


Re: [9fans] Help with a sam cleanup script

2021-07-21 Thread Silas McCroskey
> #!/bin/sed '/^#/d'

apologies. quotes do not belong there.

#!/bin/sed /^#/d

--
9fans: 9fans
Permalink: 
https://9fans.topicbox.com/groups/9fans/T10b1d559ae7d981e-Mfff65af821d77519fd6c8034
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription


Re: [9fans] A few questions about sam

2021-07-22 Thread Silas McCroskey
> The sam window is not always responsive to commands. Under what specific 
> conditions is this the case?

I can think of a few cases:

* You issued an I/O command (shell, read file, write file, etc.) and
it's still in progress (there will always be output you can wait for
in these cases, e.g. the second '!' for shell commands). There's no
way I know of to kill an issued command from within sam (e.g. del key
doesn't work); if you launched something that's infinite looping or
the like you'd have to find it via ps and send a signal/note.
* You're entering commands on something other than the last line
("history" is editable, as in normal plan 9 terminals, which can be
particularly confusing in sam, as there's no prompt).
* You've started a compound command spanning multiple lines (e.g. with
{ } braces) and haven't completed it yet.

> is there a way to repeat the last entered command in sam without having to 
> snarf and paste? I know one can repeat the last search with //.

Not that I know of, sadly. Bare 's' to repeat is one of the things I
miss most about ed. Samterm's 'send' (send the highlighted text (or
the current snarf buffer) for execution) might be a slightly faster
idiom than snarf+paste+enter, though.

> In ed the "e" command allows one to switch files. It replaces the current 
> file with another. To add a file to the list in sam, one should use B not e. 
> Is that correct? I.e. it would seem "e" is allowed but not sam's natural way 
> of doing things?

B and b are both useful for this, yes. The former will load a new file
if that path isn't already in the menu, the latter will only switch to
already-loaded files.

'b' can be combined with X to good effect, in spite of that clearly
not being an anticipated case:
X/pathregex/b

will print "?blank expected" but still switch to the file matching
pathregex, so you don't need to type (or copy+paste) the full path.

- Silas

--
9fans: 9fans
Permalink: 
https://9fans.topicbox.com/groups/9fans/T60b5c1929a63b077-Mf5cfe43f0a56bf959f4d436a
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription


Re: [9fans] A few questions about sam

2021-07-22 Thread Silas McCroskey
> * I did try using 'send' but it gives me a ?bad delimiter `e' error.
send is a command on the middle-click menu in samterm, not part of the
sam language.

--
9fans: 9fans
Permalink: 
https://9fans.topicbox.com/groups/9fans/T60b5c1929a63b077-Ma800732a0dcfc142af454d8d
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription


Re: [9fans] Searching sam for text

2021-08-02 Thread silas poulson
On 2 Aug 2021, at 17:47, Paul Lalonde 
mailto:paul.a.lalo...@gmail.com>> wrote:

I occasionally do (in acme, sam MMV)
,x/open/+-{
p
}

For only a few results I’ve found simply ,x//= and then sending the 
results good enough, especially Acme where the plumber lets you jump to the 
result.

Sending document to grep with ,> grep -n  slightly neater though does 
mean leaving sam’s command set.

Silas

--
9fans: 9fans
Permalink: 
https://9fans.topicbox.com/groups/9fans/T6d4564e82d943342-M74570921159ae06ff4e5c6be
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription