emacs-devel
[Top][All Lists]
Advanced

[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: Mon, 02 Jul 2007 10:27:09 +0200
User-agent: Mozilla Thunderbird 1.0 (Windows/20041206)

So the only remaining change to be done is to inhibit execution of
certain hooks in `format-decode' and around the calls to
`after-insert-file-functions'.

Please have a look at the attached patch (my acquaintance with C code
is marginal).  Handa-san could you please check whether such a patch
would introduce conflicts with the unicode-2 branch.

*** fileio.c    Mon Jul  2 07:27:56 2007
--- fileio.c    Mon Jul  2 08:23:20 2007
***************
*** 3720,3727 ****
    register int how_much;
    register int unprocessed;
    int count = SPECPDL_INDEX ();
!   struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
!   Lisp_Object handler, val, insval, orig_filename;
    Lisp_Object p;
    int total = 0;
    int not_regular = 0;
--- 3720,3727 ----
    register int how_much;
    register int unprocessed;
    int count = SPECPDL_INDEX ();
!   struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
!   Lisp_Object handler, val, insval, orig_filename, old_undo;
    Lisp_Object p;
    int total = 0;
    int not_regular = 0;
***************
*** 3744,3751 ****
    val = Qnil;
    p = Qnil;
    orig_filename = Qnil;
  
!   GCPRO4 (filename, val, p, orig_filename);
  
    CHECK_STRING (filename);
    filename = Fexpand_file_name (filename, Qnil);
--- 3744,3752 ----
    val = Qnil;
    p = Qnil;
    orig_filename = Qnil;
+   old_undo = Qnil;
  
!   GCPRO5 (filename, val, p, orig_filename, old_undo);
  
    CHECK_STRING (filename);
    filename = Fexpand_file_name (filename, Qnil);
***************
*** 4704,4727 ****
    /* Decode file format */
    if (inserted > 0)
      {
!       int empty_undo_list_p = 0;
! 
!       /* If we're anyway going to discard undo information, don't
!        record it in the first place.  The buffer's undo list at this
!        point is either nil or t when visiting a file.  */
!       if (!NILP (visit))
        {
!         empty_undo_list_p = NILP (current_buffer->undo_list);
!         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
--- 4705,4806 ----
    /* Decode file format */
    if (inserted > 0)
      {
!       /* Don't run point motion or modification hooks when decoding. */
!       int count = SPECPDL_INDEX ();
!       specbind (Qinhibit_point_motion_hooks, Qt);
!       specbind (Qinhibit_modification_hooks, Qt);
! 
!       /* Save old undo list and don't record undo for decoding. */
!       old_undo = current_buffer->undo_list;
!       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);
        }
  
!       /* For consistency with format-decode call these now iff inserted > 0
!        (martin 2007-06-28) */
!       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);
!       }
!       
!       if (NILP (visit))
!       {
!         Lisp_Object lbeg, lend;
!         XSETINT (lbeg, PT);
!         XSETINT (lend, PT + inserted);
!         if (CONSP (old_undo))
!           {
!             Lisp_Object tem = XCAR (old_undo);
!             if (CONSP (tem) && INTEGERP (XCAR (tem)) &&
!                 INTEGERP (XCDR (tem)) && (XCAR (tem)) == lbeg)
!               /* In the non-visiting case record only the final insertion. */
!               current_buffer->undo_list =
!                 Fcons (Fcons (lbeg, lend), Fcdr (old_undo));
!           }
!       }
!       else
!       /* In the visiting case restore the previous value. */
!       current_buffer->undo_list = old_undo;
!       
!       unbind_to (count, Qnil);
      }
  
    /* Call after-change hooks for the inserted text, aside from the case
***************
*** 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)
      {
--- 4813,4818 ----


reply via email to

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