nano-devel
[Top][All Lists]
Advanced

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

Re: [Nano-devel] a problem with tabs after the overhaul


From: David Ramsey
Subject: Re: [Nano-devel] a problem with tabs after the overhaul
Date: Fri, 17 Mar 2017 15:12:51 -0500

On Fri, Mar 17, 2017 at 2:17 PM, Benno Schulenberg
<address@hidden> wrote:
> I don't have another way, yet, but there must be one.

Okay.

>> As for why the cursor jams, it's because placewewant is column 72,
>
> You mean 75, right?  Because otherwise the modulo wouldn't be zero:

In integer arithmetic, 72 / 75 is zero, and 72 % 75 is zero as well.

But I actually meant was_column; having xplustabs() used in multiple
places gets rather confusing.  I'll go through it step by step.

1. Shrink the terminal to 75 columns by whatever means.

2. Load gdb with nano.

3. Assuming you're in the same directory as the nano binary, and in gdb:
"break do_down"

and then

"run --ignore --soft --nowrap --smart +233 ../doc/faq.html".

4. After nano loads the file, press Tab 14 times, press Home, and then
press Down.

5. gdb will break on do_down().  was_column is set to xplustabs(), which
is 0; leftedge is set to the beginning of the chunk was_column is on,
which is 0; and target_column is set to placewewant, which is 0.

6. After the go_forward_chunks() call, leftedge is set to 75, and
target_column is unchanged and still 0.  current_x is set to actual_x of
leftedge + target_column, which is 9.

7. After the function ends, in gdb: "cont".  Press Down again.

8. gdb will break on do_down() again.  was_column is set to xplustabs(),
which is now 72 (the beginning of the tab that straddles the screen
edge); leftedge is set to the beginning of the chunk was_column is now
on, which is 0; and target_column is set to placewewant, which is now 0.

9. After the go_forward_chunks() call, leftedge is set to 75, and
target_column is unchanged and still 0.  current_x is set to actual_x of
leftedge + target_column, which is 9.  [Note that this is the same as step 6.]

Hence the loop.

> The actual placewewant, the intended position of the cursor, is then:
> chunknumber * editwincols + placewewant % editwincols.
>
> Just like we have an openfile-current_y, we will need an
> openfile->current_chunk -- the chunk number.

If the line ends early, that's when your proposed formula stops working
properly.

In my earliest attempts, I tried doing that and making every chunk start
at a multiple of editwincols, even when the line broke early, but that
caused problems because it led to there being effectively nonexistent
columns at the end of the line, which broke actual_x() completely, among
other things.  (If the line ends at column 78 when there are 80 columns
per line, which chunk does a placewewant of 79 refer to, since it's the
column we want, but which may not be available if the line is too
short?)

And just getting the leftedge that placewewant is on and subtracting it
from placewewant won't work either if placewewant is past where the
chunk ends early, because then it'll get the leftedge of the next chunk
instead of the chunk it's supposed to be on.  And there's no way to know
where the end of the chunk is without knowing where the beginning of the
chunk is, since previous chunks may have ended early as well.  Hence my
having to make placewewant relative to the current leftedge.

I know my solution may seem complex, but you have no idea how many
iterations of broken code I had to go through before I had to go with
what I did.  That being said... if you can figure out another way, good
luck, but I've driven myself crazy enough over other attempted
solutions.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]