Board index » delphi » OT (?): GExperts: %BEFORE% macro?

OT (?): GExperts: %BEFORE% macro?


2003-09-05 02:23:23 PM
delphi93
Hello,
this might be a little bit off topic:
what does the "%BEFORE%" macro in the "Expand macro" expert do??
TIA,
Ralf
 
 

Re:OT (?): GExperts: %BEFORE% macro?

Ralf Kaiser writes:
Quote
this might be a little bit off topic:
what does the "%BEFORE%" macro in the "Expand macro" expert do??
It forces the subsequent macros to look before the cursor for their
substitution values. For example the procedure name before the cursor, not
after it. I assume you are compiling from the GExperts source code, so see
GX_MacroParser.pas for details.
Erik
 

Re:OT (?): GExperts: %BEFORE% macro?

Erik Berry <XXXX@XXXXX.COM>writes:
Quote
Ralf Kaiser writes:
>this might be a little bit off topic:
>what does the "%BEFORE%" macro in the "Expand macro" expert do??

It forces the subsequent macros to look before the cursor for their
substitution values. For example the procedure name before the
cursor, not after it. I assume you are compiling from the GExperts
source code, so see GX_MacroParser.pas for details.

Hello,
i see! Thanks!
Another thing that has to with this expert:
I have a macro that looks like this:
try
%SELECTION%
finally
|
end;
When i execute this macro and the selection was only in the current line
(not multiple lines) then i get the expected result. If i mark two or more
lines the i get the following result (let's say the complete line with the
text "MARKED TEST" was marked in the editor)
MARKED TEXT
try
MARKED TEXT
finally
(CURSOR IS HERE)
end;
Can "%SELECTION%" not be used with more then one line??
Thanks in advance,
Ralf
--
mailto:XXXX@XXXXX.COM
www.emperortools.de
 

Re:OT (?): GExperts: %BEFORE% macro?

Ralf Kaiser writes:
Quote
When i execute this macro and the selection was only in the current line
(not multiple lines) then i get the expected result. If i mark two or more
lines the i get the following result (let's say the complete line with the
text "MARKED TEST" was marked in the editor)

MARKED TEXT
try
MARKED TEXT
finally
(CURSOR IS HERE)
end;
This expert is fairly literal with respect to the output it produces. I
believe you are expecting the tool to delete the selection when it expands
the macro, but it currently does not do this. Have a try with the current
GExperts CVS code. Test with the following code where the selection is the
two assignment lines including the newline after "20;":
procedure TForm1.FormCreate(Sender: TObject);
begin
i := 10;
j := 20;
end;
The output is this:
procedure TForm1.FormCreate(Sender: TObject);
begin
i := 10;
j := 20;
try
i := 10;
j := 20;
finally
|
end;
end;
In a very literal sense this is the correct output, though I doubt it is
what you would prefer in your case, since the assignments are duplicated.
If you instead use %CLIPBOARD%, cut the selection, and space over twice on
the empty line before executing, you get this which is much closer to what
you want:
procedure TForm1.FormCreate(Sender: TObject);
begin
try
i := 10;
j := 20;
finally
|
end;
end;
The only remaining issue would be the spacing. In a very literal sense,
the spacing is "correct", but obviously it is not how you would want things
in your case. The spacing could be fixed though by removing two spaces
from the macro itself.
Quote
Can "%SELECTION%" not be used with more then one line??
Yes, but the usefulness depends on your needs. Should the expert always
delete the selected text when a macro expands? The answer would depend on
how users use this tool, and I don't think I have a good idea of that yet.
You have provided one data point. If you can make a convincing case that
your situation would be the general case that most users would expect, it
might be something we can change. The same goes for the spacing issue. If
someone can come up with a well-defined rule that seems to make all/most of
the common cases work as expected, that could be changed as well.
A problem is almost inherent in the usage of %SELECTION% - namely that
the end of the selection must simultaneously indicate two things (in the
default keybinding at least): the extent of the replace string for
%SELECTION% and the insertion point for the generated macro text. Often
the desired behavior is to not have these two items be the same row/column,
so another macro (like CLIPBOARD) would work better, since it decouples the
text insert and selection end positions.
Erik
 

Re:OT (?): GExperts: %BEFORE% macro?

"Erik Berry" <XXXX@XXXXX.COM>schrieb im Newsbeitrag
Quote
This expert is fairly literal with respect to the output it produces. I
believe you are expecting the tool to delete the selection when it expands
the macro, but it currently does not do this.
Hello,
yes you are right, that is exactly what i expected!
Quote
Have a try with the current
GExperts CVS code. Test with the following code where the selection is
the
two assignment lines including the newline after "20;":

OK, i will try it.
Quote
In a very literal sense this is the correct output, though I doubt it is
what you would prefer in your case, since the assignments are duplicated.
If you instead use %CLIPBOARD%, cut the selection, and space over twice on
the empty line before executing, you get this which is much closer to what
you want:

for the moment i could live with the %CLIPBOARD% solution ...
Quote
The only remaining issue would be the spacing. In a very literal sense,
the spacing is "correct", but obviously it is not how you would want
things
in your case. The spacing could be fixed though by removing two spaces
from the macro itself.

Spacing or formatting would not be the problem (for me) as i am using a
source formatter that would correct this.
Quote
>Can "%SELECTION%" not be used with more then one line??

Yes, but the usefulness depends on your needs. Should the expert always
delete the selected text when a macro expands? The answer would depend on
how users use this tool, and I don't think I have a good idea of that yet.
You have provided one data point. If you can make a convincing case that
your situation would be the general case that most users would expect, it
might be something we can change. The same goes for the spacing issue.
If
someone can come up with a well-defined rule that seems to make all/most
of
the common cases work as expected, that could be changed as well.
What about leaving the %SELECTION% macro as it is and add another one that
deletes the selected text on expanding? So everyone could decide which one
to use.
Thanks for your hints.
Bye,
Ralf