aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlenn Morris2013-01-30 22:35:45 -0800
committerGlenn Morris2013-01-30 22:35:45 -0800
commit9dbda100755158fd070931748f2b80ad09bc6815 (patch)
tree4051909615adf3e1c618976602e66a2cbcc23a6e
parentad4de702e19bf1a8065cb84b6eefbc68190d9c3f (diff)
downloademacs-9dbda100755158fd070931748f2b80ad09bc6815.tar.gz
emacs-9dbda100755158fd070931748f2b80ad09bc6815.zip
Reduce delay between backing up a file and saving new version
* lisp/files.el (basic-save-buffer-2): Choose coding system for writing the file before backing it up. * src/fileio.c (choose_write_coding_system): Make it callable from Lisp. (Fwrite_region): If coding-system-for-write is set, don't call choose_write_coding_system. Move the last piece of choose_write_coding_system here. (syms_of_fileio): Add choose-write-coding-system. Fixes: debbugs:13522
-rw-r--r--lisp/ChangeLog6
-rw-r--r--lisp/files.el13
-rw-r--r--src/ChangeLog8
-rw-r--r--src/fileio.c37
4 files changed, 51 insertions, 13 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 6ac51724328..c1142a45e8d 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,9 @@
12013-01-31 Glenn Morris <rgm@gnu.org>
2
3 * files.el (basic-save-buffer-2): Choose coding system for
4 writing the file before backing it up, to reduce delay between
5 backing up and writing the new version. (Bug#13522)
6
12013-01-31 Michal Nazarewicz <mina86@mina86.com> 72013-01-31 Michal Nazarewicz <mina86@mina86.com>
2 8
3 * simple.el (cycle-spacing): New command. 9 * simple.el (cycle-spacing): New command.
diff --git a/lisp/files.el b/lisp/files.el
index b015b53db3c..3bc3059c68f 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -4656,7 +4656,7 @@ Before and after saving the buffer, this function runs
4656;; This returns a value (MODES EXTENDED-ATTRIBUTES BACKUPNAME), like 4656;; This returns a value (MODES EXTENDED-ATTRIBUTES BACKUPNAME), like
4657;; backup-buffer. 4657;; backup-buffer.
4658(defun basic-save-buffer-2 () 4658(defun basic-save-buffer-2 ()
4659 (let (tempsetmodes setmodes) 4659 (let (tempsetmodes setmodes writecoding)
4660 (if (not (file-writable-p buffer-file-name)) 4660 (if (not (file-writable-p buffer-file-name))
4661 (let ((dir (file-name-directory buffer-file-name))) 4661 (let ((dir (file-name-directory buffer-file-name)))
4662 (if (not (file-directory-p dir)) 4662 (if (not (file-directory-p dir))
@@ -4672,6 +4672,14 @@ Before and after saving the buffer, this function runs
4672 buffer-file-name))) 4672 buffer-file-name)))
4673 (setq tempsetmodes t) 4673 (setq tempsetmodes t)
4674 (error "Attempt to save to a file which you aren't allowed to write")))))) 4674 (error "Attempt to save to a file which you aren't allowed to write"))))))
4675 ;; This may involve prompting, so do it now before backing up the file.
4676 ;; Otherwise there can be a delay while the user answers the
4677 ;; prompt during which the original file has been renamed. (Bug#13522)
4678 (setq writecoding
4679 ;; Args here should match write-region call below around
4680 ;; which we use writecoding.
4681 (choose-write-coding-system nil nil buffer-file-name nil t
4682 buffer-file-truename))
4675 (or buffer-backed-up 4683 (or buffer-backed-up
4676 (setq setmodes (backup-buffer))) 4684 (setq setmodes (backup-buffer)))
4677 (let* ((dir (file-name-directory buffer-file-name)) 4685 (let* ((dir (file-name-directory buffer-file-name))
@@ -4753,10 +4761,11 @@ Before and after saving the buffer, this function runs
4753 (logior (car setmodes) 128)))))) 4761 (logior (car setmodes) 128))))))
4754 (let (success) 4762 (let (success)
4755 (unwind-protect 4763 (unwind-protect
4756 (progn
4757 ;; Pass in nil&nil rather than point-min&max to indicate 4764 ;; Pass in nil&nil rather than point-min&max to indicate
4758 ;; we're saving the buffer rather than just a region. 4765 ;; we're saving the buffer rather than just a region.
4759 ;; write-region-annotate-functions may make us of it. 4766 ;; write-region-annotate-functions may make us of it.
4767 (let ((coding-system-for-write writecoding)
4768 (coding-system-require-warning nil))
4760 (write-region nil nil 4769 (write-region nil nil
4761 buffer-file-name nil t buffer-file-truename) 4770 buffer-file-name nil t buffer-file-truename)
4762 (setq success t)) 4771 (setq success t))
diff --git a/src/ChangeLog b/src/ChangeLog
index bb03ba10bb0..08eb9b50a9b 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,11 @@
12013-01-31 Glenn Morris <rgm@gnu.org>
2
3 * fileio.c (choose_write_coding_system): Make it callable from Lisp.
4 (Fwrite_region): If coding-system-for-write is set, don't
5 call choose_write_coding_system. Move the last piece of
6 choose_write_coding_system here. (Bug#13522)
7 (syms_of_fileio): Add choose-write-coding-system.
8
12013-01-30 Eli Zaretskii <eliz@gnu.org> 92013-01-30 Eli Zaretskii <eliz@gnu.org>
2 10
3 * w32.c (sys_open): Zero out the flags for the new file descriptor. 11 * w32.c (sys_open): Zero out the flags for the new file descriptor.
diff --git a/src/fileio.c b/src/fileio.c
index e788bebab61..ac0ce202a02 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -249,6 +249,7 @@ static Lisp_Object Qfile_acl;
249static Lisp_Object Qset_file_acl; 249static Lisp_Object Qset_file_acl;
250static Lisp_Object Qfile_newer_than_file_p; 250static Lisp_Object Qfile_newer_than_file_p;
251Lisp_Object Qinsert_file_contents; 251Lisp_Object Qinsert_file_contents;
252Lisp_Object Qchoose_write_coding_system;
252Lisp_Object Qwrite_region; 253Lisp_Object Qwrite_region;
253static Lisp_Object Qverify_visited_file_modtime; 254static Lisp_Object Qverify_visited_file_modtime;
254static Lisp_Object Qset_visited_file_modtime; 255static Lisp_Object Qset_visited_file_modtime;
@@ -4615,14 +4616,24 @@ build_annotations_unwind (Lisp_Object arg)
4615 4616
4616/* Decide the coding-system to encode the data with. */ 4617/* Decide the coding-system to encode the data with. */
4617 4618
4618static Lisp_Object 4619DEFUN ("choose-write-coding-system", Fchoose_write_coding_system,
4619choose_write_coding_system (Lisp_Object start, Lisp_Object end, Lisp_Object filename, 4620 Schoose_write_coding_system, 3, 6, 0,
4620 Lisp_Object append, Lisp_Object visit, Lisp_Object lockname, 4621 doc: /* Choose the coding system for writing a file.
4621 struct coding_system *coding) 4622Arguments are as for `write-region'.
4623This function is for internal use only. It may prompt the user. */ )
4624 (Lisp_Object start, Lisp_Object end, Lisp_Object filename,
4625 Lisp_Object append, Lisp_Object visit, Lisp_Object lockname)
4622{ 4626{
4623 Lisp_Object val; 4627 Lisp_Object val;
4624 Lisp_Object eol_parent = Qnil; 4628 Lisp_Object eol_parent = Qnil;
4625 4629
4630 /* Mimic write-region behavior. */
4631 if (NILP (start))
4632 {
4633 XSETFASTINT (start, BEGV);
4634 XSETFASTINT (end, ZV);
4635 }
4636
4626 if (auto_saving 4637 if (auto_saving
4627 && NILP (Fstring_equal (BVAR (current_buffer, filename), 4638 && NILP (Fstring_equal (BVAR (current_buffer, filename),
4628 BVAR (current_buffer, auto_save_file_name)))) 4639 BVAR (current_buffer, auto_save_file_name))))
@@ -4715,10 +4726,6 @@ choose_write_coding_system (Lisp_Object start, Lisp_Object end, Lisp_Object file
4715 } 4726 }
4716 4727
4717 val = coding_inherit_eol_type (val, eol_parent); 4728 val = coding_inherit_eol_type (val, eol_parent);
4718 setup_coding_system (val, coding);
4719
4720 if (!STRINGP (start) && !NILP (BVAR (current_buffer, selective_display)))
4721 coding->mode |= CODING_MODE_SELECTIVE_DISPLAY;
4722 return val; 4729 return val;
4723} 4730}
4724 4731
@@ -4874,9 +4881,15 @@ This calls `write-region-annotate-functions' at the start, and
4874 We used to make this choice before calling build_annotations, but that 4881 We used to make this choice before calling build_annotations, but that
4875 leads to problems when a write-annotate-function takes care of 4882 leads to problems when a write-annotate-function takes care of
4876 unsavable chars (as was the case with X-Symbol). */ 4883 unsavable chars (as was the case with X-Symbol). */
4877 Vlast_coding_system_used 4884 Vlast_coding_system_used = NILP (Vcoding_system_for_write) ?
4878 = choose_write_coding_system (start, end, filename, 4885 Fchoose_write_coding_system (start, end, filename,
4879 append, visit, lockname, &coding); 4886 append, visit, lockname) :
4887 Vcoding_system_for_write;
4888
4889 setup_coding_system (Vlast_coding_system_used, &coding);
4890
4891 if (!STRINGP (start) && !NILP (BVAR (current_buffer, selective_display)))
4892 coding.mode |= CODING_MODE_SELECTIVE_DISPLAY;
4880 4893
4881#ifdef CLASH_DETECTION 4894#ifdef CLASH_DETECTION
4882 if (!auto_saving) 4895 if (!auto_saving)
@@ -5861,6 +5874,7 @@ syms_of_fileio (void)
5861 DEFSYM (Qset_file_acl, "set-file-acl"); 5874 DEFSYM (Qset_file_acl, "set-file-acl");
5862 DEFSYM (Qfile_newer_than_file_p, "file-newer-than-file-p"); 5875 DEFSYM (Qfile_newer_than_file_p, "file-newer-than-file-p");
5863 DEFSYM (Qinsert_file_contents, "insert-file-contents"); 5876 DEFSYM (Qinsert_file_contents, "insert-file-contents");
5877 DEFSYM (Qchoose_write_coding_system, "choose-write-coding-system");
5864 DEFSYM (Qwrite_region, "write-region"); 5878 DEFSYM (Qwrite_region, "write-region");
5865 DEFSYM (Qverify_visited_file_modtime, "verify-visited-file-modtime"); 5879 DEFSYM (Qverify_visited_file_modtime, "verify-visited-file-modtime");
5866 DEFSYM (Qset_visited_file_modtime, "set-visited-file-modtime"); 5880 DEFSYM (Qset_visited_file_modtime, "set-visited-file-modtime");
@@ -6085,6 +6099,7 @@ This includes interactive calls to `delete-file' and
6085 defsubr (&Sdefault_file_modes); 6099 defsubr (&Sdefault_file_modes);
6086 defsubr (&Sfile_newer_than_file_p); 6100 defsubr (&Sfile_newer_than_file_p);
6087 defsubr (&Sinsert_file_contents); 6101 defsubr (&Sinsert_file_contents);
6102 defsubr (&Schoose_write_coding_system);
6088 defsubr (&Swrite_region); 6103 defsubr (&Swrite_region);
6089 defsubr (&Scar_less_than_car); 6104 defsubr (&Scar_less_than_car);
6090 defsubr (&Sverify_visited_file_modtime); 6105 defsubr (&Sverify_visited_file_modtime);