Mercurial > emacs
comparison src/fileio.c @ 101335:df6accf4cd6f
(Vwrite_region_post_annotation_function)
(Vwrite_region_annotation_buffers): New vars.
(build_annotations_unwind): Just reset
Vwrite_region_annotation_buffers.
(Fwrite_region): Initialize Vwrite_region_annotation_buffers.
Call write-region-post-annotation-function.
(build_annotations): Add to Vwrite_region_annotation_buffers if
buffer changes.
author | Chong Yidong <cyd@stupidchicken.com> |
---|---|
date | Thu, 22 Jan 2009 04:42:51 +0000 |
parents | e038c1a8307c |
children | dc93dbd4d490 |
comparison
equal
deleted
inserted
replaced
101334:0096f2a0e5a4 | 101335:df6accf4cd6f |
---|---|
175 Lisp_Object Qafter_insert_file_set_coding; | 175 Lisp_Object Qafter_insert_file_set_coding; |
176 | 176 |
177 /* Functions to be called to create text property annotations for file. */ | 177 /* Functions to be called to create text property annotations for file. */ |
178 Lisp_Object Vwrite_region_annotate_functions; | 178 Lisp_Object Vwrite_region_annotate_functions; |
179 Lisp_Object Qwrite_region_annotate_functions; | 179 Lisp_Object Qwrite_region_annotate_functions; |
180 Lisp_Object Vwrite_region_post_annotation_function; | |
180 | 181 |
181 /* During build_annotations, each time an annotation function is called, | 182 /* During build_annotations, each time an annotation function is called, |
182 this holds the annotations made by the previous functions. */ | 183 this holds the annotations made by the previous functions. */ |
183 Lisp_Object Vwrite_region_annotations_so_far; | 184 Lisp_Object Vwrite_region_annotations_so_far; |
185 | |
186 /* Each time an annotation function changes the buffer, the new buffer | |
187 is added here. */ | |
188 Lisp_Object Vwrite_region_annotation_buffers; | |
184 | 189 |
185 /* File name in which we write a list of all our auto save files. */ | 190 /* File name in which we write a list of all our auto save files. */ |
186 Lisp_Object Vauto_save_list_file_name; | 191 Lisp_Object Vauto_save_list_file_name; |
187 | 192 |
188 /* Whether or not files are auto-saved into themselves. */ | 193 /* Whether or not files are auto-saved into themselves. */ |
4248 RETURN_UNGCPRO (unbind_to (count, val)); | 4253 RETURN_UNGCPRO (unbind_to (count, val)); |
4249 } | 4254 } |
4250 | 4255 |
4251 static Lisp_Object build_annotations P_ ((Lisp_Object, Lisp_Object)); | 4256 static Lisp_Object build_annotations P_ ((Lisp_Object, Lisp_Object)); |
4252 | 4257 |
4253 /* If build_annotations switched buffers, switch back to BUF. | |
4254 Kill the temporary buffer that was selected in the meantime. | |
4255 | |
4256 Since this kill only the last temporary buffer, some buffers remain | |
4257 not killed if build_annotations switched buffers more than once. | |
4258 -- K.Handa */ | |
4259 | |
4260 static Lisp_Object | 4258 static Lisp_Object |
4261 build_annotations_unwind (buf) | 4259 build_annotations_unwind (arg) |
4262 Lisp_Object buf; | 4260 Lisp_Object arg; |
4263 { | 4261 { |
4264 Lisp_Object tembuf; | 4262 Vwrite_region_annotation_buffers = arg; |
4265 | |
4266 if (XBUFFER (buf) == current_buffer) | |
4267 return Qnil; | |
4268 tembuf = Fcurrent_buffer (); | |
4269 Fset_buffer (buf); | |
4270 Fkill_buffer (tembuf); | |
4271 return Qnil; | 4263 return Qnil; |
4272 } | 4264 } |
4273 | 4265 |
4274 /* Decide the coding-system to encode the data with. */ | 4266 /* Decide the coding-system to encode the data with. */ |
4275 | 4267 |
4496 XSETFASTINT (start, BEG); | 4488 XSETFASTINT (start, BEG); |
4497 XSETFASTINT (end, Z); */ | 4489 XSETFASTINT (end, Z); */ |
4498 Fwiden (); | 4490 Fwiden (); |
4499 } | 4491 } |
4500 | 4492 |
4501 record_unwind_protect (build_annotations_unwind, Fcurrent_buffer ()); | 4493 record_unwind_protect (build_annotations_unwind, |
4494 Vwrite_region_annotation_buffers); | |
4495 Vwrite_region_annotation_buffers = Fcons (Fcurrent_buffer (), Qnil); | |
4502 count1 = SPECPDL_INDEX (); | 4496 count1 = SPECPDL_INDEX (); |
4503 | 4497 |
4504 given_buffer = current_buffer; | 4498 given_buffer = current_buffer; |
4505 | 4499 |
4506 if (!STRINGP (start)) | 4500 if (!STRINGP (start)) |
4532 = choose_write_coding_system (start, end, filename, | 4526 = choose_write_coding_system (start, end, filename, |
4533 append, visit, lockname, &coding); | 4527 append, visit, lockname, &coding); |
4534 | 4528 |
4535 #ifdef CLASH_DETECTION | 4529 #ifdef CLASH_DETECTION |
4536 if (!auto_saving) | 4530 if (!auto_saving) |
4537 { | 4531 lock_file (lockname); |
4538 #if 0 /* This causes trouble for GNUS. */ | |
4539 /* If we've locked this file for some other buffer, | |
4540 query before proceeding. */ | |
4541 if (!visiting && EQ (Ffile_locked_p (lockname), Qt)) | |
4542 call2 (intern ("ask-user-about-lock"), filename, Vuser_login_name); | |
4543 #endif | |
4544 | |
4545 lock_file (lockname); | |
4546 } | |
4547 #endif /* CLASH_DETECTION */ | 4532 #endif /* CLASH_DETECTION */ |
4548 | 4533 |
4549 encoded_filename = ENCODE_FILE (filename); | 4534 encoded_filename = ENCODE_FILE (filename); |
4550 | 4535 |
4551 fn = SDATA (encoded_filename); | 4536 fn = SDATA (encoded_filename); |
4600 } | 4585 } |
4601 } | 4586 } |
4602 | 4587 |
4603 UNGCPRO; | 4588 UNGCPRO; |
4604 | 4589 |
4605 #if 0 | |
4606 /* The new encoding routine doesn't require the following. */ | |
4607 | |
4608 /* Whether VMS or not, we must move the gap to the next of newline | |
4609 when we must put designation sequences at beginning of line. */ | |
4610 if (INTEGERP (start) | |
4611 && coding.type == coding_type_iso2022 | |
4612 && coding.flags & CODING_FLAG_ISO_DESIGNATE_AT_BOL | |
4613 && GPT > BEG && GPT_ADDR[-1] != '\n') | |
4614 { | |
4615 int opoint = PT, opoint_byte = PT_BYTE; | |
4616 scan_newline (PT, PT_BYTE, ZV, ZV_BYTE, 1, 0); | |
4617 move_gap_both (PT, PT_BYTE); | |
4618 SET_PT_BOTH (opoint, opoint_byte); | |
4619 } | |
4620 #endif | |
4621 | |
4622 failure = 0; | 4590 failure = 0; |
4623 immediate_quit = 1; | 4591 immediate_quit = 1; |
4624 | 4592 |
4625 if (STRINGP (start)) | 4593 if (STRINGP (start)) |
4626 { | 4594 { |
4668 if (errno != EINTR && errno != EINVAL) | 4636 if (errno != EINTR && errno != EINVAL) |
4669 failure = 1, save_errno = errno; | 4637 failure = 1, save_errno = errno; |
4670 } | 4638 } |
4671 #endif | 4639 #endif |
4672 | 4640 |
4673 /* Spurious "file has changed on disk" warnings have been | |
4674 observed on Suns as well. | |
4675 It seems that `close' can change the modtime, under nfs. | |
4676 | |
4677 (This has supposedly been fixed in Sunos 4, | |
4678 but who knows about all the other machines with NFS?) */ | |
4679 #if 0 | |
4680 | |
4681 #define FOO | |
4682 fstat (desc, &st); | |
4683 #endif | |
4684 | |
4685 /* NFS can report a write failure now. */ | 4641 /* NFS can report a write failure now. */ |
4686 if (emacs_close (desc) < 0) | 4642 if (emacs_close (desc) < 0) |
4687 failure = 1, save_errno = errno; | 4643 failure = 1, save_errno = errno; |
4688 | 4644 |
4689 #ifndef FOO | |
4690 stat (fn, &st); | 4645 stat (fn, &st); |
4691 #endif | 4646 |
4692 /* Discard the unwind protect for close_file_unwind. */ | 4647 /* Discard the unwind protect for close_file_unwind. */ |
4693 specpdl_ptr = specpdl + count1; | 4648 specpdl_ptr = specpdl + count1; |
4694 /* Restore the original current buffer. */ | 4649 |
4695 visit_file = unbind_to (count, visit_file); | 4650 /* Call write-region-post-annotation-function. */ |
4651 while (!NILP (Vwrite_region_annotation_buffers)) | |
4652 { | |
4653 Lisp_Object buf = XCAR (Vwrite_region_annotation_buffers); | |
4654 if (!NILP (Fbuffer_live_p (buf))) | |
4655 { | |
4656 Fset_buffer (buf); | |
4657 if (FUNCTIONP (Vwrite_region_post_annotation_function)) | |
4658 call0 (Vwrite_region_post_annotation_function); | |
4659 } | |
4660 Vwrite_region_annotation_buffers | |
4661 = XCDR (Vwrite_region_annotation_buffers); | |
4662 } | |
4663 | |
4664 unbind_to (count, Qnil); | |
4696 | 4665 |
4697 #ifdef CLASH_DETECTION | 4666 #ifdef CLASH_DETECTION |
4698 if (!auto_saving) | 4667 if (!auto_saving) |
4699 unlock_file (lockname); | 4668 unlock_file (lockname); |
4700 #endif /* CLASH_DETECTION */ | 4669 #endif /* CLASH_DETECTION */ |
4789 Reset START and END from the buffer bounds | 4758 Reset START and END from the buffer bounds |
4790 and discard all previous annotations because they should have | 4759 and discard all previous annotations because they should have |
4791 been dealt with by this function. */ | 4760 been dealt with by this function. */ |
4792 if (current_buffer != given_buffer) | 4761 if (current_buffer != given_buffer) |
4793 { | 4762 { |
4763 Vwrite_region_annotation_buffers | |
4764 = Fcons (Fcurrent_buffer (), | |
4765 Vwrite_region_annotation_buffers); | |
4794 XSETFASTINT (start, BEGV); | 4766 XSETFASTINT (start, BEGV); |
4795 XSETFASTINT (end, ZV); | 4767 XSETFASTINT (end, ZV); |
4796 annotations = Qnil; | 4768 annotations = Qnil; |
4797 } | 4769 } |
4798 Flength (res); /* Check basic validity of return value */ | 4770 Flength (res); /* Check basic validity of return value */ |
5649 These are usually two numbers but not always; see the documentation | 5621 These are usually two numbers but not always; see the documentation |
5650 for `write-region'. The function should return a list of pairs | 5622 for `write-region'. The function should return a list of pairs |
5651 of the form (POSITION . STRING), consisting of strings to be effectively | 5623 of the form (POSITION . STRING), consisting of strings to be effectively |
5652 inserted at the specified positions of the file being written (1 means to | 5624 inserted at the specified positions of the file being written (1 means to |
5653 insert before the first byte written). The POSITIONs must be sorted into | 5625 insert before the first byte written). The POSITIONs must be sorted into |
5654 increasing order. If there are several functions in the list, the several | 5626 increasing order. |
5655 lists are merged destructively. Alternatively, the function can return | 5627 |
5656 with a different buffer current; in that case it should pay attention | 5628 If there are several annotation functions, the lists returned by these |
5657 to the annotations returned by previous functions and listed in | 5629 functions are merged destructively. As each annotation function runs, |
5658 `write-region-annotations-so-far'.*/); | 5630 the variable `write-region-annotations-so-far' contains a list of all |
5631 annotations returned by previous annotation functions. | |
5632 | |
5633 An annotation function can return with a different buffer current. | |
5634 Doing so removes the annotations returned by previous functions, and | |
5635 resets START and END to `point-min' and `point-max' of the new buffer. | |
5636 | |
5637 After `write-region' completes, Emacs calls the function stored in | |
5638 `write-region-post-annotation-function', once for each buffer that was | |
5639 current when building the annotations (i.e., at least once), with that | |
5640 buffer current. */); | |
5659 Vwrite_region_annotate_functions = Qnil; | 5641 Vwrite_region_annotate_functions = Qnil; |
5660 staticpro (&Qwrite_region_annotate_functions); | 5642 staticpro (&Qwrite_region_annotate_functions); |
5661 Qwrite_region_annotate_functions | 5643 Qwrite_region_annotate_functions |
5662 = intern ("write-region-annotate-functions"); | 5644 = intern ("write-region-annotate-functions"); |
5645 | |
5646 DEFVAR_LISP ("write-region-post-annotation-function", | |
5647 &Vwrite_region_post_annotation_function, | |
5648 doc: /* Function to call after `write-region' completes. | |
5649 The function is called with no arguments. If one or more of the | |
5650 annotation functions in `write-region-annotate-functions' changed the | |
5651 current buffer, the function stored in this variable is called for | |
5652 each of those additional buffers as well, in addition to the original | |
5653 buffer. The relevant buffer is current during each function call. */); | |
5654 Vwrite_region_post_annotation_function = Qnil; | |
5655 staticpro (&Vwrite_region_annotation_buffers); | |
5663 | 5656 |
5664 DEFVAR_LISP ("write-region-annotations-so-far", | 5657 DEFVAR_LISP ("write-region-annotations-so-far", |
5665 &Vwrite_region_annotations_so_far, | 5658 &Vwrite_region_annotations_so_far, |
5666 doc: /* When an annotation function is called, this holds the previous annotations. | 5659 doc: /* When an annotation function is called, this holds the previous annotations. |
5667 These are the annotations made by other annotation functions | 5660 These are the annotations made by other annotation functions |