bug-gnu-emacs
[Top][All Lists]
Advanced

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

Re: reindent-then-newline-and-indent doesn't indent properly in emacs 22


From: nuxdoors
Subject: Re: reindent-then-newline-and-indent doesn't indent properly in emacs 22.1
Date: Sun, 14 Oct 2007 00:24:58 +0200
User-agent: Icedove 1.5.0.12 (X11/20070607)

Ok the problem is not occuring in the official version of emacs 22.1, at
least not in the same obvious way. Sorry about the alarmous report. I
still have found a minor bug related to this in the official version
though, described below.

<my life>
I have found the problem to be much more obvious in the latest testing
emacs version (22.1+1-2) and will thus file a bug report at debian.org

I reported here because i saw the reindent-then-newline-and-indent
function on the Savannah CVS Surfing service (which was the same as the
one found in my emacs) was making the assumption that
indent-according-to-mode was indenting without moving the cursor
position, which i thought could be the source of the problem.

It turns out this is the source of the problem for my debian version,
where i use a develock advised version of lisp-indent-line which leaves
the cursor at the beginning of text, just after the indentation
characters. It doesn't happen in the official version though because it
seems pretty every indentation function included in the various modes
keeps the cursor in place ( i didn't test all the modes though of course ).
</my life>

In respect to the official emacs version, here is the description of a
bug with indent-to-left-margin (which used to be the default indentation
function for the Fundamental Mode so although this isn't even a command
and thus not available to alt-x some people might still use it ) :

Let's create indentation_test.txt like this :

cat > indentation_test.txt <<EOF
    First line. Second line to be indented like the first one.

Local Variables:
left-margin:4
indent-line-function:indent-to-left-margin
End:
EOF

Then i called emacs compiled from source like this :
emacs -Q -nw indentation_test.txt

answer yes at the local variable question.

The "|" character represents the cursor position.
Move you cursor to/on the "S" letter like this :

    First line. |Second line to be indented like the first one.

Then do a reindent-then-newline-and-indent, you will get this :

First line.
    |Second line to be indented like the first one.

This isn't visible but there is still a space at the end of the first
line. I believe we should get this :

    First line.
    |Second line to be indented like the first one.

(no space at the end of the first line and the "S" is on the same column
as "F")

The problem arises because indent-to-left-margin is one of the rare
indentation functions who leaves the cursor at the beginning of the text
after indenting.

So if we think that an indentation function should always leave the
cursor in place, i guess this isn't a bug and we can say
indent-to-left-margin is at fault here ( or the user who doesn't use a
more recent indentation function ).
On the other hand i have been reading the info docs and string docs in
indent.el for example and i can't find a place where it is said that an
indentation function should always preserve the cursor position. The
proper functionning of reindent-then-newline-and-indent is based on that
assumption, or at least that indent-according-to-mode respect that, but
it is not stated in the indent-according-to-mode's doc string that it
should.

I think either that statement should be made somewhere or
reindent-then-newline-and-indent shouldn't make that assumption, it
could for example encapsulate the indent-according-to-mode call itself
in a save-excursion form, which would solve the issue.





reply via email to

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