View Issue Details

IDProjectCategoryView StatusLast Update
0038125LazarusIDEpublic2021-02-17 09:48
ReporterOkobaPatino Assigned ToJuha Manninen  
Status closedResolutionfixed 
Product Version2.1 (SVN) 
Summary0038125: JCF fails formatting using defines in uses
DescriptionThis will fail:
uses classes, {$ifdef WINDOWS} windows {$ELSE} linux {$ENDIF};
But not this one:
uses classes {$ifdef WINDOWS}, windows {$ELSE}, linux {$ENDIF};
TagsNo tags attached.
Fixed in Revision
Attached Files


related to 0019754 acknowledged Jedi Code Format (JCF) parser needs to be replaced with codetools parser 
related to 0038196 resolvedJuha Manninen JCF will move the breakpoints 


Domingo Galmés

2020-11-24 14:20

reporter   ~0127158

I have tested and fails if the option 'Enable preprocessor parsing' is disabled.
If you enable this option in the format settings, works well.

About your comment merging JCF and codetools i think i don't have the time nor the skills for do that task.

Sample code used for testing.

unit unit4;

{$mode objfpc}{$H+}


uses Classes {$ifdef WINDOWS}, windows {$ELSE}, linux {$ENDIF};


uses Classes, {$ifdef WINDOWS} windows {$ELSE} linux {$ENDIF};

  generic TFakeClass<_GT> = class
    class function gmax(a, b: _GT): _GT;


2020-11-24 14:31

reporter   ~0127159

Yes, it does not fail nor format the code; it will also insert a space every time you format! After hitting it several times, it will be like:
program Project1;

 {$ifdef WINDOWS} windows {$ELSE} linux {$ENDIF};


Did you add any custom option for preprocessing?
P.S: I understand, and thank you for keeping JCF uptodate; that makes coding more joyful.

Domingo Galmés

2020-11-24 21:53

reporter   ~0127162

I have been testing the problem a bit, and I see that with the current implementation if the use of the preprocessor is not enabled, jcf treats the directives {$ IFDEF} {$ELSE},... as comments and therefore gives the error when it does not find a comma between windows and linux in the following statement.

uses Classes, {$ ifdef WINDOWS} windows {$ ELSE} linux {$ ENDIF};
It transforms in
uses Classes, windows linux;

On the other hand, if we allow the use of the jcf preprocessor, it only formats the part that meets the {$ IF} condition

In short, I don't see an easy way to change jcf's behavior to format the two parts of {$ IF} {$ ELSE} {$ END} so I won't be able to send any patches to fix the "problem". I'm sorry.

I have not added any custom options for preprocessing.

With the following code the behavior of jcf is better seen.

unit unit4;

uses Classes {$ ifndef WINDOWS}, Windows {$ ELSE}, linux {$ ENDIF};


uses Classes, {$ ifdef WINDOWS} windows {$ ELSE} linux {$ ENDIF};

{$ ifdef WINDOWS}
generic TFakeClass <_GT> = class
class function gmax (a, b: _GT): _GT;
{$ ELSE}
generic TFakeClass <_GT> = class
class function gmax (a, b: _GT): _GT;

Juha Manninen

2020-11-25 01:46

developer   ~0127169

> About your comment merging JCF and codetools i think i don't have the time nor the skills for do that task.

I didn't see the actual comment but Codetools solves a different problem than JCF. Codetools parses also code that is broken temporarily while you edit. It parses all used units to get you available identifiers based on context of your code. In a big project like Lazarus itself it goes through huge amounts of code in the background. It is optimized for speed and data structure efficiency.
JCF does not need to care about external units or libraries. It is enough to understand Pascal syntax.
Long time ago I opened the related issue about using Codetools for a formatting tool but I am not sure any more if it was a good idea.


2020-11-25 07:02

reporter   ~0127171

Thank you Domingo.


2021-02-16 15:00

reporter   ~0128952

@JuhaManninen this is fixed in 0038196, thanks to @DomingoGP.

Juha Manninen

2021-02-16 15:38

developer   ~0128953

Ok, resolving.


2021-02-17 09:48

reporter   ~0128964


Issue History

Date Modified Username Field Change
2020-11-24 13:56 OkobaPatino New Issue
2020-11-24 14:20 Domingo Galmés Note Added: 0127158
2020-11-24 14:31 OkobaPatino Note Added: 0127159
2020-11-24 21:53 Domingo Galmés Note Added: 0127162
2020-11-25 01:28 Juha Manninen Relationship added related to 0019754
2020-11-25 01:46 Juha Manninen Note Added: 0127169
2020-11-25 07:02 OkobaPatino Note Added: 0127171
2021-02-16 15:00 OkobaPatino Note Added: 0128952
2021-02-16 15:37 Juha Manninen Relationship added related to 0038196
2021-02-16 15:38 Juha Manninen Assigned To => Juha Manninen
2021-02-16 15:38 Juha Manninen Status new => resolved
2021-02-16 15:38 Juha Manninen Resolution open => fixed
2021-02-16 15:38 Juha Manninen LazTarget => -
2021-02-16 15:38 Juha Manninen Note Added: 0128953
2021-02-17 09:48 OkobaPatino Status resolved => closed
2021-02-17 09:48 OkobaPatino Note Added: 0128964