With REPLACE how to delete all blank lines? lazarus / 9-Editor ---------------------------------------------------------------------- Elmug · 2011-08-24 20:30 Good people, Could someone please advice how to use the Replace command, to find all blank lines and delete them? Of course we'd still have the option to Yes/No. Thanks! ---------------------------------------------------------------------- eny · 2011-08-24 20:37 It doesn't look like the IDE supports it (not that you'd ever need it for source code editing). Textpad and Notepad++ support it (amongst others) if you want to modify (non-sourcecode) files like this. ---------------------------------------------------------------------- Martin_fr · 2011-08-24 20:56 Check "Regular Expression" and "Multiline pattern" in the replace dialog. Then search for \n\r?\s*\n\r? This will delete any line that contains only spaces/tabs, or nothing \n\r?[\n\r?]+ to only delete lines that are real empty, no spaces -------------- I do have to check, it may be a bug in the reg-expr engine, since it matches 2 (or more) linebreaks, yet only substitutes one less ---------------------------------------------------------------------- eny · 2011-08-24 21:18 Quote from: Martin_fr on August 24, 2011, 10:56:50 pmCheck "Regular Expression" and "Multiline pattern" in the replace dialog. Then search for \n\r?\s*\n\r? This will delete any line that contains only spaces/tabs, or nothing \n\r?[\n\r?]+ to only delete lines that are real empty, no spaces -------------- I do have to check, it may be a bug in the reg-expr engine, since it matches 2 (or more) linebreaks, yet only substitutes one less Too bad the IDE is not intuitive in this matter and only works partially. It doesn't work with only the \n parameter (which indicates a new line hence that should work). And it doesn't recognize the expression ^$\n which should give you the blank lines. ---------------------------------------------------------------------- Elmug · 2011-08-25 01:10 Thaks good people, for the replies. I would not want any other editor in the Lazarus system. The one developed for it is great. On the issue, though, the more it looks to me that each line is a variable length string, or something like that, so there'd be no way to copy it into the replace buffer? This capability, though, is not that critical. I think if they provide for it in the Environment options, to have zero blank lines in procedures would  be nice. Thanks! ---------------------------------------------------------------------- User137 · 2011-08-25 04:29 On topic, it seems like replace command really can't do this. It would not be able to distinct empty line that is inside procedure and between procedures. Codetools don't have this functionality either i think, but you can make a tool by yourself that parses through code and cleans empty lines. TStringList can load the file and Delete command remove line if Strings[LineIndex]=''. Difficult part is procedure recognition... Maybe count only begin and end words. Every "begin" increases counter by 1 and every "end" reduces it 1. If counter >0 you know that you are looking at code inside a procedure. Or more simply if you tailor it to yourself and assume that all code inside is indented more than 1, then only begin and end starting from first character from line only counts. This will be easy way to ignore commented code. (Not that i support this kind of coding style myself... Empty lines are a great way to make code more readable.) ---------------------------------------------------------------------- Shebuka · 2011-08-25 07:56 Quote from: Elmug on August 24, 2011, 10:30:05 pmGood people, Could someone please advice how to use the Replace command, to find all blank lines and delete them? Of course we'd still have the option to Yes/No. Thanks! JEDI Code Formatter can do this. In it's options there is 'blank lines' section in wich you can configure the max number of blank lines. ---------------------------------------------------------------------- Elmug · 2011-09-05 08:20 Quote from: Shebuka on August 25, 2011, 09:56:50 amQuote from: Elmug on August 24, 2011, 10:30:05 pmGood people, Could someone please advice how to use the Replace command, to find all blank lines and delete them? Of course we'd still have the option to Yes/No. Thanks! JEDI Code Formatter can do this. In it's options there is 'blank lines' section in wich you can configure the max number of blank lines. Hi and thanks for the suggestion, but I've been through that approach before. It does not allow me to set zero blank lines in procedures. ---------------------------------------------------------------------- Shebuka · 2011-09-05 10:16 Quote from: Elmug on September 05, 2011, 10:20:02 amQuote from: Shebuka on August 25, 2011, 09:56:50 amQuote from: Elmug on August 24, 2011, 10:30:05 pmGood people, Could someone please advice how to use the Replace command, to find all blank lines and delete them? Of course we'd still have the option to Yes/No. Thanks! JEDI Code Formatter can do this. In it's options there is 'blank lines' section in wich you can configure the max number of blank lines. Hi and thanks for the suggestion, but I've been through that approach before. It does not allow me to set zero blank lines in procedures. Have you tried to set the 'Max number of empty lines everywhere' (ita to eng translation) to 0? If yes and it doesn't work then there is a bug inside formatter. ---------------------------------------------------------------------- Scoops · 2011-09-05 12:35 QuoteHave you tried to set the 'Max number of empty lines everywhere' (ita to eng translation) to 0? If yes and it doesn't work then there is a bug inside formatter. No bug inside JEDI Code Formatter, go through the docs and you will see it was programmed like that, from what i remember the "Minimum number" allowed for the "Max number of empty lines" is hardcoded to 2, sorry if that makes no sense. ---------------------------------------------------------------------- BigChimp · 2011-09-05 12:50 Well, conceivably that could be changed in the code to no lines... unless it is constrained by other issues... ---------------------------------------------------------------------- Scoops · 2011-09-05 13:17 I downloaded the source once and found the said hardcoded No.2, so i suppose it's easy enough, but did'nt try.  I'll have another look tonight to let you know in which file (can't remember) unless someone else beats me to it. Normally it's nice to keep empty lines is source as it helps to identify certain sections of your code, so i can understand the minimum of 2. ---------------------------------------------------------------------- Shebuka · 2011-09-05 14:25 Quote from: Scoops on September 05, 2011, 03:17:04 pmI downloaded the source once and found the said hardcoded No.2, so i suppose it's easy enough, but did'nt try.  I'll have another look tonight to let you know in which file (can't remember) unless someone else beats me to it. Normally it's nice to keep empty lines is source as it helps to identify certain sections of your code, so i can understand the minimum of 2. I agree with you, the code with blank lines that delimit it in 'section' or 'parts' that visibly tells you 'ok i'done with this object' or 'this case block ends here' is much_much_much more readable and 'intuitive', specially when you come to revisit it after some time (in this case comments are also welcome). But still, i think that if someone want, he must be able to set 'Max number of empty lines everywhere' to whatever integer he wants. ---------------------------------------------------------------------- Elmug · 2011-09-15 02:55 Having blank lines in a procedure has thrown me off as when copying to duplicate a procedure..See an "end'' followed by a blank line and copy paste only to there, specially when the procedure is long and does not fit in the screen. When I want blank lines as delimiters, I now use {.} as a spacer. Before I was using {} but then the J formatter got rid of all empty comments. To me it's much more solid to have a procedure be a continuous chunk of lines with NO empty lines, for the reasons given. ---------------------------------------------------------------------- Martin_fr · 2011-09-15 08:10 Quote from: Elmug on September 15, 2011, 04:55:24 amHaving blank lines in a procedure has thrown me off as when copying to duplicate a procedure..See an "end'' followed by a blank line and copy paste only to there, specially when the procedure is long and does not fit in the screen. You know "divider lines"? http://wiki.lazarus.freepascal.org/New_IDE_features_since#divider_line s_in_editor ---------------------------------------------------------------------- dkjMusic · 2011-09-15 13:02 Elmug, wrt "...specially when the procedure is long and does not fit in the screen", I ran into this a lot also, so I turned Code Folding for procedures on. This allows me to fold the long procedure/function and then only copy one line! ---------------------------------------------------------------------- Elmug · 2011-09-15 23:22 Thanks everyone for the tips and points of view.