aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard M. Stallman1994-07-24 05:42:51 +0000
committerRichard M. Stallman1994-07-24 05:42:51 +0000
commit6fc6f94bb27d81ce743ba44eca99a4259176d96d (patch)
tree13e1e0cc4b962585223284c0feb8cfc9d44986bc /src
parent29397c5869d5499b1502a463c9b3c5724d07b1ee (diff)
downloademacs-6fc6f94bb27d81ce743ba44eca99a4259176d96d.tar.gz
emacs-6fc6f94bb27d81ce743ba44eca99a4259176d96d.zip
(Fwrite_region): Do unwind the new unwind protect.
(Vwrite_region_annotations_so_far): New variable. (syms_of_fileio): Set up Lisp var. (build_annotations): Handle annotate functions that switch buffers. Set Vwrite_region_annotations_so_far. (Fwrite_region): Handle change of buffer in build_annotations. Add an unwind protect to restore original buffer and kill the temp.
Diffstat (limited to 'src')
-rw-r--r--src/fileio.c65
1 files changed, 62 insertions, 3 deletions
diff --git a/src/fileio.c b/src/fileio.c
index 329ab55d18f..aa8ceabaaf6 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -121,6 +121,10 @@ Lisp_Object Vafter_insert_file_functions;
121/* Functions to be called to create text property annotations for file. */ 121/* Functions to be called to create text property annotations for file. */
122Lisp_Object Vwrite_region_annotate_functions; 122Lisp_Object Vwrite_region_annotate_functions;
123 123
124/* During build_annotations, each time an annotation function is called,
125 this holds the annotations made by the previous functions. */
126Lisp_Object Vwrite_region_annotations_so_far;
127
124/* File name in which we write a list of all our auto save files. */ 128/* File name in which we write a list of all our auto save files. */
125Lisp_Object Vauto_save_list_file_name; 129Lisp_Object Vauto_save_list_file_name;
126 130
@@ -2927,6 +2931,23 @@ and (2) it puts less data in the undo list.")
2927 2931
2928static Lisp_Object build_annotations (); 2932static Lisp_Object build_annotations ();
2929 2933
2934/* If build_annotations switched buffers, switch back to BUF.
2935 Kill the temporary buffer that was selected in the meantime. */
2936
2937static Lisp_Object
2938build_annotations_unwind (buf)
2939 Lisp_Object buf;
2940{
2941 Lisp_Object tembuf;
2942
2943 if (XBUFFER (buf) == current_buffer)
2944 return Qnil;
2945 tembuf = Fcurrent_buffer ();
2946 Fset_buffer (buf);
2947 Fkill_buffer (tembuf);
2948 return Qnil;
2949}
2950
2930DEFUN ("write-region", Fwrite_region, Swrite_region, 3, 5, 2951DEFUN ("write-region", Fwrite_region, Swrite_region, 3, 5,
2931 "r\nFWrite region to file: ", 2952 "r\nFWrite region to file: ",
2932 "Write current region into specified file.\n\ 2953 "Write current region into specified file.\n\
@@ -2954,6 +2975,7 @@ to the file, instead of any buffer contents, and END is ignored.")
2954 struct stat st; 2975 struct stat st;
2955 int tem; 2976 int tem;
2956 int count = specpdl_ptr - specpdl; 2977 int count = specpdl_ptr - specpdl;
2978 int count1;
2957#ifdef VMS 2979#ifdef VMS
2958 unsigned char *fname = 0; /* If non-0, original filename (must rename) */ 2980 unsigned char *fname = 0; /* If non-0, original filename (must rename) */
2959#endif /* VMS */ 2981#endif /* VMS */
@@ -2962,6 +2984,7 @@ to the file, instead of any buffer contents, and END is ignored.")
2962 Lisp_Object annotations; 2984 Lisp_Object annotations;
2963 int visiting, quietly; 2985 int visiting, quietly;
2964 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; 2986 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
2987 struct buffer *given_buffer;
2965#ifdef MSDOS 2988#ifdef MSDOS
2966 int buffer_file_type 2989 int buffer_file_type
2967 = NILP (current_buffer->buffer_file_type) ? O_TEXT : O_BINARY; 2990 = NILP (current_buffer->buffer_file_type) ? O_TEXT : O_BINARY;
@@ -3013,7 +3036,16 @@ to the file, instead of any buffer contents, and END is ignored.")
3013 XFASTINT (end) = Z; 3036 XFASTINT (end) = Z;
3014 } 3037 }
3015 3038
3039 record_unwind_protect (build_annotations_unwind, Fcurrent_buffer ());
3040 count1 = specpdl_ptr - specpdl;
3041
3042 given_buffer = current_buffer;
3016 annotations = build_annotations (start, end); 3043 annotations = build_annotations (start, end);
3044 if (current_buffer != given_buffer)
3045 {
3046 start = BEGV;
3047 end = ZV;
3048 }
3017 3049
3018#ifdef CLASH_DETECTION 3050#ifdef CLASH_DETECTION
3019 if (!auto_saving) 3051 if (!auto_saving)
@@ -3215,8 +3247,10 @@ to the file, instead of any buffer contents, and END is ignored.")
3215#ifndef FOO 3247#ifndef FOO
3216 stat (fn, &st); 3248 stat (fn, &st);
3217#endif 3249#endif
3218 /* Discard the unwind protect */ 3250 /* Discard the unwind protect for close_file_unwind. */
3219 specpdl_ptr = specpdl + count; 3251 specpdl_ptr = specpdl + count1;
3252 /* Restore the original current buffer. */
3253 unbind_to (count);
3220 3254
3221#ifdef CLASH_DETECTION 3255#ifdef CLASH_DETECTION
3222 if (!auto_saving) 3256 if (!auto_saving)
@@ -3260,7 +3294,11 @@ DEFUN ("car-less-than-car", Fcar_less_than_car, Scar_less_than_car, 2, 2, 0,
3260 3294
3261/* Build the complete list of annotations appropriate for writing out 3295/* Build the complete list of annotations appropriate for writing out
3262 the text between START and END, by calling all the functions in 3296 the text between START and END, by calling all the functions in
3263 write-region-annotate-functions and merging the lists they return. */ 3297 write-region-annotate-functions and merging the lists they return.
3298 If one of these functions switches to a different buffer, we assume
3299 that buffer contains altered text. Therefore, the caller must
3300 make sure to restore the current buffer in all cases,
3301 as save-excursion would do. */
3264 3302
3265static Lisp_Object 3303static Lisp_Object
3266build_annotations (start, end) 3304build_annotations (start, end)
@@ -3275,7 +3313,21 @@ build_annotations (start, end)
3275 GCPRO2 (annotations, p); 3313 GCPRO2 (annotations, p);
3276 while (!NILP (p)) 3314 while (!NILP (p))
3277 { 3315 {
3316 struct buffer *given_buffer = current_buffer;
3317 Vwrite_region_annotations_so_far = annotations;
3278 res = call2 (Fcar (p), start, end); 3318 res = call2 (Fcar (p), start, end);
3319 /* If the function makes a different buffer current,
3320 assume that means this buffer contains altered text to be output.
3321 Reset START and END from the buffer bounds
3322 and discard all previous annotations because they should have
3323 been dealt with by this function. */
3324 if (current_buffer != given_buffer)
3325 {
3326 Lisp_Object tem;
3327 start = BEGV;
3328 end = ZV;
3329 annotations = Qnil;
3330 }
3279 Flength (res); /* Check basic validity of return value */ 3331 Flength (res); /* Check basic validity of return value */
3280 annotations = merge (annotations, res, Qcar_less_than_car); 3332 annotations = merge (annotations, res, Qcar_less_than_car);
3281 p = Fcdr (p); 3333 p = Fcdr (p);
@@ -4074,6 +4126,13 @@ increasing order. If there are several functions in the list, the several\n\
4074lists are merged destructively."); 4126lists are merged destructively.");
4075 Vwrite_region_annotate_functions = Qnil; 4127 Vwrite_region_annotate_functions = Qnil;
4076 4128
4129 DEFVAR_LISP ("write-region-annotations-so-far",
4130 &Vwrite_region_annotations_so_far,
4131 "When an annotation function is called, this holds the previous annotations.\n\
4132These are the annotations made by other annotation functions\n\
4133that were already called. See also `write-region-annotate-functions'.");
4134 Vwrite_region_annotations_so_far = Qnil;
4135
4077 DEFVAR_LISP ("inhibit-file-name-handlers", &Vinhibit_file_name_handlers, 4136 DEFVAR_LISP ("inhibit-file-name-handlers", &Vinhibit_file_name_handlers,
4078 "A list of file name handlers that temporarily should not be used.\n\ 4137 "A list of file name handlers that temporarily should not be used.\n\
4079This applies only to the operation `inhibit-file-name-operation'."); 4138This applies only to the operation `inhibit-file-name-operation'.");