all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* How to convert this macro to Elisp?
@ 2010-02-16  0:16 kj
  2010-02-16  2:05 ` Harald Hanche-Olsen
  2010-02-16 13:07 ` Alberto Luaces
  0 siblings, 2 replies; 4+ messages in thread
From: kj @ 2010-02-16  0:16 UTC (permalink / raw
  To: help-gnu-emacs




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?

The last two lines of the macro above point to a potential wrinkle.
'raw-text<RET>' is my interactive response when Emacs asked what
to do about characters that it was unable to encode using the
requested encoding.  I imagine that in some cases this warning will
not appear, so this response would be unnecessary.

TIA!

~K



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

* Re: How to convert this macro to Elisp?
  2010-02-16  0:16 How to convert this macro to Elisp? kj
@ 2010-02-16  2:05 ` Harald Hanche-Olsen
  2010-02-16 14:27   ` kj
  2010-02-16 13:07 ` Alberto Luaces
  1 sibling, 1 reply; 4+ messages in thread
From: Harald Hanche-Olsen @ 2010-02-16  2:05 UTC (permalink / raw
  To: help-gnu-emacs

+ 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


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

* Re: How to convert this macro to Elisp?
  2010-02-16  0:16 How to convert this macro to Elisp? kj
  2010-02-16  2:05 ` Harald Hanche-Olsen
@ 2010-02-16 13:07 ` Alberto Luaces
  1 sibling, 0 replies; 4+ messages in thread
From: Alberto Luaces @ 2010-02-16 13:07 UTC (permalink / raw
  To: help-gnu-emacs

kj writes:


[...]

> How can I convert this to Elisp?

You are asking for "insert-kbd-macro".

> The last two lines of the macro above point to a potential wrinkle.
> 'raw-text<RET>' is my interactive response when Emacs asked what
> to do about characters that it was unable to encode using the
> requested encoding.  I imagine that in some cases this warning will
> not appear, so this response would be unnecessary.

I don't know how to solve the interaction issue, sorry.

--
Alberto




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

* Re: How to convert this macro to Elisp?
  2010-02-16  2:05 ` Harald Hanche-Olsen
@ 2010-02-16 14:27   ` kj
  0 siblings, 0 replies; 4+ messages in thread
From: kj @ 2010-02-16 14:27 UTC (permalink / raw
  To: help-gnu-emacs

In <pco4olij5ot.fsf@math.ntnu.no> Harald Hanche-Olsen <hanche@math.ntnu.no> writes:

>+ 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))))

Thanks!!!  This gets me started.

~K


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

end of thread, other threads:[~2010-02-16 14:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-16  0:16 How to convert this macro to Elisp? kj
2010-02-16  2:05 ` Harald Hanche-Olsen
2010-02-16 14:27   ` kj
2010-02-16 13:07 ` Alberto Luaces

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.