yaottiの日記

2009-10-14

はてな用リンク作成elisp

09:36

(defun url-hatenafy ()
  (interactive)
  (let* ((url (thing-at-point 'url))
         (hatena-url (concat "[" url ":title]"))
         (pos (bounds-of-thing-at-point 'url)))
    (save-excursion
      (kill-region (car pos) (cdr pos))
      (insert hatena-url))))

URLの途中でM-x url-hatenafyすると

Example Domain

という形式になる.simple-hatena-modeを使っているので結構便利

elisp的な話

bounds-of-thing-at-point

(begin . end)という形で,引数の種類の始点/終点を返す.引数にはthing-at-pointと同じように,'wordや'lineなどを指定する.

(thing-at-point 'word)とかは結構便利

save-exrusion

defun, interactiveの次に一番良くelispに出てくるかも.

(save-exrusion hoge fuga piyo ...)と書くと,hoge, fuga, piyoを実行した後に元の場所にポインタを戻す.

これで括ってやることで,ポインタを動かす処理をした後に元の位置へ戻す,という作業がいらなくなる.

AffandiAffandi2012/02/22 10:23I found just what I was nedeed, and it was entertaining!

gafqvldlgafqvldl2012/02/23 20:18AnGpfJ <a href="http://tzacwnxuhsga.com/">tzacwnxuhsga</a>

btuiddfabtuiddfa2012/02/24 02:15CmPwFR , [url=http://zpiivtaodiuu.com/]zpiivtaodiuu[/url], [link=http://chqiwvksrugu.com/]chqiwvksrugu[/link], http://kdonteqzagih.com/

TaofeekTaofeek2013/12/22 15:34Such a deep anesrw! GD&RVVF

OpenOpen2013/12/24 22:51These topics are so <a href="http://rvbood.com">cofnsuing</a> but this helped me get the job done.

GerardinoGerardino2013/12/25 21:51Stay with this guys, you're heniplg a lot of people. http://dovrgjnfb.com [url=http://glkmvywezk.com]glkmvywezk[/url] [link=http://psakbppu.com]psakbppu[/link]

BicusBicus2013/12/26 03:13I was really confused, and this answered all my <a href="http://zqzywjurf.com">quiotesns.</a>

YeNnyYeNny2013/12/27 07:25Please keep thwnirog these posts up they help tons. http://dflslabra.com [url=http://tjfmetbysr.com]tjfmetbysr[/url] [link=http://khmsramtybk.com]khmsramtybk[/link]