Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs Mode for a c-like language

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.

like image 917
Oren Avatar asked Feb 24 '12 04:02

Oren


2 Answers

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.

like image 161
Stefan Avatar answered Sep 28 '22 04:09

Stefan


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.

like image 25
Tikhon Jelvis Avatar answered Sep 28 '22 05:09

Tikhon Jelvis