help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to convert this macro to Elisp?


From: Harald Hanche-Olsen
Subject: Re: How to convert this macro to Elisp?
Date: Mon, 15 Feb 2010 21:05:38 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.92 (darwin)

+ kj <no.email@please.post>:

> I have a macro that I want to convert to Elisp.  Furthermore, I
> want the resulting code to be completely non-interactive.
>
> Here's what the macro looks like:
>
> C-x RET c               ;; universal-coding-system-argument
> euc-jp                  ;; self-insert-command * 6
> RET                     ;; newline
> C-x C-f                 ;; find-file
> test                    ;; self-insert-command * 4
> RET                     ;; newline
> C-x RET f               ;; set-buffer-file-coding-system
> utf-8                   ;; self-insert-command * 5
> RET                     ;; newline
> C-x C-s                 ;; save-buffer
> raw-text                ;; self-insert-command * 8
> RET                     ;; newline
>
> How can I convert this to Elisp?

Something like this might work (not properly tested):

(defun select-utf-8-or-raw (from to &rest _)
  (if (memq 'utf-8 (find-coding-systems-region from to))
      'utf-8 'raw-text))
(defun change-file-coding-to-utf-8 (filename from-coding)
  (let ((coding-system-for-read from-coding))
    (find-file filename)
    (set-buffer-file-coding-system 'utf-8)
    (let ((select-safe-coding-system-function 'select-utf-8-or-raw))
      (save-buffer))))

A proper solution should probably use lower-level functions, however.

-- 
* Harald Hanche-Olsen     <URL:http://www.math.ntnu.no/~hanche/>
- It is undesirable to believe a proposition
  when there is no ground whatsoever for supposing it is true.
  -- Bertrand Russell


reply via email to

[Prev in Thread] Current Thread [Next in Thread]