Topic: Match_Paren() (1 of 41), Read 192 times
Conf: VEDIT Macro Language Support
From: Pauli Lindgren
Date: Tuesday, September 12, 2000 09:19 AM

I was trying to do a macro that uses Match_Paren() command to match the parenthesis:


repeat(ALL) {
search('|P',ERRBREAK)
if (Match_Paren() == 0) {
Statline_Message("** No matching parrenthesis! **")
Return
}
Match_Paren()
char()
}

The problem is that if a match is not found, an error message dialog box is displayed and the macro execution stops. I want to do the error handling inside the macro and then continue the operation.
If I use Match_Paren(NOERR), the error message dialog box is not displayed, but the execution does not go inside the if() either, as if there was no error at all.

How can I handle the error within the macro?

 


Topic: Match_Paren() (2 of 41), Read 187 times
Conf: VEDIT Macro Language Support
From: Christian Ziemski
Date: Tuesday, September 12, 2000 10:56 AM

For me your code works (using Match_paren(NOERR)).

Maybe we are using different versions of VEDIT...

But you can try:

Match_Paren(NOERR)
if(Error_Match) {
Statline_Message("** No matching parrenthesis! **")
Return
}


Christian

 


Topic: Match_Paren()in VEDIT 5.20.4 (3 of 41), Read 175 times
Conf: VEDIT Macro Language Support
From: Peter Rejto
Date: Saturday, December 09, 2000 02:45 PM

Pauli,
I have tried your macro in my Vedit 5.20.4 and this is what I got if it could not a find a parenthesis. That is to say, when it found an orphaned parenthesis:
1. It moved the cursor to the orphaned parenthesis.
2. Displayed on the Stat_Line your error message.
3. It exited the macro.

Do I understand it correctly: This is different from your experience inasmuch as I did not get an error dialog box.

For my short .vdm files your simple macro is a great help. Thank you very much.

For my long .tex files your simple macro is a help, but here I would like to have more options. I would like to have something like the WILDFILE.VDM "Enter desired options" section. Since this is a sophisticated file and since we are in the middle of finals, I have no chance to study it now.
Incidentally are these options related to your technical question of running your macro within the "if" part. Sorry, I can not quote you verbatim since I do not know how to get into your original message.

I noticed that the webborad gives us the option of sending the message to somebody's attention. I do hope that Christian will read this part and he will help me out as usual concerning the adaptation of the "Enter desired options" section of WILDFILE.VDM.
At the same time I would like to have the reaction of Fritz, who is a TeX power user.

Thanks, and looking forward to hearing from you gentlemen.

-peter.

 


Topic: Re: Match_Paren()in VEDIT 5.20.4 (4 of 41), Read 175 times
Conf: VEDIT Macro Language Support
From: Christian Ziemski
Date: Saturday, December 09, 2000 03:52 PM

Peter:

Sorry, but your posting is a bit confusing. Without context it's hard
to read.

1) Please don't change the subject within a thread, otherwise we
mailinglist users don't have a thread any more ...
(And have to search our database manually for the eventually related
posting.)

2) You wrote:
>Sorry, I can not quote you verbatim since I do not know how to
>get into your original message.

Why not "Reply with quote"?

Or copy&paste the relevant text parts to your posting and edit them
manually.

Sorry for those words but if you want to get help you shouldn't make
it so difficult for the readers. ;-)


But now to the technical and 3)rd item:

What exactly do you want the macro to do??

VEDIT's online help says much about Match_Paren():

Match_Paren(NOERR) Suppress the error message in case of an
unsuccessful search for the matching
(or next) parenthesis.

Match_Paren(ERRBREAK) Performs a "Break" out of any command loop in
case of an unsuccessful search.

Return: Return 2 if the matching parentheses was found.
Return 1 if the next parentheses character was found.
Return 0 if it was not successful.

Error_Flag and Error_Match are set if the search is
not successful.

==> Note the different return codes (They are relatively new).


And what kind of additional options do you think of?


Christian


PS: Hopefully my posting isn't confusing to you. ;-)

 


Topic: Re: Match_Paren()in VEDIT 5.20.4 (5 of 41), Read 174 times
Conf: VEDIT Macro Language Support
From: Peter Rejto
Date: Sunday, December 10, 2000 01:23 AM

On 12/9/2000 3:52:56 PM, Christian Ziemski wrote:
>Peter:

2) You wrote:
>Sorry,
>I can not quote you verbatim since I do
>not know how to
>get into your original
>message.

Why not "Reply with
>quote"?

Thanks Christian, I overlooked this option.
Now that you pointed it out, I see how useful and simple it is!

Or copy&paste the relevant text
>parts to your posting and edit
>them
manually.

I am trying the copy&paste part right now:


