EmacsAdventCalendarの2日目の記事です.
前日はK1LoWさん,次の日はtomoyaさんです.
使い道がなさそうなlispを思いついたからそれを書いてみます.
twit.elの設定をまた書こうかと思ったけど,あんまり使ってるひとがいなさそうだからなぁ・・・
C-u 10 M-x interval-time-insert-start
とすると10分おきにカーソル位置に[09/12/17 10:34:20]って感じにタイムスタンプを挿入します.
M-x interval-time-insert-stop
とするとタイマーを止めることができます.
一応On/Offするくらいしか機能はないですが,コメントアウトした状態で挿入したりできるようになってもおもしろいのかな
下のをまるごと.emacsに書けば使えるようになるはずです.タイマーをリストするanything情報源 - http://rubikitch.com/に移転しましたを使うと,タイマーに登録されてることがわかると思います.
どんな時に使うかというと,勉強会に行った時にメモをとりながらタイムスタンプも自動的に挿入してくれるという代物な訳です.
コーディング中に使うならフォーマットの前後に/* 〜 */とかつけといた方が便利かもしれない.
ま,ほんとの理由は,話の長い人がしゃべってる内容を打ち込みながら,予定時刻が来たらわかるようにしようと思っただけなんですけどね.
思ったよりも簡単にかけたからよかった.英語は難しい...
(defvar interval-time-timer nil) (defun interval-time-now () "insert timestamp" (insert (format-time-string "\n[%y/%m/%d %H:%M:%S]\n"))) (defun interval-time-insert-start (&optional interval) "Insert timestamp to cursor every INTERVAL minutes" (interactive "P") (setq interval (if (or (null interval) (< interval 1)) 1 interval)) (if interval-time-timer (message "already started timer") (setq interval-time-timer (run-with-timer (* interval 60) (* interval 60) 'interval-time-now)))) (defun interval-time-insert-stop () "stop timer of interval-time-insert" (interactive) (cancel-timer interval-time-timer) (setq interval-time-timer nil))
ついでにtwit.elで40ページ丸ごと取得
ついでに最近書いてみて便利やったlispを載せておきます
外から帰ってきて,twitterのTLをまとめて取得したいなーと思った時に,1ページ目から順に連続して取得してくれます.1から順に取得する様子が見れるので,既に見たところにきたらC-gで止めることもできます.
ただ,バッファ名にページ番号を表示するというハックをしていないと*Twit-recent*バッファを上書きしながら40回更新するだけになってしまうので,気をつけてくださいな.
;; 指定したページまでまとめて取得する ;; バッファ名にページ番号が入っていないと上書きするので注意 (defun twit-show-all-tweet (&optional page) "get Time Line all pages from page 1 to page PAGE" (interactive "P") (setq page (if (null page) 40 (if (< page 1) 1 page))) (loop for i from 1 to page do (twit-show-recent-tweets i)))
twit.elでバッファ名にページ番号を表示する
これを書いとけばバッファ名にページ番号が入るので,一番下までスクロールした状態でも次のページが何ページ目かわかります.
;; change the format of buffer-name ;; *Twit-recent* -> *Twit-recent:page* (defadvice twit-show-recent-tweets (around around-twit-show-recent-tweets) (interactive "P") (setq page (twit-check-page-prefix page)) (pop-to-buffer (with-twit-buffer (format "*Twit-recent:%s*" page) (twit-write-title "Recent Tweets (Page %s) [%s]\n" page (format-time-string "%c")) (twit-write-recent-tweets (twit-parse-xml (format twit-friend-timeline-file page) "GET"))))) (ad-activate 'twit-show-recent-tweets) ;;* recent async timer (defadvice twit-follow-recent-tweets-async-callback (around around-twit-follow-recent-tweets-async-callback) (when (not status) (save-window-excursion (save-excursion (with-twit-buffer "*Twit-recent:1*" (twit-write-title "Following Recent tweets: %s\n" (format-time-string "%c")) (twit-write-recent-tweets xml)))))) (ad-activate 'twit-follow-recent-tweets-async-callback)