Identifier capitalization? lazarus / 9-Editor ---------------------------------------------------------------------- Peter H · 2020-11-30 11:28 Hello, I want for all Identifiers in a progamm to make the capitalization equal to the declaration. Example: var    VeryImportantNumber:integer; "if veryimportantnumber = 0 then" should become "if VeryImportantNumber = 0 then" and this for all identifiers in the program. Is this possible? ---------------------------------------------------------------------- Handoko · 2020-11-30 11:38 Use Find & Replace feature: Source Code Editor > Ctrl + F > fill the Text to find field > Enable the Replace with checkbox and provide the identifier with the correct capitalization > Disable Case sensitive checkbox > Set the Origin option to From beginning > Set the Search scope option to Global > Set the Direction to Forward search > Click the Replace All button If you want to do it on multiple files: Lazarus main menu > Search > Find in files I'm not sure, I don't use it but I think you can also try JEDI Code Format: Lazarus main menu > Source > JEDI Code Format ---------------------------------------------------------------------- Peter H · 2020-11-30 11:57 Yes thank you, but this will only work for a single identifier. I think this can also (and better) be done with "Refactor" but this also works on a single identifier. I tried Jedi Code format, this doesnt do it, it only unifies the capitalization for keywords. I watched on Youtube tutorial videos for delphi where identifiers are automatically correctly capitalized during or after typing and I asked myself if there is a similar feature or tool for freepascal/Lazarus. Thereoretically the compiler could do this, because the compiler knows and understands all declarations. ---------------------------------------------------------------------- PascalDragon · 2020-11-30 12:03 Quote from: Peter H on November 30, 2020, 12:57:24 pmI watched on Youtube tutorial videos for delphi where identifiers are automatically correctly capitalized during or after typing and I asked myself if there is a similar feature or tool for freepascal. Lazarus does that as well when you use its code completion (Default: Ctrl + Space) functionality (if there is only one valid identifier it will complete that without showing the code completion window). Quote from: Peter H on November 30, 2020, 12:57:24 pmThereoretically the compiler could do this, because the compiler knows all declarations. No, the compiler does not modify source files. ---------------------------------------------------------------------- Handoko · 2020-11-30 12:04 Quote from: Peter H on November 30, 2020, 12:57:24 pmI tried Jedi Code format, this doesnt do it, it only unifies the capitalization for keywords. You can configure it: Lazarus main menu > Source > JEDI Code Format > Format Settings > left panel: Clarify > Capitalization > Identifiers Quote from: Peter H on November 30, 2020, 12:57:24 pmI watched on Youtube tutorial videos for delphi where identifiers are automatically correctly capitalized during or after typing and I asked myself if there is a similar feature or tool for freepascal. Just as PascalDragon said. I always use Ctrl+Space when typing identifier so my codes are always capitalized uniformly. ---------------------------------------------------------------------- Peter H · 2020-11-30 12:09 Thank you, I will try it. Of course the compiler should not modify the source. However, theoretically it could emit a new file with correct capitalization, if there where a comand line option. This is just an idea of mine, I know it is not possible currently. ---------------------------------------------------------------------- PascalDragon · 2020-11-30 12:12 Quote from: Peter H on November 30, 2020, 01:09:04 pmHowever, theoretically it could emit a new file with correct capitalization, if there where a comand line option. This is just an idea of mine, I know it is not possible currently. That would be a completely unnecessary complication of the compiler who currently does not care about the case of identifiers at all. Use tools that have the purpose of adjusting the source and let the compiler simply do its job. ---------------------------------------------------------------------- jwdietrich · 2020-11-30 12:23 Quote from: PascalDragon on November 30, 2020, 01:12:05 pmThat would be a completely unnecessary complication of the compiler who currently does not care about the case of identifiers at all. Use tools that have the purpose of adjusting the source and let the compiler simply do its job. Fully agree. This would be the realm of separate tools. ---------------------------------------------------------------------- JuhaManninen · 2020-11-30 12:30 Quote from: jwdietrich on November 30, 2020, 01:23:52 pmFully agree. This would be the realm of separate tools. It would be a job for Codetools. The "Rename identifier..." feature already does it for a single variable. A new feature "Match capitalization of identifiers..." or similar could be added. It will be accepted for sure if somebody implements it. ---------------------------------------------------------------------- MarkMLl · 2020-12-16 14:40 Quote from: JuhaManninen on November 30, 2020, 01:30:47 pmQuote from: jwdietrich on November 30, 2020, 01:23:52 pmFully agree. This would be the realm of separate tools. It would be a job for Codetools. The "Rename identifier..." feature already does it for a single variable. A new feature "Match capitalization of identifiers..." or similar could be added. It will be accepted for sure if somebody implements it. That would be nice. I know that case sensitivity in Pascal tends to... excite strong emotions and heated discourse, but nobody in their right mind could object (surely!) to a helper which made sure that capitalisation was consistent. But I'd imagine that it would be far more difficult for Pascal than for C/C++, on account of the language's support for nested functions. MarkMLl ---------------------------------------------------------------------- marcov · 2020-12-16 14:49 Quote from: Peter H on November 30, 2020, 01:09:04 pmThank you, I will try it. Of course the compiler should not modify the source. However, theoretically it could emit a new file with correct capitalization, if there where a comand line option. No. The/A compiler does not read a file into a representation that can be converted back to formatted source. E.g. it doesn't even look at parts that are in an inactive IFDEF.  For that there are source to source tools like jedi formatter, fcl- passrc etc. ---------------------------------------------------------------------- MarkMLl · 2020-12-17 21:49 Quote from: marcov on December 16, 2020, 03:49:38 pmNo. The/A compiler does not read a file into a representation that can be converted back to formatted source. E.g. it doesn't even look at parts that are in an inactive IFDEF.  I think that saying "a compiler" there is pushing credibility. A C/C++ compiler with integrated preprocessor would emit the original file if not told to make changes. The parser in a compiler normally stores at least one line verbatim so that it can point to the location of an error message, and it would not be difficult to output each line after it had been processed. A code listing from a compiler normally has the original source in a form that can be extracted. OK, so FPC doesn't do it like that... but there is no reason why in the general case a single-pass compiler shouldn't emit corrected variable names as it runs, since the symbol table is built before code is generated. MarkMLl ---------------------------------------------------------------------- marcov · 2020-12-17 21:58 Quote from: MarkMLl on December 17, 2020, 10:49:43 pmQuote from: marcov on December 16, 2020, 03:49:38 pmNo. The/A compiler does not read a file into a representation that can be converted back to formatted source. E.g. it doesn't even look at parts that are in an inactive IFDEF.  I think that saying "a compiler" there is pushing credibility. A C/C++ compiler with integrated preprocessor would emit the original file if not told to make changes. The parser in a compiler normally stores at least one line verbatim so that it can point to the location of an error message, and it would not be difficult to output each line after it had been processed. Without wanting to split hairs about details of what constitutes a compiler, I yield. Have fun with your split hairs. ---------------------------------------------------------------------- DomingoGP · 2024-09-11 18:33 I know that this thread is a bit old, but I want to report that Jedi code format now supports this feature, added to trunk (version 3.99). Better late than never