9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] Script to apply Edit commands in acme
@ 2023-01-16  3:49 revrari
  2023-01-16  8:17 ` sirjofri
  0 siblings, 1 reply; 9+ messages in thread
From: revrari @ 2023-01-16  3:49 UTC (permalink / raw)
  To: 9fans

[-- Attachment #1: Type: text/plain, Size: 730 bytes --]

In sam I can create a script file consisting of a list of edit commands to apply to the document. I then invoke *,| ssam -f my_script *to apply it.
I would like to do something similar in acme.
For example, create a script with these two commands to cleanup whitespace:
Edit ,x/^ +/d
Edit ,x/ +$/d
I would like to know if such a script would require the regular #!/bin/rc heading, and how it would be invoked from within acme. I tried to do something in my scripts folder, but it did not work.


------------------------------------------
9fans: 9fans
Permalink: https://9fans.topicbox.com/groups/9fans/Taf408751bc6fb344-M3eb35eb0b706b85667532f19
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription

[-- Attachment #2: Type: text/html, Size: 1334 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] Script to apply Edit commands in acme
  2023-01-16  3:49 [9fans] Script to apply Edit commands in acme revrari
@ 2023-01-16  8:17 ` sirjofri
  2023-01-16  9:06   ` revrari
  0 siblings, 1 reply; 9+ messages in thread
From: sirjofri @ 2023-01-16  8:17 UTC (permalink / raw)
  To: 9fans

Hello,

the shebang (#!/bin/rc) just says which shell you want to run it. You could also use /bin/ed, if you want to run ed commands, for example.

Acme can do pretty crazy stuff to extend it. For example, you can write your own scripts (or programs) in any language you like. Middle-click can execute simple programs with no magic. See also /acme/ folder for examples.

There can be simple programs like spell checkers that are just scripts using the file path as parameters, and there are more complex programs that actually use the acme filesystem to do crazy stuff. For example, you can adjust the buffer as you like, write into the tag line whatever you like, capture mouse input in the tag line and do whatever you like, oben new acme windows, ....

For your specific question about Edit commands, I don't know of a way. However, if there is a way I'm sure you can find it in the man pages.

What could work though, is running ssam (or sam) on the data file in your acme filesystem. It just exposes an interface for each of your acme windows with a few files to control it.

sirjofri

------------------------------------------
9fans: 9fans
Permalink: https://9fans.topicbox.com/groups/9fans/Taf408751bc6fb344-M75bfff0a46aceb39fb2713c0
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] Script to apply Edit commands in acme
  2023-01-16  8:17 ` sirjofri
@ 2023-01-16  9:06   ` revrari
  2023-01-18 16:44     ` Henri Ducrocq
  0 siblings, 1 reply; 9+ messages in thread
From: revrari @ 2023-01-16  9:06 UTC (permalink / raw)
  To: 9fans

