Author Topic: Ability to change tab width and indentation outside of formatting profiles  (Read 5577 times)

rowbearto

  • Senior Community Member
  • Posts: 2335
  • Hero Points: 132
I work in a very large project with many many developers. There are many source files with both tabs and spaces in them. I can easily figure out what the original developer has his tab spacing set to so that I can configure SE to show the file in a "neat" way, the way the original developer saw it.

But this requires me to setup 6 different Formatting Profiles. 3 profiles for 2, 4 and 8 times 2 for tab and space. If I edit one of these files, I want to be consistent with what that developer did. The majority of indents may be with tabs or may be with spaces. And there are usually 3 different settings: 2, 4 and 8.

Having 6 different formatting profiles is hard to maintain. Lets say I want to change something other than the tab/space indent width? Then I need to make that update in 6 different profiles.

Also, the only difference in these profiles is: "indent with tabs", "Syntax Indent", "tab size", and "original tab size". I usually set the latter 3 ("syntax indent", "tab size" and "original tab size") to the same value, otherwise I get issues when I beautify or write code.

Ideally if I could have 2 pulldowns on my toolbar, where 1 pulldown allows me to select "tab or space indent", and another pulldown that allows me to set the spacing (2,4,8) it would be really nice, and then these settings could be used for the beautifier as well, as I use different beautifiers depending on the different style of that source file.
« Last Edit: September 07, 2017, 06:42:21 PM by rowbearto »

rowbearto

  • Senior Community Member
  • Posts: 2335
  • Hero Points: 132
Re: Ability to change tab width and indentation outside of formatting profiles
« Reply #1 on: September 08, 2017, 02:18:18 PM »
Now I see that there is a command "gui-tabs" (or Document->Tabs) that can change the tab stop setting, so that fulfills part of my need.

I'd also like some other "gui" like commands to change for the current file:

1) Turn on/off "indent with tabs" for this particular file, such as "gui-indent-with-tabs [on/off]"
2) When set to indenting with spaces, a "gui-space-indent-size <number>" so that for a particular file I can change how many spaces are inserted when I indent with spaces.

If these settings could also be used when I attempt to beautify selections in this file it would also be helpful.

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6826
  • Hero Points: 526
Re: Ability to change tab width and indentation outside of formatting profiles
« Reply #2 on: September 12, 2017, 03:23:53 PM »
v22 supports formatting profile overrides (Tools>Beautify>Beautifier Profile Overrides). With the GUI, you can specify a tree a files with a specify language type to use a specific beautifier profile. If you manual edit a .seeditorconfig.xml file, you can specify one specific file that you want to use a specific beautifier profile (I've commented out the patterns element but it would be what you would want to use). Note that the .seeditorconfig.xml file IS NOT stored in the config directory and it's location is very important since it only effects files at or beneath it. Also, make sure you enable .seeditorconfig.xml support (Tools>Options>Editing>General>Apply .editorconfig, .seeditorconfig.xml settings).

Code: [Select]
<!-- configs property attribute not yet supported in this XML file
    which looks like a .cfg.xml file. -->
<options root="1">
<language n="language.c" version="1">
<beautifier_default_profile v="Allman"/>
</language>
<language n="language.js" version="1">
<beautifier_default_profile v="Test"/>
</language>
<!--patterns>
<p n='**/*.cpp'>
<beautifier_default_profile v="special"/>
</p>
<p n='junk.cpp' recurse="0">
<beautifier_default_profile v="junk.cpp special"/>
</p>
</patterns-->
</options>

rowbearto

  • Senior Community Member
  • Posts: 2335
  • Hero Points: 132
Re: Ability to change tab width and indentation outside of formatting profiles
« Reply #3 on: September 12, 2017, 03:51:57 PM »
Clark: This is an interesting feature but then it has a drawback.

It would require me to maintain at least 6 different beautifier profiles - 3 indenting settings - 2,4,8, and then times 2 for indent with tabs/spaces.

So when I want to change something in the profile that is unrelated to indent/tab size and indent tab or spaces, I would need to update it in 6 different profiles - so it isn't desirable.

If the xml would allow me to specify a beautifier profile along with parameters, arg1=(syntax indent+tab size), arg2=indent tabs on/off, then I would only need to maintain 1 profile.

With existing feature set, I'm looking for a way to do it outside of the formatting profile so that I can maintain 1 profile. When I have time, I will write a macro that will allow me to change spacing/indent tabs for the current profile (for the language). It has the drawback that I will need to change it each time I switch to a new type of file, but I could bind the macros to a key and quickly change it. Not as ideal as specifying the size/indent with tabs in the XML, but I think it would be the way for me to go. I think the way to do it is:

From: macros/se/lang/api/LanguageSettings.e

// syntax indent, call:
LanguageSettings.setSyntaxIndent(_str langID, int value)

// tab size, call:
LanguageSettings.setTabs(_str langID, _str value)

// indent with tabs/spaces, call:
LanguageSettings.setIndentWithTabs(_str langID, bool value)

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6826
  • Hero Points: 526
Re: Ability to change tab width and indentation outside of formatting profiles
« Reply #4 on: September 12, 2017, 05:10:05 PM »
Your plan looks simple if will work for you.

rowbearto

  • Senior Community Member
  • Posts: 2335
  • Hero Points: 132
Re: Ability to change tab width and indentation outside of formatting profiles
« Reply #5 on: September 12, 2017, 05:19:25 PM »
Yes, but more ideally (may be hard for you to develop), I'd like either or both of:

Quote
If the xml would allow me to specify a beautifier profile along with parameters, arg1=(syntax indent+tab size), arg2=indent tabs on/off, then I would only need to maintain 1 profile.

Quote
Now I see that there is a command "gui-tabs" (or Document->Tabs) that can change the tab stop setting, so that fulfills part of my need.

I'd also like some other "gui" like commands to change for the current file:

1) Turn on/off "indent with tabs" for this particular file, such as "gui-indent-with-tabs [on/off]"
2) When set to indenting with spaces, a "gui-space-indent-size <number>" so that for a particular file I can change how many spaces are inserted when I indent with spaces.

If these settings could also be used when I attempt to beautify selections or type in this file it would also be helpful.

rowbearto

  • Senior Community Member
  • Posts: 2335
  • Hero Points: 132
Re: Ability to change tab width and indentation outside of formatting profiles
« Reply #6 on: September 12, 2017, 05:35:50 PM »
and this would also be nice:

Quote
Ideally if I could have 2 pulldowns on my toolbar, where 1 pulldown allows me to select "tab or space indent", and another pulldown that allows me to set the spacing (2,4,8) it would be really nice, and then these settings could be used for the beautifier as well, as I use different beautifiers depending on the different style of that source file.

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6826
  • Hero Points: 526
Re: Ability to change tab width and indentation outside of formatting profiles
« Reply #7 on: September 12, 2017, 05:57:03 PM »
I know you might not have control over this but if your company has a standard coding style, you might want to consider beautifying those files which don't adhere to the standard. It becomes a royal pain to deal with source code with all kinds of different coding styles. At least SlickEdit source diff feature can determine actually changes.

Of course, this maybe be very unrealistic. Not all developers care about standards. We're a small company and have had some dev guys just do there own thing (very annoying).

rowbearto

  • Senior Community Member
  • Posts: 2335
  • Hero Points: 132
Re: Ability to change tab width and indentation outside of formatting profiles
« Reply #8 on: September 17, 2017, 05:08:51 PM »
I think I found an ideal solution for me in some custom macros I just wrote, so no change to SE needed. Looks like the ability to change syntax indent and indent with spaces/tabs for the current buffer only without updating the beautifier profile already exists. I created new commands that I have bound to keys to allow me to do whatever I like.

I was able to create the following key bindings to serve all my purposes:

Code: [Select]
Ctrl+Alt+2       setTabAndIndent2                               Set indent and tab size to 2 in current buffer and in language settings/beautifier profile
Shift+Alt+2      setTabAndIndent2Buf                            Set indent and tab size to 2 in current buffer only
Ctrl+Alt+4       setTabAndIndent4                               Set indent and tab size to 4 in current buffer and in language settings/beautifier profile
Shift+Alt+4      setTabAndIndent4Buf                            Set indent and tab size to 4 in current buffer only
Ctrl+Alt+8       setTabAndIndent8                               Set indent and tab size to 8 in current buffer and in language settings/beautifier profile
Shift+Alt+8      setTabAndIndent8Buf                            Set indent and tab size to 8 in current buffer only
Ctrl+Alt+S       setIndentWithSpaces                            Change to indent with spaces in current buffer and in language settings/beautifier profile
Shift+Alt+S      setIndentWithSpacesBuf                         Change to indent with spaces in current buffer only
Ctrl+Alt+T       setIndentWithTabs                              Change to indent with tabs in current buffer and in language settings/beautifier profile
Shift+Alt+T      setIndentWithTabsBuf                           Change to indent with tabs in current buffer only
Ctrl+Alt+U       updateAllTabsWithLanguageSettings              Update all buffers that are the same lang as current buffer with language settings/beautifier profile for indent/tab size/indent with tabs/spaces

Below is the macro code:

Code: [Select]
/**
 * Sets the tab and indent spacing both current buffer and
 * language settings/beautifier profile.
 *
 * @param indentSize
 */
_command void setTabAndIndent(int indentSize=2) name_info(','VSARG2_READ_ONLY|VSARG2_REQUIRES_MDI_EDITORCTL|VSARG2_MARK)
{
   setTabAndIndentLang(indentSize);
   setTabAndIndentBuf(indentSize);
}

/**
 * Sets the tab and indent spacing in the language settings/beautifier profile, but
 * does not update the current buffer.
 *
 * @param indentSize
 */
_command void setTabAndIndentLang(int indentSize=2) name_info(','VSARG2_READ_ONLY|VSARG2_REQUIRES_MDI_EDITORCTL|VSARG2_MARK)
{
   // Below 2 lines taken from revertCurrentBuffer() in macros/adaptiveformatting.e
   bufId := _mdi.p_child;
   _str langId=bufId.p_LangId;

   LanguageSettings.setSyntaxIndent(langId, indentSize);
   _str tabSizeStr = '+'indentSize;
   // _message_box('tabSizeStr = 'tabSizeStr);
   LanguageSettings.setTabs(langId, tabSizeStr);
}

/**
 * Sets the tab and indent spacing in the current buffer, but
 * not in the language settings/beautifier profile.
 *
 * @param indentSize
 */
_command void setTabAndIndentBuf(int indentSize=2) name_info(','VSARG2_READ_ONLY|VSARG2_REQUIRES_MDI_EDITORCTL|VSARG2_MARK)
{
   // _str langId = _Filename2LangId(p_buf_name);

   // Below 2 lines taken from revertCurrentBuffer() in macros/adaptiveformatting.e
   bufId := _mdi.p_child;
   _str langId=bufId.p_LangId;

   bufId.p_SyntaxIndent = indentSize;

   _str tabSizeStr = '+'indentSize;
   // _message_box('tabSizeStr = 'tabSizeStr);
   bufId.p_tabs = tabSizeStr;
}

/**
 * Sets the tab and indent spacing to 2 in both current buffer
 * and language settings/beautifier profile.
 *
 */
_command void setTabAndIndent2(int indentSize=2) name_info(','VSARG2_READ_ONLY|VSARG2_REQUIRES_MDI_EDITORCTL|VSARG2_MARK)
{
   setTabAndIndent(2);
}

/**
 * Sets the tab and indent spacing to 2 in current buffer, but
 * not in the language settings/beautifier profile. Useful for binding to a key.
 *
 */
