Skip to content

Instantly share code, notes, and snippets.

@naota
Forked from masutaka/twinstall.el
Created October 26, 2011 14:26
Show Gist options
  • Save naota/1316516 to your computer and use it in GitHub Desktop.
Save naota/1316516 to your computer and use it in GitHub Desktop.
(defvar twinstall-curl-program (executable-find "curl"))
(defvar twinstall-hash-tags "#emacsjp #twinstall")
(defvar twinstall-should-tweet nil)
(defvar twinstall-url nil)
(defun twinstall-tweet-url (url)
(let* ((name (file-name-nondirectory url))
(text (cond
((string= (concat auto-install-emacswiki-base-url name) url)
(format "EmacsWikiから%sをインストールしました。 %s %s"
name twinstall-hash-tags url))
(t
(format "%sをインストールしました。 %s %s"
name twinstall-hash-tags url)))))
(twittering-call-api
'update-status
`((status . ,text)))))
(defadvice auto-install-buffer-save (before twinstall-set-url activate)
(setq twinstall-url auto-install-download-url))
(defadvice auto-install-install (before twinstall-set-shoud-tweet activate)
(setq twinstall-should-tweet t))
(defadvice auto-install-install-next-file (before twinstall-tweet-url activate)
(when (and twinstall-should-tweet twinstall-url)
(twinstall-tweet-url twinstall-url))
(setq twinstall-url nil
twinstall-should-tweet nil))
(defun twinstall-from-tweet ()
(interactive)
(let ((text (get-text-property (point) 'text)))
(when (string-match " #emacsjp #twinstall \\(http://t\\.co/.*\\)$" text)
(twinstall-from-tco (match-string 1 text)))))
(defun twinstall-from-tco (tco-url)
(when (string-match "\\`http://t\\.co/" tco-url)
(let ((url (twinstall-expand-url tco-url)))
(auto-install-from-url url))))
(defun twinstall-expand-url (url)
(with-temp-buffer
(call-process twinstall-curl-program nil t nil "-v" url)
(goto-char (point-min))
(if (re-search-forward "^< Location: \\(.*\\)\r$" nil t)
(match-string 1)
url)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment