Jump to content
Mike Torrettinni

Can GExperts format multiline method definition to single line?

Recommended Posts

Can GExperts reformat this:

procedure VirtualStringTree1GetText(Sender: TBaseVirtualTree; Node:
        PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType; var CellText:
        string);

 

into single line:

 

procedure VirtualStringTree1GetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType; var CellText: string);

 

In definition and/or in implementation. I think single line is much more readable, when it's a long unit with lots of methods.

Share this post


Link to post
5 minutes ago, Mike Torrettinni said:

Can GExperts reformat this:


procedure VirtualStringTree1GetText(Sender: TBaseVirtualTree; Node:
        PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType; var CellText:
        string);

 

If you use MMX, with right margin sent to some high value, then edit the routine: Ctrl-E, Enter, the result will be to put the signature all on one line. It will do so in both the interface and implementation sections, in one action.

Edited by Bill Meyer
  • Thanks 2

Share this post


Link to post
5 minutes ago, Bill Meyer said:

If you use MMX, with right margin sent to some high value, then edit the routine: Ctrl-E, Enter, the result will be to put the signature all on one line. It will do so in both the interface and implementation sections, in one action.

I do use MMX, well just started. I set right margin high (500). I tried, but I can reproduce the behavior you are describing with CTRL+E, Enter... where exactly should my cursor be to press CTRL+E and then Enter, in code, in MMX?

Share this post


Link to post
21 minutes ago, Mike Torrettinni said:

I do use MMX, well just started. I set right margin high (500). I tried, but I can reproduce the behavior you are describing with CTRL+E, Enter... where exactly should my cursor be to press CTRL+E and then Enter, in code, in MMX?

Should only need to be in the scope, in other words, the cursor in the signature, or anywhere in the method you wish to affect. (Sorry, I cropped that image a bit. It is the Pascal Editing page.)

image.thumb.png.0dc8247f21171b18c4489af4291c1154.png

Edited by Bill Meyer

Share this post


Link to post
9 minutes ago, Bill Meyer said:

Should only need to be in the scope, in other words, the cursor in the signature, or anywhere in the method you wish to affect.

image.thumb.png.0dc8247f21171b18c4489af4291c1154.png

Wrap margin is set to 500. but still it doesn't work - or, I don't know how to use it properly. No matter where my focus is, CTRL+E does not do anything. I even tried selecting the method and CTRL+E and nothing.

Share this post


Link to post
1 minute ago, Mike Torrettinni said:

Wrap margin is set to 500. but still it doesn't work - or, I don't know how to use it properly. No matter where my focus is, CTRL+E does not do anything. I even tried selecting the method and CTRL+E and nothing.

Which version are you in? I have seen modules in D2007 IDE which I am unable to Ctrl-E edit. Try creating a small project with a routine which needs to be un-wrapped. If it works, then there is something in the project you are testing now which is giving the IDE fits.

Share this post


Link to post

Aha, it works on new methods - adding new method will be a 1 line definition, when double clicking method in Object inspector.

It doesn't convert old/existing methods.

 

I have D 10.2.3 and MMX 14.0.5 build 2276

Edited by Mike Torrettinni
more info

Share this post


Link to post
48 minutes ago, Mike Torrettinni said:

Aha, it works on new methods - adding new method will be a 1 line definition, when double clicking method in Object inspector.

It doesn't convert old/existing methods.

 

I have D 10.2.3 and MMX 14.0.5 build 2276

Actually, it does, or did, convert existing. Just did it in D2007 and in XE7. Will try it later in 10.2.3, to see whether it fails. Obviously, I am not using v14 in those older IDEs.

Update: Works as I described in Delphi 10.3.1 with MMX 14.0.5. I do not have 10.2.3 available here at the moment.

Edited by Bill Meyer

Share this post


Link to post
33 minutes ago, Bill Meyer said:

Actually, it does, or did, convert existing.

It does. When the cursor is somewhere in that method (declaration or implementation) pressing <Ctrl>-E followed by <Enter> to open, close and accept that dialog will unwrap these lines.

Share this post


Link to post
Just now, Uwe Raabe said:

It does. When the cursor is somewhere in that method (declaration or implementation) pressing <Ctrl>-E followed by <Enter> to open, close and accept that dialog will unwrap these lines.

Confirmed here, though I did also see Ctrl-E fail to open the edit dialog in D2007 today. I am assuming it is contextual, as I do routinely use it in D2007.

Share this post


Link to post

It works! I closed and re-opened Delphi, now CTRL+E shows Edit procedure dialog, before it didn't. And just pressing Enter, it reformats definition for that method.

Great, thanks!

 

Any way to reformat the whole existing unit at once?

Share this post


Link to post
53 minutes ago, Mike Torrettinni said:

It works! I closed and re-opened Delphi, now CTRL+E shows Edit procedure dialog, before it didn't. And just pressing Enter, it reformats definition for that method.

Great, thanks!

 

Any way to reformat the whole existing unit at once?

Sort the class(es). That will apply the cleaning to all members (I think!). But look first at the sorting options. If you are using source control, think carefully before you leap. 😉

Edited by Bill Meyer

Share this post


Link to post
23 minutes ago, Bill Meyer said:

Sort the class(es).

AFAIK, that won't work.

 

As an alternative you can use the built in Delphi code format feature with <Ctrl>-D.

  • Like 1
  • Thanks 1

Share this post


Link to post
26 minutes ago, Uwe Raabe said:

AFAIK, that won't work.

 

As an alternative you can use the built in Delphi code format feature with <Ctrl>-D.

Thanks, I think I have enough to work with, for now.

Share this post


Link to post
4 hours ago, Uwe Raabe said:

AFAIK, that won't work.

 

As an alternative you can use the built in Delphi code format feature with <Ctrl>-D.

Oops, my bad! I was doing other things, and unable to confirm before I write that. And then began to think I was wrong.

Share this post


Link to post
10 hours ago, Mike Torrettinni said:

Can GExperts reformat this:


procedure VirtualStringTree1GetText(Sender: TBaseVirtualTree; Node:
        PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType; var CellText:
        string);

 

into single line:

 


procedure VirtualStringTree1GetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType; var CellText: string);

 

In definition and/or in implementation. I think single line is much more readable, when it's a long unit with lots of methods.

No, GExperts can't (because nobody answered that question yet).

  • Thanks 2

Share this post


Link to post
8 hours ago, Bill Meyer said:

Sort the class(es).

I filed a feature request for a new sort option to normalize the code while sorting.

  • Like 3

Share this post


Link to post
7 hours ago, Uwe Raabe said:

I filed a feature request for a new sort option to normalize the code while sorting.

A further thought: Perhaps a command to normalize without sorting class(es)? Resorting the classes would make for some source control issues in future. The normalization of signatures, though it would obviously affect source control, would be relatively minor, by comparison.

 

  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×