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:

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.


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/ GtkWarning: BlitzMaxMenu: missing action BlitzMaxMenuAction

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).


# Here you can set your BlitzMax path (the folder where your MaxIDE, bin, mod, … is)

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

# If path is empty then exit
if [ -z $BLITZMAX_PATH ]
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 ""

# If path is no folder then exit
if [ ! -d $BLITZMAX_PATH ]
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 ""

# The file with the commands

# If the needed file does not exist then output error message and exit
if [ ! -f $COMMANDS_TXT ]
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 ""

# Create temporary folder which does not already exist
while [ -d $DIR ]
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

# Copy the contents of the commands.txt file to the remain file

# 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
sed "/$1/!d" $REMAIN > $MATCH
sed "/$1/d" $REMAIN > $REMAIN+

sed "s/$2/$3/" $MATCH | uniq >> $4~
SED='s/^\(.*\)$/ <keyword>\1<\/keyword>/'
if [ "$5" != "" ]
SED="/$5/d; $SED"
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">
<property name="mimetypes">application/x-blitzmax;text/x-blitzmax;text/plain</property>
<property name="globs">*.bmx</property>
<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"/>
<default-regex-options case-sensitive="false"/>
<context id="blitzmax">
<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"/>
<context id="line-comment" style-ref="comment" end-at-line-end="true">
<context ref="def:in-line-comment"/>
<context id="multiline-comment" style-ref="comment">
<context ref="def:in-comment"/>
<context id="string" style-ref="string" end-at-line-end="true">
<context id="preprocessor" style-ref="preprocessor" end-at-line-end="true">
<start extended="true">
<context ref="line-comment"/>
<context id="null-value" style-ref="null-value">
<context id="boolean" style-ref="boolean">
<context id="hexadecimals" style-ref="hexadecimal">
<context id="short-types" style-ref="short-type">
<context id="operators" style-ref="operator">
<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>
</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

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

# 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 ]
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 ]

# 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.