From: Glenn Morris <rgm@gnu.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 13522@debbugs.gnu.org, vincent@vinc17.net
Subject: bug#13522: 24.2; save-buffer removes edited file under some conditions
Date: Wed, 30 Jan 2013 03:59:25 -0500 [thread overview]
Message-ID: <3b8v7byrki.fsf@fencepost.gnu.org> (raw)
In-Reply-To: <y5txq5n0rm.fsf@fencepost.gnu.org> (Glenn Morris's message of "Fri, 25 Jan 2013 03:07:57 -0500")
Glenn Morris wrote:
> Maybe the right solution is to have the select-safe-coding-system check
> in basic-save-buffer-2 before backup-buffer, then pass the resulting
> coding system to write-region somehow so it does not need to query
> again.
Very lightly tested patch:
*** lisp/files.el 2013-01-10 15:50:04 +0000
--- lisp/files.el 2013-01-30 08:53:30 +0000
***************
*** 4656,4662 ****
;; This returns a value (MODES EXTENDED-ATTRIBUTES BACKUPNAME), like
;; backup-buffer.
(defun basic-save-buffer-2 ()
! (let (tempsetmodes setmodes)
(if (not (file-writable-p buffer-file-name))
(let ((dir (file-name-directory buffer-file-name)))
(if (not (file-directory-p dir))
--- 4656,4662 ----
;; This returns a value (MODES EXTENDED-ATTRIBUTES BACKUPNAME), like
;; backup-buffer.
(defun basic-save-buffer-2 ()
! (let (tempsetmodes setmodes writecoding)
(if (not (file-writable-p buffer-file-name))
(let ((dir (file-name-directory buffer-file-name)))
(if (not (file-directory-p dir))
***************
*** 4672,4677 ****
--- 4672,4680 ----
buffer-file-name)))
(setq tempsetmodes t)
(error "Attempt to save to a file which you aren't allowed to write"))))))
+ (setq writecoding
+ (choose-write-coding-system nil nil buffer-file-name nil t
+ buffer-file-truename))
(or buffer-backed-up
(setq setmodes (backup-buffer)))
(let* ((dir (file-name-directory buffer-file-name))
***************
*** 4753,4762 ****
(logior (car setmodes) 128))))))
(let (success)
(unwind-protect
- (progn
;; Pass in nil&nil rather than point-min&max to indicate
;; we're saving the buffer rather than just a region.
;; write-region-annotate-functions may make us of it.
(write-region nil nil
buffer-file-name nil t buffer-file-truename)
(setq success t))
--- 4756,4765 ----
(logior (car setmodes) 128))))))
(let (success)
(unwind-protect
;; Pass in nil&nil rather than point-min&max to indicate
;; we're saving the buffer rather than just a region.
;; write-region-annotate-functions may make us of it.
+ (let ((write-region-coding-system writecoding))
(write-region nil nil
buffer-file-name nil t buffer-file-truename)
(setq success t))
=== modified file 'src/fileio.c'
*** src/fileio.c 2013-01-23 20:07:28 +0000
--- src/fileio.c 2013-01-30 08:55:45 +0000
***************
*** 249,254 ****
--- 249,255 ----
static Lisp_Object Qset_file_acl;
static Lisp_Object Qfile_newer_than_file_p;
Lisp_Object Qinsert_file_contents;
+ Lisp_Object Qchoose_write_coding_system;
Lisp_Object Qwrite_region;
static Lisp_Object Qverify_visited_file_modtime;
static Lisp_Object Qset_visited_file_modtime;
***************
*** 4615,4628 ****
/* Decide the coding-system to encode the data with. */
! static Lisp_Object
! choose_write_coding_system (Lisp_Object start, Lisp_Object end, Lisp_Object filename,
! Lisp_Object append, Lisp_Object visit, Lisp_Object lockname,
! struct coding_system *coding)
{
Lisp_Object val;
Lisp_Object eol_parent = Qnil;
if (auto_saving
&& NILP (Fstring_equal (BVAR (current_buffer, filename),
BVAR (current_buffer, auto_save_file_name))))
--- 4616,4637 ----
/* Decide the coding-system to encode the data with. */
! DEFUN ("choose-write-coding-system", Fchoose_write_coding_system,
! Schoose_write_coding_system, 3, 6, 0,
! doc: /* Choose coding system for write.
! Arguments as for `write-region'. */ )
! (Lisp_Object start, Lisp_Object end, Lisp_Object filename,
! Lisp_Object append, Lisp_Object visit, Lisp_Object lockname)
{
Lisp_Object val;
Lisp_Object eol_parent = Qnil;
+ if (NILP (start))
+ {
+ XSETFASTINT (start, BEGV);
+ XSETFASTINT (end, ZV);
+ }
+
if (auto_saving
&& NILP (Fstring_equal (BVAR (current_buffer, filename),
BVAR (current_buffer, auto_save_file_name))))
***************
*** 4715,4724 ****
}
val = coding_inherit_eol_type (val, eol_parent);
- setup_coding_system (val, coding);
-
- if (!STRINGP (start) && !NILP (BVAR (current_buffer, selective_display)))
- coding->mode |= CODING_MODE_SELECTIVE_DISPLAY;
return val;
}
--- 4724,4729 ----
***************
*** 4874,4882 ****
We used to make this choice before calling build_annotations, but that
leads to problems when a write-annotate-function takes care of
unsavable chars (as was the case with X-Symbol). */
! Vlast_coding_system_used
! = choose_write_coding_system (start, end, filename,
! append, visit, lockname, &coding);
#ifdef CLASH_DETECTION
if (!auto_saving)
--- 4879,4893 ----
We used to make this choice before calling build_annotations, but that
leads to problems when a write-annotate-function takes care of
unsavable chars (as was the case with X-Symbol). */
! Vlast_coding_system_used = NILP (Vwrite_region_coding_system) ?
! Fchoose_write_coding_system (start, end, filename,
! append, visit, lockname) :
! Vwrite_region_coding_system;
!
! setup_coding_system (Vlast_coding_system_used, &coding);
!
! if (!STRINGP (start) && !NILP (BVAR (current_buffer, selective_display)))
! coding.mode |= CODING_MODE_SELECTIVE_DISPLAY;
#ifdef CLASH_DETECTION
if (!auto_saving)
***************
*** 5861,5866 ****
--- 5872,5878 ----
DEFSYM (Qset_file_acl, "set-file-acl");
DEFSYM (Qfile_newer_than_file_p, "file-newer-than-file-p");
DEFSYM (Qinsert_file_contents, "insert-file-contents");
+ DEFSYM (Qchoose_write_coding_system, "choose-write-coding-system");
DEFSYM (Qwrite_region, "write-region");
DEFSYM (Qverify_visited_file_modtime, "verify-visited-file-modtime");
DEFSYM (Qset_visited_file_modtime, "set-visited-file-modtime");
***************
*** 5890,5895 ****
--- 5902,5912 ----
of file names regardless of the current language environment. */);
Vdefault_file_name_coding_system = Qnil;
+ DEFVAR_LISP ("write-region-coding-system", Vwrite_region_coding_system,
+ doc: /* If non-nil, coding system for `write-region'.
+ You should only ever `let'-bind this around a `write-region' call. */);
+ Vwrite_region_coding_system = Qnil;
+
DEFSYM (Qformat_decode, "format-decode");
DEFSYM (Qformat_annotate_function, "format-annotate-function");
DEFSYM (Qafter_insert_file_set_coding, "after-insert-file-set-coding");
***************
*** 6085,6090 ****
--- 6102,6108 ----
defsubr (&Sdefault_file_modes);
defsubr (&Sfile_newer_than_file_p);
defsubr (&Sinsert_file_contents);
+ defsubr (&Schoose_write_coding_system);
defsubr (&Swrite_region);
defsubr (&Scar_less_than_car);
defsubr (&Sverify_visited_file_modtime);
next prev parent reply other threads:[~2013-01-30 8:59 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-22 1:47 bug#13522: 24.2; save-buffer removes edited file under some conditions Vincent Lefevre
2013-01-24 20:28 ` Glenn Morris
2013-01-25 0:02 ` Vincent Lefevre
2013-01-25 0:48 ` Glenn Morris
2013-01-25 7:35 ` Eli Zaretskii
2013-01-25 8:07 ` Glenn Morris
2013-01-30 8:59 ` Glenn Morris [this message]
2013-01-30 19:34 ` Stefan Monnier
2013-01-31 6:36 ` Glenn Morris
2014-08-11 1:06 ` Glenn Morris
2022-03-14 11:21 ` Lars Ingebrigtsen
2022-03-14 13:37 ` Eli Zaretskii
2022-03-14 13:43 ` Lars Ingebrigtsen
2022-03-14 14:05 ` Eli Zaretskii
2022-03-14 15:20 ` Vincent Lefevre
2022-03-14 17:02 ` Eli Zaretskii
2022-03-14 17:32 ` Vincent Lefevre
2022-03-15 11:42 ` Lars Ingebrigtsen
2022-03-15 14:23 ` Eli Zaretskii
2022-03-15 14:25 ` Lars Ingebrigtsen
2022-03-15 15:55 ` Vincent Lefevre
2022-04-30 16:47 ` Lars Ingebrigtsen
2022-04-30 16:51 ` Lars Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3b8v7byrki.fsf@fencepost.gnu.org \
--to=rgm@gnu.org \
--cc=13522@debbugs.gnu.org \
--cc=eliz@gnu.org \
--cc=vincent@vinc17.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).