IDE directives: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | - | ||
| 2 | - | ||
| 3 | - | ||
| 4 | - | ||
| 5 | - | ||
| 6 | - | ||
| 7 | - | ||
| 8 | - | ||
| 9 | - | ||
| 10 | 1 | # Overview | |
| 11 | 2 | ||
| 12 | - | ||
| 13 | - | ||
| 3 | + | 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: | |
| 4 | + | ||
| 5 | + | ``` pascal | |
| 14 | 6 | {%H-} | |
| 15 | 7 | ``` | |
| 16 | 8 | ||
| 17 | - | ||
| 9 | + | 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. | |
| 18 | 10 | ||
| 19 | 11 | # Hide one hint, note or warning | |
| 20 | 12 | ||
| 21 | - | ||
| 22 | - | ||
| 13 | + | To hide a single hint, note or warning you use the following IDE directive: | |
| 14 | + | ||
| 15 | + | ``` pascal | |
| 23 | 16 | procedure DoSomething({%H-}NotUsed: char); | |
| 24 | - | ||
| 25 | - | ||
| 26 | - | ||
| 27 | - | ||
| 17 | + | begin | |
| 28 | 18 | ||
| 29 | - | ||
| 30 | - | ||
| 31 | - | ||
| 19 | + | end; | |
| 32 | 20 | ``` | |
| 33 | 21 | ||
| 34 | - | ||
| 22 | + | This will suppress the line in the Lazarus Messges window that otherwise would report | |
| 35 | 23 | ||
| 36 | - | ||
| 24 | + | `Hint: Parameter "NotUsed" not used` | |
| 37 | 25 | ||
| 38 | - | ||
| 26 | + | The compiler still issues the Hint, but the {%H-} IDE directive causes the IDE to filter the Hint out of the Messages view. | |
| 39 | 27 | ||
| 28 | + | 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. | |
| 29 | + | ||
| 30 | + | This feature was introduced in Lazarus 0.9.29. | |
| 31 | + | ||
| 40 | 32 | # File encoding | |
| 41 | 33 | ||
| 42 | - | ||
| 43 | - | ||
| 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: | |
| 35 | + | ||
| 36 | + | ``` pascal | |
| 44 | 37 | {%encoding CP1250} | |
| 45 | 38 | ``` | |
| 46 | 39 | ||
| 47 | - | ||
| 40 | + | See the unit lcl/lconvencoding.pas for all possible values. | |
| 48 | 41 | ||
| 49 | 42 | # Run/Build file | |
| 50 | 43 | ||
| 51 | - | ||
| 44 | + | 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. | |
| 52 | 45 | ||
| 53 | - | ||
| 54 | - | ||
| 55 | - | ||
| 56 | - | ||
| 57 | - | ||
| 58 | - | ||
| 59 | - | ||
| 60 | - | ||
| 46 | + | - {%BuildCommand \<command line used for building, default is \$(CompPath) \$(EdFile)\>} | |
| 47 | + | - {%BuildWorkingDir \<working directory, default is the file path\>} | |
| 48 | + | - {%BuildScan \<parsers\>} List of parsers used for build output | |
| 49 | + | - {%RunCommand \<command line used to run, default is \$NameOnly(\$(EdFile))\>} | |
| 50 | + | - {%RunWorkingDir \<working directory, default is the file path\>} | |
| 51 | + | - {%RunFlags \<flags, default Build+\>} where flags is a space separated list of options. E.g. {%RunFlags Messages+ Build+} | |
| 52 | + | - Build+ build before run, default: on | |
| 53 | + | - Messages+ show run output in the Messages window, default: off | |
| 61 | 54 | ||
| 62 | - | ||
| 55 | + | See [[IDE Window: Configure Build file|Configure Build File]]. | |
| 63 | 56 | ||
| 64 | 57 | # Other IDE Directives | |
| 65 | 58 | ||
| 66 | - | ||
| 67 | - | ||
| 59 | + | - {%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} | |
| 60 | + | - {%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. | |
| 68 | 61 | ||
| 69 | 62 | # Reading / finding IDE directives | |
| 70 | 63 | ||
| 71 | - | ||
| 64 | + | The codetools unit basiccodetools contains several functions for reading IDE directives: | |
| 72 | 65 | ||
| 73 | - | ||
| 74 | - | ||
| 66 | + | - FindNextIDEDirective | |
| 67 | + | - CodeToolBoss.GetIDEDirectives | |
| 75 | 68 | ||
| 76 | 69 | --- | |
| 77 | - | ||
| 70 | + | *From the Free Pascal wiki, page "IDE directives", as it stood on 2020-02-17 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