[-- Attachment #1: Type: text/plain, Size: 300 bytes --]

Great tips. Thank you. I had no idea I could run ed commands that way. 
------------------------------------------
9fans: 9fans
Permalink: https://9fans.topicbox.com/groups/9fans/Taf408751bc6fb344-M2ed9c18cedf4f94ca36b7c63
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription

[-- Attachment #2: Type: text/html, Size: 792 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] Script to apply Edit commands in acme
  2023-01-16  9:06   ` revrari
@ 2023-01-18 16:44     ` Henri Ducrocq
  2023-01-18 16:54       ` Paul Lalonde
  0 siblings, 1 reply; 9+ messages in thread
From: Henri Ducrocq @ 2023-01-18 16:44 UTC (permalink / raw)
  To: 9fans

Here is a script I wrote to run any arbitrary command (Edit, Look, etc)
in a window (current one by default):
  https://gist.github.com/perpen/9902359ddf09b24129277ce121e3e86d

E.g.: Aexe 'Edit ,blah'

It's quite horrible, as it appends the command to the body to run it
using an event (would have been simpler running the command from the
tag, but there is race making that impossible iirc).

I ended up not using it, so it is not much tested. And I wrote it for
plan 9, not
sure how that would work with plan9port.

On Mon, Jan 16, 2023 at 9:06 AM <revrari@mweb.co.za> wrote:
>
> Great tips. Thank you. I had no idea I could run ed commands that way.
> 9fans / 9fans / see discussions + participants + delivery options Permalink

------------------------------------------
9fans: 9fans
Permalink: https://9fans.topicbox.com/groups/9fans/Taf408751bc6fb344-M11c0f3c688a704b33e48632a
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] Script to apply Edit commands in acme
  2023-01-18 16:44     ` Henri Ducrocq
@ 2023-01-18 16:54       ` Paul Lalonde
  2023-01-19  9:33         ` revrari
  0 siblings, 1 reply; 9+ messages in thread
From: Paul Lalonde @ 2023-01-18 16:54 UTC (permalink / raw)
  To: 9fans

[-- Attachment #1: Type: text/plain, Size: 1237 bytes --]

You can, of course, execute multiple commands in one Edit, either lineline
or chroding the "{}" block:
Edit {
,x/a/c/b/
,x/d/c/e/
}


On Wed, Jan 18, 2023 at 8:46 AM Henri Ducrocq <henri.ducrocq@gmail.com>
wrote:

> Here is a script I wrote to run any arbitrary command (Edit, Look, etc)
> in a window (current one by default):
>   https://gist.github.com/perpen/9902359ddf09b24129277ce121e3e86d
>
> E.g.: Aexe 'Edit ,blah'
>
> It's quite horrible, as it appends the command to the body to run it
> using an event (would have been simpler running the command from the
> tag, but there is race making that impossible iirc).
>
> I ended up not using it, so it is not much tested. And I wrote it for
> plan 9, not
> sure how that would work with plan9port.
>
> On Mon, Jan 16, 2023 at 9:06 AM <revrari@mweb.co.za> wrote:
> >
> > Great tips. Thank you. I had no idea I could run ed commands that way.
> > 9fans / 9fans / see discussions + participants + delivery options
> Permalink

------------------------------------------
9fans: 9fans
Permalink: https://9fans.topicbox.com/groups/9fans/Taf408751bc6fb344-Mfc6d82c231782e86759f2c05
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription

[-- Attachment #2: Type: text/html, Size: 2756 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] Script to apply Edit commands in acme
  2023-01-18 16:54       ` Paul Lalonde
@ 2023-01-19  9:33         ` revrari
  2023-01-20  5:25           ` Ben Hancock
  0 siblings, 1 reply; 9+ messages in thread
From: revrari @ 2023-01-19  9:33 UTC (permalink / raw)
  To: 9fans

[-- Attachment #1: Type: text/plain, Size: 252 bytes --]

Great tips. Thank you. 
------------------------------------------
9fans: 9fans
Permalink: https://9fans.topicbox.com/groups/9fans/Taf408751bc6fb344-M6ae700b031c62aa50ebf7c05
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription

[-- Attachment #2: Type: text/html, Size: 744 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] Script to apply Edit commands in acme
  2023-01-19  9:33         ` revrari
@ 2023-01-20  5:25           ` Ben Hancock
  2023-01-20  7:23             ` igor
  0 siblings, 1 reply; 9+ messages in thread
From: Ben Hancock @ 2023-01-20  5:25 UTC (permalink / raw)
  To: 9fans

(Re-posting this message as earlier send appeared to fail; apologies for
any duplication.)

revrari@mweb.co.za writes:
> In sam I can create a script file consisting of a list of edit
> commands to apply to the document. [...] I would like to know if such
> a script would require the regular #!/bin/rc heading, and how it
> would be invoked from within acme.

The paradigm is much the same in acme. As noted earlier, the shebang
just determines which shell the script will run in; you can choose
any shell, or use any executable. You'll just want to make sure that
the script is in your $PATH.

For example, you could create this as $HOME/bin/lstrip:

#! /bin/sh
ssam 'x/^ +?/d'

Make it executable, then write some text in acme:

This is
  some text
    that will be cleaned

If you select this text, type "|lstrip" in the tag (without the quotes),
and Button-2 (middle click) it, you will get the desired effect:

This is
some text
that will be cleaned

To operate on the entire window, type "Edit ,|lstrip" and execute that
with B2. By the way, as for your other example of cleaning whitespace at
the end of a newline (Edit ,x/ +$/d), acme does this by default on Put.

The other way you might approach this is just to keep a text file of
commonly used commands around. Then you can select the command you want,
and mouse-chord B2-B1 on "Edit" in the tag of the desired window to
execute that command.

  - Ben

------------------------------------------
9fans: 9fans
Permalink: https://9fans.topicbox.com/groups/9fans/Taf408751bc6fb344-Mab8c70f37dc76a709197b202
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] Script to apply Edit commands in acme
  2023-01-20  5:25           ` Ben Hancock
@ 2023-01-20  7:23             ` igor
  2023-01-20 14:24               ` Ben Hancock
  0 siblings, 1 reply; 9+ messages in thread
From: igor @ 2023-01-20  7:23 UTC (permalink / raw)
  To: 9fans; +Cc: igor

Quoth Ben Hancock <ben@benghancock.com>:
[…]
> By the way, […] cleaning whitespace at the end of a newline
> (Edit ,x/ +$/d), acme does this by default on Put.
[…]

Minor correction: There exist ACME patches accomplishing the above.
Howbeit, ACME does not strip trailing whitespace on Put by default.


------------------------------------------
9fans: 9fans
Permalink: https://9fans.topicbox.com/groups/9fans/Taf408751bc6fb344-M7878a439846f17b1a1d8594b
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] Script to apply Edit commands in acme
  2023-01-20  7:23             ` igor
@ 2023-01-20 14:24               ` Ben Hancock
  0 siblings, 0 replies; 9+ messages in thread
From: Ben Hancock @ 2023-01-20 14:24 UTC (permalink / raw)
  To: 9fans

igor@9lab.org wrote:

> Quoth Ben Hancock <ben@benghancock.com>:
> […]
> > By the way, […] cleaning whitespace at the end of a newline
> > (Edit ,x/ +$/d), acme does this by default on Put.  
> […]
> 
> Minor correction: There exist ACME patches accomplishing the above.
> Howbeit, ACME does not strip trailing whitespace on Put by default.
> 

Thanks Igor. I'm using the plan9port version of acme, and I typically
run in autoindent mode, which seems to trigger this behavior.

From the man page:

> When a window is in autoindent mode [...] and a newline character is
> typed, acme copies leading white space on the current line to the new
> line, and when a window is Put, acme removes all trailing end-of-line
> white space before writing the file.  The option -a causes each
> window to start in autoindent mode.

You are indeed correct that when starting without the '-a' flag, this
is not the behavior.

Cheers.

  - Ben


------------------------------------------
9fans: 9fans
Permalink: https://9fans.topicbox.com/groups/9fans/Taf408751bc6fb344-Md0954cf3a725613753213c68
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-01-20 14:24 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-16  3:49 [9fans] Script to apply Edit commands in acme revrari
2023-01-16  8:17 ` sirjofri
2023-01-16  9:06   ` revrari
2023-01-18 16:44     ` Henri Ducrocq
2023-01-18 16:54       ` Paul Lalonde
2023-01-19  9:33         ` revrari
2023-01-20  5:25           ` Ben Hancock
2023-01-20  7:23             ` igor
2023-01-20 14:24               ` Ben Hancock

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).