Code Formatting

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

Code Formatting

Jeffrey Odell-2
A request and a question:

1) Would Like "Reformat Only" Context Menu Command When Editing Methods

When editing a method, I would like a menu option to format the source only,
without saving.  Preferably this would have a Ctrl key associated with it.
My work style (admittedly from VA with Envy/QA) is to code , format, code ,
format, save.  The format step (CTRL-W) serves two purposes:

   1) Checks the syntax of what I have typed in so far;
   2) Reformats

When I'm done with the method, I save (CTRL-S).

While I enter code, I don't worry about formatting as I type, because I can
always hit CTRL-W to format immediately.

This is a real 'XP' feeling thing and would enhance the "zoom" factor.

2) Do I subclass the Smalltalk Formatter visitor to tweak the format to my
liking?  Are there any other ways of tweaking?

Thx -

jlo


Reply | Threaded
Open this post in threaded view
|

Re: Code Formatting

Blair McGlashan
Jeff

You wrote in message news:[hidden email]...
> A request and a question:
>
> 1) Would Like "Reformat Only" Context Menu Command When Editing Methods
>
> When editing a method, I would like a menu option to format the source
only,
> without saving.  Preferably this would have a Ctrl key associated with it.
> My work style (admittedly from VA with Envy/QA) is to code , format, code
,
> format, save.  The format step (CTRL-W) serves two purposes:
>
>    1) Checks the syntax of what I have typed in so far;
>    2) Reformats
>
> When I'm done with the method, I save (CTRL-S).
>
> While I enter code, I don't worry about formatting as I type, because I
can
> always hit CTRL-W to format immediately.
>
> This is a real 'XP' feeling thing and would enhance the "zoom" factor.

I tend to do this by just pressing Ctrl+Shift+S (Reformat/Accept), which
will reformat and then save the method if it is valid. In fact I almost
always press Ctrl+Shift+S in preference to Ctrl+S now. We can certainly add
a command to just do the reformat (though it won't work if the method is not
syntactically valid).

>
> 2) Do I subclass the Smalltalk Formatter visitor to tweak the format to my
> liking?  Are there any other ways of tweaking?

The formatter is from the Refactoring Browser. John Brant did mention
something to me about a configurable formatter. John?

Regards

Blair


Reply | Threaded
Open this post in threaded view
|

Re: Code Formatting

Jeffrey Odell-2
See below - thanks -

jlo

"Blair McGlashan" <[hidden email]> wrote in message
news:[hidden email]...

> Jeff
>
> You wrote in message news:[hidden email]...
> > A request and a question:
> >
> > 1) Would Like "Reformat Only" Context Menu Command When Editing Methods
> >
> > When editing a method, I would like a menu option to format the source
> only,
> > without saving.  Preferably this would have a Ctrl key associated with
it.
> > My work style (admittedly from VA with Envy/QA) is to code , format,
code

> ,
> > format, save.  The format step (CTRL-W) serves two purposes:
> >
> >    1) Checks the syntax of what I have typed in so far;
> >    2) Reformats
> >
> > When I'm done with the method, I save (CTRL-S).
> >
> > While I enter code, I don't worry about formatting as I type, because I
> can
> > always hit CTRL-W to format immediately.
> >
> > This is a real 'XP' feeling thing and would enhance the "zoom" factor.
>
> I tend to do this by just pressing Ctrl+Shift+S (Reformat/Accept), which
> will reformat and then save the method if it is valid. In fact I almost
> always press Ctrl+Shift+S in preference to Ctrl+S now. We can certainly
add
> a command to just do the reformat (though it won't work if the method is
not
> syntactically valid).
>

It probably only matters if you are using source code control like Envy in
VA or, as I do now, STS with Dolphin.  I like to be able to Compile/Reformat
without saving so I don't get a lot of 'phantom' editions that only
represent partial implementations.  When I look at edition changes, I don't
want to wade through the intermediate editions to figure out what change I
made.

I can probably work through the browsers and figure out what needs to be
changed if that helps.  I'd rather have it in the base product than have it
be my local change.  I could send a change set of code.  Let me know -

> >
> > 2) Do I subclass the Smalltalk Formatter visitor to tweak the format to
my

> > liking?  Are there any other ways of tweaking?
>
> The formatter is from the Refactoring Browser. John Brant did mention
> something to me about a configurable formatter. John?
>
> Regards
>
> Blair
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Code Formatting

Blair McGlashan
Jeff

You wrote in message news:[hidden email]...

> > > While I enter code, I don't worry about formatting as I type, because
I

