unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Detecting the coding system of a file programmatically
@ 2018-08-10  1:02 Andrea Cardaci
  2018-08-10  7:28 ` Eli Zaretskii
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Andrea Cardaci @ 2018-08-10  1:02 UTC (permalink / raw)
  To: Emacs developers

Hi,

I'm in a situation where I need to batch process (readonly) a number
of file with Emacs, my current approach is the following:

(with-temp-buffer
  (insert-file-contents-literally path)
  (decode-coding-region (point-min) (point-max) 'utf-8)
  (... do suff with the buffer ...))

I use `insert-file-contents-literally' because the non-literally
counterpart is too slow (about twice as much apparently) as it does a
bunch of stuff in addition to simply populate the buffer.
Unfortunately, one of these things is to decode the buffer.

Now instead of hardcoding 'utf-8 I'd like to detect the correct
encoding where possible, so I tried experimenting with
`find-operation-coding-system'. I created a latin-1 file (which gets
recognised properly when I visit it) and tried the following:

(with-temp-buffer
  (setq path "~/tmp/latin-1")
  (insert-file-contents-literally path)
  (find-operation-coding-system
   'insert-file-contents
   (cons path (current-buffer))))

But all I get is (undecided). Now my question is twofold: is this the
best approach for what I'm trying to achieve? And in any case, why
does the latter example does not work as expected? (And hence how I
can detect the coding system programmatically?)


Best,

Andrea



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-08-17 11:33 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-10  1:02 Detecting the coding system of a file programmatically Andrea Cardaci
2018-08-10  7:28 ` Eli Zaretskii
2018-08-10 13:37   ` Andrea Cardaci
2018-08-10 13:54     ` Eli Zaretskii
2018-08-10 14:47       ` Andrea Cardaci
2018-08-10 15:26 ` Stefan Monnier
2018-08-16 21:27 ` Juri Linkov
2018-08-17 11:33   ` Andrea Cardaci

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).