xyzzyはlispが使えるEmacs風のWindows用エディタです。
そのlispを使って任意さん(元偽春菜)を調教してみようというのがこのページの目的です。
とりあえず無保証という事でお願いします。
もし間違いなんぞを発見なんぞしましたら、BBSとかに「間違ってるゾ、ゴルァ。(゚Д゚)」とかいろいろ教えていただけると幸いです。
● xyzzyから任意さん(元偽春菜)にsstpプロトコル通信
(require "wip/winapi")
;
;SENDリクエスト
;
(defun sstp-send(script hwnd option &rest list)
(let (s status entry)
(setq s (connect "127.0.0.1" "11000"))
(format s "SEND SSTP/1.3~%")
(format s "Sender: ~A~%" (software-type))
(if hwnd
(format s "HWnd: ~D~%" hwnd))
(format s "Script: ~A~%" script)
(dolist (entry list)
(format s "Entry: ~A~%" entry))
(if option
(format s "Option: ~A~%" option))
(format s "~%")
(setq status (read-line s nil))
(close s)
status))
;
;EXECUTEリクエスト
;
(defun sstp-execute(command)
(let (s status data)
(setq s (connect "127.0.0.1" "11000"))
(format s "EXECUTE SSTP/1.0~%")
(format s "Sender: ~A~%" (software-type))
(format s "Command: ~A~%" command)
(format s "~%")
(setq status (read-line s nil))
(read-line s nil)
(setq data (read-line s nil))
(close s)
data))
(defun sstp-execute-getname()
(sstp-execute "getname"))
;
;GIVEリクエスト
;
(defun sstp-give(dataname data)
(let (s status)
(setq s (connect "127.0.0.1" "11000"))
(format s "GIVE SSTP/1.1~%")
(format s "Sender: ~A~%" (software-type))
(format s "~A: ~A~%" dataname data)
(format s "~%")
(setq status (read-line s nil))
(close s)
status))
(defun sstp-give-document(document)
(sstp-give "Document" document))
(defun sstp-give-songname(songname)
(sstp-give "Songname" songname))
;
;COMMUNICATEリクエスト
;
(defun sstp-communicate(sentence)
(let (s status)
(setq s (connect "127.0.0.1" "11000"))
(format s "COMMUNICATE SSTP/1.1~%")
(format s "Sender: ~A~%" (software-type))
(format s "Sentence: ~A~%" sentence)
(format s "~%")
(setq status (read-line s nil))
(close s)
status))
;
;ミニバッファ関係
;
(defun sstp-send-minibuffer(s)
(interactive "sScript:")
(sstp-send s nil ""))
(defun sstp-send-haruna(s)
(interactive "sScript:")
(sstp-send (concat "\\h\\s0" s "\\e") nil ""))
(defun sstp-send-unyu(s)
(interactive "sScript:")
(sstp-send (concat "\\u" s "\\e") nil ""))
;
;SSTP1.3関係
;
(defun haruna-close-selected-buffer ()
(interactive)
(cond ((not (need-buffer-save-p (selected-buffer)))
(kill-buffer (selected-buffer)))
((haruna-yes-no-or-cancel-p "~aを保存する?" (selected-buffer))
(if (save-buffer-dialog)
(kill-buffer (selected-buffer))))
(t
(not-modified)
(kill-buffer (selected-buffer)))))
(defun haruna-yes-no-or-cancel-p (fmt &rest arg)
(let ((msg (winapi:make-MSG)) r)
(sstp-send
(format nil (concat "\\h\\s0" fmt "\\n\\n\\q0[#temp0][はい]\\q1[#temp1][いいえ]\\q2[#temp2][キャンセル]\\z") arg)
(get-window-handle)
""
"#temp0"
"\\m[1025,0,0]\\h\\s0やっといたよ\\m[1025,0,1]\\e"
"#temp1"
"\\m[1025,1,0]\\h\\s0やめたよ\\m[1025,1,1]\\e"
"#temp2"
"\\m[1025,2,0]\\h\\s0キャンセルしたよ\\m[1025,2,1]\\e")
(winapi:GetMessage msg 0 0 0)
(setq r (winapi:MSG-wParam msg))
(if (= r 2)
(quit)
(= r 0))))
● 使い方
sstp.lとかに保存して、バイトコンパイルしたりしなかったりして、.xyzzyファイルに(load-library "sstp.l")とかして使えます。
SENDリクエスト(なんかダメ臭いのかも。もう少しなんとか出来るのかも)
(sstp-send "\\h\\s0いくら大学教授とはいえ‥‥\\w8\\w8書斎に偶然あんな本が置いてあったと思うか?\\e"
nil
"nodescript")
とか、
(sstp-send "\\h\\s0どんな感じ?\\n\\n\\q0[#temp0][まあまあ]\\q1[#temp1][今ひとつ]\\z"
nil
""
"#temp0"
"\\h\\s0ふーん。\\e"
"#temp1"
"\\h\\s0酒に逃げるなヨ!\\e")
とか、
(sstp-send "\\h\\s0どんな感じ?\\n\\n\\q0[#temp0][まあまあ]\\q1[#temp1][今ひとつ]\\z"
(get-window-handle)
""
"#temp0"
"\\m[1025,0,0]\\h\\s0ふーん。\\m[1025,0,1]\\e"
"#temp1"
"\\m[1025,1,0]\\h\\s0酒に逃げるなヨ!\\m[1025,1,1]\\e")
とかしたりして使えます。
EXECUTEリクエスト
(sstp-execute "getname")
または、
(sstp-execute-getname)
GIVEリクエスト
(sstp-give "Document" "こんにちはさくらです。闇の力を秘めし鍵よ真の姿を我の前に示せレリーズ。汝のあるべき姿に戻れクロウカード。")
または、
(sstp-give-document "こんにちはさくらです。闇の力を秘めし鍵よ真の姿を我の前に示せレリーズ。汝のあるべき姿に戻れクロウカード。")
COMMUNICATEリクエスト
(sstp-communicate "さくらって八方美人で信用できないよね。")
● xyzzyのミニバッファから任意さん(元偽春菜)に毒電波を送る
M-x sstp-send-harunaと入力すると、ミニバッファにScript:と出てくるので、なにやら言葉を入力してENTERすると、任意さん(元偽春菜)が毒電波を受信します。
sstp-send-harunaの所をsstp-send-unyuにすると、うにゅうが受信します。
● xyzzyの起動時に任意さん(元偽春菜)に毒電波を送る
(load-library "sstp.l")
(add-hook 'ed::*post-startup-hook* #'(lambda () (sstp-send "\\h\\s0xyzzy起動!\\e" nil "")))
とか.xyzzyファイルに記述すると、xyzzy起動時に任意さん(元偽春菜)がお話します。
正式な使い方かどうかわからないけど、動くからOKという事で。
● xyzzyの起動時に任意さん(元偽春菜)にダイアログ代わりをさせる。
今回の目玉。超実用的(ウソ)。
haruna-close-selected-bufferを.xyzzyファイルにてきとーなキー(例えばC-x kとか)で定義します。
定義の仕方は他のHPを見てね(ただの手抜き)。
すると、定義したキーでバッファを削除しようとすると、任意さん(元偽春菜)が、

と聞いてきます。
う〜ん、実用的なのかこれは?
時間切れがあるのが非実用的なのかも。
まあ、haruna-yes-no-or-cancel-pは他にもいろいろ応用が利くかも知れないから、よしという事にしといて下さい。
今更どうしようもないが、もう少し何とかならんものかのぅ。
えんいー
BACK