[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: insert-file-contents and format-decode
From: |
martin rudalics |
Subject: |
Re: insert-file-contents and format-decode |
Date: |
Sun, 17 Jun 2007 15:34:08 +0200 |
User-agent: |
Mozilla Thunderbird 1.0 (Windows/20041206) |
> Can you please write and test a fix for this bug?
I test the attached patch for a week now and didn't encounter any
problems. In addition to fixing the bug I described it moves the call
of after-change hooks _after_ the call to `after-insert-file-functions'.
The earlier behavior was IMO wrong. Someone more familiar with the code
of fileio.c should have a look at that though.
*** fileio.c.~1.581.~ Sun Jun 10 17:46:54 2007
--- fileio.c Sun Jun 17 15:08:20 2007
***************
*** 4715,4729 ****
current_buffer->undo_list = Qt;
}
! insval = call3 (Qformat_decode,
! Qnil, make_number (inserted), visit);
! CHECK_NUMBER (insval);
! inserted = XFASTINT (insval);
if (!NILP (visit))
current_buffer->undo_list = empty_undo_list_p ? Qnil : Qt;
}
/* Call after-change hooks for the inserted text, aside from the case
of normal visiting (not with REPLACE), which is done in a new buffer
"before" the buffer is changed. */
--- 4715,4789 ----
current_buffer->undo_list = Qt;
}
! if (NILP (replace))
! {
! insval = call3 (Qformat_decode,
! Qnil, make_number (inserted), visit);
! CHECK_NUMBER (insval);
! inserted = XFASTINT (insval);
! }
! else
! {
! /* Suppose replace is non-nil and we succeeded in not replacing the
! beginning or end of the buffer text with the file's contents. In this
! case we neverthelss have to call format-decode with `point' positioned
! at the beginning of the buffer and `inserted' equalling the number of
! characters in the buffer. Otherwise, format-decode might fail to
! correctly analyze the beginning or end of the buffer. Hence we
! temporarily save `point' and `inserted' here and restore `point' iff
! format-decode didn't insert or delete any text. Otherwise we leave
! `point' at point-min. */
! int opoint = PT;
! int opoint_byte = PT_BYTE;
! int oinserted = ZV - BEGV;
!
! TEMP_SET_PT_BOTH (BEGV, BEGV_BYTE);
! insval = call3 (Qformat_decode,
! Qnil, make_number (oinserted), visit);
! CHECK_NUMBER (insval);
! if (insval = oinserted)
! SET_PT_BOTH (opoint, opoint_byte);
! inserted = XFASTINT (insval);
! }
if (!NILP (visit))
current_buffer->undo_list = empty_undo_list_p ? Qnil : Qt;
}
+ p = Vafter_insert_file_functions;
+ while (CONSP (p))
+ {
+ if (NILP (replace))
+ {
+ insval = call1 (XCAR (p), make_number (inserted));
+ if (!NILP (insval))
+ {
+ CHECK_NUMBER (insval);
+ inserted = XFASTINT (insval);
+ }
+ }
+ else
+ {
+ /* For the rationale of this see the comment on format-decode above.
*/
+ int opoint = PT;
+ int opoint_byte = PT_BYTE;
+ int oinserted = ZV - BEGV;
+
+ TEMP_SET_PT_BOTH (BEGV, BEGV_BYTE);
+ insval = call1 (XCAR (p), make_number (oinserted));
+ if (!NILP (insval))
+ {
+ CHECK_NUMBER (insval);
+ if (insval = oinserted)
+ SET_PT_BOTH (opoint, opoint_byte);
+ inserted = XFASTINT (insval);
+ }
+ }
+
+ QUIT;
+ p = XCDR (p);
+ }
+
/* Call after-change hooks for the inserted text, aside from the case
of normal visiting (not with REPLACE), which is done in a new buffer
"before" the buffer is changed. */
***************
*** 4734,4752 ****
update_compositions (PT, PT, CHECK_BORDER);
}
- p = Vafter_insert_file_functions;
- while (CONSP (p))
- {
- insval = call1 (XCAR (p), make_number (inserted));
- if (!NILP (insval))
- {
- CHECK_NUMBER (insval);
- inserted = XFASTINT (insval);
- }
- QUIT;
- p = XCDR (p);
- }
-
if (!NILP (visit)
&& current_buffer->modtime == -1)
{
--- 4794,4799 ----
- insert-file-contents and format-decode, martin rudalics, 2007/06/06
- Re: insert-file-contents and format-decode, Richard Stallman, 2007/06/08
- Re: insert-file-contents and format-decode,
martin rudalics <=
- Re: insert-file-contents and format-decode, Richard Stallman, 2007/06/18
- Re: insert-file-contents and format-decode, martin rudalics, 2007/06/19
- Re: insert-file-contents and format-decode, Richard Stallman, 2007/06/23
- Re: insert-file-contents and format-decode, Richard Stallman, 2007/06/23
- Re: insert-file-contents and format-decode, martin rudalics, 2007/06/24
- Re: insert-file-contents and format-decode, Richard Stallman, 2007/06/25
- Re: insert-file-contents and format-decode, martin rudalics, 2007/06/26
- Re: insert-file-contents and format-decode, Richard Stallman, 2007/06/26
- Re: insert-file-contents and format-decode, martin rudalics, 2007/06/27
- Re: insert-file-contents and format-decode, Richard Stallman, 2007/06/27