C0 | Documentation
About Downloads Tutorial References Courses
C0 Tutorial C0 and other languages Other references

Setting up your environment

You should have already seen how to add the C0 compiler cc0 and the C0 interpreter coin to your PATH so that when you type cc0 or coin at the command line. You've also seen how to edit a file in some editor of your choice, either Emacs or Vim. For you to be an effective 122 student, it is important for your PATH to be set up automatically when you log in, and it is also important for your editor to know some things about C0.

This task has two steps, and should be done on an Andrew machine. First you'll set up your PATH, and second you'll set up your editor(s). Except when you're (optionally) setting up Sublime Text, you should either be using a cluster computer or connected to unix.andrew.cmu.edu with SSH.

Setting up your PATH

This step will be done for you if you're in the GPI course and follow the instructions here. You can skip to setting up your editor.

For this step, you need to first type the following command. The next steps you follow depend on what gets printed when you run this command:

% echo $SHELL

Follow the appropriate instructions below. After you follow those instructions, log out and log back in: cc0 and coin should now be recognized commands.

...if you see /bin/csh when you run echo $SHELL

Use an editor (emacs of vim) to open the file $HOME/.cshrc. If the file doesn't exist yet, create it so that it contains just the following line; if the file already exists then add the following line at the very end:

setenv PATH ${PATH}:/afs/andrew/course/15/122/bin

...if you see /bin/bash when you run echo $SHELL

Use an editor (emacs or vim) to open the file $HOME/.bashrc. If the file doesn't exist yet, create it so that it contains just the following line; if the file already exists then add the following line at the very end:

export PATH=$PATH:/afs/andrew/course/15/122/bin

Then, open the file $HOME/.bash_login. Add the following line:

source ~/.bashrc

Setting up your editor

There are three editors that are popular with 122 students. The Emacs and Vim instructions assume you are using a cluster Unix machine or SSHing into unix.andrew.cmu.edu. The Sublime Text instructions assume you're working on your personal computer.

Emacs

To set up C0 for Emacs, run the following command:

% /afs/andrew.cmu.edu/course/15/122/bin/editor_config/emacs/setup.sh

Then, just quit and relaunch emacs, and syntax highlighting and indentation should work.

Vim

To set up C0 for Vim, run the following command:

% /afs/andrew.cmu.edu/course/15/122/bin/editor_config/vim/setup.sh

Then, just quit and relaunch vim, and syntax highlighting and indentation should work.

Sublime Text

The setup for Sublime Text is more complicated than for the other editors, and it is not available on cluster computers, so we recommend you try emacs or vim first. It is more intuitive to use for people who have not used emacs or vim before.

If you do not have Sublime Text installed, you can download it here. Next, install the Sublime Package Control using the instructions here. To install the SFTP plugin (which allows you to edit files on AFS), use [ctrl|cmd]+shift+p to open the command palette. Then type "install", and press enter. Then, click "Package Control: Install Package," and then type "SFTP", and press enter. The plugin will now be installed. Finally, go to File->SFTP/FTP->Setup Server, and a new file will open to setup the connection. Delete the template and paste in (substituting your andrew id where appropriate):

 {
    "type": "sftp",
    "sync_down_on_open": true,
    "sync_same_age": true,
    "host": "linux.andrew.cmu.edu",
    "user": "YOUR_ANDREW_ID",
    "remote_path": "/afs/andrew.cmu.edu/usr/YOUR_ANDREW_ID/private/15122",
    "connect_timeout": 30,
  }

Save this file under the name AFS. This is the name you will use to refer to this connection.

Now you can edit a file using File->SFTP/FTP->Browse Server. Saving the file will cause it to be uploaded to AFS, where you can compile and run it. Finally, to turn on syntax highlighting, open a .c0 file, and then select View->Syntax->Open All With Current Extension As->C. (C syntax is close enough to c0 syntax that this option will work fine).

You can also try Mahmoud Al-Ismail's C0-specific syntax highlighter https://github.com/mahmoudalismail/SublimeC0.