Re: [BUG] Disappearing of first line after Ctrl-Y



Hello, Andrew.

On Wed, 6 Nov 2002, Andrew V. Samoilov wrote:

> Dmitry Semyonov wrote:

> > The patch for edit.c that fixes all the discribed problems is attached.
> > At the same time I think that 'Ctrl-Y F3' related bug was just shaded
> > out but not fixed.
>
> At first your patch cannot be applied clearly because it is in DOS
> format (carriage return before newline).

Strange, I don't see any 0x0D codes in the attached patch.


> Also I cannot understand, why
> you replace tabulation with spaces. It will be fine if you will use
> indent -kr -i4 -psl -pcs for each function you change.

I don't use TAB's, and don't like TABbed sources since different people
may have different settings for the length of TAB character. I've seen
some source code (not mc) which was unreadable due to the fact, it was
written by different programmers who used 2, 4, and 8 spaces for TAB
length. Also, it is unhandy to resetup an editor for different sources.

But if mc sources have strictly defined coding style, I would like to
read it, and will follow it for possible mc contributions. I've just
read doc/DEVEL, and I guess a note about using of 'indent' utility is
only a recommendation, not the MUST USE rule.

BTW, why default script for external formatter uses different indent
arguments than defined in docs/DEVEL?


> And your patch changes current behaviour of mcedit.  ASCII zero is equal
> to newline now.  I cannot say I like this, but you should be consistent.
> Now 0 is checked in the right part of the line, but this check is
> ommited at the left.

Thanks for the comment.
I'm not familiar with mc sources, and by some reason I misleadingly
thought only EOF was checked on the right part.

BTW, edit_delete() returns 0 in the case of EOF, while edit_get_byte()
returns '\n' in the same case. Misleading code, isn't it?


New version of the patch, consistent and indented :-)

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

--- edit.c      Wed Nov  6 19:27:17 2002
+++ edit.c.new  Wed Nov  6 19:31:49 2002
@@ -1767,17 +1767,32 @@
     }
 }

-void edit_delete_line (WEdit * edit)
+void
+edit_delete_line (WEdit * edit)
 {
-    int c;
-    do {
-       c = edit_delete (edit);
-    } while (c != '\n' && c);
-    do {
-       c = edit_backspace (edit);
-    } while (c != '\n' && c);
-    if (c)
-       edit_insert (edit, '\n');
+    /*
+     * Delete right part of the line.
+     * Note that edit_get_byte() returns '\n' when byte position is
+     *   beyond EOF.
+     */
+    while (edit_get_byte (edit, edit->curs1) != '\n') {
+       (void) edit_delete (edit);
+    }
+
+    /*
+     * Delete '\n' char.
+     * Note that edit_delete() will not corrupt anything if called while
+     *   cursor position is EOF.
+     */
+    (void) edit_delete (edit);
+
+    /*
+     * Delete left part of the line.
+     * Note, that edit_get_byte() returns '\n' when byte position is < 0.
+     */
+    while (edit_get_byte (edit, edit->curs1 - 1) != '\n') {
+       (void) edit_backspace (edit);
+    };
 }

 static void insert_spaces_tab (WEdit * edit, int half)




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