bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problem with auto-coding-functions


From: Dmitriyi Paduchikh
Subject: Problem with auto-coding-functions
Date: Sat, 16 Jun 2007 18:53:04 +0600
User-agent: Gnus/5.11 (Gnus v5.11)

Dear Emacs developers,

I am using Debian package emacs-snapshot 20070608-1 of Romain Francoise. It
is a snapshot of Emacs 22 branch.

I wrote a function for auto-coding-functions hook which would run a program
called Enca[1] as a subprocess to determine encoding of the text. Function
runs enca by calling call-process-region. See attachment for full source.
This worked OK when opening a file, however if I tried to save file with C-x
C-m c utf-8, Emacs asked:

   Selected encoding no-conversion disagrees with iso-8859-5-unix specified
   by file contents. Really save (else edit coding cookies and try again)?
   (yes or no)

I think that iso-8859-5-unix comes from Enca. Enca incorrectly determines
Cyrillic text in emacs-mule as ISO-8859-5. But no-conversion was very
confusing. As it appears (see backtrace in the attachment) it is due to
select-safe-coding-system being called recursively via call-process-region.
I solved this by binding auto-coding-functions to nil inside my function.
However some problems remain.

First, auto-coding-functions get executed via select-safe-coding-system on
decoded text whereas documentation of auto-coding-functions promises that
functions will be called on undecoded text. Clearly there is a bug here. If
functions need to be called on both decoded and undecoded text this should
be mentioned in the documentation, and some method of distinguishing wether
the text is decoded or not should be provided.

Second, when saving with C-x C-m c utf-8, Emacs still asks

   Selected encoding utf-8-unix disagrees with iso-8859-5-unix specified by
   file contents. Really save (else edit coding cookies and try again)? (yes
   or no)

which is somewhat annoying. I would rather prefer that Emacs just silently
saved file with coding system given via C-x C-m c (utf-8 in my case) despite
whatever coding system auto-coding-functions suggest.

Third, if I set coding system by C-x C-m f, Emacs silently saves file with
the coding system returned by auto-coding-functions (iso-8859-5 in my case)
no matter what coding system was specified with C-x C-m f. This looks wrong
to me. IMHO it would be better if Emacs respected the explicit user choice
and at least asked him.

Note. My language environment is Russian using koi8-r if this matters.


Footnotes: 
[1] Extremely Naive Charset Analyser. Available as Debian package, or else
    look for it at http://packages.debian.org/unstable/source/enca

Attachment: auto-enca.el
Description: application/emacs-lisp

Attachment: debug-coding
Description: The backtrace


reply via email to

[Prev in Thread] Current Thread [Next in Thread]