mcedit bug



Hi,

I'm a student of the computer science at the Otto-von-Guericke
university in Magdeburg, Germany. I always loved the Norton Commander
and since I'm using Linux the Midnight Commander has become my absolute
favorite. 

Here is my request:
I've just got the Midnight Commander v4.5.99a and it seems that there is
a little bug in the internal editor. I will explain it with the help of
an example.

---
if (type->isFunction()) {
  return new FunctionInfo(type);
} else if (type->isClass()) {
  return new ClassInfo(type);
} else {
  return new ErrorInfo(type);
}
---

Imagine this piece of source code is edited with mcedit. Now C style
comments shall be putted around the whole `isClass()' check beginning
before the first `else' and ending before the second `else'. Here is how
it should look like:

---
if (type->isFunction()) {
  return new FunctionInfo(type);
} /*else if (type->isClass()) {
  return new ClassInfo(type);
} */else {
  return new ErrorInfo(type);
}
---

This I want to do automatically(!) by marking the corresponding block
and calling a command of the user menu. Therefore I've added the
following commands to the [c] section of the user menu:

---
+ f \.h$ | f \.c$ | f \.cc$ | f \.C$ | f \.H$ | f \.cpp$
3       C++ style comment
	TEMPFILE="$(dirname %b)/cooledit.temp"
	sed -e "s  *@//&@g" %b > $TEMPFILE
	cat $TEMPFILE > %b 

+ f \.h$ | f \.c$ | f \.cc$ | f \.C$ | f \.H$ | f \.cpp$
4       C++ style comment undo
	TEMPFILE="$(dirname %b)/cooledit.temp"
	sed -e "s ^//\(.*\)\$ \1@g" %b > $TEMPFILE
	cat $TEMPFILE > %b 

+ f \.h$ | f \.c$ | f \.cc$ | f \.C$ | f \.H$ | f \.cpp$
5       C style comment
	TEMPFILE="$(dirname %b)/cooledit.temp"
	echo -n "/*" > $TEMPFILE
	cat %b >> $TEMPFILE
	cat $TEMPFILE > %b
	echo -n "*/" >> %b 
---

Here it goes: First I mark the block from the first `else' to the second
`else'. Then I call the user menu (F11) and choose the `C style
comment'. But surprisingly the result looks like this:

---
if (type->isFunction()) {
  return new FunctionInfo(type);
/*else if (type->isClass()) {
  return new ClassInfo(type);
} */} else {
  return new ErrorInfo(type);
}
---

I've looked into the sources of the Midnight Commander and I have found
the following in the file edit.c, line 2704+, function user_edit():

---
if (!rc) {
    edit_cursor_to_bol (edit); 
    edit_insert_file (edit, block_file);
    edit_cursor_to_eol (edit); 
}
---

This is the problem: before the contents of the file "cooledit.block"
are inserted the cursor is moved to the beginning of the line and the
file is inserted at the wrong position. Does this behavior has a special
reason? Commenting it out solves the problem and the result is like
expected. Apart from that I also think that moving the cursor to the end
of the line after inserting the file is a little bit confusing for the
user (for me ;-). But that isn't so important.

I really hope I was telling you something new. The editor user menu is
really a good thing. If you want (and I hope it) you may adopt the user
menu commands listed above for your (global) user menu. Automatic C and
C++ commenting is a so cool feature :-) There are no copyrights, of
course ;-)

A last thing: What do you think about `word completion' within the
editor? That would be a very cool feature. And is there a 'redo'
anywhere? The `undo' is very important for me and a `redo' would it be,
too.

Somewhere in the FAQ there was a hint to mention whether I am on the
mailing list or not. I am not. 

Bye and best regards,
Matthias Urban



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]