From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Norbert Eisinger Newsgroups: gmane.emacs.bugs Subject: bug#4816: change of coding system without inquiry Date: Sat, 31 Oct 2009 17:32:56 +0100 Message-ID: <4AEC66B8.6000909@informatik.uni-muenchen.de> References: <4AE77C59.5060106@informatik.uni-muenchen.de> <4AEAE7F8.6010609@informatik.uni-muenchen.de> Reply-To: eisinger@informatik.uni-muenchen.de, 4816@emacsbugs.donarmstrong.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1257048527 19546 80.91.229.12 (1 Nov 2009 04:08:47 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 1 Nov 2009 04:08:47 +0000 (UTC) Cc: 4816@emacsbugs.donarmstrong.com To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Nov 01 05:08:40 2009 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1N4Rk6-0007vr-VU for geb-bug-gnu-emacs@m.gmane.org; Sun, 01 Nov 2009 05:08:39 +0100 Original-Received: from localhost ([127.0.0.1]:57676 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N4Rk6-0005wA-9v for geb-bug-gnu-emacs@m.gmane.org; Sun, 01 Nov 2009 00:08:38 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N4H6q-0003o5-5G for bug-gnu-emacs@gnu.org; Sat, 31 Oct 2009 12:47:24 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N4H6k-0003mc-SY for bug-gnu-emacs@gnu.org; Sat, 31 Oct 2009 12:47:23 -0400 Original-Received: from [199.232.76.173] (port=38904 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N4H6k-0003mR-Nq for bug-gnu-emacs@gnu.org; Sat, 31 Oct 2009 12:47:18 -0400 Original-Received: from rzlab.ucr.edu ([138.23.92.77]:36921) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1N4H6j-0002qw-L4 for bug-gnu-emacs@gnu.org; Sat, 31 Oct 2009 12:47:18 -0400 Original-Received: from rzlab.ucr.edu (rzlab.ucr.edu [127.0.0.1]) by rzlab.ucr.edu (8.14.3/8.14.3/Debian-5) with ESMTP id n9VGlFHi001314; Sat, 31 Oct 2009 09:47:15 -0700 Original-Received: (from debbugs@localhost) by rzlab.ucr.edu (8.14.3/8.14.3/Submit) id n9VGe7ui000411; Sat, 31 Oct 2009 09:40:07 -0700 Resent-Date: Sat, 31 Oct 2009 09:40:07 -0700 X-Loop: owner@emacsbugs.donarmstrong.com Resent-From: Norbert Eisinger Resent-To: bug-submit-list@donarmstrong.com Resent-CC: Emacs Bugs 2Resent-Date: Sat, 31 Oct 2009 16:40:07 +0000 Resent-Message-ID: Resent-Sender: owner@emacsbugs.donarmstrong.com X-Emacs-PR-Message: followup 4816 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: Original-Received: via spool by 4816-submit@emacsbugs.donarmstrong.com id=B4816.125700678932286 (code B ref 4816); Sat, 31 Oct 2009 16:40:07 +0000 Original-Received: (at 4816) by emacsbugs.donarmstrong.com; 31 Oct 2009 16:33:09 +0000 X-Spam-Bayes: score:0.5 Bayes not run. spammytokens:Tokens not available. hammytokens:Tokens not available. Original-Received: from acheron.ifi.lmu.de (acheron.ifi.lmu.de [129.187.214.135]) by rzlab.ucr.edu (8.14.3/8.14.3/Debian-5) with ESMTP id n9VGX5PM032283 for <4816@emacsbugs.donarmstrong.com>; Sat, 31 Oct 2009 09:33:08 -0700 Original-Received: from [10.153.74.162] (koro.pms.ifi.lmu.de [141.84.9.33]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: eisinger) by acheron.ifi.lmu.de (Postfix) with ESMTP id D081C94A1BA; Sat, 31 Oct 2009 17:33:03 +0100 (CET) User-Agent: Thunderbird 2.0.0.23 (X11/20090817) In-Reply-To: X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Resent-Date: Sat, 31 Oct 2009 12:47:23 -0400 X-Mailman-Approved-At: Sun, 01 Nov 2009 00:08:16 -0400 X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:32336 Archived-At: Stefan Monnier wrote: > > I think you're right that we should at > least do a y-or-n-p prompt when changing the buffer-file-coding-system,= > unless the change is to a "superset coding system" (like from us-ascii > to latin-1). I understand the tightrope walk. When you ask users about technical stuff= , they feel bothered if it does not make any difference to them. When you don't ask them, they feel patronized if it does make a difference. The superset strategy is probably a reasonable compromise. I believe that something like the following might still go wrong, but this is a construed example and I did not test it: File announcement.tex contains \include{config.tex} ... \LECTURER ... % only ASCII characters in this file Latin-1 encoded file config.tex contains \usepackage[latin1]{inputenc} \newcommand{\LECTURER}{Fran=E7ois} Later someone edits announcement.tex, adds the letter =E7 to it and saves= it, thus changing the coding system from ascii to the superset utf-8. After t= hat the two occurrences of =E7 are differently encoded. But, again, this is an unusual case. In normal cases we should be OK with= the superset strategy. > There is currently no direct way to ask Emacs to prompt when changing > the coding system Setting select-safe-coding-system-accept-default-p to (function (lambda (coding-system) nil)) would not have this effect in the case we are discussing, would it? > Can you try the patch below to see if it gives you the behavior you wan= t? I could not apply the patch, but I am at the limit of my knowledge. Should I have gunzipped the file first? Below is a description of what I did. Best regards, Norbert =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D Local timezone: +0100 Emacs version: GNU Emacs 22.2.1 (i486-pc-linux-gnu, X toolkit, Xaw3d scroll bars) of 200= 8-09-05 on vernadsky, modified by Ubuntu $ locate mule-cmds /usr/share/emacs/22.2/lisp/international/mule-cmds.el.gz /usr/share/emacs/22.2/lisp/international/mule-cmds.elc /usr/share/xemacs-21.4.21/lisp/mule/mule-cmds.elc $ ls -l /usr/share/emacs/22.2/lisp/international/mule-cmds.* -rw-r--r-- 1 root root 79042 2008-09-05 23:28 mule-cmds.elc -rw-r--r-- 1 root root 30300 2008-01-10 13:15 mule-cmds.el.gz $ cd /usr/share/emacs/22.2/lisp/international $ /usr/bin/emacs -Q & copy&paste the patch into buffer *scratch* menu Tools -> Apply Patch -> To a File select buffer *scratch* and file mule-cmds.el ,----[ *scratch* ] | | =3D=3D=3D modified file 'lisp/international/mule-cmds.el' | --- lisp/international/mule-cmds.el 2009-10-24 18:33:25 +0000 | +++ lisp/international/mule-cmds.el 2009-10-30 15:01:02 +0000 | @@ -979,6 +979,17 @@ | (if safe | (setq coding-system (car safe)))) | | + (unless (or (local-variable-p 'buffer-file-coding-system) | + (eq coding-system buffer-file-coding-system) | + ;; We'd rather only bother the user if the coding-sy= stem | + ;; change would cause the file's content to change, = so we'd | + ;; want to check whether the new coding-system is a = superset | + ;; of the previous one. | + (memq buffer-file-coding-system '(nil undecided us-a= scii)) | + (y-or-n-p (format "Change encoding from %s to %s? " | + buffer-file-coding-system coding-s= ystem))) | + (setq coding-system nil)) | + | ;; If all the defaults failed, ask a user. | (when (not coding-system) | (setq coding-system (select-safe-coding-system-interactively | @@ -1024,6 +1035,7 @@ | %s specified by file contents. Really save (else edit coding cookies = \ | and try again)? " coding-system auto-cs)) | (error "Save aborted")))) | + | (when (and tick (/=3D tick (buffer-chars-modified-tick))) | (error "Cancelled because the buffer was modified")) | coding-system))) | `---- ,----[ *Messages* ] | ("/usr/bin/emacs" "-Q") | For information about GNU Emacs and the GNU system, type C-h C-a. | Mark set | Loading ediff...done | Is the patch already in a buffer? (y or n) | Making completion list... | Loading help-mode...done | Applying patch ... done | ediff-patch-file-internal: Patch appears to have failed `---- ,----[ *ediff-message* ] | Patch program has failed due to a bad patch file, | it couldn't apply all hunks, OR | it couldn't create the backup for the file being patched. | | The former could be caused by a corrupt patch file or because the "patc= h" | program doesn't understand the format of the patch file in use. | | The second problem might be due to an incompatibility among these setti= ngs: | ediff-patch-program =3D "patch" ediff-patch-options = =3D "-f" | ediff-backup-extension =3D ".orig" ediff-backup-specs = =3D "-z.orig -b" | | See Ediff on-line manual for more details on these variables. | In particular, check the documentation for `ediff-backup-specs'. | | In any of the above cases, Ediff doesn't compare files automatically. | However, if the patch was applied partially and the backup file was cre= ated, | you can still examine the changes via M-x ediff-files `---- ,----[ mule-cmds.el.rej ] | *************** | *** 979,984 **** | (if safe | (setq coding-system (car safe)))) | | ;; If all the defaults failed, ask a user. | (when (not coding-system) | (setq coding-system (select-safe-coding-system-interactively | --- 979,995 ---- | (if safe | (setq coding-system (car safe)))) | | + (unless (or (local-variable-p 'buffer-file-coding-system) | + (eq coding-system buffer-file-coding-system) | + ;; We'd rather only bother the user if the coding-s= ystem | + ;; change would cause the file's content to change,= so we'd | + ;; want to check whether the new coding-system is a= superset | + ;; of the previous one. | + (memq buffer-file-coding-system '(nil undecided us-= ascii)) | + (y-or-n-p (format "Change encoding from %s to %s? "= | + buffer-file-coding-system coding-= system))) | + (setq coding-system nil)) | + | ;; If all the defaults failed, ask a user. | (when (not coding-system) | (setq coding-system (select-safe-coding-system-interactively | *************** | *** 1024,1029 **** | %s specified by file contents. Really save (else edit coding cookies= \ | and try again)? " coding-system auto-cs)) | (error "Save aborted")))) | (when (and tick (/=3D tick (buffer-chars-modified-tick))) | (error "Cancelled because the buffer was modified")) | coding-system))) | --- 1035,1041 ---- | %s specified by file contents. Really save (else edit coding cookies= \ | and try again)? " coding-system auto-cs)) | (error "Save aborted")))) | + | (when (and tick (/=3D tick (buffer-chars-modified-tick))) | (error "Cancelled because the buffer was modified")) | coding-system))) | `---- $ ls -l mule-cmds* -rw-r--r-- 1 root root 30300 2009-10-31 15:26 mule-cmds.el -rw-r--r-- 1 root root 79042 2008-09-05 23:28 mule-cmds.elc -rw-r--r-- 1 root root 30300 2008-01-10 13:15 mule-cmds.el.orig -rw-r--r-- 1 root root 1797 2009-10-31 15:26 mule-cmds.el.rej $ diff mule-cmds.el.orig mule-cmds.el $ ### files do not differ $ ### lines 978 to 990 of a gunzipped safety copy made before $ ### line number 986 seems to be the line numbered 979 in the patch $ head -n 990 /tmp/mule-cmds-safety-copy.el | tail -n -13 ;; Classify the defaults into safe, rejected, and unsafe. (dolist (elt default-coding-system) (if (memq (cdr elt) codings) (if (and (functionp accept-default-p) (not (funcall accept-default-p (cdr elt)))) (push (car elt) rejected) (push (car elt) safe)) (push (car elt) unsafe))) (if safe (setq coding-system (car safe)))) ;; If all the defaults failed, ask a user. (when (not coding-system)