* * *

Author Topic: User-contributed list of useful code templates  (Read 426 times)

carl_caulkett

  • Full Member
  • ***
  • Posts: 243
User-contributed list of useful code templates
« on: June 30, 2017, 02:34:48 pm »
Lazarus 1.6.4
FPC 3.0.2
macOS 10.12.5 Sierra

Hello, I'm having problems trying to set up the simplest of Code Templates. For example, I select Code Templates, Press "Add", type "p" as the token, type "procedure |" as the comment (why "comment"? this is badly worded!), press "OK", then "OK" again.

Then, in the public area of a class definition, I type "p" and press Cmd-J (the Key Mappings guide has "Code template completion" listed as being activated by "Meta + J"). All the happens is that the "p" disappears and the cursor move back one character to where the "p" was. What obvious step have I missed?

Also does anyone know of any example lists of useful code templates. In fact shouldn't Lazarus come supplied with sample templates already? If so, I appear to have lost mine.

Thanks,
Carl
« Last Edit: July 10, 2017, 06:23:39 pm by carl_caulkett »
macOS 10.12.6
Lazarus 1.8.0 RC4
FPC 3.0.2

carl_caulkett

  • Full Member
  • ***
  • Posts: 243
Re: Problems using Code Templates
« Reply #1 on: June 30, 2017, 02:48:27 pm »
Doh! I didn't realise that there was a nice big memo box waiting for me to type things into. The coloration of the dialog box fooled me into thinking there was nothing there.

I was able to restore the default list of Lazarus templates by copying lazarus_dci_file.dci from Graeme Geldenhuys's Github Lazarus repository, so, thanks, Graeme!
« Last Edit: June 30, 2017, 03:19:24 pm by carl_caulkett »
macOS 10.12.6
Lazarus 1.8.0 RC4
FPC 3.0.2

carl_caulkett

  • Full Member
  • ***
  • Posts: 243
User-contributed list of useful code templates
« Reply #2 on: June 30, 2017, 03:18:51 pm »
I'd forgotten how awesome code templates are. It's taking me back to my Delphi 7 + CodeRush days, where I had a brilliant set of templates. I'm just starting to add some.

For example ";;" expands to ":=|" with "space" as the trigger - saves having to press the shift key a few thousand times!
"c" expands to "constructor Create;"
"cc" expands to "constructor Create(AOwner: TComponent); override;

and so on...

In my experience the best way of using Code templates is not to construct massive blocks of code, but to have commonly used small snippets from which larger blocks of code can quickly be constructed.

How about we turn this thread into a user-contributed list of useful code templates?

Over to you folks!
« Last Edit: July 10, 2017, 06:24:32 pm by carl_caulkett »
macOS 10.12.6
Lazarus 1.8.0 RC4
FPC 3.0.2

carl_caulkett

  • Full Member
  • ***
  • Posts: 243
User-contributed list of useful code templates
« Reply #3 on: June 30, 2017, 03:28:46 pm »
Of course, what would be really nice is for the Code Template mechanism to be able to tell whether the token was typed in the interface section or the implementation section of the code. I wonder if Macros would help here...
« Last Edit: July 10, 2017, 06:24:18 pm by carl_caulkett »
macOS 10.12.6
Lazarus 1.8.0 RC4
FPC 3.0.2

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus