Twitter投稿用API関数を単体で使う (xyttr Advent Calendar 9日目)

この記事はxyttr Advent Calendar 2011の記事です。

xyttrパッケージよりexportされているTwitter API関数を使用すると、自作xyzzy lispプログラムとTwitterの連携が簡単に実現できます。 (xyttr referenceTwitter REST APIの辺り参照)

投稿用API関数xyttr:api-update-asyncを使用した例を3つほどでっち上げたので参考にしてみてください。

gitのcommitメッセージをツイート

;;; .xyzzyとかに書く
(require "xyttr")
(xyttr::xyttr-init) ; タイムラインバッファを開く前にAPI関数を使用する場合に必要

(defun tweet-commit-msg ()
  (let ((fn (get-buffer-file-name)))
    (when (and fn (string-match "/\\.git/COMMIT_EDITMSG$" fn))
      (let ((msg (save-excursion
		   (beginning-of-buffer)
		   (next-line)
		   (buffer-substring 0 (1- (point))))))
	(xyttr:api-update-async :status (concat "committed: " msg))))))

(add-hook 'ed::*after-save-buffer-hook* 'tweet-commit)

msysgitでEDITORにxyzzyを指定して作業してる人用。
このままだと何の作業してるのか分からないので公開できる範囲で情報を足すと良いでしょう。

メジャーモード起動時にツイート

(defun tweet-mode ()
  (xyttr:api-update-async :status (concat  mode-name "はじめました。")))

(add-hook 'ed::*hoge-mode-hook* 'tweet-mode)

意識高そうな言語のmode-hook変数に加えておくと良いと思います。

.xyzzy開いたらツイート

(defun tweet-dot-xyzzy ()
  (when (string= (file-namestring (get-buffer-file-name)) ".xyzzy")
    (xyttr:api-update-async :status "また.xyzzyいじってる")))

(add-hook 'ed::*find-file-hooks* 'tweet-dot-xyzzy)

ほどほどにしましょう



以上、あまり役に立たない利用例でした。 何か面白い連携方法があったら教えてください。