From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Thien-Thi Nguyen Newsgroups: gmane.emacs.help Subject: Re: How to determine encoding for file? Date: Tue, 26 Jan 2010 10:01:49 +0100 Message-ID: <87ockhutmq.fsf@ambire.localdomain> References: <87y6jn2mgd.fsf@hubble.lan.informatimago.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1264498974 28307 80.91.229.12 (26 Jan 2010 09:42:54 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 26 Jan 2010 09:42:54 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Jan 26 10:42:47 2010 Return-path: Envelope-to: geh-help-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 1NZhwE-0000KG-Oy for geh-help-gnu-emacs@m.gmane.org; Tue, 26 Jan 2010 10:42:23 +0100 Original-Received: from localhost ([127.0.0.1]:47614 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NZhwG-0002Zu-01 for geh-help-gnu-emacs@m.gmane.org; Tue, 26 Jan 2010 04:42:24 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NZhvg-0002Up-Q4 for help-gnu-emacs@gnu.org; Tue, 26 Jan 2010 04:41:48 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NZhvd-0002TB-Oh for help-gnu-emacs@gnu.org; Tue, 26 Jan 2010 04:41:46 -0500 Original-Received: from [199.232.76.173] (port=47315 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NZhvc-0002T4-Ov for help-gnu-emacs@gnu.org; Tue, 26 Jan 2010 04:41:45 -0500 Original-Received: from host149-68-dynamic.45-79-r.retail.telecomitalia.it ([79.45.68.149]:55908 helo=ambire.localdomain) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NZhvc-0001tJ-50 for help-gnu-emacs@gnu.org; Tue, 26 Jan 2010 04:41:44 -0500 Original-Received: from ttn by ambire.localdomain with local (Exim 4.63) (envelope-from ) id 1NZhJ0-0001jP-1O for help-gnu-emacs@gnu.org; Tue, 26 Jan 2010 10:01:50 +0100 In-Reply-To: (kj's message of "Mon, 25 Jan 2010 14:55:06 +0000 (UTC)") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.91 (gnu/linux) X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. X-Greylist: delayed 2231 seconds by postgrey-1.27 at monty-python; Tue, 26 Jan 2010 04:41:43 EST X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:71473 Archived-At: () kj () Mon, 25 Jan 2010 14:55:06 +0000 (UTC) Dumb but effective. Out of curiosity, how many rounds did it take? What was the encoding found, in the end? If such a method is unavoidable, perhaps Emacs should have: (defun interactive-search-encoding (&optional candidates) "Search `coding-system-priority-list' interactively. For each encoding, do `revert-buffer-with-coding-system', and query the user if the result is acceptable. Stop looping if so. Optional (prefix) arg CANDIDATES is a list of encodings (symbols) to try. Return non-nil if an acceptable encoding is found." (interactive (list (let ((raw (read-string "Try (space-separated) encodings: "))) (when (stringp raw) (mapcar 'intern (split-string raw)))))) (unless candidates (setq candidates (coding-system-priority-list))) (let ((revert-without-query '(".*"))) (find-if (lambda (coding) (revert-buffer-with-coding-system coding) (when (y-or-n-p (format "%s acceptable? " coding)) (message "buffer-file-coding-system now %s" buffer-file-coding-system) t)) candidates))) Emacs does have `select-safe-coding-system', but it is not interactive. thi