<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 
 <title>Bluish Coder: acme</title>
 <link href="http://bluishcoder.co.nz/tag/acme/atom.xml" rel="self"/>
 <link href="http://bluishcoder.co.nz/"/>
 <updated>2018-01-10T15:35:12+13:00</updated>
 <id>http://bluishcoder.co.nz/</id>
 <author>
   <name>Bluishcoder</name>
   <email>admin@bluishcoder.co.nz</email>
 </author>

 
 <entry>
   <title>Editing remote files with Acme in Inferno OS</title>
   <link href="http://bluishcoder.co.nz/2013/06/11/editing-remote-files-with-acme-in-inferno-os.html"/>
   <updated>2013-06-11T01:00:00+12:00</updated>
   <id>http://bluishcoder.co.nz/2013/06/11/editing-remote-files-with-acme-in-inferno-os</id>
   <content type="html">&lt;p&gt;&lt;a href=&quot;http://www.vitanuova.com/inferno/&quot;&gt;Inferno OS&lt;/a&gt; ships with a version of the &lt;a href=&quot;http://acme.cat-v.org/&quot;&gt;acme&lt;/a&gt; text editor. I&#39;ve tried to use acme on and off for a bit and it never stuck. I&#39;ve always been a &lt;code&gt;vim&lt;/code&gt; and &lt;code&gt;emacs&lt;/code&gt; user. Recently I watched a video by Russ Cox called &lt;a href=&quot;http://research.swtch.com/acme&quot;&gt;A Tour of Acme&lt;/a&gt; that motivated me to try it again.&lt;/p&gt;

&lt;p&gt;The video is short and covers a lot of what makes Acme interesting. Most of it is related to the extensibility of the editor via shell commands dealing with piped input and output alongside the power of &lt;a href=&quot;http://sam.cat-v.org/&quot;&gt;sam&lt;/a&gt; editing commands.&lt;/p&gt;

&lt;p&gt;Some useful acme papers and tutorials are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://research.swtch.com/acme&quot;&gt;A Tour of Acme&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://doc.cat-v.org/plan_9/4th_edition/papers/acme/&quot;&gt;Acme: A User Interface for Programmers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://man.cat-v.org/inferno/1/acme&quot;&gt;Acme man page&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://doc.cat-v.org/bell_labs/sam_lang_tutorial/&quot;&gt;A Tutorial for the Sam Command Language&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://doc.cat-v.org/plan_9/4th_edition/papers/sam/&quot;&gt;The Text Editor Sam&lt;/a&gt; (for more on the command language)&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;For a recent task I had restored a backup of my &lt;a href=&quot;http://double.co.nz/creatures/&quot;&gt;Creatures Developer Resource&lt;/a&gt; website, recovering from &lt;a href=&quot;http://bluishcoder.co.nz/2013/04/03/parts-of-this-site-temporarily-down.html&quot;&gt;a hard drive failure&lt;/a&gt;. I wanted to remove the Google ad code from each page of the website.&lt;/p&gt;

&lt;p&gt;To do this from within Inferno and using Acme I first ensured I had the &lt;code&gt;styx&lt;/code&gt; service running on the remote web server and had the host file system bound so remote users could connect to it:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;; bind &#39;#U*&#39; /mnt/host
; svc/styx
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;On my client Inferno machine I mounted this remote directory and ran &lt;code&gt;acme&lt;/code&gt; to edit the files on it.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;% mount tcp!example.com!styx /n/host
% acme
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The &lt;code&gt;acme&lt;/code&gt; editor starts and from here I can edit files on the remote server by accessing &lt;code&gt;/n/host/mnt/host&lt;/code&gt;. The first step was to load all HTML files in the webserver directory into &lt;code&gt;acme&lt;/code&gt;. This was done by executing the following command in an &lt;code&gt;acme&lt;/code&gt; window that had its location set to &lt;code&gt;/n/host/mnt/host/var/www/example.com&lt;/code&gt; (using mouse button 2 to execute):&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Edit B &amp;lt;du -an|grep &#39;html?$&#39;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;From the &lt;a href=&quot;http://doc.cat-v.org/plan_9/4th_edition/papers/sam/&quot;&gt;Sam Reference&lt;/a&gt; it can be seen that &lt;code&gt;B&lt;/code&gt; is used to load files into the editor. In this case I load the output of the command &lt;code&gt;du -an|grep &#39;html?$&#39;&lt;/code&gt;. The command &lt;code&gt;du -an&lt;/code&gt; provides a recursive list of all files in the current directory and subdirectories and the &lt;code&gt;grep&lt;/code&gt; limits it to those ending in &lt;code&gt;htm&lt;/code&gt; or &lt;code&gt;html&lt;/code&gt;. Once executed acme has loaded all the files we&#39;re interested in from the remote server.&lt;/p&gt;

&lt;p&gt;The Google Ad snippet to be removed looks like:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;!-- Gooogle --&amp;gt;
...
&amp;lt;!-- Gooogle --&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The following &lt;code&gt;sam&lt;/code&gt; command will find this snippet and delete it:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;,x&amp;lt;!-- Gooogle --&amp;gt;(.|\n)*&amp;lt;!-- Gooogle --&amp;gt;/ d
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The &lt;code&gt;,&lt;/code&gt; means the starting range is the entire file. The &lt;code&gt;x&lt;/code&gt; command executes another comand for each part of the range that matches the regular expression - in this case the entire Google Ad snippet. The command to execute for each match is &lt;code&gt;d&lt;/code&gt; which is to delete the region. To have &lt;code&gt;acme&lt;/code&gt; run this on all open HTML files I used:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Edit X/html?$/ ,x&amp;lt;!-- Gooogle --&amp;gt;(.|\n)*&amp;lt;!-- Gooogle --&amp;gt;/ d
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The &lt;code&gt;X&lt;/code&gt; command iterates over all open windows with the name matching the regular expression and runs the following command, which I described above. This results in all the ad snippets from being removed from all the HTML files. To save them back to disk:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Edit X/html?$/ w
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And to close the &lt;code&gt;acme&lt;/code&gt; windows:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Edit X/html?$/ D
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The task is done, closing &lt;code&gt;acme&lt;/code&gt; and unmounting the remote file system:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;% unmount /n/host
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This task was pretty simple and could be done with a number of existing Unix tools but I wanted to give Acme a try with a real world task. It worked well editing remote files, and iterating towards the correct &lt;code&gt;sam&lt;/code&gt; commands to use was easy by interactively testing on single files and using the &lt;code&gt;p&lt;/code&gt; command to print ranges instead of deleting. Make sure &lt;a href=&quot;http://bluishcoder.co.nz/2012/12/18/authentication-and-encryption-in-inferno-os.html&quot;&gt;authentication&lt;/a&gt; is set up before sharing remote files though!&lt;/p&gt;
</content>
 </entry>
 
 
</feed>
