unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* insert-file-contents and format-decode
@ 2007-06-06 14:06 martin rudalics
  2007-06-08  7:12 ` Richard Stallman
  0 siblings, 1 reply; 28+ messages in thread
From: martin rudalics @ 2007-06-06 14:06 UTC (permalink / raw)
  To: emacs-devel

To reproduce:

Open etc/enriched.doc, insert at buffer start the text

Contents

and do M-x revert-buffer.  Admire the guts of enriched.doc.


To explain:

The third element of `format-alist' is a regexp with the following
documentation:

REGEXP  is a regular expression to match against the beginning of the file;
         it should match only files in that format. ...

The regexp for enriched mode is "Content-[Tt]ype:[ \t]*text/enriched".
When reverting the buffer `insert-file-contents' attempts to preserve
"markers pointing to the unchanged parts" and thus not change "Content"
but insert "-[Tt]ype:[ \t]*text/enriched ...." after it.  The subsequent
matching step in `format-decode' fails because `point' is in between
"Content" and "-[Tt]ype:[ \t]*text/enriched" due to

       /* Set point before the inserted characters.  */
       SET_PT_BOTH (temp, same_at_start);

Apparently, the marker preserving optimization was written without
paying attention to `format-decode'.


To fix:

The call to `format-decode' in

       insval = call3 (Qformat_decode,
		      Qnil, make_number (inserted), visit);

should be performed with `point' at the original position and `inserted'
equalling the number of characters that would have been inserted without
the optimization.  After the call `point' may be restored to the
optimized position iff insval == inserted, that is, format-decode has
not modified the length of the "inserted" text (this might still fail in
pathological cases where format-decode removes and adds the same number
of characters but we shouldn't be too concerned about that).

Maybe someone familiar with the optimizations in `insert-file-contents'
could give it a try?


To consider:

The example given above is contrived.  The bug will become annoying when
you wrap the regexp in a comment to avoid, for example, a compiler
error.  In that case, any "real" comment at the beginning of the file
may trigger the bug.

FWIW, the `after-insert-file-functions' call

       insval = call1 (XCAR (p), make_number (inserted));

should be fixed in a similar manner.

^ permalink raw reply	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2007-08-06 14:22 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-06 14:06 insert-file-contents and format-decode martin rudalics
2007-06-08  7:12 ` Richard Stallman
2007-06-17 13:34   ` martin rudalics
2007-06-18 21:31     ` Richard Stallman
2007-06-19  7:50       ` martin rudalics
2007-06-23 18:26         ` Richard Stallman
2007-06-23 18:26         ` Richard Stallman
2007-06-24 10:30           ` martin rudalics
2007-06-25 13:19             ` Richard Stallman
2007-06-26  6:54               ` martin rudalics
2007-06-26 22:48                 ` Richard Stallman
2007-06-27  6:33                   ` martin rudalics
2007-06-27 19:50                     ` Richard Stallman
2007-06-30 11:11                       ` martin rudalics
2007-07-01  0:30                         ` Richard Stallman
2007-07-02  8:14                           ` martin rudalics
2007-07-03  4:24                             ` Richard Stallman
2007-07-03  6:47                               ` martin rudalics
2007-07-04  3:43                                 ` Richard Stallman
2007-06-26 22:48                 ` Richard Stallman
2007-06-27  6:34                   ` martin rudalics
2007-06-27 23:43                     ` Richard Stallman
2007-06-30 11:32                       ` martin rudalics
2007-07-01  0:30                         ` Richard Stallman
2007-07-02  8:27                           ` martin rudalics
2007-07-03  4:24                             ` Richard Stallman
2007-07-03  6:43                               ` martin rudalics
2007-08-06 14:22                                 ` Richard Stallman

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).