From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: Detecting the coding system of a file programmatically Date: Fri, 10 Aug 2018 16:54:12 +0300 Message-ID: <83tvo2minv.fsf@gnu.org> References: <83ftzmof3s.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1533909143 14163 195.159.176.226 (10 Aug 2018 13:52:23 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 10 Aug 2018 13:52:23 +0000 (UTC) Cc: emacs-devel@gnu.org To: Andrea Cardaci Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Aug 10 15:52:19 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fo7py-0003aI-Vm for ged-emacs-devel@m.gmane.org; Fri, 10 Aug 2018 15:52:19 +0200 Original-Received: from localhost ([::1]:56394 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fo7s5-0004E2-LQ for ged-emacs-devel@m.gmane.org; Fri, 10 Aug 2018 09:54:29 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35684) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fo7rs-0004AB-G7 for emacs-devel@gnu.org; Fri, 10 Aug 2018 09:54:17 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fo7ro-0003KB-EI for emacs-devel@gnu.org; Fri, 10 Aug 2018 09:54:16 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:45706) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fo7ro-0003K1-BH; Fri, 10 Aug 2018 09:54:12 -0400 Original-Received: from [176.228.60.248] (port=2284 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1fo7rn-0004Go-Ow; Fri, 10 Aug 2018 09:54:12 -0400 In-reply-to: (message from Andrea Cardaci on Fri, 10 Aug 2018 15:37:08 +0200) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:228377 Archived-At: > From: Andrea Cardaci > Date: Fri, 10 Aug 2018 15:37:08 +0200 > Cc: Emacs developers > > (decode-coding-region (point-min) (point-max) 'undecided) > > which in my use case it resulted in a more snappy performance. > Basically this latter `decode-coding-region' doesn't introduce a > noticeable slowing to the `insert-file-contents-literally', instead > using `decode-coding-inserted-region' is more or less as slow as using > `insert-file-contents' alone. I guess I'll go with the former. Suit yourself, but you need to be aware that while speeding up the code, you lose some features, which may or may not be important, such as setting the default coding-system based on the file's name. If this code ever needs to handle a file whose contents fools the Emacs guesswork (which is based on a small part of the buffer contents), your shortcut might misfire. E.g., UTF-8 encoded files sometimes dupe Emacs into thinking they are encoded in some Windows codepage, if that codepage is the default encoding under the user's locale, so processing XML or LaTeX files might use a wrong encoding.