MJBComp 2 Posted August 12, 2022 (edited) if i type 'if' in a procedure Delphi automatically buts an empty line below the if statement: when i type "if" and hit the space bar Delphi put the word "True then" and adds a blank line below it. I Do Not want this behavior. When i type "if" i want nothing to happen. I don't want Delphi to finish my statement or put any line breaks or keywords after. I have looked at Tools | Options | Language | Formatter | Delphi | Line breaks but haven't found changing any of those modifies this 'built in behavior'. Any ideas? (Delphi 10.4.2 Sidney) (64 bit Windows VCL App) begin if True then end; Edited August 12, 2022 by MJBComp Share this post Link to post
MJBComp 2 Posted August 12, 2022 (edited) Ok i figured out why its happening. View | Tool Windows | Templates Its the "if" Delphi template causing it. But when i delete that template the behavior still remains. If i close Delphi and restart the template is restored back. If i try and modify the "if" template and try and save it i get this error: "Unable to create backup folder 'c:\program files(x86}\embarcadero\21.0\ObjRepos\EN\code_templates\Delphi\_history\' So next i went directly to that folder and renamed the if.xml file to if.xm_ but Delphi still loads the "if" template. So its obviously being stored elsewhere. Any ideas? Edited August 12, 2022 by MJBComp Share this post Link to post
corneliusdavid 214 Posted August 12, 2022 1 hour ago, MJBComp said: Its the "if" Delphi template causing it. But when i delete that template the behavior still remains. If i close Delphi and restart the template is restored back. If i try and modify the "if" template and try and save it i get this error: "Unable to create backup folder 'c:\program files(x86}\embarcadero\21.0\ObjRepos\EN\code_templates\Delphi\_history\' Yes, this is the Live Templates feature of Delphi (one of my favorite productivity features, actually). A default set of templates gets installed in C:\Program Files (x86)\Embarcadero\Studio\21.0\ObjRepos\en\Code_Templates\Delphi as you discovered but remember that anything under C:\Program Files (x86) is read-only by default, so renaming or changing a Live Template from Delphi might not affect the actual file--or, as you encountered, you'd get the "Unable to create backup folder" error as Delphi tries to create a backup of the template before saving the new changes (which it will also fail to do unless you're running Delphi as Administrator). In addition to the default templates mentioned above, any new ones you create are stored in C:\Users\<your username>\Documents\Embarcadero\Studio\code_templates\Delphi. Since your user folder IS writable, you can rename/modify/delete the templates there all you want. You can turn off the auto-completion of the templates (which forces you to hit Ctrl+J to activate one) by going into Tools > Options > User Interface > Editor > Language, switching to the "Code Insight" tab, and unchecking "Auto complete" under "Code template completion". 1 Share this post Link to post
MJBComp 2 Posted August 12, 2022 (edited) corneliusdavid, Ok you solved one question and one remains. I do prefer to press Ctrl + J to invoke the Live Templates so your solution worked. I was under the impression that unchecking that option also turned off code completion for functions/procedures as well but glad to see it does exactly what i want. The unsolved question is i use cnPack (3rd party) add-in for my 'code templates' and have for years. Can you explain why when i open the Delphi Template Manager and try and delete the "if" template it won't actually remove. It will show as deleted. But if i close the Template Manager, close and re open Delphi the "if" template is back. I don't mind using some of the default Delphi templates but i have others in cnPack i want to use instead. I mean, the feature is built into Delphi to be able to delete templates but i can't find a way to do this. Even if i create my own template with the behavior i want and place it in C:\Users\<your username>\Documents\Embarcadero\Studio\code_templates\Delphi. it won't run if its named the same as one of the Default Templates which i'd simply like to just delete or rename so it won't run. Edited August 12, 2022 by MJBComp Share this post Link to post
corneliusdavid 214 Posted August 12, 2022 8 hours ago, MJBComp said: Can you explain why when i open the Delphi Template Manager and try and delete the "if" template it won't actually remove. It will show as deleted. But if i close the Template Manager, close and re open Delphi the "if" template is back. Probably because the default "if" template is under C:\Program Files (x86)\... which is read-only. I'm guessing Delphi removes it from it's run-time list while it is open but re-populates the list from the files when it starts back up--and since the file itself was not deleted, re-reads it. If you really, REALLY want that "if" template to go away, close Delphi, manually delete C:\Program Files (x86)\Embarcadero\Studio\21.0\ObjRepos\en\Code_Templates\Delphi\if.xml, then re-start Delphi. Share this post Link to post