Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indentation of annotations and initial equation #2

Open
raulrpearson opened this issue Dec 20, 2016 · 6 comments
Open

Indentation of annotations and initial equation #2

raulrpearson opened this issue Dec 20, 2016 · 6 comments

Comments

@raulrpearson
Copy link

I'd really like to use Emacs to edit and clean up Modelica files. I'm only using modelica-mode.el, but I have some issues with indentation.

Using an example from Modelica by Example, this is what I'd expect to get:

within ModelicaByExample.BasicEquations.SimpleExample;
model FirstOrderExperiment "Defining experimental conditions"
  Real x "State variable";
initial equation
  x = 2 "Used before simulation to compute initial values";
equation
  der(x) = 1-x "Drives value of x toward 1.0";
  annotation(
    experiment(
      StartTime=0,
      StopTime=8));
end FirstOrderExperiment;

This is what I get instead:

within ModelicaByExample.BasicEquations.SimpleExample;
model FirstOrderExperiment "Defining experimental conditions"
  Real x "State variable";
  initial equation
  x = 2 "Used before simulation to compute initial values";
equation
  der(x) = 1-x "Drives value of x toward 1.0";
  annotation(
	     experiment(
			StartTime=0,
			StopTime=8));
end FirstOrderExperiment;

Notice:

  • initial equation gets pushed 2 spaces forward when presumably it shouldn't.
  • Annotations (or things that use brackets, I guess) get indented to align with enclosing brackets. This isn't incorrect per se, but it quickly makes for very long lines in annotations, which are difficult to read since they end up truncated or wrapped, creating a very unsightly source code.
  • We end up with a mixture of tabs and spaces for indentation.

Is this a problem with my setup or is this expected behaviour? I don't mind putting in some time to provide fixes or enhancements if someone provides some pointers, since I'm not familiar with Elisp. Thanks!

@raulrpearson
Copy link
Author

I think I fixed the the indentation problem with initial equation by adding to the regular expression in line 496. I haven't pushed to my fork yet, but will do soon.

@dietmarw
Copy link
Contributor

This sounds like an interesting fix. I can not think the current behaviour is intended. So looking forward to your PR 😄

@raulrpearson
Copy link
Author

Fair enough, I'll post it as soon as I get it. It's on hold right now because I was spending too much time customizing Emacs and too little time on my Modelica code 😄. I managed to improve it somewhat by changing some of the logic in mdc-calculate-indent, but it's not quite there yet.

@JKRT
Copy link

JKRT commented Jul 24, 2019

@raulrpearson

I maintain a heavily modified fork of modelica-mode (You can really call it XModelica-mode I guess 🖌). Which I finally decided to update yesterday. It differs quite a bit from the original from where it is derived this :D Awesome work btw @maintainers! From insights I know I have a few users and subforks of my own.

I do actually support the functionality you desire and some more things.

`within ModelicaByExample.BasicEquations.SimpleExample;
model FirstOrderExperiment "Defining experimental conditions"
  Real x "State variable";
initial equation
  x = 2 "Used before simulation to compute initial values";
equation
  der(x) = 1-x "Drives value of x toward 1.0";
  annotation(
             experiment(
             StartTime=0,
             StopTime=8));
end FirstOrderExperiment;`

Sadly I indent annotations in much the same way, but initial equation e.t.c s are working as they should : ). If you are interested you can fork mine, put up any issues you have and so on : )

@raulrpearson
Copy link
Author

Good to hear, @JKRT. If you're running a fork, have you considered submitting a PR to merge your contributions?

I'm not doing much Modelica these days, otherwise I'd give your fork a try. Thanks for letting me know.

@JKRT
Copy link

JKRT commented Jul 27, 2019

Good to hear, @JKRT. If you're running a fork, have you considered submitting a PR to merge your contributions?

I'm not doing much Modelica these days, otherwise I'd give your fork a try. Thanks for letting me know.

It is pretty much its own thing by know, and I usually make quite steep changes and break it from time to time. It differs too much to really be mergeable with the original.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants