Author Topic: Different Tab size for different projects  (Read 4011 times)

stumo

  • Community Member
  • Posts: 5
  • Hero Points: 0
Different Tab size for different projects
« on: December 10, 2007, 12:03:36 pm »
Hi, I'm using V11.0.2

To avoid confusion, I'm talking about the number of spaces that make up a 'Tab' keypress here in a source file.

I want to have different tab sizes for the different projects I work on.  They are all C source code, and I want to avoid having to go the file extension setup form, every time I change to a different project. 

Some projects use 2 spaces, others 3, and others 4.  When working on these big projects, it is a company requirement to keep the tab sizes the same as existing code.  I can be working on 3 different projects at any one time, so it is becoming a real pain having to use extension setup each time.

<edit> by "project", I actually mean "workspace"

Cheers
Stu.
« Last Edit: December 10, 2007, 12:07:21 pm by stumo »

hs2

  • Senior Community Member
  • Posts: 2735
  • Hero Points: 287
Re: Different Tab size for different projects
« Reply #1 on: December 10, 2007, 12:47:08 pm »
You could use this macro command e.g. as 'Project Open' command (e.g. 'hs2-indent c 3') to do that:
Code: [Select]
// options: 'ext Indent IndentWithTabs'
_command int hs2_indent (_str options = 'fundamental 3 0')
{
   _str ext ='';
   typeless Indent, IndentWithTabs;

   parse options with ext Indent IndentWithTabs;
   if ( ext == '' )              ext            = 'fundamental';
   if ( Indent == '' )           Indent         = 3;
   if ( IndentWithTabs == '' )   IndentWithTabs = 0;

   index = find_index ('def-options-'ext, MISC_TYPE);
   if ( !index )
   {
      return(-1);
   }
   parse name_info (index) with syntax_indent expansion min_kw g3 be_style indent_first_level main_style indent_case UseContOnParameters .;
   info = Indent' 'expansion' 'min_kw' 'g3' 'be_style' 'indent_first_level' 'main_style' 'indent_case' 'UseContOnParameters;
   _setext (ext, 'options', info);
   _setext (ext, 'p_tabs', '+'Indent);
   _setext (ext, 'IWT', IndentWithTabs);
   _update_buffers (ext);
   _mdi.p_child.p_SyntaxIndent = Indent;

   return(0);
}

Note that it affects the global setup, but you can quickly invoke it on cmdline to switch back to your defaults or just an add wrapper command.

Hope it helps,
HS2
« Last Edit: February 04, 2008, 06:18:21 pm by hs2 »

stumo

  • Community Member
  • Posts: 5
  • Hero Points: 0
Re: Different Tab size for different projects
« Reply #2 on: December 10, 2007, 01:13:03 pm »
Thanks HS2, you are a legend, as ever.

MartyL

  • Senior Community Member
  • Posts: 161
  • Hero Points: 26
  • Synergex Software Engineer
Re: Different Tab size for different projects
« Reply #3 on: December 10, 2007, 05:11:06 pm »
That is an extremely useful macro.

Thanks!

thefrogger

  • Community Member
  • Posts: 38
  • Hero Points: 2
Re: Different Tab size for different projects
« Reply #4 on: January 02, 2008, 07:43:33 pm »
This will solve one of my problems as well, where some projects need to convert tabs to spaces while others can keep them as tabs. Thanks hs2! I did run into a couple of issues getting the hs2_indent macro to work though.

This may be obvious to long-time SE users and/or users that clip out the macro text and add it to an existing user macro file, but I first tried saving the text into "hs2_intent.e" and using 'Macro -> Load Module' to load it. It complains of an undefined MISC_TYPE unless I add to the top of the file:
#include "slick.sh"
Again, probably obvious to most, but mentioned here for other new users that might be looking for the same solution.

With the macro loaded and working correctly, I tried adding "hs2_indent c 3 1" to the Project Properties Open tab, but when I click OK I end up with an error box containing:

-----
This property or method is not allowed on this object
hs2_indent.ex 272 hs2_indent(c 3 1)   p_window_id: 447   p_object: OI_COMMAND_BUTTON   p_name: _ok
project.ex 600 static(D:\Amiga\AA2\projects\shufflepix\shufflepix.vpj)
   p_window_id: 447
   p_object: OI_COMMAND_BUTTON
   p_name: _ok
project.ex 34236 static()   p_window_id: 447   p_object: OI_COMMAND_BUTTON   p_name: _ok
project.ex 33752 _project_form._ok.\x{159a}()   p_window_id: 328   p_object: OI_EDITOR   p_name: list1
dlgeditv.ex 7360 show(-mdi -modal -xy _project_form,D:\Amiga\AA2\projects\shufflepix\shufflepix.vpj,
   3:   3
   4:   
   p_window_id: 24
   p_object: OI_TREE_VIEW
   p_name: _proj_tooltab_tree
project.ex 379 static(,D:\Amiga\AA2\projects\shufflepix\shufflepix.vpj)
   p_window_id: 24
   p_object: OI_TREE_VIEW
   p_name: _proj_tooltab_tree
project.ex 493 project_edit()   p_window_id: 24   p_object: OI_TREE_VIEW   p_name: _proj_tooltab_tree
-----

The functionality ultimately worked correctly when switching projects, but maybe someone can diagnose the above error and determine whether I did something wrong, or ???

BTW, if I close this error box, SlickEdit is completely locked up with no way to recover other than to kill the task. If I click on the '?' icon first, even if I don't submit a report, then I can close the error box and SE continues normally.

--
John

hs2

  • Senior Community Member
  • Posts: 2735
  • Hero Points: 287
Re: Different Tab size for different projects
« Reply #5 on: January 02, 2008, 08:10:58 pm »
Due to some reason SE executes the macro also when clicking Ok which leads to the problem you've encountered.
Please change the line
Quote
p_SyntaxIndent = Indent;
to
Quote
_mdi.p_child.p_SyntaxIndent = Indent;
That should avoid the stack-dump.
BTW: I pressed ESCape a couple of times (which closed the crashed dialog box) until I got back to the edit window.

HS2

thefrogger

  • Community Member
  • Posts: 38
  • Hero Points: 2
Re: Different Tab size for different projects
« Reply #6 on: January 02, 2008, 08:42:16 pm »
Verified that this change avoids the stack-dump, and still works correctly when project-switching. Thanks for the quick fix.

However, pressing Esc a couple of times does leave the Project Properties dialog open here with SE locked up. (Re-tested before making the above change that avoids the error). It actually task-switches away from SE after the second Esc. Upon return to SE, both the Properties window and the edit window are visually inactive -- there is no active window, so nothing to accept input and resolve the stuck condition.

Not sure why that's different for me, nor why opening the '?' window before dismissing the error seems to resolve the matter. This behavior too was verified multiple times, and consistent.

--
John

hs2

  • Senior Community Member
  • Posts: 2735
  • Hero Points: 287
Re: Different Tab size for different projects
« Reply #7 on: January 02, 2008, 08:47:47 pm »
I know the 'completely lost' input focus problem from my own macro experiments ;)
However, when trying the fix it could bail out somehow ... dunno.
HS2