sourcepawn-mode

(sourcepawn-mode is available at GitHub.)

I use emacs to develop, and that includes writing plugins for SourceMod. However, I’ve had to use c++-mode if I wanted any sort of automatic indentation or code highlighting. The problem is, this mode just doesn’t quite fit right: SourcePawn is not C++. The code highlighting is a tad off, and if you don’t use semicolons (which are not required in Pawn), the auto-indent screws itself up.

I got tired of trying to shoehorn Pawn into c++-mode, so I went and wrote sourcepawn-mode.

To download, see the Installing section.

Current Features

sourcepawn-mode is, quite honestly, a very immature major mode. It doesn’t do very much yet, but what it does is helpful:

Bugs, Suggestions, and Patches

Bug reports, as always, are welcome. Patches are even more welcome, if you feel like spelunking through my beginners elisp code. Just contact me and tell me what’s up.

This mode is likely extremely biased towards my coding style and emacs usage style, but by no means should it stay like that. If something doesn’t work the way you think it should, I’m always open to suggestions.

License

sourcepawn-mode is licensed under the GNU GPL v3.

Installing

I know that sourcepawn-mode works on GNU emacs 22.2.1. For other versions and flavors, your mileage may vary. Please contact me if it doesn’t work on your version, and you can’t upgrade and want it fixed.

Download

You can download any of these versions (I recommend the most recent), or you can checkout my development version from GitHub. If you go the git route, see the section below about generating sourcepawn-mode.el before continuing.

sourcepawn-mode-0.1 (August 5, 2010, commit cf1b928)

Editing .emacs

Once downloaded and uncompressed, you will have a folder with various files. Copy the file sourcepawn-mode.el to somewhere where Emacs can find it. If you don’t know where that is, we can just tell emacs to look in this folder instead.

(Note: do not copy sourcepawn-mode.el.in, copy sourcepawn-mode.el. The first one will not work!)

After copying this file (or not), we must edit your .emacs file, which should be in your home directory. If you’ve never done this (though you should have), you may have to create it.

Add these lines to the bottom (or wherever):

;; if you have to, tell emacs where to find this file
;; if you put the file in emacs's path, you don't need this
(add-to-list 'load-path "/home/agrif/sourcepawn-mode")

;; tell emacs to autoload an interactive function named 'sourcepawn-mode'
(autoload 'sourcepawn-mode "sourcepawn-mode" nil t)
;; also tell it to use sourcepawn-mode for *.sp files
(add-to-list 'auto-mode-alist '(".sp\\'" . sourcepawn-mode))

There! It should be working now. Go test it out and bask in the font-lock colored text glory!

Generating sourcepawn-mode.el

(Note: Most people will never have to do this. This section is for developers and git sources only.)

sourcepawn-mode scans the standard SourcePawn include files to generate a list of keywords and constants for it to highlight, then creates sourcepawn-mode.el (the main file) from the source in sourcepawn-mode.el.in and the generated lists. The files available on this page already have this file generated, so you can just install using the instructions above.

If you got sourcepawn-mode from Github, or if you just want to, you can generate a new copy of sourcepawn-mode.el from sourcepawn-mode.el.in and the SourcePawn include files from a SourceMod release.

Copying the SourcePawn Includes

You have to copy over the SourcePawn includes to the sp-include directory. These include files can be found in sourcemod/scripting/include/. For me, this command would be:

agrif@hesperus:~/sourcepawn-mode$ cp ~/valve/orangebox/tf/addons/sourcemod/scripting/include/* sp-include/

If you want, you can delete the version.tpl file. It may get in the way in the future; for now, it’s harmless.

Scanning and Generating

Now, run make to autogenerate the keywords and make sourcepawn-mode.el. This requires emacs and make to be installed on the current machine. If you don’t have make installed, you could run these commands instead, in the root of the package:

agrif@hesperus:~/sourcepawn-mode$ emacs --script tools/scan.el
agrif@hesperus:~/sourcepawn-mode$ emacs --script tools/generate.el

The first command scans the files in sp-include, and dumps lists of keywords into keywords/generated/. The second command reads these lists, and the static lists in keywords, compiles them into optimized regexps, and inserts them into sourcepawn-mode.el.in, thus creating sourcepawn-mode.el, the final file.

You can now proceed with installing as described above.