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

helm-vim-advent-calender-2012を書きました

emacs vac2012

http://atnd.org/events/33746


どんな記事があるかが気になるので適当に書いてみました

コード

curlコマンドと helmがあればたぶん動きます。

(defvar vac2012-url "http://atnd.org/events/33746")
(defvar vac2012-entries-cache nil)
(defvar vac2012-entry-regexp
  "【\\([0-9]+\\)日目】<a href=\"\\([^\"]+\\)\">\\([^>]+\\)</a>")

(defun vac2012-collect-entries ()
  (if (and vac2012-entries-cache (not current-prefix-arg))
      vac2012-entries-cache
    (let ((cmd (format "curl %s" vac2012-url)))
      (with-temp-buffer
        (unless (zerop (call-process-shell-command cmd nil t))
          (error "Failed: %s" cmd))
        (goto-char (point-min))
        (loop initially (goto-char (point-min))
              while (re-search-forward vac2012-entry-regexp nil t)
              collect
              (cons t
                    (list
                     :date (string-to-number (match-string-no-properties 1))
                     :url  (match-string-no-properties 2)
                     :title (match-string-no-properties 3))) into entries
              finally
              return (setq vac2012-entries-cache (reverse entries)))))))

(defun vac2012-transform-candidate (candidate)
  (format "%4d日目: %s"
          (plist-get candidate :date)
          (plist-get candidate :title)))

(defun vac2012-jump-url (candidate)
  (browse-url (plist-get candidate :url)))

(defvar helm-vac2012-source
  '((name . "Vim Advent Calendar 2012")
    (init . vac2012-collect-entries)
    (candidates . vac2012-entries-cache)
    (real-to-display . vac2012-transform-candidate)
    (action . vac2012-jump-url)))

(defun helm-vim-advent-calender-2012 ()
  (interactive)
  (helm :sources '(helm-vac2012-source) :buffer "*Vim Advent Calenader 2012*"))

イメージ


エントリを選択すると、ブラウザでそのページを開きます。