unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Kevin Rodgers <ihs_4664@yahoo.com>
Subject: Re: single function to open utf-16 file?
Date: Mon, 10 Jul 2006 16:16:34 -0600	[thread overview]
Message-ID: <e8ujlf$dmv$1@sea.gmane.org> (raw)
In-Reply-To: <1152553539.512324.82140@b28g2000cwb.googlegroups.com>

tom.tulinsky@gmail.com wrote:
> can tell me how to easily open a utf-16 file, or a function for me that
> will open a utf-16 file in PC-win32 Emacs 21.3.1? Currently I have to
> do
> 
>    'C-x C-m c utf-16-le RET' followed by C-x C-f
> 
> I have tried to write a function or create a keyboard macro to do this,
> but they did not work because
> 
>      C-x C-m c (universal-coding-system-argument)
> 
> is some kind of special function and demands the next command be
> entered from the keyboard.
> 
> I want a single elisp function that I can bind to a key.

Do the files begin with a BOM?  If so, something like this should work:

(push '("\\`\xEF\xBB\xBF" . utf-8) auto-coding-regexp-alist)
(push '("\\`\xFE\xFF" . utf-16-be) auto-coding-regexp-alist)
(push '("\\`\xFF\xFE" . utf-16-le) auto-coding-regexp-alist)

Are all your files UTF-16?  If so, this should work:

(prefer-coding-system 'utf-16-le)

If only some of your files are UTF-16 but they can be recognized by
their directory or file name, you can frob the file-coding-system-alist
variable (see the modify-coding-system-alist function).

If you only know for sure that the file is UTF-16 after you visit it
and see it displayed, you can immediately correct that with
`C-x <RET> r utf-16-le <RET>', which is suitable for a keyboard macro.

As a last resort, something like this (cribbed from
universal-coding-system-argument) might work:

(defun find-file-utf-16-le (&rest find-file-args)
   "Temporarily bind coding systems to `utf-16-le' before calling 
`find-file'."
   (interactive)
   (if (interactive-p)
       (let ((prefix-arg current-prefix-arg)
	    (coding-system-for-read coding-system)
	    (coding-system-for-write coding-system)
	    (coding-system-require-warning t))
	(call-interactively 'find-file))
     (apply 'find-file find-file-args)))

-- 
Kevin

  reply	other threads:[~2006-07-10 22:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-10 17:45 single function to open utf-16 file? tom.tulinsky
2006-07-10 22:16 ` Kevin Rodgers [this message]
     [not found] ` <mailman.3947.1152569868.9609.help-gnu-emacs@gnu.org>
2006-07-10 23:59   ` Johan Bockgård

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='e8ujlf$dmv$1@sea.gmane.org' \
    --to=ihs_4664@yahoo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).