diff options
| author | Chong Yidong | 2009-01-22 04:42:51 +0000 |
|---|---|---|
| committer | Chong Yidong | 2009-01-22 04:42:51 +0000 |
| commit | 67fbc0cb3ae4c523798c4dde7867e5c637cea2ff (patch) | |
| tree | b62e5c4dcf4463fcac99cf4b8be07f53c3b8639b /src | |
| parent | 918b848ba10bf471e2f1d5c80355b10482605a49 (diff) | |
| download | emacs-67fbc0cb3ae4c523798c4dde7867e5c637cea2ff.tar.gz emacs-67fbc0cb3ae4c523798c4dde7867e5c637cea2ff.zip | |
(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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/fileio.c | 123 |
1 files changed, 58 insertions, 65 deletions
diff --git a/src/fileio.c b/src/fileio.c index 255d1a9117a..9651ac8e18b 100644 --- a/src/fileio.c +++ b/src/fileio.c | |||
| @@ -177,11 +177,16 @@ Lisp_Object Qafter_insert_file_set_coding; | |||
| 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; |
| 184 | 185 | ||
| 186 | /* Each time an annotation function changes the buffer, the new buffer | ||
| 187 | is added here. */ | ||
| 188 | Lisp_Object Vwrite_region_annotation_buffers; | ||
| 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 | ||
| @@ -4250,24 +4255,11 @@ variable `last-coding-system-used' to the coding system actually used. */) | |||
| 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 | ||
| @@ -4498,7 +4490,9 @@ This does code conversion according to the value of | |||
| 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; |
| @@ -4534,16 +4528,7 @@ This does code conversion according to the value of | |||
| 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); |
| @@ -4602,23 +4587,6 @@ This does code conversion according to the value of | |||
| 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 | ||
| @@ -4670,29 +4638,30 @@ This does code conversion according to the value of | |||
| 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) |
| @@ -4791,6 +4760,9 @@ build_annotations (start, end) | |||
| 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; |
| @@ -5651,16 +5623,37 @@ 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"); |
| 5663 | 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); | ||
| 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. |