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