Subject: Re: bug#5235: 23.1; Unibyte keyboard input problem

From: Eli Zaretskii <[email-masked]>
Date: Sat, 26 Dec 2009 23:24:47 +0200

> From: Tomasz Zbrożek <[email-masked]>
> Date: Sat, 26 Dec 2009 20:19:38 +0100
> 
> >So does this mean using latin-2 solves your original problem as well?
> >That is, are you able to edit the source files without the annoying
> >questions from Emacs when you save the files?
> 
> No, latin-2 does not solve my problem:) I do not want to read/write file in 
> latin-2 but cp1250! 

Does the patch below give good results?

You will need to rebuild Emacs or manually load mule-cmds.elc, after
patching and compiling it.  Then set
select-safe-coding-system-respect-auto-coding to a non-nil value, and
see if the annoying question goes away while the files are saved
correctly without screwing up the cp852 characters.

Index: lisp/international/mule-cmds.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/international/mule-cmds.el,v
retrieving revision 1.386
diff -u -r1.386 mule-cmds.el
--- lisp/international/mule-cmds.el	9 Dec 2009 00:55:55 -0000	1.386
+++ lisp/international/mule-cmds.el	26 Dec 2009 21:21:17 -0000
@@ -807,6 +807,9 @@
     (set-window-configuration window-configuration)
     coding-system))
 
+(defvar select-safe-coding-system-respect-auto-coding nil
+  "If non-nil, always use coding system from coding cookies &c if possible.")
+
 (defun select-safe-coding-system (from to &optional default-coding-system
 				       accept-default-p file)
   "Ask a user to select a safe coding system from candidates.
@@ -976,7 +979,14 @@
 		(push (car elt) safe))
 	    (push (car elt) unsafe)))
 	(if safe
-	    (setq coding-system (car safe))))
+	    (setq coding-system (car safe))
+	  ;; If default-coding-system is in unsafe, and the user
+	  ;; insists, use it.
+	  (if (and select-safe-coding-system-respect-auto-coding
+		   default-coding-system
+		   (memq (caar default-coding-system) unsafe))
+	      (setq coding-system (caar default-coding-system)))))
+
 
       ;; If all the defaults failed, ask a user.
       (when (not coding-system)