> > can
> > > always hit CTRL-W to format immediately.
> > >
> > > This is a real 'XP' feeling thing and would enhance the "zoom" factor.
> >
> > I tend to do this by just pressing Ctrl+Shift+S (Reformat/Accept), which
> > will reformat and then save the method if it is valid. In fact I almost
> > always press Ctrl+Shift+S in preference to Ctrl+S now. We can certainly
> add
> > a command to just do the reformat (though it won't work if the method is
> not
> > syntactically valid).
> >
>
> It probably only matters if you are using source code control like Envy in
> VA or, as I do now, STS with Dolphin.  I like to be able to
Compile/Reformat
> without saving so I don't get a lot of 'phantom' editions that only
> represent partial implementations.  When I look at edition changes, I
don't
> want to wade through the intermediate editions to figure out what change I
> made.

Very good point. We'll put it in. Defect #459.

Regards

Blair


Reply | Threaded
Open this post in threaded view
|

Re: Code Formatting

Blair McGlashan
"Blair McGlashan" <[hidden email]> wrote in message
news:[hidden email]...
> >
> > It probably only matters if you are using source code control like Envy
in
> > VA or, as I do now, STS with Dolphin.  I like to be able to
> Compile/Reformat
> > without saving so I don't get a lot of 'phantom' editions that only
> > represent partial implementations.  When I look at edition changes, I
> don't
> > want to wade through the intermediate editions to figure out what change
I
> > made.
>
> Very good point. We'll put it in. Defect #459.

A quick follow up. The workspace Edit/Reformat command does actually do what
you want. If there is no selection, then it will reformat the entire method
(as a method). If there is text selected, then it attempts to reformat the
selected text only (as an expression). You will find that the text is also
syntax coloured. It does not save the method.

