[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Detecting the coding system of a file programmatically
From: |
Andrea Cardaci |
Subject: |
Re: Detecting the coding system of a file programmatically |
Date: |
Fri, 10 Aug 2018 15:37:08 +0200 |
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