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 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] 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