From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Harald Hanche-Olsen Newsgroups: gmane.emacs.help Subject: Re: How to convert this macro to Elisp? Date: Mon, 15 Feb 2010 21:05:38 -0500 Organization: Norwegian university of science and technology Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1266288055 30578 80.91.229.12 (16 Feb 2010 02:40:55 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 16 Feb 2010 02:40:55 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Feb 16 03:40:45 2010 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1NhDMh-0007He-Dw for geh-help-gnu-emacs@m.gmane.org; Tue, 16 Feb 2010 03:40:43 +0100 Original-Received: from localhost ([127.0.0.1]:53696 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NhDMe-0002nY-II for geh-help-gnu-emacs@m.gmane.org; Mon, 15 Feb 2010 21:40:40 -0500 Original-Path: news.stanford.edu!usenet.stanford.edu!news.glorb.com!news2.glorb.com!xlned.com!feeder1.xlned.com!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!uio.no!ntnu.no!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 41 Original-NNTP-Posting-Host: euler.math.ntnu.no Original-X-Trace: orkan.itea.ntnu.no 1266285939 21601 129.241.15.252 (16 Feb 2010 02:05:39 GMT) Original-X-Complaints-To: usenet@ntnu.no Original-NNTP-Posting-Date: Tue, 16 Feb 2010 02:05:39 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.92 (darwin) Cancel-Lock: sha1:59zM5Mt7sqn6YwxzkoOW9OohWwA= Original-Xref: news.stanford.edu gnu.emacs.help:176809 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:71877 Archived-At: + kj : > 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 - It is undesirable to believe a proposition when there is no ground whatsoever for supposing it is true. -- Bertrand Russell