Is there a way to mark a piece of code so the "Source Formatter" (Ctrl-D) in Delphi skips it during formatting?

Comments

  1. Have you tried commenting it out temporarily?

    ReplyDelete
  2. Ondrej Kelle it's quite a few bits spread over the code, so commenting is a bit impractical.

    ReplyDelete
  3. Ondrej Kelle that's even worse, because comments are formatted also. I've been wishing for this functionality for years, because the built-in code formatter makes a mess of inline functions and fluid interfaces.

    ReplyDelete
  4. Uwe Raabe there are quite a few pieces of code that the formatter messes up. Initialisation sections, structured consts, hint directives, etc. And there are pieces that are hand-formatters because of readability that I'd like to keep that way.

    ReplyDelete
  5. Don't know if this helps, but you can keep your line breaks by placing // at the end of the broken line.

    ReplyDelete
  6. You can just not use the built in one and use the Jedi one.

    ReplyDelete
  7. Warren Postma how good is the Jedi one with generics? (The GExperts last time wasn't doing well, the Jedi one is too long ago).

    ReplyDelete
  8. You could do the opposite. Select the piece of code you want to format and press ctrl-D.

    ReplyDelete
  9. I should try it out. I think the JEDI stuff gets maintained better than GExperts.

    ReplyDelete
  10. You can write your code into a separate include file (MySkip.inc) then include it "{$I MySkip.inc} "into your unit (.pas file).

    ReplyDelete
  11. Mahdi Safsafi I'd need like a dozen inc files (: And then the Delphi IDE still has inc issues.

    ReplyDelete
  12. Use of .inc files to do much more than contain {$IFDEF VER180} type stuff is a fun way to get in all kinds of troubles

    ReplyDelete
  13. That's why I always format code when finishing writing methods, like Leif Uneus said: select method code, ctrl+d --> profit. Yes, I format code on "chunks", maybe its clumsy at first, but you get used to it

    BTW it would be really cool to use something like a region and tell the formatter "don't touch this"

    ReplyDelete
  14. Being able to make the Code Formatter skip blocks of code would be useful. I only recently started using it. Until this time I always did the formatting myself along the lines of the VCL code. CF is useful indeed, but I really wish it had worked differently. I prefer the way it works in VS - it formats when I hit enter to go to the next line. I can see what it did and also, why should I have to all the time hit Ctrl+D (which BTW doesn't work in IDE Classic key mapping and I'm forced to use the mouse/Alt+E+arrows to select the option - can somebody please confirm this in Seattle and Berlin, so I can file a QR). I have a file with several region markers with comments within and outside the regions and CF completely messes up my beautiful comments. All the regions and comments go to the end of the file (will file this as well).
    Maybe it would make a good plug-in: Live Code Formatter! Also, one that understood skip markers and/or remember manual negations/corrections of the auto-formatting.

    ReplyDelete
  15. I see an opportunity for a new IDE wizard: Parse the code for a pair of delimiters, save a copy of it, let the formatter do it's work, restore the code, profit ;-)

    ReplyDelete

Post a Comment