eval-last-sexp -> syntax error -> deletes rest of buffer!

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

eval-last-sexp -> syntax error -> deletes rest of buffer!

David Reitter-6
Place the following in the middle of a buffer (with text following):

`[(,test ,)]

Set the point right after the (malformed) expression and hit C-x C-e.
You will find that an error is correctly reported (invalid-read-
syntax ")"), but that the complete rest of the buffer (after the  
point) IS DELETED.

Annoyingly, undo doesn't bring it back, nor is the deleted part of  
the buffer  properly killed and put into the killring.


This happens on today's CVS build. The bug has been around for a while.





In GNU Emacs 22.0.50.1 (powerpc-apple-darwin8.1.0)
of 2005-06-01 on madonna
Distributor `Apple Computers', version 10.4.1
configured using `configure '--without-x' '--prefix=/usr/local''

Important settings:
   value of $LC_ALL: nil
   value of $LC_COLLATE: nil
   value of $LC_CTYPE: nil
   value of $LC_MESSAGES: nil
   value of $LC_MONETARY: nil
   value of $LC_NUMERIC: nil
   value of $LC_TIME: nil
   value of $LANG: nil
   locale-coding-system: iso-latin-1
   default-enable-multibyte-characters: t

Major mode: Debugger

Minor modes in effect:
   encoded-kbd-mode: t
   tool-bar-mode: t
   mouse-wheel-mode: t
   tooltip-mode: t
   auto-compression-mode: t
   menu-bar-mode: t
   unify-8859-on-encoding-mode: t
   utf-translate-cjk-mode: t
   line-number-mode: t
   next-error-follow-minor-mode:  Fol

Recent input:
M-v <escape> x c l i p - <backspace> <tab> y <tab>
<return> <down-mouse-1> <mouse-1> <escape> x <up> <return>
<down-mouse-1> <mouse-1> <down-mouse-1> <mouse-1> <left>
<right> C-x C-e <help-echo> <menu-bar> <help-menu>
<report-emacs-bug>

Recent messages:
Loading tool-bar...done
Loading image...done
For information about the GNU Project and its goals, type C-h C-p.
Loading encoded-kb...done
call-interactively: End of buffer
Mark set [2 times]
Loading debug...done
Entering debugger...
Loading help-mode...done
Loading emacsbug...done



_______________________________________________
Emacs-pretest-bug mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/emacs-pretest-bug
Reply | Threaded
Open this post in threaded view
|

Re: eval-last-sexp -> syntax error -> deletes rest of buffer!

Richard Stallman
    Set the point right after the (malformed) expression and hit C-x C-e.
    You will find that an error is correctly reported (invalid-read-
    syntax ")"), but that the complete rest of the buffer (after the  
    point) IS DELETED.

    Annoyingly, undo doesn't bring it back, nor is the deleted part of  
    the buffer  properly killed and put into the killring.

The text has not been killed.
The buffer is only narrowed temporarily.


_______________________________________________
Emacs-pretest-bug mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/emacs-pretest-bug
Reply | Threaded
Open this post in threaded view
|

Re: eval-last-sexp -> syntax error -> deletes rest of buffer!

David Reitter-6
On 3 Jun 2005, at 09:01, Richard Stallman wrote:

>     Set the point right after the (malformed) expression and hit C-
> x C-e.
>     You will find that an error is correctly reported (invalid-read-
>     syntax ")"), but that the complete rest of the buffer (after the
>     point) IS DELETED.
>
>     Annoyingly, undo doesn't bring it back, nor is the deleted part of
>     the buffer  properly killed and put into the killring.
>
> The text has not been killed.
> The buffer is only narrowed temporarily.

Seems to me like half of my buffer has gone to Nirvana. How do I get  
it back? That's not obvious from the info description of eval-last-
sexp, and I don't understand why it would go away like that. I found  
out thanks to your tip and a search in the manual: C-x n w.

But why is the buffer narrowed "temporarily" just when I have this  
kind of syntax error, but not when there's other kinds? I've been  
doing thousands of C-x C-e over last last couple of months, and the  
buffer is just "narrowed temporarily" in this particular situation.

At least the manual should document it (in eval-last-sexp and  
wherever it's done) and explain when exactly the buffer is narrowed.


_______________________________________________
Emacs-pretest-bug mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/emacs-pretest-bug
Reply | Threaded
Open this post in threaded view
|

Re: eval-last-sexp -> syntax error -> deletes rest of buffer!

Luc Teirlinck
David Reitter wrote:

   Seems to me like half of my buffer has gone to Nirvana. How do I get  
   it back? That's not obvious from the info description of eval-last-
   sexp, and I don't understand why it would go away like that. I found  
   out thanks to your tip and a search in the manual: C-x n w.

You got [(MODE Narrow)] in the mode line, the [...] showing you that
you are in a recursive edit.  If you do  C-] to exit the recursive
edit, the narrowing disappears, you do not need to do an explicit
C-x n w.

I do not know whether this behavior occurs by default in releases, or
only in CVS and pretests, which are more debugging oriented.

Sincerely,

Luc.


_______________________________________________
Emacs-pretest-bug mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/emacs-pretest-bug
Reply | Threaded
Open this post in threaded view
|

Re: eval-last-sexp -> syntax error -> deletes rest of buffer!

Luc Teirlinck
In reply to this post by David Reitter-6
>From my previous reply:

   If you do C-] to exit the recursive edit,

I should have said: to abort the recursive edit.  Just exiting with
C-M-c does not work in this situation, because you get:

(error "Cannot return from the debugger in an error")

Sincerely,

Luc.


_______________________________________________
Emacs-pretest-bug mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/emacs-pretest-bug
Reply | Threaded
Open this post in threaded view
|

Re: eval-last-sexp -> syntax error -> deletes rest of buffer!

Luc Teirlinck
In reply to this post by David Reitter-6
David Reitter wrote:

   But why is the buffer narrowed "temporarily" just when I have this  
   kind of syntax error, but not when there's other kinds?

Because the error occurred while the buffer was narrowed.  That only
applies to a minority of errors.  The narrowing was inside a
`save-excursion', which widens again _after_ an error.  But in the CVS
version of Emacs, an error enters the debugger, which enters a
recursive edit at the place the error occurred.  It shows you the
state of the buffer at the time the error occurred, and in your
example, that state is narrowed.  After you do C-], the save-excursion
takes effect and the buffer widens again.

