From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Glenn Morris Newsgroups: gmane.emacs.bugs Subject: bug#13522: 24.2; save-buffer removes edited file under some conditions Date: Wed, 30 Jan 2013 03:59:25 -0500 Message-ID: <3b8v7byrki.fsf@fencepost.gnu.org> References: <87622qaszq.fsf@xvii.vinc17.org> <20130125000256.GC3397@xvii.vinc17.org> <83libhlnpz.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1359536436 10690 80.91.229.3 (30 Jan 2013 09:00:36 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 30 Jan 2013 09:00:36 +0000 (UTC) Cc: 13522@debbugs.gnu.org, vincent@vinc17.net To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Jan 30 10:00:55 2013 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1U0TXL-0000JV-An for geb-bug-gnu-emacs@m.gmane.org; Wed, 30 Jan 2013 10:00:55 +0100 Original-Received: from localhost ([::1]:37210 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U0TX3-0002yg-DF for geb-bug-gnu-emacs@m.gmane.org; Wed, 30 Jan 2013 04:00:37 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:52480) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U0TWw-0002yJ-Eg for bug-gnu-emacs@gnu.org; Wed, 30 Jan 2013 04:00:35 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U0TWu-0003UU-BW for bug-gnu-emacs@gnu.org; Wed, 30 Jan 2013 04:00:30 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:49749) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U0TWu-0003SE-7M for bug-gnu-emacs@gnu.org; Wed, 30 Jan 2013 04:00:28 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1U0TXR-0006M9-Oy for bug-gnu-emacs@gnu.org; Wed, 30 Jan 2013 04:01:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Glenn Morris Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 30 Jan 2013 09:01:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 13522 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: confirmed Original-Received: via spool by 13522-submit@debbugs.gnu.org id=B13522.135953640524369 (code B ref 13522); Wed, 30 Jan 2013 09:01:01 +0000 Original-Received: (at 13522) by debbugs.gnu.org; 30 Jan 2013 09:00:05 +0000 Original-Received: from localhost ([127.0.0.1]:55213 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1U0TWX-0006L0-0Q for submit@debbugs.gnu.org; Wed, 30 Jan 2013 04:00:05 -0500 Original-Received: from fencepost.gnu.org ([208.118.235.10]:37160) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1U0TWU-0006KN-KR for 13522@debbugs.gnu.org; Wed, 30 Jan 2013 04:00:04 -0500 Original-Received: from rgm by fencepost.gnu.org with local (Exim 4.71) (envelope-from ) id 1U0TVu-0003CS-40; Wed, 30 Jan 2013 03:59:26 -0500 X-Spook: Downing Street World Trade Center Blowpipe Plame class X-Ran: /-Hg7m,\{zoejgS-m`{Jzz0=R9F7GOq\uud'XfZt=O-teO"8HjNmsoY[rZqSs0/mUdK+)m X-Hue: black X-Attribution: GM In-Reply-To: (Glenn Morris's message of "Fri, 25 Jan 2013 03:07:57 -0500") User-Agent: Gnus (www.gnus.org), GNU Emacs (www.gnu.org/software/emacs/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:70460 Archived-At: 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);