Difference between revisions of "IDE directives"

From Free Pascal wiki
Jump to navigationJump to search
m (Fixed syntax highlighting; deleted category included in page template)
 
(7 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
{{IDE_directives}}
 +
 
=Overview=
 
=Overview=
  
 
IDE directives are similar to compiler directives: a special kind of comment placed in your source code. They are enclosed by curly brackets with an opening percentage sign. For example:
 
IDE directives are similar to compiler directives: a special kind of comment placed in your source code. They are enclosed by curly brackets with an opening percentage sign. For example:
  
<syntaxhighlight>
+
<syntaxhighlight lang=pascal>
 
{%H-}
 
{%H-}
 
</syntaxhighlight>
 
</syntaxhighlight>
Line 13: Line 15:
 
To hide a single hint, note or warning you use the following IDE directive:
 
To hide a single hint, note or warning you use the following IDE directive:
  
<syntaxhighlight>
+
<syntaxhighlight lang=pascal>
 
procedure DoSomething({%H-}NotUsed: char);
 
procedure DoSomething({%H-}NotUsed: char);
 
begin
 
begin
Line 32: Line 34:
 
You can specify what encoding the IDE should use for a source file by adding a BOM or an encoding directive at the very start of a source file:
 
You can specify what encoding the IDE should use for a source file by adding a BOM or an encoding directive at the very start of a source file:
  
<syntaxhighlight>
+
<syntaxhighlight lang=pascal>
 
{%encoding CP1250}
 
{%encoding CP1250}
 
</syntaxhighlight>
 
</syntaxhighlight>
Line 40: Line 42:
 
=Run/Build file=
 
=Run/Build file=
  
*{%BuildCommand ...}
+
The IDE can run and build single files instead of projects. The parameters for building/running a file are stored as IDE directives within the file itself.
*{%BuildWorkingDir ...}
+
 
*{%BuildScan ...}
+
*{%BuildCommand <command line used for building, default is $(CompPath) $(EdFile)>}
*{%RunCommand ...}
+
*{%BuildWorkingDir <working directory, default is the file path>}
*{%RunWorkingDir ...}
+
*{%BuildScan <parsers>} List of parsers used for build output
*{%RunFlags ...}
+
*{%RunCommand <command line used to run, default is $NameOnly($(EdFile))>}
 +
*{%RunWorkingDir <working directory, default is the file path>}
 +
*{%RunFlags <flags, default Build+>}  where flags is a space separated list of options. E.g. {%RunFlags Messages+ Build+}
 +
** Build+  build before run, default: on
 +
** Messages+  show run output in the Messages window, default: off
  
 
See [[IDE_Window:_Configure_Build_file|Configure Build File]].
 
See [[IDE_Window:_Configure_Build_file|Configure Build File]].
Line 51: Line 57:
 
=Other IDE Directives=
 
=Other IDE Directives=
  
*{%Region} Allows to define your own [[IDE_Window:_Editor_Options_Code_Folding|Code Folding]] blocks, by putting this special comment into the code. ends with {%Endregion}
+
*{%Region} Allows you to define your own [[IDE_Window:_Editor_Options_Code_Folding|Code Folding]] blocks, by putting this special comment into the code. You have to specify the end of the folded region with {%Endregion}
 +
*{%MainUnit path/to/unit.pas} Used as first line in an include file to give codetools a hint where the unit file is. Any '''/''' and '''\''' are converted to the current path delimiter.
  
 
=Reading / finding IDE directives =
 
=Reading / finding IDE directives =
Line 59: Line 66:
 
*FindNextIDEDirective
 
*FindNextIDEDirective
 
*CodeToolBoss.GetIDEDirectives
 
*CodeToolBoss.GetIDEDirectives
 
[[Category:IDE]]
 
[[Category:Directives]]
 

Latest revision as of 07:55, 17 February 2020

English (en) español (es) français (fr)

Overview

IDE directives are similar to compiler directives: a special kind of comment placed in your source code. They are enclosed by curly brackets with an opening percentage sign. For example:

{%H-}

The compiler sees them simply as comments which it ignores. The IDE uses these directives to store source-specific information which is independent of project and session.

Hide one hint, note or warning

To hide a single hint, note or warning you use the following IDE directive:

procedure DoSomething({%H-}NotUsed: char);
begin

end;

This will suppress the line in the Lazarus Messges window that otherwise would report

Hint: Parameter "NotUsed" not used

The compiler still issues the Hint, but the {%H-} IDE directive causes the IDE to filter the Hint out of the Messages view.

Note: You can right click on a hint in the message window and choose the context menu option "Hide message via directive" to insert the directive automatically.

This feature was introduced in Lazarus 0.9.29.

File encoding

You can specify what encoding the IDE should use for a source file by adding a BOM or an encoding directive at the very start of a source file:

{%encoding CP1250}

See the unit lcl/lconvencoding.pas for all possible values.

Run/Build file

The IDE can run and build single files instead of projects. The parameters for building/running a file are stored as IDE directives within the file itself.

  • {%BuildCommand <command line used for building, default is $(CompPath) $(EdFile)>}
  • {%BuildWorkingDir <working directory, default is the file path>}
  • {%BuildScan <parsers>} List of parsers used for build output
  • {%RunCommand <command line used to run, default is $NameOnly($(EdFile))>}
  • {%RunWorkingDir <working directory, default is the file path>}
  • {%RunFlags <flags, default Build+>} where flags is a space separated list of options. E.g. {%RunFlags Messages+ Build+}
    • Build+ build before run, default: on
    • Messages+ show run output in the Messages window, default: off

See Configure Build File.

Other IDE Directives

  • {%Region} Allows you to define your own Code Folding blocks, by putting this special comment into the code. You have to specify the end of the folded region with {%Endregion}
  • {%MainUnit path/to/unit.pas} Used as first line in an include file to give codetools a hint where the unit file is. Any / and \ are converted to the current path delimiter.

Reading / finding IDE directives

The codetools unit basiccodetools contains several functions for reading IDE directives:

  • FindNextIDEDirective
  • CodeToolBoss.GetIDEDirectives