SlickEdit Community

SlickEdit Product Discussion => SlickEdit® => Topic started by: JimmieC on August 21, 2018, 09:02:20 PM

Title: Beautify setting for blank line above\below block (statement)? v22.0.2.1
Post by: JimmieC on August 21, 2018, 09:02:20 PM
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.
Title: Re: Beautify setting for blank line above\below block (statement)? v22.0.2.1
Post by: patrick on August 21, 2018, 11:11:54 PM
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.
Title: Re: Beautify setting for blank line above\below block (statement)? v22.0.2.1
Post by: JimmieC on August 22, 2018, 01:48:28 PM
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...
Title: Re: Beautify setting for blank line above\below block (statement)? v22.0.2.1
Post by: patrick on August 22, 2018, 01:59:28 PM
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.
Title: Re: Beautify setting for blank line above\below block (statement)? v22.0.2.1
Post by: JimmieC on August 22, 2018, 02:13:46 PM
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.
Title: Re: Beautify setting for blank line above\below block (statement)? v22.0.2.1
Post by: patrick on August 22, 2018, 02:44:10 PM
That's working for me with my configuration.  I turned on debug, and there weren't any parse errors detected.

A couple of possiblities.
Title: Re: Beautify setting for blank line above\below block (statement)? v22.0.2.1
Post by: JimmieC on August 22, 2018, 05:40:50 PM
File attached...
user.cfg.xml
Title: Re: Beautify setting for blank line above\below block (statement)? v22.0.2.1
Post by: patrick on August 22, 2018, 06:15:35 PM
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.
Title: Re: Beautify setting for blank line above\below block (statement)? v22.0.2.1
Post by: JimmieC on August 23, 2018, 01:38:34 PM
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".

Title: Re: Beautify setting for blank line above\below block (statement)? v22.0.2.1
Post by: patrick on August 23, 2018, 02:17:50 PM
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.