BlitzMax Plugin for gedit

Archives Forums/Linux Discussion/BlitzMax Plugin for gedit

hamZta(Posted 2009) [#1]
Hey there!

I've just written a small plugin for gedit, so you can compile BlitzMax source code.

Get it here: http://chaos-interactive.de/en/geditbmax/

The source of the plugin isn't very pretty, but feel free to extend it as you like (sending me your changes would be nice ;) ).

Combine it with the highlighting files around here and you get a pretty decend BlitzMax editor, I think.

regards,
hamZta


Otus(Posted 2009) [#2]
Thanks! A couple of questions and wishes:

Should the "Compile..." menu option open a window? I don't see anything unless I tick "Run after compiling" or there's a compile error.

It would be nice if there was a keyboard shortcut for "Compile" and if that would also save the current file. Also, after running gedit from the terminal I see the following warning you might want to correct:

/home/jan/.gnome2/gedit/plugins/bmax.py:158: GtkWarning: BlitzMaxMenu: missing action BlitzMaxMenuAction
manager.ensure_update()


I may have a look at these myself, but I don't have much experience in Python, let alone pygtk...


Artemis(Posted 2009) [#3]
And for all those of you who want everything highlighted and not just the standard stuff I have a blitzmax language creator for gedit.

It looks through the makedocs-generated "commands.txt" file and even splits that up into variables (AppTitle, …) keywords (Module, Funtion, …) types (String, Int, … and everything starting with a 'T' followed by an uppercase letter) and functions.

It automatically creates the language file and copies it to the right place.

It is very useful to combine it with a script that builds your modules so that after a module build, makedocs and language-file-creation (and a restart of gedit) you have all your stuff highlighted.

Tested on Ubuntu 9.10 but it should work for everyone with a current bash (v.4).

format_codebox('
#!/bin/bash

# Here you can set your BlitzMax path (the folder where your MaxIDE, bin, mod, … is)
BLITZMAX_PATH="/opt/BlitzMax"

# If path is given as an argument then use that path
if [ -n $1 ]
then
if [ "$1" != "" ]
then
BLITZMAX_PATH=$1
fi
fi

# If path is empty then exit
if [ -z $BLITZMAX_PATH ]
then
echo ""
echo "Usage: $0 BLITZMAX_PATH"
echo " BLITZMAX_PATH is the root folder of you BlitzMax installation -- that is where your bin and mod folder is"
echo ""
exit
fi

# If path is no folder then exit
if [ ! -d $BLITZMAX_PATH ]
then
echo ""
echo "Error: $BLITZMAX_PATH is no folder"
echo ""
echo "Usage: $0 BLITZMAX_PATH"
echo " BLITZMAX_PATH is the root folder of you BlitzMax installation -- that is where your bin and mod folder is"
echo ""
exit
fi

# The file with the commands
COMMANDS_TXT="$BLITZMAX_PATH/docs/html/Modules/commands.txt"

# If the needed file does not exist then output error message and exit
if [ ! -f $COMMANDS_TXT ]
then
echo ""
echo "Error: $COMMANDS_TXT does not exist at the specified folder"
echo "Try rebuilding your documentation by using 'bin/makedocs' from your BlitzMax installation"
echo ""
echo "Usage: $0 BLITZMAX_PATH"
echo " BLITZMAX_PATH is the root folder of you BlitzMax installation -- that is where your bin and mod folder is"
echo ""
exit
fi

# Create temporary folder which does not already exist
DIR=/tmp/bmx-lg.tmp
while [ -d $DIR ]
do
DIR=$DIR#
done
mkdir $DIR

# Define two needed files
# match: this will take all the lines which match a regex
# remain: all lines which do not match go in here so we can process them further
MATCH="$DIR/match"
REMAIN="$DIR/remain"

# Copy the contents of the commands.txt file to the remain file
cp $COMMANDS_TXT $REMAIN

# Process the remaining lines
# $1 - the regex to split matching and remaining files
# $2 and $3 - the search and replace regexes to extract just the commands from
# the doc line
# $4 - the file where the commands should be written
# $5 - additional excludes from the lines
process()
{
sed "/$1/!d" $REMAIN > $MATCH
sed "/$1/d" $REMAIN > $REMAIN+
mv $REMAIN+ $REMAIN

sed "s/$2/$3/" $MATCH | uniq >> $4~
SED='s/^\(.*\)$/ <keyword>\1<\/keyword>/'
if [ "$5" != "" ]
then
SED="/$5/d; $SED"
fi
sed "$SED" $4~ >> $4
rm $4~
}

# Process all predifined variables like "AppDir" or "CurrentEvent"
# Variable:Type
process '^[A-Za-z0-9_]*:[A-Za-z0-9_]* : ' '^\([A-Za-z0-9_]*\).*' '\1' $DIR/var
# Variable:Type=*
process '^[A-Za-z0-9_]*:[A-Za-z0-9_]*=.* : ' '^\([A-Za-z0-9_]*\).*' '\1' $DIR/var
# Variable="*"
process '^.*=".*" : ' '^\([A-Za-z0-9_]*\).*' '\1' $DIR/var

# Process all types (the standard types plus all Identifier
# starting with a 'T' followed by an uppercase letter
process '^\(T[A-Z].*\|Byte\|Short\|Int\|Long\|Float\|Double\|String\) : ' '^\([^ ]*\).*' '\1' $DIR/type

# Process all Keywords (If, Module, Mod, …)
# Also remove Null, True and False from the list because they are defined differently
process '^[A-Za-z0-9_]* : ' '^\([^ ]*\).*' '\1' $DIR/keyword '^\(Null\|True\|False\)$'

# Process all funtions (everything with round brackets)
process '^.*(.* : ' '^\([A-Za-z0-9_]*\).*' '\1' $DIR/func


# The language file
# It's split into five pieces to easily concatenate it afterwards
echo '<?xml version="1.0" encoding="UTF-8"?>
<!-- This BlitzMax language file is autogenerated - do not change -->
<language id="blitzmax" _name="BlitzMax" version="2.0" _section="Sources">
<metadata>
<property name="mimetypes">application/x-blitzmax;text/x-blitzmax;text/plain</property>
<property name="globs">*.bmx</property>
</metadata>
<styles>
<style id="comment" _name="Comment" map-to="def:comment"/>
<style id="string" _name="String" map-to="def:string"/>
<style id="preprocessor" _name="Preprocessor" map-to="def:preprocessor"/>
<style id="null-value" _name="Null Value" map-to="def:special-constant"/>
<style id="boolean" _name="Boolean value" map-to="def:boolean"/>
<style id="hexadecimal" _name="Hexadecimal number" map-to="def:base-n-integer"/>
<style id="short-type" _name="Short Data Type" map-to="def:type"/>
<style id="operator" _name="Operator" map-to="def:operator"/>
<style id="variable" _name="Variable" map-to="def:identifier"/>
<style id="type" _name="Data Type" map-to="def:type"/>
<style id="keyword" _name="Keyword" map-to="def:keyword"/>
<style id="function" _name="Function" map-to="def:keyword"/>
</styles>
<default-regex-options case-sensitive="false"/>
<definitions>
<context id="blitzmax">
<include>
<context ref="line-comment"/>
<context ref="multiline-comment"/>
<context ref="string"/>
<context ref="preprocessor"/>
<context ref="null-value"/>
<context ref="boolean"/>
<context ref="hexadecimals"/>
<context ref="short-types"/>
<context ref="operators"/>
<context ref="variables"/>
<context ref="types"/>
<context ref="keywords"/>
<context ref="functions"/>
</include>
</context>
<context id="line-comment" style-ref="comment" end-at-line-end="true">
<start>'"'"'</start>
<include>
<context ref="def:in-line-comment"/>
</include>
</context>
<context id="multiline-comment" style-ref="comment">
<start>^\s*rem\\b</start>
<end>^\s*end\s?rem\\b</end>
<include>
<context ref="def:in-comment"/>
</include>
</context>
<context id="string" style-ref="string" end-at-line-end="true">
<start>"</start>
<end>"</end>
</context>
<context id="preprocessor" style-ref="preprocessor" end-at-line-end="true">
<start extended="true">
^\s*\?\s*(not\s+)?\S+\\b
</start>
<include>
<context ref="line-comment"/>
</include>
</context>
<context id="null-value" style-ref="null-value">
<keyword>Null</keyword>
</context>
<context id="boolean" style-ref="boolean">
<keyword>False</keyword>
<keyword>True</keyword>
</context>
<context id="hexadecimals" style-ref="hexadecimal">
<match>\$[A-Fa-f0-9]+</match>
</context>
<context id="short-types" style-ref="short-type">
<match>(?&lt;=[[:alnum:]]|_)(@@?|%%?|#|!|\$[WwZz]?)(?![[:alnum:]]|_)</match>
</context>
<context id="operators" style-ref="operator">
<match>(:?(\+|-|\*|/)|~|^|&amp;|\||(&lt;|&gt;)=?|&lt;&gt;|=|,|\.\.?)</match>
</context>
<context id="variables" style-ref="variable">' > $DIR/lng0
echo ' </context>
<context id="types" style-ref="type">' > $DIR/lng1
echo ' </context>
<context id="keywords" style-ref="keyword">' > $DIR/lng2
echo ' </context>
<context id="functions" style-ref="function">' > $DIR/lng3
echo ' </context>
</definitions>
</language>' > $DIR/lng4

# Concatenate the parts of the language file with the keyword files
cat $DIR/lng0 $DIR/var $DIR/lng1 $DIR/type $DIR/lng2 $DIR/keyword $DIR/lng3 $DIR/func $DIR/lng4 > $DIR/blitzmax.lng

# Language folder
LANG_FOLDER="$HOME/.local/share/gtksourceview-2.0/language-specs"
LANG_FILE="$LANG_FOLDER/blitzmax.lang"

# If the user folder for language files does not exist then create it
if [ ! -d $LANG_FOLDER ]
then
mkdir --parents $LANG_FOLDER
fi

# If a blitzmax.lang file already exists then check wheter it is autogenerated
# and create a backup if it is not
if [ -f $LANG_FILE ]
then
TOKEN=$(sed '/<!-- This BlitzMax language file is autogenerated - do not change -->/!d; s/<!-- This BlitzMax language file is autogenerated - do not change -->/+/' $LANG_FILE)
if [ -z $TOKEN ]
then
mv $LANG_FILE $LANG_FILE.bak
fi
fi

# Copy the created file to the language file
cp $DIR/blitzmax.lng $LANG_FILE

# Delete temporary folder
rm -fR $DIR
')


Blitzplotter(Posted 2009) [#4]
this is cool.