_command void setTabAndIndent2Buf(int indentSize=2) name_info(','VSARG2_READ_ONLY|VSARG2_REQUIRES_MDI_EDITORCTL|VSARG2_MARK)
{
   setTabAndIndentBuf(2);
}

/**
 * Sets the tab and indent spacing to 4 in both current buffer
 * and language settings/beautifier profile.
 *
 */
_command void setTabAndIndent4(int indentSize=2) name_info(','VSARG2_READ_ONLY|VSARG2_REQUIRES_MDI_EDITORCTL|VSARG2_MARK)
{
   setTabAndIndent(4);
}

/**
 * Sets the tab and indent spacing to 4 in current buffer, but
 * not in the language settings/beautifier profile. Useful for binding to a key.
 *
 */
_command void setTabAndIndent4Buf(int indentSize=2) name_info(','VSARG2_READ_ONLY|VSARG2_REQUIRES_MDI_EDITORCTL|VSARG2_MARK)
{
   setTabAndIndentBuf(4);
}

/**
 * Sets the tab and indent spacing to 8 in both current buffer
 * and language settings/beautifier profile.
 *
 */
_command void setTabAndIndent8(int indentSize=2) name_info(','VSARG2_READ_ONLY|VSARG2_REQUIRES_MDI_EDITORCTL|VSARG2_MARK)
{
   setTabAndIndent(8);
}

/**
 * Sets the tab and indent spacing to 8 in current buffer, but
 * not in the language settings/beautifier profile. Useful for binding to a key.
 *
 */
_command void setTabAndIndent8Buf(int indentSize=2) name_info(','VSARG2_READ_ONLY|VSARG2_REQUIRES_MDI_EDITORCTL|VSARG2_MARK)
{
   setTabAndIndentBuf(8);
}

/**
 * Sets the indent with tabs or indent with spaces in both the
 * current buffer and in the language settings/beautifier profile.
 *
 * @param tabTrueSpacesFalse  true=indent with tabs,
 *                            false=indent with spaces
 */
_command void setIndentWithTabsOrSpaces(bool tabTrueSpacesFalse=false) name_info(','VSARG2_READ_ONLY|VSARG2_REQUIRES_MDI_EDITORCTL|VSARG2_MARK)
{
   setIndentWithTabsOrSpacesLang(tabTrueSpacesFalse);
   setIndentWithTabsOrSpacesBuf(tabTrueSpacesFalse);
}

/**
 * Sets the indent with tabs or indent with spaces in the
 * language settings/beautifier profile, but not in the current
 * buffer.
 *
 * @param tabTrueSpacesFalse  true=indent with tabs,
 *                            false=indent with spaces
 */
_command void setIndentWithTabsOrSpacesLang(bool tabTrueSpacesFalse=false) name_info(','VSARG2_READ_ONLY|VSARG2_REQUIRES_MDI_EDITORCTL|VSARG2_MARK)
{
   bufId := _mdi.p_child;
   _str langId=bufId.p_LangId;
   LanguageSettings.setIndentWithTabs(langId, tabTrueSpacesFalse);
}

/**
 * Sets the indent with tabs or indent with spaces in the
 * current buffer but not in the language settings/beautifier
 * profile.
 *
 * @param tabTrueSpacesFalse  true=indent with tabs,
 *                            false=indent with spaces
 */
_command void setIndentWithTabsOrSpacesBuf(bool tabTrueSpacesFalse=false) name_info(','VSARG2_READ_ONLY|VSARG2_REQUIRES_MDI_EDITORCTL|VSARG2_MARK)
{
   bufId := _mdi.p_child;
   _str langId=bufId.p_LangId;
   bufId.p_indent_with_tabs = tabTrueSpacesFalse;
}

/**
 * Sets indent with spaces in both the current buffer and in the
 * language settings/beautifier profile.
 *
 * Useful for binding to a key.
 */
_command void setIndentWithSpaces() name_info(','VSARG2_READ_ONLY|VSARG2_REQUIRES_MDI_EDITORCTL|VSARG2_MARK)
{
   setIndentWithTabsOrSpaces(false);
}

