6

I'm trying to write a new emacs mode for a new template c-like language, which I have to use for some academic research.

I want the code to be colored and indented like in c-mode, with the following exceptions:

  • The '%' is not used as an operator, but as the first character in some specific keywords (like: "%p", "%action", etc.)
  • The code lines do not end with a semicolon.

Is it possible to create a derived-mode (from c-mode) and set it to ignore the original purposes of '%' and ';'? Is it possible to make the feature of "automatic-indentation after pressing RET" work without ';'?

Are there similar modes for similar languages (with '{}' brackets, but without semicolons) that I could try to patch?

Should I try to write a major mode from scratch?

I thought about patching the R-mode from http://ess.r-project.org/, but this mode does not support comments of the form "/* comment */".

The most important feature that I'm looking for is the brackets-indentation, i.e. indenting code inside a '{}' block after pressing RET (and without the extra-indentation after lines that do not end with ';'). Partial solutions will help too.

3 Answers 3

3

More generally, CC-mode has been extended and generalized over time to accomodate ever more languages, and the latest CC-mode is supposed to be reasonably good at isolating the generic code from the language-specific code. So take a look at some of the major modes that use CC-mode (e.g. awk-mode), and get in touch with CC-mode's maintainer who will be able to help you figure out hwo to do what you want.

1
  • I tried patching the CC-mode according to awk-mode (in which the lines do not have to end with ';') but it was too much code to understand and fix.
    – Oren
    Feb 25, 2012 at 22:13
2

If you don't mind something really simple, you can look at Gosu mode. Gosu is a language that has curly braces and no semi-colons, so you should be all set for your minimum. It also uses the same comment syntax as C.

The implementation of the mode for it is really simple and based on generic mode, so modifying it to work the way you want should be easy. It is not based on C-mode.

This is what I used to make a mode for the language I was working on for my compilers class, and it was really easy even with limited elisp experience. On the other hand, the indentation is fairly simple--it works for most code, but is not as complete as C-mode's.

1
  • Instead of using the Gosu mode, I used the Google Go mode and patched it.
    – Oren
    Feb 25, 2012 at 7:05
2

Check out arduino-mode: https://github.com/bookest/arduino-mode/blob/master/arduino-mode.el

It is a C based mode that uses the cc-mode features to quickly create something very useful and unique to arduino programming. Using this as a simple template should help a lot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.