make-comint を使う

前に twitter をダラダラと見るだけの python スクリプトを書いたんだけど、それを emacs から使いたくなった。
make-comint は、指定したコマンドを別プロセスで起動して、 emacs のバッファとそのプロセスの入出力をつないでくれるお気楽関数なのです。
ちなみに make-comint の最後の引数は起動するコマンドへのオプションです。
適当に持ってきた elisp ソースをいじったので使っていない変数とかもあったりしますが一応備忘録として。

(defun tw (&optional sleeptime)
  "twitter mode"
  (interactive "p")
  (setup-tw))

(defvar tw-path "/opt/local/bin/tw")

(defun setup-tw ()
  (setq coding-system-for-read 'utf-8)
  (switch-to-buffer (get-buffer-create "*tw*") t)
  (setq truncate-lines nil)
  (setq truncate-partial-width-windows nil)
  (with-current-buffer
      (make-comint "tw" tw-path nil "--no-color")
    (buffer-string)))

(provide 'tw)

(追記)
プロセス間の通信に使うエンコーディングの指定は以下のようにするほうがいいっぽい。

(setq process-coding-system-alist
  (cons '("tw" . utf-8) process-coding-system-alist))

これを追加すると (setq coding-system-for-read 'utf-8) は不要に。