simple-hatena のヘルパーメソッドを書いた

最近 twitter 関連で @hogehoge, とか #hogehoge とか書くことがある.
これをリンクに変換したいので,書いてみた.

まーこんな短かいのでも一応使えるよ.ということで.

;;; transrate twitter-id notation to hatena-notation
;;; and transrate hashtag(#) to hatena-notation
(defun my-hatena-convert-twitter-notation-to-link ()
  "カーソル付近の@ 付きID をはてな記法のリンクに変換する.
又は,カーソル付近の# 付き文字列をはてな記法のリンクに変換する.
"
  (interactive)
  (let ((bounds (bounds-of-thing-at-point 'symbol)))
    (if bounds
        (let* ((beg (car bounds))
               (pre (- beg 1))
               (end (cdr bounds))
               (prestr (buffer-substring pre (+ 1 pre)))
               (idstr (buffer-substring beg end)))
          (cond ((string-equal "@" prestr)
                 (delete-region pre end)
                 (insert (my-hatena-convert-twitter-id-to-link idstr)))
                ((string-equal "#" prestr)
                 (delete-region pre end)
                 (insert (my-hatena-convert-twitter-hashtag-to-link idstr))))))))

(defun my-hatena-convert-twitter-id-to-link (id)
  "twitter の id をはてな記法のリンクに変換する"
  (if id
      (concat "[http://twitter.com/" id ":title=@" id "]")))

(defun my-hatena-convert-twitter-hashtag-to-link (tag)
  "twitter の hashtag をはてな記法のリンクに変換する"
  (if tag
      (concat "[http://twitter.com/search?q=%23" tag ":title=#" tag "]"))) ;; %23 = # だよ