Emacs mode for AS3

I’ve rewritten my actionscript-mode to support AS3. I’ve stripped out everything related to AS2, but you can still get the old version from here.

actionscript-mode.el

I have been using this new mode for a couple months and I haven’t had any problems, but your coding style might differ from mine, so please let me know if you run into any issues.

Update: Here is the other set of functions that I use when I code actionscript. As I said before, you probably will want to just pick and choose some functions from this file since it is highly customized to my personal environment and has a lot of dependencies.

as-config.el

17 Responses to “Emacs mode for AS3”

  1. irimi Says:

    Great job, thanks a lot ! I was glad to see that someone had coded a real AS mode for Emacs, at last !

    But could you add some explanations for those who don’t understand , especially to customize and/or create an “as-config.el” file ?

    I’m coding in AS2.0, and I noticed that the mode didn’t manage to show me the methods in my .as files in the speedbar (I tried the old and the new “actionscript-mode.el”). In fact I noticed that it didn’t work because of the “:Type” at the end of the function declaration (for example : “public function myFunction():Object”). How can correct add that ?

    Thanks again for this mode !

  2. austin Says:

    Thanks for pointing that out. I don’t use the speedbar, so I hadn’t noticed. I do use which-function-mode, however, and I knew that it wasn’t working correctly. They both use imenu, support for which was missing in actionscript-mode.

    So, based on your example, I found a few bugs and fixed them. which-function-mode now works correctly for me, but the speedbar has never shown me anything. I’ll look into that when I have more time.

    I posted a new version of the as3 file, but I’m not maintaining the as2 one any more. If you want to try to update the as2 one, I think you just need to update the function “as-get-function-re” with the version in the new as3 file. No guarantees on that, but let me know if it doesn’t work.

  3. xbytor Says:

    This looks like a nice mode. However, I’m having some issues with local vars. What versions of cc-mode and font-lock does this work with?

    -X

  4. austin Says:

    I’m using cc-mode 5.28 and font-lock 21.1. I know that things don’t work properly with the latest version of cc-mode, and whichever version is currently included with Emacs 22. I think they changed a lot of stuff and it’s going to be a pain to get this derivative mode back in order.

    What problems are you having?

  5. xbytor Says:

    I type in ‘var d’ into a blank file. As soon as I hit the ‘d’ key, I get this as the error:

    (1) (warning/warning) Error caught in `font-lock-pre-idle-hook’: (void-function font-lock-match-c-style-declaration-item-and-skip-to-next)

    It’s the only problem I’ve noticed.

    The versions of xemacs that I’m using are:

    XEmacs 21.4 (patch 20) “Double Solitaire” (win32) of Sat Dec 09 2006 on VSHELTON-PC2

    and

    XEmacs 21.4 (patch 19) “Constance Variable” (cygwin, Mule) of Tue Jan 31 2006 on vzell-de

    I’ll see if I can track down the versions of cc-mode and font-lock that you’re using.

    -X

  6. Jonathan Says:

    Yeah, I can’t seem to get it to work with my emacs. It is v21.3.1, but the cc-mode is 5.30. If I load action-script.el and try to eval it, I get undefined variables like c-identifier-re and c-protection-key. Here’s what I get if I try to byte-compile it:

    While compiling toplevel forms:
    ** assignment to free variable actionscript-conditional-key
    ** reference to free variable c-protection-key
    ** assignment to free variable c-keywords
    ** reference to free variable actionscript-conditional-key
    ** assignment to free variable c-conditional-key
    ** assignment to free variable c-method-key
    ** assignment to free variable c-baseclass-key
    ** assignment to free variable c-inexpr-class-key
    ** reference to free variable as-imenu-generic-expression

    While compiling the end of the data:
    ** The function `c-identifier-re’ is not known to be defined.

  7. austin Says:

    Yeah, I got those same exact errors when I tried to use a more recent cc-mode. The problem is that my actionscript-mode is based off of some older cc-mode features that have changed. I tried to see if I could fix it, but the problem seems pretty deep. I’d either have to start over and create a new derived mode, or better, create an independent actionscript-mode. Either way, it’s going to take a lot of effort, and I’m not sure when I will have time for it.

    For more information see “API changes for derived modes” in this cc-mode changelog for version 5.30: http://cc-mode.sourceforge.net/changes-530.php

  8. Julien CROUZET Says:

    Very nice job !

    Here is a proposal to invoke actionscript-mode when opening .as (and .as1 .as2 .as3) files :

    ;; Make actionscript-mode the default mode for .as files
    (defcustom as-file-patterns (list “\\.as[123]?\\’” “\\.as\\’”)
    “*List of file patterns for which to automatically invoke actionscript-mode.”
    :type ‘(repeat (regexp :tag “Pattern”))
    :group ‘as)
    (let ((as-file-patterns-temp as-file-patterns))
    (while as-file-patterns-temp
    (add-to-list ‘auto-mode-alist
    (cons (car as-file-patterns-temp) ‘actionscript-mode))
    (setq as-file-patterns-temp (cdr as-file-patterns-temp))))

  9. austin Says:

    Hi Julien,

    Why do you think that’s better than just:

    (add-to-list ‘auto-mode-alist ‘(”\\.as[123]?$” . actionscript-mode))

    Am I missing something?

  10. Cameron Says:

    Regarding incompatibility with the recent versions of cc-mode:

    I am using emacs 23.0.0.1, font-lock 21.1, and cc-mode 5.31.3. Rather than try to fix anything, I located an old version of cc-mode here, unzipped the directory to my site folder, and changed the beginning of actionscript-mode.el to


    (setq load-path (cons (substitute-in-file-name "$HOME/emacs/cc-mode-5.28") load-path))
    (require 'cc-mode)

    Now the old cc-mode loads only when using actionscript-mode. If I want to edit C files, I’ll start another emacs session. Not a perfect solution, but better than nothing.

    Moving right along, I downloaded and tried to use the es-config.el file, which looks to have some nice tools. However, I don’t have as-profiler, which is required at line 1. Is that code also available?

    Thanks for putting this good stuff out here!

  11. austin Says:

    Hi Cameron,

    Thanks for the info about cc-mode.

    The as-profiler stuff depends on a server that catches special trace messages from my swfs. I haven’t posted that stuff b/c it’s pretty rough and currently it requires that you have SBCL installed on your system. You should be able to comment out the “require” line and maybe a couple others and everything will work fine without it.

  12. Joe Says:

    Looking forward to playing with this. Just a note, if you want to get the 5.30 version of cc-mode just check it out from cvs:
    cvs -z3 -d:pserver:anonymous@cc-mode.cvs.sourceforge.net:/cvsroot/cc-mode co -rBranch_5_30 cc-mode

  13. Joe Says:

    woops, you nead version 5.29
    cvs -z3 -d:pserver:anonymous@cc-mode.cvs.sourceforge.net:/cvsroot/cc-mode co -rRelease_5_29 cc-mode

  14. matt Says:

    thanks a lot! starting to use this heavily,
    but found miss-hilighting after this code..

    var regexp:RegExp = /]*?href=[’”](.*?(.jpg|.jpeg|.gif|.bmp|.png))[’”][^]*?>[^]*?]*?src=[’”](.*?(.jpg|.jpeg|.gif|.bmp|.png))[’”][^]*?>/ig;

    can it be fixed?
    might should fix my regexp first..

  15. austin Says:

    Hi matt,
    There are so many special characters in that regexp that must be confusing the system. I’m not sure if I can fix it, but I know the semantic parsing in actionscript-mode could be improved. I just don’t know if it’ll ever be able to handle unquoted arbitrary regular expressions. You might try using the RegExp constructor instead of a regexp literal, like this one, from the livedocs: var re1:RegExp = new RegExp(”bob”, “i”); You’d probably have to escape those quotes in your regexp, though.

  16. Bela Says:

    Is there a way to customize emacs not to show “\” when line is too long?

    when the line is too long, emacs will append “\” to indicate there is an additional line. Is there a way to customize emacs not to show “\” when line is too long?

    Thanks.

  17. austin Says:

    Bela,

    If you want long lines to visually wrap to the next line, add this to your .emacs:
    (setq-default truncate-lines nil)

    If you want different behavior for different modes, you’ll have to figure out how to set that value per mode.

    If you just want the slashes to disappear, but the behavior to remain the same, then I don’t know how to do that.