/**
 * Sets indent with spaces in the current buffer only and NOT in
 * the language settings/beautifier profile.
 *
 * Useful for binding to a key.
 */
_command void setIndentWithSpacesBuf() name_info(','VSARG2_READ_ONLY|VSARG2_REQUIRES_MDI_EDITORCTL|VSARG2_MARK)
{
   setIndentWithTabsOrSpacesBuf(false);
}

/**
 * Sets indent with tabs in both the current buffer and in the
 * language settings/beautifier profile.
 *
 * Useful for binding to a key.
 */
_command void setIndentWithTabs() name_info(','VSARG2_READ_ONLY|VSARG2_REQUIRES_MDI_EDITORCTL|VSARG2_MARK)
{
   setIndentWithTabsOrSpaces(true);
}

/**
 * Sets indent with tabs in the current buffer only and NOT in
 * the language settings/beautifier profile.
 *
 * Useful for binding to a key.
 */
_command void setIndentWithTabsBuf() name_info(','VSARG2_READ_ONLY|VSARG2_REQUIRES_MDI_EDITORCTL|VSARG2_MARK)
{
   setIndentWithTabsOrSpacesBuf(true);
}

/**
 * This command will update all buffers that are the same
 * language as the current buffer with the languages
 * settings/beautifier profile values of:
 *
 * syntax indent
 * tab size
 * indent with spaces/tabs
 *
 */
_command void updateAllTabsWithLanguageSettings() name_info(','VSARG2_READ_ONLY|VSARG2_REQUIRES_MDI_EDITORCTL|VSARG2_MARK)
{
   bufId := _mdi.p_child;
   _str langId=bufId.p_LangId;

   typeless indent_with_tabs_save = LanguageSettings.getIndentWithTabs(langId);
   typeless indentSize = LanguageSettings.getSyntaxIndent(langId);
   typeless tabsSizeStr = LanguageSettings.getTabs(langId);

   // Copied this from:
   //  _update_buffers_for_all_languages()
   //  in: macros/alllanguages.e
   _safe_hidden_window();
   int view_id=0;
   save_view(view_id);
   int first_buf_id=p_buf_id;

   // Loop over each buffer.
   for (;;) {

      // get the language for this buffer
      currentLang := p_LangId;

      if ( currentLang == langId )
      {
         p_indent_with_tabs = indent_with_tabs_save;
         p_SyntaxIndent = indentSize;
         p_tabs = tabsSizeStr;
      }

      // Copied below from:
      //  _update_buffers_for_all_languages()
      //  in: macros/alllanguages.e
      // go to our next buffer
      _next_buffer('HN');
      if ( p_buf_id==first_buf_id ) {
         break;
      }
   }

   // Copied below from:
   //  _update_buffers_for_all_languages()
   //  in: macros/alllanguages.e
   activate_window(view_id);
}
« Last Edit: September 17, 2017, 05:11:53 PM by rowbearto »

rowbearto

  • Senior Community Member
  • Posts: 2335
  • Hero Points: 132
Re: Ability to change tab width and indentation outside of formatting profiles
« Reply #9 on: September 18, 2017, 12:47:17 PM »
Thinking more, there is 1 thing that is not ideal about my solution, each time I load a file I need to hit the right keys to set up the indent settings rather than it getting remembered.

Is there a way that I can tell SE to execute one of my custom macros whenever it opens a file? Then my macro could look through a configuration file (that it manages) to see if this file should get any special indent settings and apply those settings to this buffer only.

This is similar to the .seeditorconfig.xml file, except with .seeditorconfig.xml I need to maintain multiple beautifier profiles that only differ in indent settings.

If I could get SE to call my hook/callback macro whenever it opens a file, then I can have it apply the indent settings just to that buffer based on a config file.

So does such a hook/callback functionality exist? If not, could it be added?

Thanks,
Rob