Author Topic: Per-project indentation styles?  (Read 4433 times)

timur

  • Senior Community Member
  • Posts: 205
  • Hero Points: 3
Per-project indentation styles?
« on: March 01, 2013, 04:57:29 PM »
I know this must be a FAQ, but I can't find the answer anywhere, so I'm forced to ask it again.

I work on several different projects, all written in C (not C++).  Each project has different indentation styles -- some use hard tabs at 8, some use no tabs at 4, etc.

I need to have per-project indentation support, but I can't figure out how to enable that.  I'm using SlickEdit v16.  Is this supported, and if so, where?

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: Per-project indentation styles?
« Reply #1 on: March 01, 2013, 05:58:41 PM »
It's not supported.  It seems a lot of us want this feature, so hopefully it's working its way up in the priority queue.

The Adaptive Formatting feature can help somewhat.  It can usually figure out hard/soft tabs, indent width, brace style, and a few other things based on context in a file.  It doesn't help when creating new files, though.

Also it's possible to make a macro that runs whenever a project is opened, and such a macro could conceivably modify all the various formatting settings.  That seems messy and expensive, prone to side effects, and requires every project to have such a macro to prevent bleed-through between projects.

timur

  • Senior Community Member
  • Posts: 205
  • Hero Points: 3
Re: Per-project indentation styles?
« Reply #2 on: March 01, 2013, 07:51:56 PM »
What are the macro commands for setting the indentation?

timur

  • Senior Community Member
  • Posts: 205
  • Hero Points: 3
Re: Per-project indentation styles?
« Reply #3 on: March 01, 2013, 08:23:09 PM »
Never mind, I figured it out.

_command void tabs_to_4() name_info(',')
{
   p_indent_with_tabs = false;
   p_SyntaxIndent = 4;
}

_command void tabs_to_8() name_info(',')
{
   p_indent_with_tabs = true;
   p_SyntaxIndent = 8;
}

RaffoPazzo

  • Community Member
  • Posts: 77
  • Hero Points: 2
Re: Per-project indentation styles?
« Reply #4 on: March 05, 2013, 09:31:28 AM »
I'm using v17 and, if I've not understood wrongly, this is fully supported! So you would like to give it a shot.

I also think that in v16 you could get the job done by creating your "PROJ-A-TYPE C" language, let it inherit the usual "C/C++" or "ANSI-C" (or the on you use now) so it behave like its "parent" and override coding styles.

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: Per-project indentation styles?
« Reply #5 on: March 05, 2013, 05:19:11 PM »
@RaffoPazzo, if it's fully supported in v17, can you point out how to do it?


Re: v16, creating custom new languages named "Project-One-C" may be a partial workaround, but it doesn't scale when working in many projects each of which uses multiple languages.


I think the attached macro is a much better solution, if the needs are simple (i.e. only affect soft/hard tabs, tab width, syntax indent width, brace style, space padding style, and pointer style).

Caveats:
1.  The macro has no UI; to change its logic requires editing the macro and recompiling it.  It's been working great for me for many years, but I haven't shared it before because it requires Slick-C knowledge to "train" it what the styles are and when to apply specific styles.
2.  The macro doesn't try to figure out which SE project a file is in.  Instead it just does some simple path prefix/substring tests to deduce which style to use.  There's probably a way to look up the specific SE project from a file, but I don't know how offhand, and this approach has always been good enough for my needs.
« Last Edit: March 05, 2013, 05:20:59 PM by chrisant »

RaffoPazzo

  • Community Member
  • Posts: 77
  • Hero Points: 2
Re: Per-project indentation styles?
« Reply #6 on: March 05, 2013, 06:07:05 PM »
Tools -> Options -> Languages -> Application Languages -> C/C++ -> Formatting

There you should have a Profile list box with all the defaults profiles and you can add yours.

Each project should remember this setting. Eventually, if not, is just a matter of selecting an item from a list box, pretty quick.

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: Per-project indentation styles?
« Reply #7 on: March 06, 2013, 02:47:45 AM »
Unfortunately, no.  That dropdown definitely is global, not per-project (I just tried it with a few projects and confirmed -- it's global).

I think our usage scenario is different from yours, RaffoPazzo.

I think if one rarely changes projects, then selecting an item from that list box is reasonable.

But consider someone who works in many different workspaces (corresponding to different software products), and each workspace has multiple projects, each of which has different rules for multiple different languages.  I'd have to select different items from that listbox for multiple languages many times per day.  That's unreasonable, especially to a programmer who knows a machine could do it automatically.  :-)

By the way, I don't want that dropdown to be tied to a project.  That would be cumbersome, and besides those profiles don't cover everything.  I don't have a clear sense of how I want per-project configuration to be presented in the UI (or what the underlying schema should be), but I'm aware that's the kind of information that would most help the SE team design such a feature.

JakeMontgomery

  • Community Member
  • Posts: 79
  • Hero Points: 8
Re: Per-project indentation styles?
« Reply #8 on: March 07, 2013, 12:54:38 PM »
I would also like a way to switch more easily between formatting styles. Like some of the others, I work on multiple code bases, each with a different coding style. While the whole "adaptive" system is nice for some, I need to be absolutely sure that I am getting the style appropriate for the given project.

One suggestion, which might be more readily achievable, would be a toolbar droplist that showed the "Formatting" profile for the document type of the current buffer. This way, it would be much easier to switch profiles when switching projects.

For now, the approach I have taken is to add a _prjopen_ hook that sets the "c" Formatting profile based on the project, when it is loaded. Unfortunately, there is no API for setting the Formatting profile for a language, and applying it to all open buffers, like the Tools>Options>Languages>Application Languages>C/C++>Formatting>Profile droplist does. So my method is a bit kludgy, as it involves copied code to (more or less) simulate beautifier.e:_new_beautifier_config_apply().

I agree that, for most people, having the Formatting be per-project would be confusing. If there was a "set_language_formatting_profile(lagId, profile_name)" routine, that took care of the current buffers, as well as setting the profile, then those power users who wanted to customize the experience, would have a much easier time doing so.