twitter-modeで、つぶやきからURLを取り出してブラウザで開く
xyzzyのtwitter-modeでつぶやき内のURLを抽出したいシチュはたくさんあると思うので作ってみました。「O」キーを押すとつぶやきの中のURLを抽出してブラウザに投げるという処理を作ります。
(define-key *summary-map* #\O 'summary-open-web2) (defun summary-find-text-url () (let (recipient) (long-operation (multiple-value-bind (from to tag foreground background bold underline strike-out prefix extend) (find-text-attribute-point (point)) (cond ((twstatus-p tag) (setq recipient (twstatus-text tag)) (string-match "\\(http[s]*://[a-zA-Z.0-9,/?=~%_$#!*-]+\\)" recipient) (setq recipient (match-string 1)) ) ((twdirect-p tag) (setq recipient (twdirect-text tag)) (string-match "\\(http[s]*://[a-zA-Z.0-9,/?=~%_$#!*-]+\\)" recipient) (setq recipient (match-string 1)) ) (t (twdebug "~S" tag)))) ) recipient)) (defun summary-open-web2 () (interactive) (setq recipient (summary-find-text-url )) (when recipient (open-web recipient)))
これをsummary.lあたりに突っ込んで下さい。URLの抽出正規表現はテキトーに作ったので漏れがあるかも。つぶやきにURLが2つある場合は1つしか抽出しないので宿題にします。2つある場合はメニューをポップアップさせてどっちか選ぶようにしたいなあ。