all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* single function to open utf-16 file?
@ 2006-07-10 17:45 tom.tulinsky
  2006-07-10 22:16 ` Kevin Rodgers
       [not found] ` <mailman.3947.1152569868.9609.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 3+ messages in thread
From: tom.tulinsky @ 2006-07-10 17:45 UTC (permalink / raw)


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.

Thanks.

tt 

On Windows XP Pro.

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

* Re: single function to open utf-16 file?
  2006-07-10 17:45 single function to open utf-16 file? tom.tulinsky
@ 2006-07-10 22:16 ` Kevin Rodgers
       [not found] ` <mailman.3947.1152569868.9609.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 3+ messages in thread
From: Kevin Rodgers @ 2006-07-10 22:16 UTC (permalink / raw)


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

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

* Re: single function to open utf-16 file?
       [not found] ` <mailman.3947.1152569868.9609.help-gnu-emacs@gnu.org>
@ 2006-07-10 23:59   ` Johan Bockgård
  0 siblings, 0 replies; 3+ messages in thread
From: Johan Bockgård @ 2006-07-10 23:59 UTC (permalink / raw)


Kevin Rodgers <ihs_4664@yahoo.com> writes:

> 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.

`C-x RET r' (revert-buffer-with-coding-system) doesn't exist in Emacs
21.

-- 
Johan Bockgård

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

end of thread, other threads:[~2006-07-10 23:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-07-10 17:45 single function to open utf-16 file? tom.tulinsky
2006-07-10 22:16 ` Kevin Rodgers
     [not found] ` <mailman.3947.1152569868.9609.help-gnu-emacs@gnu.org>
2006-07-10 23:59   ` Johan Bockgård

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.