読者です 読者をやめる 読者になる 読者になる

YAPC::Asia 2012のスケジュールを Emacsから見る

emacs helm yapc

mattn/yapc-asia-timetable-viewer-vim · GitHub


を発見して、Emacs版を書いてみました。Vim Scriptがさっぱりなので
どういう挙動か全くわかりませんので、きっとこんなだろうと妄想して
作ってみました。

コード

;;; yapc-schedule.el --- View YAPC::Asia 2012 schedule with helm interface

;; Copyright (C) 2012 by Syohei YOSHIDA

;; Author: Syohei YOSHIDA <syohex@gmail.com>
;; URL:
;; Version: 0.01

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;;; Code:

(eval-when-compile
  (require 'cl))

(require 'helm)
(require 'json)

(defvar yapc-sched:url "http://yapcasia.org/2012/talk/schedule?format=json")
(defvar yapc-sched:dates '("2012-09-27" "2012-09-28" "2012-09-29"))

(defun yapc-sched:construct-url (date-str)
  (format "%s&date=%s" yapc-sched:url date-str))

(defun yapc-sched:get-schedule (url)
  (with-temp-buffer
    (let* ((cmd (format "curl -s '%s'" url))
           (ret (call-process-shell-command cmd nil t)))
      (unless (zerop ret)
        (error (format "Can't download: %s" url)))
      (json-read-from-string (buffer-substring-no-properties
                              (point-min) (point-max))))))

(defun yapc-sched:parse-schedule (json)
  (loop for room across (assoc-default 'talks_by_venue json)
        appending
        (loop for talks across room
              for title = (assoc-default 'title talks)
              for abstract = (assoc-default 'abstract talks)
              for start = (assoc-default 'start_on talks)
              for speaker-info = (assoc-default 'speaker talks)
              for name = (assoc-default 'nickname speaker-info)
              collect
              (cons (format "%s:%s@%s" start name title) abstract))))

(defun yapc-sched:schedule ()
  (let* ((date (completing-read "Date: " yapc-sched:dates nil t))
         (url (yapc-sched:construct-url date)))
    (yapc-sched:parse-schedule (yapc-sched:get-schedule url))))

(defvar yapc-sched:abstract-buffer (get-buffer-create "*helm abstract*"))

(defvar yapc-sched:source
  '((name . "YAPC Schedule")
    (candidates . (lambda ()
                    (sort* (yapc-sched:schedule) #'string< :key #'car)))
    (persistent-action . (lambda (c)
                           (helm-c-switch-to-buffer yapc-sched:abstract-buffer)
                           (erase-buffer)
                           (insert (replace-regexp-in-string "
" "" c)))))) ;; Remove '^M'

(defun helm-yapc-schedule ()
  (interactive)
  (let ((buf (get-buffer-create "*helm yapc schedule*")))
    (helm :sources '(yapc-sched:source) :buffer buf)))

(provide 'yapc-schedule)

;;; yapc-schedule.el ends here

使い方

  • M-x helm-yapc-scheduleを実行
  • 日付を選択
  • 絞り込む

です。persistent-action(C-z)で各発表の abstractが見れます。

イメージ

こんな感じです

おわりに

YAPC::Asiaは一応チケットは持っているんですが、いけるとしても
土曜日だけでそのために 3万円出せるかと言われるときびしいので、
悩んでいます。