Sincerely,

Luc.


_______________________________________________
Emacs-pretest-bug mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/emacs-pretest-bug
Reply | Threaded
Open this post in threaded view
|

Re: eval-last-sexp -> syntax error -> deletes rest of buffer!

Luc Teirlinck
In reply to this post by David Reitter-6
>From my previous message:

  The narrowing was inside a `save-excursion', which widens again
  _after_ an error.

Sorry, I meant `save-restriction', not `save-excursion'.

Sincerely,

Luc.


_______________________________________________
Emacs-pretest-bug mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/emacs-pretest-bug
Reply | Threaded
Open this post in threaded view
|

Re: eval-last-sexp -> syntax error -> deletes rest of buffer!

Luc Teirlinck
In reply to this post by David Reitter-6
You can get rid of the behavior you described by setting
eval-expression-debug-on-error to nil.  Unlike what I thought, the
default value of this variable is t, even in released versions.  I do
not know whether this is a very good idea.  The assumption is that
anybody who uses C-x C-e must have a really extensive knowledge of
Emacs Lisp and hence will not be confused by the kind of debugger
behavior you described.  But C-x C-e is documented in the Emacs manual
and even people who do not know Lisp often seem to use it to evaluate
easy expressions of which they happen to know what they do.  One can
also hit C-x C-e by accident, for instance instead of `C-x e'.

Sincerely,

Luc.


_______________________________________________
Emacs-pretest-bug mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/emacs-pretest-bug
Reply | Threaded
Open this post in threaded view
|

Re: eval-last-sexp -> syntax error -> deletes rest of buffer!

David Reitter-6
On 4 Jun 2005, at 02:41, Luc Teirlinck wrote:

> You can get rid of the behavior you described by setting
> eval-expression-debug-on-error to nil.  Unlike what I thought, the
> default value of this variable is t, even in released versions.  I do
> not know whether this is a very good idea.

The longer the expression that is evaluated, the greater the need is  
for eval-expression-debug-on-error, since you want to see where  
exactly the error occurred. (Alternatively, it would be nice to just  
show the error message, but set the point to the position of the  
error in the code.)

What's confusing is not the debug output. What's confusing is the  
narrowing. It occurs inconsistently, depending on some implementation  
specifics, and not directed by user needs. Some very specific  
expressions / syntax errors cause narrowing to happen.

> Because the error occurred while the buffer was narrowed.  That only
> applies to a minority of errors.  The narrowing was inside a
> `save-excursion', which widens again _after_ an error.

OK. Then what should happen from a user perspective is that you  
either a) unroll changes before bringing up the debugger when they  
were not caused by the code being evaluated or b) just don't narrow  
the buffer when evaluating expressions. a) might be too complex to  
implement (safely at this time), but b) could be a little easier to do.

D


_______________________________________________
Emacs-pretest-bug mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/emacs-pretest-bug