GNOME Bugzilla – Bug 563986
wizard generates modeline inconsistent with indentation prefs
Last modified: 2012-04-22 14:46:15 UTC
Please describe the problem: When the Application Assistant generates a project, it includes the following modeline in C source files: /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ This causes the editor to use tabs for indentation with a 4-character indent. Unfortunately the wizard includes this modeline even if my Anjuta preferences are completely different (e.g. no tabs, 2-character indent). This is inconvenient and confusing. We should either make the modeline consistent with current Anjuta preferences, or simply omit the modeline altogether. Steps to reproduce: 1. 2. 3. Actual results: Expected results: Does this happen every time? Other information:
I don't see it as a big problem. The "easy" fix is to remove all modeline from all templates. But I would prefer to keep them, so I have to add some new properties in the project wizard to get this tab settings. Not a very difficult task but I prefer to take care of more important bugs. I will try to do it for the next release. If you want you can write a patch for this. It should work like the project directory, defining a new value in plugins/project-wizard/druid.c:npw_druid_add_default_property. Then update all template having modeline to use these new value. It's possible that you need to add new shell value in editor plugin to export this tab settings.
I would vote to make modeline take the values previously configured in the editor.
*** Bug 612761 has been marked as a duplicate of this bug. ***
We also should take care that the generated files are indented properly for the modelines set. As this is reported quite often, it is a good candidate for 3.0.
Do you have a procedure which can be called by the project wizard an indent the whole file according to the modeline ? Else, I'm afraid it would be difficult to indent the file correctly using autogen macros.
Hmm, actually we can only indent files that are open in the editor (and even this would require a new interface but it's trivial). So, basically two solutions: * Indent files somehow using our indenting solution, possibly rewriting it to be able to use files directly. * Use something like [+Indent+] in the wizard files that will add the correct indentation in that place. The latter is probably kind of easy to do but of course a pain to maintain. I see no other solution here at the moment though.
(In reply to comment #7) > So, basically two solutions: > * Indent files somehow using our indenting solution, possibly rewriting it to > be able to use files directly. The wizard is not able to open file in editor to indent them, so I think it needs a new interface allowing to indent files directly. But I'm not sure that reindenting a complete file can be done without any issue. > * Use something like [+Indent+] in the wizard files that will add the correct > indentation in that place. [+Indent+] will be replace by the value of the Indent variable, so we will have to write something like [+Indent+]if (a) [+Indent+]{ [+Indent+][+Indent+]a == 0; [+Indent+]} it will be quite a pain to use it everywhere. Moreover it cannot handle style differences like open brace on a separate line or not. > The latter is probably kind of easy to do but of course a pain to maintain. I > see no other solution here at the moment though. I think only the first solution is really usable but we need a new interface for this.
I though about this a bit. What we might be able to do: * After finishing the project-wizard opens all the project sources files in the document-manager (not a bad idea in general) * I calls something like ianjuta_editor_assist_auto_indent() which will automatically indent the file according to it's modeline if there is an appropriate language-support plugin. Do you think that's doable?
(In reply to comment #9) > I though about this a bit. What we might be able to do: > > * After finishing the project-wizard opens all the project sources files in the > document-manager (not a bad idea in general) > > * I calls something like ianjuta_editor_assist_auto_indent() which will > automatically indent the file according to it's modeline if there is an > appropriate language-support plugin. > > Do you think that's doable? There is a not obvious limitation with the project-wizard. When the project wizard is running, the current project is not the new project as we are just creating it. It means that if the project wizard open a document, it will be in old project so we probably have to close the document else it will be saved in the opened document of the old project. Moreover, the project wizard open the new project file by running again anjuta with the project file in the command line. It can open additional files by putting them in the command line but as one file is a project file the project wizard itself is deactivate and then (probably) reactivated. It cannot do anything when the new project is loaded. Perhaps we can plan some actions that will be done when a project is loaded but such mechanism doesn't exist at the moment. It will be easier if the auto indentation is done directly on a file without having to open it in an editor. Or perhaps we can have hidden editors. Anyway, I don't see any better solution.
> Moreover, the project wizard open the new project file by running again anjuta > with the project file in the command line. It can open additional files by > putting them in the command line but as one file is a project file the project > wizard itself is deactivate and then (probably) reactivated. It cannot do > anything when the new project is loaded. Perhaps we can plan some actions that > will be done when a project is loaded but such mechanism doesn't exist at the > moment. We should encode that information into the project profile xml in some way. The files to open are already encoded in that file when opening a regular anjuta project so we might be able to set an additional xml property like "auto-indent=yes". This will require to generate an appropriate profile xml-file for each project file of course but I guess that could be automated a lot. And we need to create correct modelines of course, but that's rather simple.
Using guile, I have been able to indent files using only autogen. You need to use only tabulation to indent your file and there is post processing step where all tabs are replaced by the right indentation. In fact, the main issue was rather to get the necessary information for the indentation. These informations were spread between the editor and the language support plugin. I have defined some common settings those can be used more easily. Thanks for your bug report.