PeterPanettone 157 Posted April 7, 2019 (edited) Does anybody know an IDE Code expert for automatically fixing very simple and obvious non-ambiguous syntax errors, for example: Transform this: Into this: Edited April 7, 2019 by PeterPanettone Share this post Link to post
David Heffernan 2345 Posted April 7, 2019 Is this the only error that you want to be fixed automatically? Share this post Link to post
PeterPanettone 157 Posted April 7, 2019 4 minutes ago, David Heffernan said: Is this the only error that you want to be fixed automatically? For now, yes. Share this post Link to post
David Heffernan 2345 Posted April 7, 2019 Wouldn't you just add the commas? I mean, how many lines of code do you have with this mistake in? 1 Share this post Link to post
Jacek Laskowski 57 Posted April 7, 2019 (edited) 48 minutes ago, David Heffernan said: Is this the only error that you want to be fixed automatically? Look for ESLint, add-on for VSCode Edited April 7, 2019 by Jacek Laskowski Share this post Link to post
PeterPanettone 157 Posted April 7, 2019 36 minutes ago, Jacek Laskowski said: Look for ESLint, add-on for VSCode In the video, it fixes just one error at a time. Can it also fix multiple errors with one action? But I doubt it can fix Delphi syntax errors... or is it configurable? Share this post Link to post
PeterPanettone 157 Posted April 7, 2019 39 minutes ago, David Heffernan said: Wouldn't you just add the commas? I mean, how many lines of code do you have with this mistake in? There would be many lines. An automatism would be faster than adding the commas manually. Ideally, I would select a block of code and the errors in this block would be fixed. Ideally, the compiler would help. Share this post Link to post
Dave Nottage 557 Posted April 7, 2019 25 minutes ago, PeterPanettone said: There would be many lines. An automatism would be faster than adding the commas manually How are those lines entered? If by typing, why not just type the commas as the code is being typed? If they're generated, why not generate the lines with commas in the first place? Share this post Link to post
PeterPanettone 157 Posted April 7, 2019 1 minute ago, Dave Nottage said: How are those lines entered? They come from an external source by pasting. Share this post Link to post
PeterPanettone 157 Posted April 7, 2019 I could easily write a small script-tool which fixes the commas. But at a more general scope, it would be interesting if it was possible to fix these syntax errors with the help of the compiler? Share this post Link to post
Uwe Raabe 2057 Posted April 7, 2019 47 minutes ago, PeterPanettone said: They come from an external source by pasting. Why don't you use MultiPaste in the first place and let it add the comma after each line. Then you end up with only one remaining error for the semicolon at the last line. 3 2 Share this post Link to post
PeterPanettone 157 Posted April 7, 2019 (edited) 1 hour ago, Uwe Raabe said: Why don't you use MultiPaste in the first place and let it add the comma after each line. Then you end up with only one remaining error for the semicolon at the last line. Thanks, Uwe, this is a VERY GOOD idea! In fact, this completely solves the problem with pasting many raw use-clause-items. Didn't even know Multipaste before. Maybe it should be called SmartPaste instead of MultiPaste, as it really is not a multiple paste action. Maybe also the dialog should automatically remember its last settings. Edited April 7, 2019 by PeterPanettone Share this post Link to post
PeterPanettone 157 Posted April 7, 2019 Thanks also to everybody for helping! Share this post Link to post
David Heffernan 2345 Posted April 8, 2019 (edited) 9 hours ago, PeterPanettone said: I could easily write a small script-tool which fixes the commas. But at a more general scope, it would be interesting if it was possible to fix these syntax errors with the help of the compiler? Writing a tool is how I would approach this. Learn a language like Python so that task like this can be done very easily and quickly. Of course, an even better solution is to fix the process that is generating erroneous code in the first place. Edited April 8, 2019 by David Heffernan Share this post Link to post
dummzeuch 1505 Posted April 8, 2019 There is also the GExperts Convert Strings editor expert. Unfortunately I just realized that it does not cover this excact case. Hm, time for an improvement: Add a suffix in addition to the existing prefix option for each line. Btw: Another solution would be to create a keyboard macro for this case. I would require one Shift+Ctrl+P keypress per line though (still better than repeating the required key sequences for every line). I have attached such a macro in case anybody is interested. It can be imported into the Keyboard Macro Manager. AppendComma.gxm Share this post Link to post
Rudy Velthuis 91 Posted May 6, 2019 (edited) On 4/7/2019 at 11:15 PM, PeterPanettone said: I could easily write a small script-tool which fixes the commas. But at a more general scope, it would be interesting if it was possible to fix these syntax errors with the help of the compiler? Has anyone ever used the macro recorder in the IDE? Just move the cursor to the first line, start recording, press end-of-line key, add comma, press down-arrow key, press start-of-line key, stop recording. Now just replay as many times as needed. Can't be for more than a few lines (and not hundreds of them, I hope). I often do things like that, for instance when I'm converting a header to a Delphi unit. The macro recorder is extremely useful for often repeated actions (i.e. on many lines) that are not so easily done with a regexp search and replace. The latter is the other way to easily convert certain patterns. Update: I see @dummzeuch had the same idea. Edited May 6, 2019 by Rudy Velthuis Share this post Link to post
dummzeuch 1505 Posted May 25, 2019 (edited) Just in case anybody is still interested: I have changed the GExperts Convert Strings Editor Expert to allow for prefixes and suffixes for all lines. Example: I want to create a string containing this code: function FindClassForm(const AClassName: string): TForm; var i: Integer; s: string; begin Result := nil; s := 'Some String'; for i := 0 to Screen.FormCount - 1 do if Screen.Forms[i].ClassNameIs(AClassName) then begin Result := Screen.Forms[i]; Break; end; end; Which means: Quote the lines and escape any existing quotes Add a variable assignment as prefix to the first line Add a " " prefix to all lines to indent the whole thing add a " + #13#10" suffix to each line but the last add a ";" suffix to the last line. The result looks like this: s := 'function FindClassForm(const AClassName: string): TForm; ' + #13#10 'var ' + #13#10 ' i: Integer; ' + #13#10 ' s: string; ' + #13#10 'begin ' + #13#10 ' Result := nil; ' + #13#10 ' s := ''Some String''; ' + #13#10 ' for i := 0 to Screen.FormCount - 1 do ' + #13#10 ' if Screen.Forms[i].ClassNameIs(AClassName) then begin ' + #13#10 ' Result := Screen.Forms[i]; ' + #13#10 ' Break; ' + #13#10 ' end; ' + #13#10 'end; '; There is no release for this yet, but you can always get the sources and compile your own dll: https://blog.dummzeuch.de/gexperts-documentation/compiling-gexperts/ Edited May 25, 2019 by dummzeuch Share this post Link to post
limelect 48 Posted May 26, 2019 This is mine http://limelect.com/downloads/add-characters-to-text-lines-on-large-scale/ Share this post Link to post