Saturday, May 30, 2009

lab 99 - catching up with inferno-os


lab 99 - catching up with inferno-os


I had fallen way behind in keeping acme-sac code up to date with inferno-os. I tried to correct that this week by merging changes and adding files from inferno-os.

I wrote a script, part of this labs files, to check the differences between inferno-os and acme-sac. I'm hoping by using this script I'll stay up to date with inferno-os as changes are made. The script compares sub-trees, such as the limbo source code hierarchy, the C source code, the manual pages, and the /lib directory. It prints out commands to diff the files or copy the file over.

% inf
inferno synchronization:
  appl    show changed limbo files
  sys     show changed C source files
  man     show changed man pages
  lib     show changed /lib files
  cmd     show changed sh scripts below /dis
  update  refresh file tree info for local and remote
  adiff   adiff selected file with inferno-os equivalent
  diff    diff selected file with inferno-os equivalent
  missing show files missing from local tree
  added   show files added to local tree
% inf update
% inf sys
diff -u /sys/emu/port/win-x11a.c /n/D/inferno-os/emu/port/win-x11a.c
cp /n/D/inferno-os/emu/port/win-x11a.c /sys/emu/port/win-x11a.c


There is a short list of directories I did not synchronize because I know every file has changed; I consider these a fork, though the changes to charon are not dramatic,

/appl/acme/  /appl/charon/  /acme/

There is a list of directories acme-sac has removed from the inferno-os hierarchy:

/FreeBSD/  /libbio/     /utils/
/Hp/       /libdynld/   /appl/alphabet/
/Inferno/  /libkern/    /appl/collab/
/Irix/     /liblogfs/   /appl/demo/
/NetBSD/   /libnandfs/  /appl/ebook/
/OpenBSD/  /libprefab/  /appl/spree/
/Plan9/    /libtk/      /appl/tiny/
/asm/      /tools/      /appl/wm/

And finally there is a sub-tree we need to actually synchronize:

Linux    appl/grid lib       libkeyring  libmp   module
Nt       appl/lib  lib9      libmath     libsec
appl     appl/math libdraw   libmemdraw  include
appl/cmd emu       libinterp libmemlayer man

After comparing these sub-trees I built a list of files that were intentionally removed and files locally changed. Any file found "missing", where inferno-os added new functionality, was copied over. Files that were not marked as locally changed but nevertheless contained changes were merged, usually overwritten with the latest from inferno-os. There is also a list of files added to acme-sac apart from anything below /acme.

I found it useful to use the side-by-side diff functionality from lab 95. I added some simple interactive merge functionality that worked if you start from the end of the file and stepped backwards through the diffs using a PrevDiff command on the adiff output and calling the command Merge to apply the currently highlighted change. The implementation of this Merge command was pretty simple because it involved just copying the selected text from the source file over to the target. Given acme's filesystem interface this is literally a file copy,

cp /mnt/acme/$b/rdsel /mnt/acme/$a/wrsel

The PrevDiff commands does the work of setting up the selected texts correctly, properly handling the case of added, changed, or deleted text.

The list of files in the changed list should be reduced. Some of these are changes that could be pushed to inferno-os. E.g., diff adds the -u flag, os has changes from rog implementing host file name translation. Some files will need to be continually merged, such as the man page indices.

The list of files and directories removed are mostly just functionality either specific to running inferno as a native os, or the Tk functionality. There shouldn't be anything there people would really miss in an acme-sac environment. Though if there is let me know.



Monday, May 18, 2009

lab 98 - acme Ctag


lab 98 - acme Ctag


Ctag is a new client for acme that reads the tags file generated by ctags. In particular I worked with Exuberant Ctags on windows. While working on acme content-assist in lab 94 I thought a next possible step was using ctags for code completion. So in writing this program I wanted to explore using exuberant ctags by doing something easier, that is by providing assistance with code navigation.

