Menu

Adding spaces like ( this )

mould
2007-08-07
2013-05-23
  • mould

    mould - 2007-08-07

    Hello!

    Just tried out JCF and it's very good! But there's one option missing to satisfy my weird needs: I'm always adding spaces after opening and before closing brackets:

    FreeMem(Block); // oh no
    FreeMem( Block ); // that's it!

    or

    d := (x + y) / z;
    d := ( x + y ) / z;

    or

    if ((A and not B) = $1) then
    if ( ( A and not B ) = $1 ) then

    Since there doesn't seem to be an option for this (although there's one to add a space before the opening bracket in calls, like FreeMem (Block), which *I* find very strange ;-) ), I added a quick fix:

    SingleSpaceBefore.pas:

    function NeedsSpaceBefore(const pt: TSourceToken): boolean;
    begin
      [...original code here...]
      if pt.TokenType = ttCloseBracket then
        Result := true;
    end;

    and SingleSpaceAfter.pas:

    function NeedsSingleSpace(const pt, ptNext: TSourceToken): boolean;
    begin
      [...original code here...]
      if pt.TokenType = ttOpenBracket then
        Result := true;
    end;

    This seems to work! Unfortunately, I can only build the cmdline version (using free delphi explorer that claims about corrupt resources, when I try to open the GUI projects), so I'm not in the position to add this as new option. :-(

    Hmm. Obviously, this turns out to be a feature request. :-) I'd really appreciate it, if somebody here could add this as a new option!

    Thanks!

     
    • Anthony Steele

      Anthony Steele - 2007-08-08

      Hi

      I'm away this weekend, but will look at folding this in after that - as an option.
      We've been having problems with the resource files lately, probably due to me using Delphi 2006, and Jean-Fabien Connault using Delphi 2007. Which are you using?

       
      • mould

        mould - 2007-08-08

        Hello Anthony

        thanks for your response! I'll be away this weekend too and there's absolutely no need to hurry! At the moment I'm using the fixed cmdline version (as described in the previous post) to format my whole source folder and it works great for me!

        Currently I'm using the Turbo-Delphi version, that can be download at http://www.turbo-delphi.com freely. (I also own a full BDS2005 but don't use it at the moment - and btw I'm not willing to upgrade, until CodeGear *finally* manages to add generics to Delphi...)

        I'm quiet shure, that the compiling problems are caused by the limitations of this Turbo Delphi, so don't bother about it!

        Btw: I like the design of your code. It merely took me 15 minutes to figure out how to add the spaces and that was simply because the code is well structured and almost self explaining. Cool! I wished I could say this from my code too... :-)

         
        • Anthony Steele

          Anthony Steele - 2007-08-09

          Thanks for the comments on the code. Quality is easier when there are no deadlines. If you don't feel that a change is just right, you can go away and think about it. If you feel that you need to refactor, you can do it. It's a welcome change from work :)

          PS: I'm checking some code into SVN.

           
    • Anthony Steele

      Anthony Steele - 2007-08-08

      Does this apply to all pairs of brackets, or just those inside procedure bodies?

       
      • mould

        mould - 2007-08-08

        Everywhere! ;-)

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.