Message("
[1] Run WILDFILE again
[2] Exit macro, return to VEDIT
[3] Exit VEDIT (save/abandon files)

Enter desired option: ")

while ( (#70=Get_Key(""))<'1' || #70>'3' ) { ) } //Get valid reply
Char_Dump(#70)

if (#70=='1') { Chain(#80) }
if (#70=='3') { Exit() Chain(#80) }


This paste is from the WILDFILE.VDM and this is what I would like to do: In option [1], I would like to replace "Run WILDFILE again" by "Run MATCH_PAREN" again. I would like to leave options [2] and [3] unchanged.

Thanks again for the "copy&paste" suggestion!
Please note that this message goes from a Win98 operating system via a linux operating system to you. I still find it amazing that I can "copy&paste" just the way I do it on my local pc. I really appreciate your pointing this out to me.

THANKS & THANKS & THANKS,
-peter.

 


Topic: Re: Match_Paren()in VEDIT 5.20.4 (6 of 41), Read 168 times
Conf: VEDIT Macro Language Support
From: Peter Rejto
Date: Sunday, December 10, 2000 09:56 AM

Christian,

I just noticed that in my previous reply I stopped short of formulating a self-contained question. So, here are the two macro segments that I would like to paste together.

The first one is Pauli's Match_Paren macro:


repeat(ALL) {


search('|P',ERRBREAK)


if (Match_Paren() == 0) {


Statline_Message("** No matching parrenthesis! **")


Return


}

The second one is the "Enter desired options" segment of WILDFILE.VDM:

Message("
[1] Run WILDFILE again
[2] Exit macro, return to VEDIT
[3] Exit VEDIT (save/abandon files)

Enter desired option: ")

while ( (#70=Get_Key(""))<'1' || #70>'3' ) { ) } //Get valid reply
Char_Dump(#70)

if (#70=='1') { Chain(#80) }
if (#70=='3') { Exit() Chain(#80) }


----------------------------

I did look up the meaning of (#80) in the WILDFILE.VDM preamble.This is what I got:

// #80 T-Reg # containing this macro

I also looked up Chain(r) in the online help, where the argument "r" refers T-reg r. Since my present argument is a Numeric Register I am stuck.

------------------------------

Thanks again,

-peter.

 


Topic: Re: Match_Paren()in VEDIT 5.20.4 (8 of 41), Read 167 times
Conf: VEDIT Macro Language Support
From: Christian Ziemski
Date: Sunday, December 10, 2000 11:10 AM

Ooops, now after sending my other answer I got that from you:

On Sun, 10 Dec 2000 09:42:32 -0500, you wrote:

>I just noticed that in my previous reply I stopped short of formulating =a self-contained question. So, here are the two macro segments that I =would like to paste together.
[....]

Not so easy to synchronize ... ;-)


Maybe you can formulate the whole task? See my mentioned other answer.


Christian

 


Topic: Re: Match_Paren()in VEDIT 5.20.4 (7 of 41), Read 169 times
Conf: VEDIT Macro Language Support
From: Christian Ziemski
Date: Sunday, December 10, 2000 11:06 AM

O.k. that's the options you want if the macro finds an orphaned
parenthesis:

>[1] Run Match_Parenthesis again
>[2] Exit macro, return to VEDIT
>[3] Exit VEDIT (save/abandon files)

But it's not clear what that should result in.


In pseudo code I think (up to now) you want that:

check the whole text{
Match_Parenthesis
if( no matching parenthesis found){
show error message
give options menu
behave like the desired option
}
forward to next parenthesis
}

Wouldn't it be easier to assign such a macro (without options dialog)
to a key and press that key to find an orphaned parenthesis, fix it
and press the key again until there is no more single parenthesis?


You can see:
It is extremly important to describe as exact as possible what you
want to do.
Otherwise we have to guess what you want.
And that's very likely not the same.


Christian

 


Topic: Re: Match_Paren()in VEDIT 5.20.4 (9 of 41), Read 168 times
Conf: VEDIT Macro Language Support
From: Peter Rejto
Date: Sunday, December 10, 2000 05:53 PM

On 12/10/2000 11:06:50 AM, Christian Ziemski wrote:

Wouldn't it be
>easier to assign such a macro
>(without options dialog)
>to a
>key and press that key to find
>an orphaned parenthesis, fix
>it
and press the key again
>until there is no more singe
>parenthesis?

Yes Christian, this would be easier indeed!
In other words, I have asked the wrong question! To my untrained eyes the pasting of these two macro segments looked like a straightforward adaptation. But apparently it
is not!

In the meantime I changed my question. I thought to issue a
Set_Marker(0,Cur_Pos)
command and then Goto say, :COUNTER1:, where
a
Set_Marker(1,Cur_Pos)
command is issued. And so on, say up to 10.
If I figure this one out, it would be a very slight improvement of your previous
suggestion. The only reason why I thought about it, is that on my Sabbatical I have used Emacs on a unix machine. I vaguely remember that the Emacs Match_Paren command is similar to this. I also wanted to have an idea, how difficult it is to port an Emacs command into Vedit.
Well, there is no need for you to answer my question. I take that you look for orphaned parentheses as per your suggestion.

Thank you very, very, much again. I learned
something.

-peter.

 


Topic: Re: Match_Paren()in VEDIT 5.20.4 (10 of 41), Read 165 times, 2 File Attachments
Conf: VEDIT Macro Language Support
From: Christian Ziemski
Date: Monday, December 11, 2000 08:02 AM

Peter:

Here are two macros I wrote on the fly to show you some possibilities.

1) SHOWPAREN.VDM to show the behaviour of Match_Paren(). Such simple macros are very helpful to understand more difficult ones.
Most of my macros are born from such first tries.

2) CHECKPAREN.VDM to check a whole file.
Please read the inline comments of this macro! They are giving more details!

Christian

 
SHOWPAREN.VDM (1KB)
 
CHECKPAREN.VDM (3KB)

 


Topic: Re: Match_Paren()in VEDIT 5.20.4 (15 of 41), Read 156 times
Conf: VEDIT Macro Language Support
From: Peter Rejto
Date: Monday, December 11, 2000 01:18 PM

On 12/11/2000 8:02:00 AM, Christian Ziemski wrote:
>Peter:
>
>Here are two macros I wrote on the fly
>to show you some possibilities.
>
>1) SHOWPAREN.VDM to show the behaviour
>of Match_Paren(). Such simple macros are
>very helpful to understand more
>difficult ones.
>Most of my macros are born from such
>first tries.
>
>2) CHECKPAREN.VDM to check a whole file.
>Please read the inline comments of this
>macro! They are giving more details!
>
>Christian

Thanks Christian,
I have downloaded them and I shall study them right away.

-peter.

 


Topic: Re: Match_Paren()in VEDIT 5.20.4 (29 of 41), Read 132 times
Conf: VEDIT Macro Language Support
From: Peter Rejto
Date: Tuesday, December 12, 2000 01:57 PM

On 12/11/2000 8:02:00 AM, Christian Ziemski wrote:
>Peter:
>
>Here are two macros I wrote on the fly
>to show you some possibilities.
> ....

>2) CHECKPAREN.VDM to check a whole file.
>Please read the inline comments of this
>macro! They are giving more details!
>
>Christian

Christian,

1. I am very enthusiastic about your CHECKPAREN.VDM macro: I do prefer to run macros from a menu versus the keyboard. Having said that, let me compare your original suggestion with your present macro. Your original suggestion was, to run the original Pauli Lindgren macro from the keyboard. This requires memorizing an additional key assignment. In your present
macro this additional key is, essentially, the Ctrl_E key. (Here, essentially, refers
to the fact that certain conditions have to be met.) In other words, I have the gain of one less key assignment to memorize.This is exactly that I was after !

2. At the same time I can use your macro as a personalized tutorial for switching
in and out of Visual Mode. In fact, I just learned that Ctrl-E is, essentially, ESCAPE C. (I do not know the exact conditions)


3. > Peter:
>Here are two macros I wrote on the fly to show you some possibilities.


Yes Christian, there are infinitely many possibilities. Do I have a single favorite
among them? No, I do not. One of my favorites is your present macro. The other favorite
would be the one emulating, as closely as possible, the XEmacs "validate-tex-region" macro.
Oops, TeX is not the subject of this conference. So, I am going to post this question
in the Vedit User Applications conference, under the topic: Match_Paren and TeX syntax.

4. Hair splitting: The Vedit default definition of "parentheses" includes the
"<,>" pair, as per the MATCH_PAREN string. I did not see a redefinition of this string
in your macro. I take that your macro will check for this pair as well. Since I plan
to use your macro for my TeX files, I thought to start it with the line,
Config_String( MATCH_PAREN, "[][()([][{}{") .
I also thought to rename it to CHECKBRACES.VDM, since the XEmacs manual defines braces
, so to speak, as "parentheses minus <". They also "check for unbalanced braces" so I
shall possibly make other stylistic changes as well.


Thanks again for everything,

-peter.


P.S. I wrote this answer on my home pc. I just learned about the new developments.
Thanks for everything gentlemen!

 


Topic: Re: Match_Paren()in VEDIT 5.20.4 (30 of 41), Read 112 times
Conf: VEDIT Macro Language Support
From: Christian Ziemski
Date: Wednesday, December 13, 2000 04:30 AM

> I do prefer to run macros from a menu versus the keyboard.

The USER or TOOLS menus are easy to use for that purpose.


> In fact, I just learned that Ctrl-E is, essentially, ESCAPE C.

No!
Ctrl-E is ESCAPE E or [VISUAL EXIT]
and Alt-F10 is ESCAPE C or [VISUAL ESCAPE]

[VISUAL EXIT] : jumps to command mode back into the eventually running macro
[VISUAL ESCAPE] : jumps to command mode with stopping an eventually running macro


> 4. Hair splitting: The Vedit default definition of "parentheses" includes the
> "<,>" pair, as per the MATCH_PAREN string. I did not see a redefinition of this string
> in your macro. I take that your macro will check for this pair as well.

No, first it did that, but my texts to check are mostly C code with many '<' and '>'
in the meaning "less than" and "greater than" and are therefore not balanced.
That gave too many false error messages running my macro.
So I decided to remove them.

But it should be no problem for you to include them again. ;-)


Christian

 


Topic: Re: Match_Paren()in VEDIT 5.20.4 (39 of 41), Read 45 times
Conf: VEDIT Macro Language Support
From: Peter Rejto
Date: Sunday, April 21, 2002 08:35 PM

Christian,

Your CHECKPAREN.VDM macro just caught a subtle typo of mine:

({eq:1.92)}; it should be ({eq:1.92}).

I just thought that other Vedit users might find your macro useful as well.

Last but not the least: A big thank you to Pauli for starting this discussion on parentheses! I have learned an awful lot from the exchanges between the two of you!

One of the things I learned from these exchanges is that there are at least two ways in which I can "match parentheses": "with or without nesting".

I tried to define for my own benefit, what does it mean that a left curly brace and a right curly brace match each other. I could not give such a definition. Nevertheless, I am confident that if you give me an example I can figure it out.(As long as your example is not too tricky.) I have a hunch that there is a whole library of computer science books studying such questions.

My intuitive feeling is that your macro picks out all of the unnested orphaned parentheses and some but not all of the nested orphaned ones.

Finally, let me ask a more specific question. Would it be possible to restrict the matching parentheses process to a given range of the file? Similarly to the way I can restrict the Search() command to a given range.

Until then, I can paste and copy a nested parentheses to a new file. There I would eliminate the outer parentheses and invoke your macro again.


Thanks again,

-peter

 


Topic: Re: Match_Paren()in VEDIT 5.20.4 (41 of 41), Read 36 times
Conf: VEDIT Macro Language Support
From: Christian Ziemski
Date: Tuesday, April 23, 2002 03:52 PM

Peter:

On Sun, 21 Apr 2002 20:36:49 -0400, you wrote:

>...
>Finally, let me ask a more specific question. Would it be possible to
>restrict the matching parentheses process to a given range of the file?
>Similarly to the way I can restrict the Search() command to a given =range.

Of course that should be possible.
Just check if there is a block marked. If that's the case use
Block_Begin and Block_End instead of BoF and EoF ...

Unfortunately you are continuing a very old thread here and I don't
have the time to go through all the thoughts again now. Sorry.

Christian

 


Topic: Re: Match_Paren()in VEDIT 5.20.4 (13 of 41), Read 161 times
Conf: VEDIT Macro Language Support
From: Ted Green
Date: Monday, December 11, 2000 11:50 AM

At 05:40 PM 12/10/2000 -0500, you wrote:
>Yes Christian, this would be easier indeed!
>In other words, I have asked the wrong question! To my untrained eyes the pasting of these two macro segments looked like a straightforward adaptation. But apparently it is

Although the Wildfile macro is one of VEDIT's most useful features, it is a very difficult macro to understand and modify.

Ted.

 


Topic: Match_Paren()in VEDIT 5.20.4 (11 of 41), Read 164 times
Conf: VEDIT Macro Language Support
From: Fritz Heberlein
Date: Monday, December 11, 2000 09:49 AM

On 12/9/2000 2:45:00 PM, Peter Rejto wrote:
>At the same time I would like
>to have the reaction of Fritz,
>who is a TeX power user.

Hihi,
i'm lucky that real Tex gurus around here can't read that..

Anyway, I'm afraid i have nothing to comment here
since my personal "solution" is obvious and simple:
place a "{" at the begin and an "}" at the end of your *.tex file and press shft-f3 (or whatever key(s) you have assigned to match_paren). If it matches everything is ok. If not, the cursor will stop at the lonely (how did you call it? orphaned? widowed? bachelored?) "{".

BTW,
i think you are aware of the large range of TeX syntax checkers available at the CTAN.

Fritz

 


Topic: Re: Match Paren()in VEDIT 5.20.4 (12 of 41), Read 167 times
Conf: VEDIT Macro Language Support
From: Christian Ziemski
Date: Monday, December 11, 2000 10:11 AM



> since my personal \"solution\" is obvious and simple:
> place a \"{\" at the begin and an \"}\" at the end of your *.tex file and press > shft-f3 (or whatever key(s) you have assigned to match_paren).
> If it matches everything is ok.
> If not, the cursor will stop at the lonely \"{\".

Good idea! But are you sure?
I tried that with no luck...


Christian

 


Topic: Re: Match Paren()in VEDIT 5.20.4 (14 of 41), Read 171 times
Conf: VEDIT Macro Language Support
From: Fritz Heberlein
Date: Monday, December 11, 2000 11:59 AM

> > since my personal \"solution\" is obvious and simple:
> > place a \"{\" at the begin and an \"}\" at the end of your *.tex
> > file and press > shft-f3 (or whatever key(s) you have assigned to
> > match_paren). If it matches everything is ok. If not, the cursor
> > will stop at the lonely \"{\".
>
> Good idea! But are you sure?
> I tried that with no luck...

Well,
you have to try it from both sides: a missing "}" can be found from
EOF, a missing "{" from BOF (rather unestetic procedure, i have to
admit, but it works).

Fritz



Dr. Friedrich Heberlein, Akad. Direktor
Seminar f. Klassische Philologie, KU Eichstaett
D-85071 Eichstaett / Bayern
Tel. +49 8421 931544
Fax +49 93 1797
Email sla019@...
http://www..../SLF/Klassphil/home.htm

 


Topic: Re: Match Paren()in VEDIT 5.20.4 (22 of 41), Read 157 times
Conf: VEDIT Macro Language Support
From: Christian Ziemski
Date: Tuesday, December 12, 2000 05:17 AM

Hi Fritz,

can you please try your checking with that code:

{ // frame for checking

if(#99==1) {
repeat(ALL){
{ // unbalanced
( // unbalanced

if(#98==0) { break }

}
}

} // frame for checking



That's one of my problem cases... ;-)

Christian

 


Topic: Re: Match Paren()in VEDIT 5.20.4 (25 of 41), Read 153 times
Conf: VEDIT Macro Language Support
From: Fritz Heberlein
Date: Tuesday, December 12, 2000 08:13 AM

To: (Recipients of 'vedit-macro-language' suppressed)
From: "vedit-macro-language Listmanager"
Subject: Re: Match Paren()in VEDIT 5.20.4
Send reply to: "VEDIT Macro Language Support"
Date sent: Tue, 12 Dec 2000 05:03:56 -0500

> From: "Christian Ziemski"
>
> Hi Fritz,
>
> can you please try your checking with that code:

That's one of my problem cases... ;-)

Christian,
this doesn't work for me either.
But, of course, when preparing a TeX document, you hardly will run
into a situation like that (hopefully).
Nontheless, a more sophisticated solution would me most welcome.

Fritz

 


Topic: Re: Match Paren()in VEDIT 5.20.4 (26 of 41), Read 153 times
Conf: VEDIT Macro Language Support
From: Christian Ziemski
Date: Tuesday, December 12, 2000 08:35 AM

>this doesn't work for me either.
>But, of course, when preparing a TeX document, you
>hardly will run into a situation like that

Aha! I don't know TeX syntax.

>Nontheless, a more sophisticated solution
>would me most welcome.

I tried it with CHECKPAREN.VDM

But it seems to be impossible with normal expense. The macro nearly must be Artificial Intelligence to do that.
Or one has to write a macro for every language(syntax).
That is nothing different than a parser like in an interpreter/compiler then ...

It's a too big project for now.


Christian

 


Topic: Re: Match Paren()in VEDIT 5.20.4 (28 of 41), Read 151 times
Conf: VEDIT Macro Language Support
From: Fritz Heberlein
Date: Tuesday, December 12, 2000 08:57 AM

>
> I tried it with CHECKPAREN.VDM

Sorry Christian, i had overlooked that. For TeX files it works as fine as
Pauli's. So, the solution for Peter's problem definitely is here. Nice that
one doesn't need to shell out to an external latex syntax checker any
more ...
Fritz

 


Topic: Re: Match Paren()in VEDIT 5.20.4 (33 of 41), Read 90 times
Conf: VEDIT Macro Language Support
From: Peter Rejto
Date: Friday, December 15, 2000 02:24 AM

On 12/12/2000 5:17:00 AM, Christian Ziemski wrote:
>Hi Fritz,
>
>can you please try your
>checking with that code:
>
>{ //
>frame for checking
>
>if(#99==1) {
> repeat(ALL){
>{ //
>unbalanced
>( //
>unbalanced
>
> if(#98==0) { break }
>
> }
>}
>
>} //
>frame for checking
>
>
>
>That's one of my problem
>cases... ;-)
>
>Christian

Hi Christian,

Do I understand your counter example correctly? Your macro may not work for nested parentheses? In any case, I did some experiments with nested parentheses. Specifically, following Fritz's suggestion I inserted the diagnostic "{" at the beginning of the file. Then I used Ctrl-]. As long as I had a single "{", this worked fine. However, if I had two of them, i.e. when they were nested, the Ctrl-] key no longer worked for me. Is this the way the Ctrl-] key is supposed to work? Can you reproduce this?

I also tried to put Fritz's suggestions into a macro, which I am enclosing. The macro did not work for me. However, if I ran the macro once and then the :TEST: submacro, then the cursor was moved to the pair of the diagnostic "{". In other words to an unbalanced "}".
I also have trouble with the Statline_Message.

Thanks again,

-peter.

--------------------
//FRITZ.VDM
//
//
:CURLY-BRACES:
Begin_Of_File
Ins_Char(10)
Ins_Char(13)
Begin_Of_File
Ins_Char(37)
Ins_Char(123)
Begin_Of_File
Char()
#98=Cur_Pos
#97=Cur_Char
Sound(440,1200,EXTRA)
Match_Paren(NOERR)
if (Return_Value != 2) {Statline_message("The {-braces are OK")}
else {Statline_message("CUR at unbalanced brace.")}
End_Of_File
Ins_Char(37)
Ins_Char(125)
Char(-1)
Match_Paren(NOERR)
if(Return_Value != 2){Statline_message("The }-braces are OK")}
else{Statline_message("CUR at unbalanced brace.")}
Return
//
:TEST:
Begin_Of_File
Char()
Sound(440,1200,EXTRA)
Match_Paren(NOERR)
if (Return_Value != 2) {Statline_message("The {-braces are OK")}
else {Statline_message("CUR at unbalanced brace.")}
Return

 


Topic: Re: Match Paren()in VEDIT 5.20.4 (36 of 41), Read 87 times
Conf: VEDIT Macro Language Support
From: Christian Ziemski
Date: Friday, December 15, 2000 11:30 AM

Peter,

sorry, but I must end the Match_Braces discussion here *for*me*.
It's too time consuming.

Other problems like your Statline_Message are still welcome.
Please describe your problem in some words.
"I also have trouble" isn't clear enough.


Christian

 


Topic: Match_Paren()in VEDIT 5.20.4 (16 of 41), Read 162 times
Conf: VEDIT Macro Language Support
From: Peter Rejto
Date: Monday, December 11, 2000 04:03 PM

On 12/11/2000 9:49:00 AM, Fritz Heberlein wrote:

>Anyway, I'm afraid i have nothing to
>comment here
>since my personal "solution" is obvious
>and simple:
>place a "{" at the begin and an "}" at
>the end of your *.tex file and press
>shft-f3 (or whatever key(s) you have
>assigned to match_paren). If it matches
>everything is ok. If not, the cursor
>will stop at the lonely (how did you
>call it? orphaned? widowed? bachelored?)
>"{".
>

Fritz,
Thanks for your solution to the orphaned parentheses task. It is indeed simple.

At present I have a slight bias against it: I do not trust myself to insert the diagnostic "{" at the begin ..... of my tex file. I am absent minded mathematician and if I forget to erase it, I am in real trouble.

I take it would be easy to write a macro to this insertion and deletion. So I am thinking in terms of a simple Heberlein macro for this task orphaned parentheses task. Actually, the original Pauli Lindgren macro is also very simple. In fact, I would appreciate your looking at this macro at the beginning of this topic.

Looking forward to hearing your reactions.
-peter.

 


Topic: Match_Paren()in VEDIT 5.20.4 (17 of 41), Read 162 times
Conf: VEDIT Macro Language Support
From: Fritz Heberlein
Date: Monday, December 11, 2000 05:29 PM

> At present I have a slight bias against
> it: I do not trust myself to insert the
> diagnostic "{" at the begin ..... of my
> tex file. I am absent minded
> mathematician and if I forget to erase
> it, I am in real trouble.

No, you certainly won't. Just try it and you will see that TeX simply ignores them.
And if you are really afraid that something terrible might happen, why not insert a "%{" and a "%}"?

Happy TeXing!

Fritz

 


Topic: Re: Match_Paren()in VEDIT 5.20.4 (18 of 41), Read 163 times
Conf: VEDIT Macro Language Support
From: Ted Green
Date: Monday, December 11, 2000 05:35 PM

I think a good solution would be a macro which inserts the beginning "{" and final "}" into a file, checks the file with Match_Paren(), removes the "{" and "}", and then reports the result, perhaps with the cursor at a likely unmatched parentheses. If someone writes a good macro, I will be happy to add it to the {USER} or {MISC, More macros} menu.

Ted.

 


Topic: Re: Match_Paren()in VEDIT 5.20.4 (19 of 41), Read 166 times
Conf: VEDIT Macro Language Support
From: Peter Rejto
Date: Tuesday, December 12, 2000 01:17 AM

On 12/11/2000 5:35:43 PM, Ted Green wrote:
>I think a good solution would
>be a macro which inserts the
>beginning "{" and final "}"
>into a file, checks the file
>with Match_Paren(), removes
>the "{" and "}", and then
>reports the result, perhaps
>with the cursor at a likely
>unmatched parentheses. If
>someone writes a good macro, I
>will be happy to add it to the
>{USER} or {MISC, More macros}
>menu.

>Ted.

Thanks Ted,
Of course this would be very nice for me. It would be also nice for me if the description of this macro would be in the Xemacs style.
In other words, instead of speaking about "orphaned parentheses" it would speak about "unbalanced braces". I no longer remember where did I read about orphaned parentheses.
My present terminology comes from the TeX Mode section, (20.9), of the GNU Emacs Manual.

This was the forerunner of Xemacs and an Xemacs Guide is available at their website:
www.xemacs.org

Once again, thanks to Christian, Fritz and to Pauli Lindgren who started all this.

-peter.

 


Topic: Re: Match_Paren()in VEDIT 5.20.4 (27 of 41), Read 153 times
Conf: VEDIT Macro Language Support
From: Fritz Heberlein
Date: Tuesday, December 12, 2000 08:36 AM

>>If
>>someone writes a good macro, I
>>will be happy to add it to the
>>{USER} or {MISC, More macros}
>>menu.
>
>>Ted.
>
>Thanks Ted,
>Of course this would be very nice for
>me.

Peter,
i'd like to suggest you to try out Paulis chk_paren.vdm.
I have tested it on a very large TeX document, and it did everything. A very nice side effect is that it checks for
missing ")"'s also (which i forget too often in my documents).--

Thank you Pauli, i have put it into my TeX menu straight away.

 


Topic: Re: Match_Paren()in VEDIT 5.20.4 (32 of 41), Read 112 times
Conf: VEDIT Macro Language Support
From: Peter Rejto
Date: Thursday, December 14, 2000 12:19 PM

On 12/12/2000 8:36:00 AM, Fritz Heberlein wrote:

>Peter
>i'd like to suggest you to try
>out Paulis chk_paren.vdm.
>I have tested it on a very
>large TeX document, and it did
>everything. A very nice side
>effect is that it checks for
>missing ")"'s also (which i
>forget too often in my
>documents).--
>
>Thank you Pauli, i have put it
>into my TeX menu straight
>away.

Fritz,
I have taken up your suggestion. In fact,I did some experiments with this macro. I am enclosing my file with the specifics. Looking forward to hearing your reactions to it.

Thanks to all of you who have given your time so generously.

-peter.



CHECKPAREN.TXT
--------
Now a string which seems to give some trouble to Pauli's CHECK_PAREN.VDM. Specifically, it finds the first unbalanced "(", but skips the next unbalanced "[".
Peter's Counter Example:
Config_String( MATCH_PAREN, "[][()({}{")
--------
Next a string which seems to give trouble to both: That is to say, it gives trouble to Christian's CHECKPAREN.VDM and to Pauli's CHECK_PAREN.VDM as well.
Christian's Counter Example:
Note that the manual Check_Paren command, Ctrl-], does give an error message!
Hi Fritz,
can you please try your checking with that code:
{ // frame for checking
if(#99==1) {
repeat(ALL){
{ // unbalanced
( // unbalanced
if(#98==0) { break }
}
}
} // frame for checking
That's one of my problem cases... ;-)
Christian
----------
Note:
For the purpose of my experiments I have removed the BoF command from the CHECKPAREN.VDM
macro. For absent minded mathematicians this is a very nice feature, so I would like
to put it back later!
----------

 


Topic: Re: Match_Paren()in VEDIT 5.20.4 (34 of 41), Read 94 times
Conf: VEDIT Macro Language Support
From: Pauli Lindgren
Date: Friday, December 15, 2000 09:19 AM

Peter Rejto wrote:
>
>CHECKPAREN.TXT
>--------
>Now a string which seems to give some
>trouble to Pauli's CHECK_PAREN.VDM.
>Specifically, it finds the first
>unbalanced "(", but skips the next
>unbalanced "[".
>Peter's Counter Example:
>Config_String( MATCH_PAREN, "[][()({}{")
>--------

I have not found such problem. In my tests, my chk_paren.vdm macro finds all the unbalanced parentheses, including "[".

Note that with chk_paren.vdm, you do not need to change the Config_String, since "<" and ">" are handled in the macro. On the other hand, you could change the config_string in the file type specific configuration (startup.vdm), and omit the check of "<" and ">" in the macro. This would make the macro more general purpose.


>{ // frame for checking
>if(#99==1) {
>repeat(ALL){
>{ // unbalanced
>( // unbalanced
>if(#98==0) { break }
>}
>}
>} // frame for checking
>That's one of my problem cases... ;-)
>Christian

Chk_paren.vdm seems to find the errors correctly on the above example.
However, in case of nested parentheses, it assumes that it is the outermost one that is missing. It is not possible to pinpoint the error more precisely.


>----------
>Note:
>For the purpose of my experiments I have
>removed the BoF command from the
>CHECKPAREN.VDM
>macro. For absent minded mathematicians
>this is a very nice feature, so I would
>like to put it back later!

If you have a BOF command, you can only check for the first error. Without it, you can move the cursor after the error location and continue the check.

-- Pauli

 


Topic: Re: Match_Paren()in VEDIT 5.20.4 (35 of 41), Read 96 times
Conf: VEDIT Macro Language Support
From: Christian Ziemski
Date: Friday, December 15, 2000 11:30 AM

>>[Christian's problem with nested braces]
>
>Chk_paren.vdm seems to find the errors correctly on the above example.
>However, in case of nested parentheses, it assumes that it is the =outermost
>one that is missing. It is not possible to pinpoint the error more =precisely.

That IS my problem. I tried to find the _exact_ position of the error.
But as I wrote earlier that seems to be impossible (for me/for now).

At least my C compiler or so will find the error then ...


Christian

 


Topic: Re: Match_Paren()in VEDIT 5.20.4 (38 of 41), Read 62 times
Conf: VEDIT Macro Language Support
From: Pauli Lindgren
Date: Monday, December 18, 2000 05:26 AM

Christian Ziemski wrote:

>That IS my problem. I tried to find the >_exact_ position of the error.
>But as I wrote earlier that seems to be >impossible (for me/for now).
>
>At least my C compiler or so will find the
Maybe, maybe not. Very often, C-compiler displays the error location incorrectly, since it is not possible for the compiler to know what you were trying to do.
In fact, I have noticed that quite often, my check parenthesis program finds the error more precisely. (I have been using similar Basic program for years.)

-- Pauli

 


Topic: Re: Match_Paren()in VEDIT 5.20.4 (37 of 41), Read 88 times
Conf: VEDIT Macro Language Support
From: Peter Rejto
Date: Friday, December 15, 2000 06:09 PM

On 12/15/2000 9:19:00 AM, Pauli Lindgren wrote:
>Peter Rejto wrote:
>>
>>CHECKPAREN.TXT
>>--------
>>Now a string which seems to give some
>>trouble to Pauli's CHECK_PAREN.VDM.
>>Specifically, it finds the first
>>unbalanced "(", but skips the next
>>unbalanced "[".
>>Peter's Counter Example:
>>Config_String( MATCH_PAREN, "[][()({}{")
>>--------
>
>I have not found such problem.
>In my tests, my chk_paren.vdm
>macro finds all the unbalanced
>parentheses, including "[".
>
>Note that with chk_paren.vdm,
>you do not need to change the
>Config_String, since "<" and
>">" are handled in the macro.
>On the other hand, you could
>change the config_string in
>the file type specific
>configuration (startup.vdm),
>and omit the check of "<" and
>">" in the macro. This would
>make the macro more general
>purpose.
>
>
>>{ // frame for checking
>>if(#99==1) {
>>repeat(ALL){
>>{ // unbalanced
>>( // unbalanced
>>if(#98==0) { break }
>>}
>>}
>>} // frame for checking
>>That's one of my problem cases... ;-)
>>Christian
>
>Chk_paren.vdm seems to find
>the errors correctly on the
>above example.
>However, in case of nested
>parentheses, it assumes that
>it is the outermost one that
>is missing. It is not possible
>to pinpoint the error more
>precisely.
>
> Pauli.

Pauli,
You just convinced me that something went wrong with my Vedit installation. So, before having anymore reactions I am going to reinstall my Vedit.

Please keep me posted about future developments of Chk_paren.vdm.
In fact, I would like to know whether there
is a counter example to your macro. In other words, is there a collection of braces where it does not detect an unbalanced one. I am interested in this question on account of the mathematical content of my files as well, not
just the TeX programming.


Thanks again, you really helped me out.

-peter.

 


Topic: Re: Match_Paren()in VEDIT 5.20.4 (20 of 41), Read 159 times
Conf: VEDIT Macro Language Support
From: Christian Ziemski
Date: Tuesday, December 12, 2000 02:25 AM

That should be easy...

But that solution still doesn't work for me in many cases (esp. nested braces).
Therefore I wrote the CHECKPAREN.VDM yesterday (see some postings earlier).

While testing that macro again I found a bug in Match_Paren() IMHO. It gives the wrong return code sometimes and behaves different if it matches '(' or '{'.
So my macro fails too.

More details via mail.

Christian

 


Topic: Re: Match_Paren()in VEDIT 5.20.4 (21 of 41), Read 161 times, 1 File Attachment
Conf: VEDIT Macro Language Support
From: Pauli Lindgren
Date: Tuesday, December 12, 2000 04:34 AM

On 12/12/2000 2:25:00 AM, Christian Ziemski wrote:
>That should be easy...
>
>But that solution still doesn't work for me in many
>cases (esp. nested braces).
>Therefore I wrote the CHECKPAREN.VDM yesterday (see some postings earlier).

I have made a version of the match parentheses macro for C language. I have been using it for some time and it seems to work fine.

The macro has some intelligence to skip C comments, C++ comments and strings. In addition to parentheses, it checks C comments and quotes for matching pair.

I usually call this macro using User Menu (I have a special version of User Menu for C programming). I only need to press Alt-U M to run the macro. The macro starts checking from current cursor position, so it is easy to continue the check by pressing Alt-U M again.

-- Pauli

 
chk_paren.vdm

 


Topic: Re: Match_Paren()in VEDIT 5.20.4 (23 of 41), Read 159 times
Conf: VEDIT Macro Language Support
From: Christian Ziemski
Date: Tuesday, December 12, 2000 05:41 AM

So that was my fault: I tried to implement a universal solution, which isn't possible at all...
I'll have a look at your C-Paren-Checker.

Christian

 


Topic: Re: Match_Paren()in VEDIT 5.20.4 (24 of 41), Read 158 times
Conf: VEDIT Macro Language Support
From: Christian Ziemski
Date: Tuesday, December 12, 2000 06:52 AM

After some investigations I found out, that if Match_Paren() doesn't find a matching brace it doesn't return '0' as documented but returns the amount of braces of that current type up to end of file.

Hmmm, maybe there is some usage of that value....

So: It's not a bug, but a feature!


Christian

 


Topic: Re: Match_Paren()in VEDIT 5.20.4 (31 of 41), Read 110 times
Conf: VEDIT Macro Language Support
From: Ted Green
Date: Wednesday, December 13, 2000 08:45 PM

I fixed the Match_Paren() command today to return the correct return values as documented in the on-line help. Therefore, it will be fixed in the next release, probably in early January.

Ted.

 


Topic: Match_Paren() (40 of 41), Read 39 times
Conf: VEDIT Macro Language Support
From: Peter Rejto
Date: Sunday, April 21, 2002 08:48 PM

On 9/12/2000 9:19:00 AM, Pauli Lindgren wrote:
>I was trying to do a macro
>that uses Match_Paren()
>command to match the
>parenthesis:
>
>
>repeat(ALL) {
> search('|P',ERRBREAK)
> if (Match_Paren() == 0) {
>Statline_Message("** No
>matching parrenthesis! **")
> Return
> }
> Match_Paren()
> char()
>}
>
>The problem is that if a match
>is not found, an error message
>dialog box is displayed and
>the macro execution stops. I
>want to do the error handling
>inside the macro and then
>continue the operation.
>If I use Match_Paren(NOERR),
>the error message dialog box
>is not displayed, but the
>execution does not go inside
>the if() either, as if there
>was no error at all.
>
>How can I handle the error
>within the macro?
>
Pauli,

After 19 month a lot of discussions after I am back to your question. Since your macro is a special case of your CHK_PAREN.VDM macro, I copied it to the file SPCHK_PAREN.VDM.

Then I made the following 3 experiments:

1. I ran the macro on the file SPCHK_PAREN.VDM. It worked like a charm.

2. I added the string "2>1" to the file and ran your macro again. I got a "waiting for disk, Ctr-C" error message. When I pressed Ctr-C the cursor went to the "2>1" string.

3. As per your suggestion I, added the
Config_String(MATCH_PAREN,"{}{{}{()(")
to my USTARTUP.VDM file. I hoped that this would eliminate ">" as an orphaned parentheses.
To my disappointment it did not.

Thanks again for starting all this exciting discussions and for your macro.

-peter.