twittering-mode –> org2blog-modeでTwitter blackbird pieを便利に

前回までのあらすじ

ツイート画像を簡単にコンテンツ化 できるというTwitter blackbird pie(TBP)をorg2blog-modeで使用する際にネックとなるのが、

  • 埋め込み方が、パーマリンクを直接書くという方法なので、ローカルに保存されるorg文書では内容が把握しにくい
  • org2blogで書き出すと、べたうちしたURLもご丁寧にaタグでくくったリンクに変換してくれるので、TBPが認識してくれない。

の2点。これを解決する方法としては、

#@なまえ
#  〜つぶやき〜
#
#+BEGIN_HTML
〜パーマリンク〜
#+END_HTML

という形のテンプレに書いてあげれば良いんじゃないか、ってことに前回 思い至ったわけだけれども、一々こんなこと書いてるの面倒だし、折角Emacsっていう便利な道具の上で遊んでいるんだし、ってことで、以下のような関数を書いてみた。

関数のあらまし

twittering-push-tweet-onto-kill-ringという関数をベースにちょこっと改造。

(defun twittering-push-tweet-onto-kill-ring-for-org2blog ()
  "Copy the tweet to the kill-ring (org2blog friendly)."
  (interactive)
  (let* ((username (get-text-property (point) 'username))
         (text (get-text-property (point) 'text))
         (honbun (if (stringp text)
                     (split-string text "\n")
                   nil))
         (i -1)
         (str "")
         (id (get-text-property (point) 'id))
         (copy (if (and username id honbun)
                   (progn
                     (while (< i (length honbun))
                       (setq str (concat str "\n# " (nth (setq i (+ i 1)) honbun))))
                     (format "#@%s: %s \n#+BEGIN_HTML\nhttps://twitter.com/#!/%s/status/%s\n#+END_HTML\n" username str username id))
                 nil)))
    (cond
     ((null copy)
      nil)
     ((and kill-ring (string= copy (current-kill 0 t)))
      (message "Already copied %s" copy))
     (t
      (kill-new copy)
      (message "Copied %s" copy)))))

当然ですが、post-idを取得しないとリンクが作れないので、tweetの書式中にpost-id(%#)を入れてあげて下さい。

使いかたは、

  1. 上記の関数を初期設定ファイルの適当なところにペロリと貼っておいて、
  2. お好みのtweetの上でM-x twittering-push-tweet-onto-kill-ring-for-org2blogするだけ。

コメントを残す