|
Hi NGS,
There are a couple of languages here. One is VBScript, the macro's language. The other is Regular Expressions, the language used to do complex searches, passed to methods like Find and Replace.
You can get info on these languages from many different places. There's at least a couple of articles here at CP about Regular Expressions (do a Search). The \:b+ notation, however, I believe is a Microsoft-specific shortcut for "one or more characters containing whitespace".
If you bring up the Find box on DevStudio you can click on the little right-arrow next to the Find button to see many of the available symbols, including the Microsoft ones.
Regards,
Alvaro
Insanity: doing the same thing over and over again and expecting different results. - Albert Einstein
|
|
|
|
|
How can I add your macros to VS.NET environment?
|
|
|
|
|
there is still the error in line 393. It will create a type mismatch error depending on the definition of the decimal sign on your machine.
It should read:
nLastLine = CInt(Mid(strPos, 1, iPos - 1))
instead of: nLastLine = CInt(Mid(strPos, 1, iPos))
kind regards
|
|
|
|
|
Thanks henning. I've made the change for the next update.
Regards,
Alvaro
Insanity: doing the same thing over and over again and expecting different results. - Albert Einstein
|
|
|
|
|
If you have a line like this
nResult = csLine.Find(',',nStart);
it is reformated like this
nResult = csLine.Find(', ', nStart);
This only happens if there is another comma following the ',' constant. The case
nResult = csLine.Find(',');
works fine.
Dirk
|
|
|
|
|
Dirk,
I found the problem and took care of it. It will be out on the next version, which I've just sent to Chris.
Thanks!
Alvaro
Insanity: doing the same thing over and over again and expecting different results. - Albert Einstein
|
|
|
|
|
Alvaro
first up great macro I find it very handy.
Recently I reinstalled to a new (to me) machine and had to reinstall all the add-ins and macros I use.
I went into Tools -> Cutomize and selected the Add-ins and Macro Files tab to select the ReformatCode macro. While here I noticed the Description that appeared for each macro highlighted, except for yours.
I compared your macro to one of the supplied macros and noticed that you had used a space between the ' at the beginning of the comment line and the comments that followed. I removed this space and your description now appears in the dialog box.
I have included the corrected comment block below incase my description is more confusing than helpful in tracking down what I mean.
'----------------------------------------------------------
'FILE DESCRIPTION: Routines to reformat C/C++ source code.
'Created by Alvaro Mendez - June 10, 1999
'Last Updated: April 9, 2001
'----------------------------------------------------------
Michael Martin
Australia
mjm68@tpg.com.au
"In Summer, I like to dance naked on the roof to celebrate the event of the temperature finally falling below 40C (usually about midnight). But the neighbors have lately taken up the habit of staying up late. And looking up, at times, from their dreary, pointless lives..."
- Roger Wright 15/05/2002
|
|
|
|
|
Thanks for catching that Martin.
I've taken care of that, along with a couple of other issues that were pending. I've just sent the update to Chris, so you should expect it here shortly.
Thanks again,
Alvaro
Insanity: doing the same thing over and over again and expecting different results. - Albert Einstein
|
|
|
|
|
These macros have saved me a TON of time and frustration!! I appreciate your contribution to the development community..
|
|
|
|
|
It's good to know that the time I've spent writing and maintaining this macro has saved others a lot of time.
But what's really driven me to have spent so much time on it is the sheer joy of running the thing. It's just sweet to watch ugly code transform into nicer code right before my eyes in a matter of seconds.
Regards,
Alvaro
PS. I've also found it quite handy on ugly Java and JavaScript code.
Insanity: doing the same thing over and over again and expecting different results. - Albert Einstein
|
|
|
|
|
Hi,
It looks like IsWithinComment subroutine is not aware of c-style comments (/* */) Is it the case? Could you please fix that?
Thanks,
Igor Proskuriakov
|
|
|
|
|
Igor,
Yes, that's the case, this macro does not account for C-style comments. The reason (or excuse, perhaps ) is that it's very difficult to accurately detect where such comments begin and end, and then keep track of their locations for every subsequent change. With C++ comments, it's easy. The comment goes to the end of the line. C-style comments can go for one or more lines and accounting for them is not something I thought would merit my time and effort.
On the plus side, if a block of code has been commented in C-style, it will also get reformatted, which is often a good thing.
Regards,
Alvaro
Insanity: doing the same thing over and over again and expecting different results. - Albert Einstein
|
|
|
|
|
This line:-
;for(;; );
Gets changed to:-
; f
or (;; )
;
Strange but true...
|
|
|
|
|
Man, I don't know what's stranger, my macro not properly formatting this code or the code itself.
I took a look at why this happens and found the problem. It'll be fixed on the next version, coming up soon.
Thanks,
Alvaro
Insanity: doing the same thing over and over again and expecting different results. - Albert Einstein
|
|
|
|
|
The macro changes
#define CHECK(xml, hr) \
if( FAILED(hr) ) {\
addFault(xml, hr); \
}
to
#define CHECK(xml, hr) \
if (FAILED(hr))
{
\
addFault(xml, hr); \
}
which the compiler isn't nearly as happy with
Niels Harremoës
|
|
|
|
|
Yup, unfortunately the macro does not distinguish between real code and code inside multi-line #defines. I haven't given it much thought but I suppose it could account for such code by simply checking the last character in the line. If it's a backslash, then the line shouldn't be touched.
Let me look into it and I'll try to post an update sometime next week.
Thanks,
Alvaro
|
|
|
|
|
A week later.... or more like a year later.
I've just taken care of this issue and sent it to Chris for an update, so you may expect it soon.
Thanks for reporting it and being patient.
Regards,
Alvaro
Insanity: doing the same thing over and over again and expecting different results. - Albert Einstein
|
|
|
|
|
There is still a little problem with multiline macro's
#define THEMACRO \
if (x!=y) x = y;
changes to
#define THEMACRO \
if (x != y)
x = y;
I think instead of checking the end of the current line for '\' and
checking for '#define' should be replaced with checking for '#define' in the current line and checking for '\' at the end of the previous line.
thanks for your great work
michael
|
|
|
|
|
I am new to this macro thing. Can anyone suggest how I might change this one to put the right bracket on the same line as the function definition?
Thank You
|
|
|
|
|
I just want to make a small comment on the MyFunc() { style:
IT SUCKS!
Having said that, if you still want to make it happen, the easiest way is to do it for ALL opening braces. Here are the steps I would follow:
1. Loop through every opening brace (not inside a comment or quoted string)
2. Select from the beginning of the line to the brace.
3. If the selection only contains blankspace,
- Delete it, and
- Backspace to the previous line.
4. Go back to step 2 until step 3 fails.
Remember to account for comments and quoted strings. Check the macro's code to see how I do it.
Regards,
Alvaro
Insanity: doing the same thing over and over again and expecting different results. - Albert Einstein
|
|
|
|
|
Alvaro Mendez wrote:
I just want to make a small comment on the MyFunc() { style:
IT SUCKS!
I agree.
|
|
|
|
|
Alvaro Mendez wrote:
IT SUCKS!
I agree, it really sucs!!!
Best regards,
Alexandru Savescu
|
|
|
|
|
Hi
I read posts about deleting files. It also happened to me. However, when I reopened Visual Studio, everything worked great.
Probably this is something similar to the problem when Visual studio looses clipboard.
And also a different problem, I could not format the following code properly
#pragma warning(disable : 4786)
#pragma warning(disable : 4503)
#include <iostream.h>
int main()
{
if (abc) test();
else test3();
A test;
test.i =5;
cout << test.nick << endl;
return 0;
}
Igor Proskuriakov
|
|
|
|
|
Thanks for the excellent work.
I have found a problem in nested switch statement. It seems that lost the nesting depth.
The code bellow is my unfinished working code.
Note: notice that the spaces are lost in mail, I have replaced "tab" character to "+".
Also, If I want to keep the style as shown in original, how do I do?
Thanks,
// ====== Original ===========================================
BOOL CALLBACK
BioDataProc (HWND hdlg, UINT msg, WPARAM wp, LPARAM lp)
{
switch(msg)
{
case WM_INITDIALOG:
PostMessage(hdlg, WM_USER, 0, 0);
return TRUE;
case WM_COMMAND:
switch(LOWORD(wp))
{
case IDM_BIO1:
case IDM_BIO2:
break;
}
break;
case WM_NOTIFY:
switch(((NMHDR FAR*)lp)->code)
{
case PSN_APPLY:
{
}
return TRUE;
case PSN_HELP:
DisplayHelp();
break;
}
break;
case WM_USER:
break;
case WM_ACTIVATE:
}
return FALSE;
}
// ====== After MakeSelectedCodeNicer =====================
BOOL CALLBACK
BioDataProc(HWND hdlg, UINT msg, WPARAM wp, LPARAM lp)
{
+switch (msg)
+{
++case WM_INITDIALOG:
+++PostMessage(hdlg, WM_USER, 0, 0);
+++return TRUE;
++case WM_COMMAND:
+++switch (LOWORD(wp))
+++{
+++case IDM_BIO1:
+++case IDM_BIO2:
++++break;
+++}
+++break;
+++case WM_NOTIFY:
++++switch (((NMHDR FAR*)lp)->code)
++++{
++++case PSN_APPLY:
+++++{
+++++}
+++++return TRUE;
++++case PSN_HELP:
+++++DisplayHelp();
+++++break;
++++}
++++break;
++++case WM_USER:
+++++break;
++++case WM_ACTIVATE:
+}
+return FALSE;
}
|
|
|
|
|
I use this macro to reformart some files,but when run to this line the marco behave unconventionally.Who can help me ?
if (ads_entsel("\nSelect baseline: ",ent1,pt) == RTNORM)
if you want test,you can new a text file and run the macro to test.In my machine ,the line is like the following(after I cancel the macro):
if (ads_entsel("\n选择基线: ",ent1 ,pt) == RTNORM)
Thanks a lot!
|
|
|
|