From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Andrea Cardaci Newsgroups: gmane.emacs.devel Subject: Re: Detecting the coding system of a file programmatically Date: Fri, 10 Aug 2018 15:37:08 +0200 Message-ID: References: <83ftzmof3s.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" X-Trace: blaine.gmane.org 1533908158 8181 195.159.176.226 (10 Aug 2018 13:35:58 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 10 Aug 2018 13:35:58 +0000 (UTC) Cc: Emacs developers To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Aug 10 15:35:54 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 1fo7a5-0001vm-4Z for ged-emacs-devel@m.gmane.org; Fri, 10 Aug 2018 15:35:53 +0200 Original-Received: from localhost ([::1]:56339 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fo7c9-0004gs-Om for ged-emacs-devel@m.gmane.org; Fri, 10 Aug 2018 09:38:01 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:59840) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fo7bW-0004gY-Ne for emacs-devel@gnu.org; Fri, 10 Aug 2018 09:37:23 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fo7bV-0005rW-SW for emacs-devel@gnu.org; Fri, 10 Aug 2018 09:37:22 -0400 Original-Received: from mail-qk0-x22b.google.com ([2607:f8b0:400d:c09::22b]:33688) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fo7bU-0005qO-I7; Fri, 10 Aug 2018 09:37:20 -0400 Original-Received: by mail-qk0-x22b.google.com with SMTP id 27-v6so6387456qkv.0; Fri, 10 Aug 2018 06:37:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=kG/rJAQx30EMxbShdm+f3cMg0E1ePfPpL70wtJXjNDo=; b=TvJ9cRjZR8tT4YMBl094ZRSX4U7jASeaq1eXSn9JZHcNHdZFoDNdaCvw/xLU/qgGcd UVnMCoPOcUlJTVGF8nLyGiiox6PE6c86h/G94G4zYXG4SY21VIM8PeaY4fxZJD2qzYGx 5MIZ/pX/d8RpwMCmxOE6inqD3wqUefkwEHsQHV7KGWRT00G9ZlxxIh0SqMcqIjwRJP6U iH3KYBB8TT4+M242cRPcJrF/uy389u2Av6EQFUwHsreRSSE3atX1EXobOvqbFYvH5Y+R JeoX/YloXTUsJaxoF/FLTiM9st3wgHzgFsVXsE/pGCHPkNDQU6m7jIWEqy6dasTQEHRs CtZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=kG/rJAQx30EMxbShdm+f3cMg0E1ePfPpL70wtJXjNDo=; b=Ypjlt7A8eCZtRjQpoewGB2pjH4phQRW0voNpGbgUU+tPDvTRS1X6d6AXkSGkPN12uK kbPqyBuOvvR0+S/RaQqN2E1GLR0ya+ByLTLGEsTFeTTjYzuHCquP+1A1v7+TdX/0D03y 42x+AmU9nZGzJNSVgjK3QfaGE3k1ZRn4opMFa+IKGgne5EJtRKDu8pr9/ARUiVCVXoHn jlvdNoI4tzEhfUhkXlqUzGDS71zV55a+bQFHg/RqrEMSKfRoxPl13MKHMzCBcPKKJmt0 S+1hxBlT1wergK8uAPiiPzhUTYXI3sg948K3BRiI1k5G9qHS90AG5M6MQD/eOZiPhWc9 9O7Q== X-Gm-Message-State: AOUpUlFlyk72wOiXq4gPZ7OXdQkv/pkJX06uXqKHC6illr61Ft/1NPRC aMj4OLH/u7K08xvuqS5NKQhReZoTLpRu+e5R5mKhuY4X X-Google-Smtp-Source: AA+uWPy45aKtAAjGMp01A1CGyJfVIPVayeS9xwceyqNBUftJPFcMDL9CsaCqTaq2odJKxJLvm2wJxpZADoD1dqeoXHw= X-Received: by 2002:ae9:c002:: with SMTP id u2-v6mr5690537qkk.391.1533908239637; Fri, 10 Aug 2018 06:37:19 -0700 (PDT) In-Reply-To: <83ftzmof3s.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c09::22b 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:228375 Archived-At: Hi Eli, Thanks for the thorough reply. > That's the wrong function to use in this case; you want > decode-coding-inserted-region instead. Yes, that works! > Thus, I expect this to work for you: > > (with-temp-buffer > (insert-file-contents-literally path) > (decode-coding-region (point-min) (point-max) > (find-operation-coding-system > 'insert-file-contents > (cons path (current-buffer))))) Yes, except that it accepts a single symbol. I also tried directly with: (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. Andrea