Exuberant ctags understands many languages, but for the current effort I tried it on Java and Python.

For example, I generated tags for the python standard libraries,

ctags -R --excmd=number --exclude=test

Then run the client on the tags file,

Ctag /n/D/Python30/tags

What you start with is a blank window. In the tagline is a File command. Give it an argument of a filename which it will grep for in the ctags file.

File mailbox


It will then show all classes and methods within matching files. You can right-click on a method name to open the file at the line where the method is defined.

Ctag gives a top down view of a project. It is like the Outline view of some IDEs. A next step would be to implement the reverse direction, but probably as part of the content assist.



lab 97 - acme Navigator


lab 97 - acme Navigator


I created a simple directory browser for acme. Called Navigator, it opens directories in the same window. This makes descending deep but unfamiliar directory hierarchies easier because it avoids the proliferation of windows that clutter the desktop.


The client understands the command Pin for creating a standard acme directory window for the current directory (to pin the current directory to the desktop). This is an example for a rather simple client for acme.



Sunday, May 17, 2009

lab 96 - acme color schemes


lab 96 - acme color schemes


The inferno version of acme always contained some code to configure the acme color scheme, but I'm not sure if it always, if ever worked.

I modified the code a little in acme-sac to make the color configuration work. And I came up with a few new schemes.

The schemes are checked into acme-sac under /acme/color. To use a different scheme add a line like this to your $home/lib/profile

run /acme/color/evening

Running the "evening" scheme will make acme look like this.


The configuration files sets a few environment variables of the following form:


This sets the foreground text color in the body text to black. It's possible to mix two colors, as for the standard acme background.


Another simple scheme is "bw" for black and white.


There is also a file /acme/color/standard for the default acme color scheme which can be copied tweaked.

Saturday, May 16, 2009

lab 95 - acme side-by-side diff


lab 95 - acme side-by-side diff


Here's a script I wrote to help do side-by-side diffs in Acme. Run adiff as normal inside acme. And then in the adiff output window type the command NextDiff. Executing this command will step through each diff in the adiff output and highlight the changed region in each file.


The script will highlight each line, avoiding the cursor jump to highlighted regions as happens by plumbing or right-clicking on a file pattern. Though the cursor jump will occur the first time the diffed files are opened, for subsequent execution of NextDiff for diffs within the same files the cursor will remain over the NextDiff command and the highlighted regions will change with file scrolling to show at least part of the changed regions.

When the files first open you'll still need to manually arrange the files side by side. There is no acme API for window placement. However, the command will save some amount of scrolling, clicking, and mouse movement within the adiff output.

Here's the script for acme-sac. Some slight changes might need to be made for inferno, and something very similar should work in p9p acme.


fn findwin {
 file = $1
 < /mnt/acme/index getlines {
  (w x y z zz f rest) := ${split ' ' $line }
  if {~ $f $file} {echo $w}

fn highlight {
 file = $1
 lineno = $2
 a := `{findwin $file}
 if {! ~ $#a 0} {
  cd /mnt/acme/$a
  <> addr {
   echo -n $lineno > addr
   echo 'dot=addr' > ctl
   echo show > ctl 
  plumb $file:$lineno

cwd = `pwd
cd /mnt/acme/$acmewin
 echo -n 'addr=dot' >ctl
 (a b) := `cat 
 echo -n '/^[^\-<>].*\n/' > addr
 echo -n 'dot=addr' > ctl
 echo -n show > ctl
 (f1 cmd f2) := `{getline data}
 (f1 l1) = ${split ':' $f1}
 (f2 l2) = ${split ':' $f2}
 f1 = `{cleanname -d $cwd $f1}
 f2 = `{cleanname -d $cwd $f2}
 highlight $f1 $l1
 highlight $f2 $l2
} <> addr

The findwin and highlight functions I have used before in the acme debugger interface, adeb, in /appl/acme/acme/debug/adeb.b.