The only thing missing is a keyboard accelerator sequence (especially useful
as we've put this on the Edit sub-menu), which we will add in resolving
#459.

Regards

Blair


Reply | Threaded
Open this post in threaded view
|

Re: Code Formatting

Jeffrey Odell-2
Aha!  I see it - thanks.  I'll work with it a bit the "hard way" and make
sure it works as I'd hoped.  I lobby for CTRL-W or CTRL-R. ;>

jlo

"Blair McGlashan" <[hidden email]> wrote in message
news:[hidden email]...
> "Blair McGlashan" <[hidden email]> wrote in message
> news:[hidden email]...
> > >
> > > It probably only matters if you are using source code control like
Envy
> in
> > > VA or, as I do now, STS with Dolphin.  I like to be able to
> > Compile/Reformat
> > > without saving so I don't get a lot of 'phantom' editions that only
> > > represent partial implementations.  When I look at edition changes, I
> > don't
> > > want to wade through the intermediate editions to figure out what
change
> I
> > > made.
> >
> > Very good point. We'll put it in. Defect #459.
>
> A quick follow up. The workspace Edit/Reformat command does actually do
what
> you want. If there is no selection, then it will reformat the entire
method
> (as a method). If there is text selected, then it attempts to reformat the
> selected text only (as an expression). You will find that the text is also
> syntax coloured. It does not save the method.
>
> The only thing missing is a keyboard accelerator sequence (especially
useful

> as we've put this on the Edit sub-menu), which we will add in resolving
> #459.
>
> Regards
>
> Blair
>
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Code Formatting

Blair McGlashan
"Jeffrey Odell" <[hidden email]> wrote in message
news:[hidden email]...
> Aha!  I see it - thanks.  I'll work with it a bit the "hard way" and make
> sure it works as I'd hoped.  I lobby for CTRL-W or CTRL-R. ;>
>

I've opted for Ctrl+W so far (though I haven't been able to work out why it
was chosen for VA, which I think you mentioned in your previous post),
because Ctrl+R is already in use for the 'Rename Temporary' refactoring, one
that I certainly use a lot.

Regards

Blair


Reply | Threaded
Open this post in threaded view
|

Re: Code Formatting

Chris Uppal-3
In reply to this post by Blair McGlashan
> I tend to do this by just pressing Ctrl+Shift+S (Reformat/Accept), which
> will reformat and then save the method if it is valid. In fact I almost
> always press Ctrl+Shift+S in preference to Ctrl+S now. We can certainly
add
> a command to just do the reformat (though it won't work if the method is
not
> syntactically valid).

Small points.

In the CHB Method>Reformat seems to do the same thing as
Workspace>Reformat/Accept; the different name gave me the impression that it
*wouldn't* save the method as a side-effect, so I think it is misleading.

(BTW, another reason to want to reformat-but-not-save is if you're using
reformatting to help read someone else's code.)

Also the reformat option is enabled even for methods with no source, and
causes a walkback when invoked.

    -- chris


Reply | Threaded
Open this post in threaded view
|

Re: Code Formatting

Blair McGlashan
Chris

You wrote in message news:[hidden email]...

> > I tend to do this by just pressing Ctrl+Shift+S (Reformat/Accept), which
> > will reformat and then save the method if it is valid. In fact I almost
> > always press Ctrl+Shift+S in preference to Ctrl+S now. We can certainly
> add
> > a command to just do the reformat (though it won't work if the method is
> not
> > syntactically valid).
>
> Small points.
>
> In the CHB Method>Reformat seems to do the same thing as
> Workspace>Reformat/Accept; the different name gave me the impression that
it
> *wouldn't* save the method as a side-effect, so I think it is misleading.

I agree it is not clear. Defect #476
>
> (BTW, another reason to want to reformat-but-not-save is if you're using
> reformatting to help read someone else's code.)
>
> Also the reformat option is enabled even for methods with no source, and
> causes a walkback when invoked.
>

Thanks, defect #477.

Regards

Blair


Reply | Threaded
Open this post in threaded view
|

Re: Code Formatting

John Brant
In reply to this post by Blair McGlashan
"Blair McGlashan" <[hidden email]> wrote in message
news:[hidden email]...

> The formatter is from the Refactoring Browser. John Brant did mention
> something to me about a configurable formatter. John?

We have the start of a configurable formatter. Currently, it formats all of
VW's methods correctly, but we only have 10 different options, so it is only
missing a few dozen options that someone may want :). If someone would like
to work on it, I can send you our current version and its tests. It's
currently for VW, but should be fairly easy to convert to Dolphin.


John Brant


Reply | Threaded
Open this post in threaded view
|

Re: Code Formatting

Blair McGlashan
"John Brant" <[hidden email]> wrote in message
news:[hidden email]...
> "Blair McGlashan" <[hidden email]> wrote in message
> news:[hidden email]...
>
> > The formatter is from the Refactoring Browser. John Brant did mention
> > something to me about a configurable formatter. John?
>
> We have the start of a configurable formatter. Currently, it formats all
of
> VW's methods correctly, but we only have 10 different options, so it is
only
> missing a few dozen options that someone may want :). If someone would
like
> to work on it, I can send you our current version and its tests. It's
> currently for VW, but should be fairly easy to convert to Dolphin.

I'd like to take you up on that, but it would be irresponsible of me given
all the other things I am supposed to be doing. What I will do, however, is
to refactor and repackage the existing parser/formatter slightly so that it
is possible to uninstall the existing (RB originated) formatter, and replace
it with a port of your new formatter. I presume it is compatible with the
old one? i.e. it is a "parse node visitor" (there is a Dolphin protocol
defined for the interface in D5).

Oh well, go on then, please send it to me....

Regards

Blair


Reply | Threaded
Open this post in threaded view
|

Re: Code Formatting

jWarrior
In reply to this post by Blair McGlashan
add my vote for ctrl-w doing a format only.

"Blair McGlashan" <[hidden email]> wrote in message
news:[hidden email]...
> "Jeffrey Odell" <[hidden email]> wrote in message
> news:[hidden email]...
> > Aha!  I see it - thanks.  I'll work with it a bit the "hard way" and
make
> > sure it works as I'd hoped.  I lobby for CTRL-W or CTRL-R. ;>
> >
>
> I've opted for Ctrl+W so far (though I haven't been able to work out why
it
> was chosen for VA, which I think you mentioned in your previous post),
> because Ctrl+R is already in use for the 'Rename Temporary' refactoring,
one
> that I certainly use a lot.
>
> Regards
>
> Blair
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Code Formatting

Jeffrey Odell-2
I think Ctrl-W was chosen for it's proximity to the other control keys in
the VA editor.  I use Ctrl-W to form, then if I'm happy, Ctrl-S

jlo

"Donald MacQueen" <[hidden email]> wrote in message
news:[hidden email]...

> add my vote for ctrl-w doing a format only.
>
> "Blair McGlashan" <[hidden email]> wrote in message
> news:[hidden email]...
> > "Jeffrey Odell" <[hidden email]> wrote in message
> > news:[hidden email]...
> > > Aha!  I see it - thanks.  I'll work with it a bit the "hard way" and
> make
> > > sure it works as I'd hoped.  I lobby for CTRL-W or CTRL-R. ;>
> > >
> >
> > I've opted for Ctrl+W so far (though I haven't been able to work out why
> it
> > was chosen for VA, which I think you mentioned in your previous post),
> > because Ctrl+R is already in use for the 'Rename Temporary' refactoring,
> one
> > that I certainly use a lot.
> >
> > Regards
> >
> > Blair
> >
> >
>
>