Author Topic: Beautify setting for blank line above\below block (statement)? v22.0.2.1  (Read 3325 times)

JimmieC

  • Senior Community Member
  • Posts: 490
  • Hero Points: 17
Attached are two .c files. The SE beautifier was applied on one of the files. While it fixed the file up better than it was, I did not get all the formatting I was looking for. I tried some various settings such as

Statements->if->Opening brace = Space Before
Statements->if->After closing parenthesis = ON

These do not provide a blank line before and after a logical (statement) block.

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
Yes, those rules you listed are just for spaces around tokens.  The rules that add/remove blank lines are under Blank Lines -> Statements and Blank Lines -> Global Declarations.

JimmieC

  • Senior Community Member
  • Posts: 490
  • Hero Points: 17
Here I enabled:
   Blank Lines->Global Declarations:
      Between classes
      Between functions/methods
      Between uncommented variables
      Before class access keyword

   Blank Lines->Statements:
     After block

The beautifier still did not put spaces around if, while, for blocks.

See attached file...

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
I get blank lines after the if blocks if I enable them and set them to 1.

Code: [Select]
   Data = (AS1_TComData)getReg(SCI0_SCIDR); /* Read data from the receiver */
   if (StatReg & (SCI0_SCISR_OR_MASK)) { /* Is HW overrun error detected? */
      setReg(SCI0_SCISR, 0);             /* Reset error request flags */
      SerFlag |= OVERRUN_ERR;            /* Set flag OVERRUN_ERR */
      OnFlags |= ON_ERROR;               /* Set flag "OnError" */
   }

   if (!(SerFlag & CHAR_IN_RX)) {       /* Is SW overrun detected? */
      BufferRead = Data;
      OnFlags |= ON_RX_CHAR;             /* Set flag "OnRxChar" */
   } else {
      SerFlag |= OVERRUN_ERR;            /* Set flag OVERRUN_ERR */
      OnFlags |= ON_ERROR;               /* Set flag "OnError" */
   }

   SerFlag |= CHAR_IN_RX;               /* Set flag "char in RX buffer" */
   if (OnFlags & ON_ERROR) {            /* Was error flag detect? */
      AS1_OnError();                     /* If yes then invoke user event */
   }

   if (OnFlags & ON_RX_CHAR) {          /* Is OnRxChar flag set? */
      AS1_OnRxChar();                    /* If yes then invoke user event */
   }

Just to double check, are the rules enabled in addition to being set to 1? (checkbox on left checked).  If that's not it, post your user.cfg.xml from your config directory.  Perhaps there's something in the combination of settings that triggers it.

JimmieC

  • Senior Community Member
  • Posts: 490
  • Hero Points: 17
Hi Patrick,
Thanks for looking at this. I am not getting those results. I think that it may be that something else in the file is confusing the beautifier. I am sending the whole file this time rather than an excerpt of the result.

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
That's working for me with my configuration.  I turned on debug, and there weren't any parse errors detected.

A couple of possiblities.
  • You've got some addition preprocessing defines in either the global C++/C settings, or you've got some in the per-workspace defines that are making the parse fail.  For the global defines, they would be in your config directory named unxcpp.h/wincpp.h.   For workspace specific defines, that would be a .h file in your workspace root directory named WORKSPACENAME_cpp.h.  If those exist, you could post those, and I can see if I can reproduce and troubleshoot using those.
  • It may be a combination of settings in your beautifier config.  I'm not sure what could interfere with the blank line rules in that way. If this is the case, I'll be able to reproduce it just using your user.cfg.xml file and debug it from there.

JimmieC

  • Senior Community Member
  • Posts: 490
  • Hero Points: 17
File attached...
user.cfg.xml

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
None of the blank line settings are set in that config.  It may just be because you're still running the session that you made the changes in, and they haven't been saved to disk.  Running save-config should flush the changes to disk.

Using the My Default profile, if I turn on blank lines after if and set it to 1 blank line, it works for the AS1.c file.

JimmieC

  • Senior Community Member
  • Posts: 490
  • Hero Points: 17
Patrick,
I shutdown my PC last night and thus restarted SE. Now I am getting the beautifier formatting that you do.

However, I am still not able to get a space before the logical statement block (if, while, for, do). Looking at the snippet that you pasted into your earlier reply, I see that you are not getting that either. Below is a snippet from the file after running the beautifier this morning.


#define ON_FREE_TX  1
#define ON_TX_CHAR  2
#pragma interrupt saveall

void AS1_InterruptTx(void)
{

    register word OnFlags = 0;           /* Temporary variable for flags */

    if(SerFlag & FULL_TX)             /* Is any char already present in the transmit buffer? */
    {
        OnFlags |= ON_TX_CHAR;             /* Set flag "OnTxChar" */
    }

    SerFlag &= ~FULL_TX;                 /* Reset flag "full TX buffer" */
    clrRegBit(SCI0_SCICR, TEIE);         /* Disable transmit interrupt */
    if(OnFlags & ON_TX_CHAR)          /* Is flag "OnTxChar" set? */
    {
        AS1_OnTxChar();                    /* If yes then invoke user event */
    }
}


------------------------------------------------------
I want to have space between:
#define ON_TX_CHAR  2
#pragma interrupt saveall

------------------------------------------------------
Also want a space between:
    clrRegBit(SCI0_SCICR, TEIE);         /* Disable transmit interrupt */
    if(OnFlags & ON_TX_CHAR)          /* Is flag "OnTxChar" set? */

------------------------------------------------------
I do not want a space between:
#pragma interrupt saveall

void AS1_InterruptTx(void)


I may have to handle the space between the #pragma and start of function as an exception because very few functions have the #pragma. I don't think the beautifier supports "space before a function unless preceded by a #pragma".


patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
There isn't a blank-line-before rule for the statements.  Left out more for parsimony than strong feelings - I'd hoped to avoid resolving conflicts between differing before and after rules of adjacent statements.  I'll look into it.  If not for v23, the point release for v23 later this year.

There is no rule for pragmas' adjacent to functions being kept with the function.  Technically, we do something similar with the comments associated with the functions, so it could probably be conditionally extended to pragmas adjacent to function.  Another thing to look at for 23 or 23.0.1.