Emacs mode for c-like language

I am trying to write a new emacs mode for a new c-like language template that I should use for some academic research.

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

  • "%" is not used as an operator, but as the first character in some specific keywords (for example: "% p", "% action", etc.).
  • Lines of code do not end with a semicolon.

Is it possible to create a derived mode (from c-mode) and set it to ignore the original targets "%" and ";"? Is it possible to use the function "automatic indentation after pressing RET" without ";"?

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

Should I try to write the main mode from scratch?

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

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

+6
source share
3 answers

If you are not against something really simple, you can watch Gosu mode . Gosu is a language that has curly braces and does not contain half columns, so you should be tuned in at least. It also uses the same comment syntax as C.

Implementing a mode for it is very simple and based on universal mode, so changing it to work the way you want should be easy. It is not based on C mode.

This is what I used to create the mode for the language I was working on for my compiler class, and it was very simple even with limited experience with elisp. On the other hand, the indentation is quite simple - it works for most codes, but not as fully as in C-mode.

+2
source

More generally, the CC mode has been expanded and generalized over time to accommodate more languages, and the last CC mode should be good enough to isolate the general code from language specific code. Therefore, take a look at some of the main modes that use CC mode (for example, awk-mode), and consult a CC-mode specialist who can help you understand how to do what you want.

+3
source

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

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

+2
source

Source: https://habr.com/ru/post/909247/


All Articles