Picaxe syntax colors on LMR

SyntaxColors.GIF

Hi, LMR!

What do you think is more readable and takes less time to understand, this:

symbol LED = 4         ' rename output4 'LED'
   
main:             ' make a label called 'main'
    readadc 0, b0
    if b0 > 55 then
        high LED         ' LED on
        pause 1000         ' wait 1 second (1000 ms)
        low LED         ' LED off
    endif
    wait 1         ' wait 1 second
    goto main         ' jump back to the start

or this:

1 symbol LED = 4 ' rename output4 'LED'

2

3 main:           ' make a label called 'main'

4     readadc 0, b0

5     if b0 > 55 then

6           high LED    ' LED on

7           pause 1000 ' wait 1 second (1000 ms)

8           low LED     ' LED off

9     endif

10    wait 1      ' wait 1 second

11    goto main   ' jump back to the start

Personally I would go for second variant as it is ten times more readable! LMR has rtf capabilities after all, why not to use it? So, here comes the problem: unfortunately Picaxe editor has no option to copy code as HTML, rtf, whatsoever... Let's fix this! :D

Ok, the workaround I found is not perfect and takes severall steps and some editing to complete, but I think sometimes it worth the time, especially if you are writing a tip or something alike.I hope this will be useful for somebody... Should we start?

Step 1. We will need a PDFCreator virtual printer. Print the code from Picaxe editor to this printer. You will get a PDF file with your code.

Step 2. Select and copy code from PDF.

Step 3. Paste it in any rtf enabled text processor. I have tried with MS Word and Sun Open Office, it works. Here you will need to do some editing as tabbing is lost. Setting font back to, say, Courier would be good as well....

Step 4. Copy nice looking code and paste it into your LMR post!

Step 5. Preview post. Sometimes you will have some font definitions or other artifacts appear after pasting from text processor. Make sure you preview post before posting and delete all undesired artifacts.

Done! :D Enjoy Picaxe syntax coloring on LMR!!!

PS. If you have other solutions to this problem, feel free to share them in comments, let's bring some colors in! :D

 

Syntax highlighting can be

Syntax highlighting can be done with Gvim, maybe more easier. You need:

Step1. Download and install Gvim.

Step2. Open your sourcefile with gvim (.bas or .c or a lot of other formats are supported).

Step3. Go to Menu  ‘Syntax’, select ‘Convert to HTML’ and save the file.

Step4. Click on HTML in the Edit box and insert the HTML file (copy and patse) in the Edit box.

The colors can be change in the Editor properties.

test.bas.html:

symbol LED = 4         ’ rename output4 ‘LED’
  
main:                  ’ make a label called ‘main’
    readadc 0, b0
    if b0 > 55 then
        high LED       ’ LED on
        pause 1000     ’ wait 1 second (1000 ms)
        low LED        ’ LED off
    endif
    wait 1             ’ wait 1 second
    goto main          ’ jump back to the start

The same works for Arduino files. Rename the .pde file in a .c file before open it in GVim.

~\arduino-0018\examples\Digital\Blink\Blink.c.html

/
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
 /

int ledPin =  13;    // LED connected to digital pin 13

// The setup() method runs once, when the sketch starts

void setup()   {                
  // initialize the digital pin as an output:
  pinMode(ledPin, OUTPUT);    
}

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()                    
{
  digitalWrite(ledPin, HIGH);   // set the LED on
  delay(1000);                  // wait for a second
  digitalWrite(ledPin, LOW);    // set the LED off
  delay(1000);                  // wait for a second
}

The syntax highlighting of GVim

The syntax highlighting of GVim isn’t perfect, because of the different dialects: Arduino vs. CPP,  PICAXE vs. Basic. For Arduino a better filter exists here.

For PICAXE Basic there is no existing solution. But it should be possible to adapt the existing basic filter.

The Arduino example looks better now:

~\arduino-0018\examples\Digital\Blink\Blink.pde.html

/
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
/

int ledPin =  13;    // LED connected to digital pin 13

// The setup() method runs once, when the sketch starts

void setup()   {                
  // initialize the digital pin as an output:
  pinMode(ledPin, OUTPUT);    
}

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()                    
{
  digitalWrite(ledPin, HIGH);   // set the LED on
  delay(1000);                  // wait for a second
  digitalWrite(ledPin, LOW);    // set the LED off
  delay(1000);                  // wait for a second
}

Syntax highlighting in Drupal

Would it be possible to add a Drupal syntax highlighting module like GeSHi Filter or Syntax highlighter to LMR? (LMR is run on Drupal, right?) I’m not sure if those support Picaxe BASIC (probably not) but it might be possible to add support for it.

 

Here is a VIM filter for

Here is a VIM filter for PICAXE basic. You have to copy the picaxe.vim file in the VIM program folder ‘‘vim72\syntax’. To use the filter, you have to add the following line to the vimrc file (in folder ‘users<username>’’ for Windows).

au BufNewFile,BufRead * if &ft == ‘basic’ | set ft=picaxe | endif

This is how the PICAXE example looks like now:

symbol LED = 4         ’ rename output4 ‘LED’
  
main:                  ’ make a label called ‘main’
    readadc 0, b0
    if b0 > 55 then
        high LED       ’ LED on
        pause 1000     ’ wait 1 second (1000 ms)
        low LED        ’ LED off
    endif
    wait 1             ’ wait 1 second
    goto main          ’ jump back to the start