make-comintを使ってみたかったので。
(defun postscript-process ()
(get-buffer-process (get-buffer "*postscript*")))
(defun run-postscript ()
(interactive)
(require 'comint)
(switch-to-buffer (make-comint "postscript" "gs")))
(push '("postscript" . utf-8) process-coding-system-alist)
(defun to-postfix (s)
(if (atom s) `(,s)
`(,@(cdr s)
,(car s))))
(defun send-postscript-no-newline (s &optional ps)
(unless ps
(setf ps (postscript-process)))
(unless ps
(error "no running postscript process"))
(dolist (obj (to-postfix s))
(if (listp obj)
(send-postscript-no-newline obj ps)
(comint-send-string ps (format "%s " obj)))))
(defun send-postscript (s &optional ps)
(unless ps
(setf ps (postscript-process)))
(unless ps
(error "no running postscript process"))
(send-postscript-no-newline s ps)
(comint-send-string ps "\n"))
(defun ps (&rest ss)
(dolist (s ss) (send-postscript-no-newline s))
(unless (postscript-process)
(error "no running postscript process"))
(comint-send-string (postscript-process) "\n"))
(defmacro with-ps-context (&rest body)
`(ps ,@(mapcar (lambda (s) `(quote ,s)) body)))
M-x run-postscriptで起動
;; 線を引く
(with-ps-context
gsave
newpath
(moveto 0 100)
(lineto 100 100)
stroke
grestore)
S式からPostScriptへの変換は、単純に順序を入れ替えているだけなのでたいした意味が無いような気がしますが、括弧にかこわれているほうが精神が落ち着きますね。
0 件のコメント:
コメントを投稿