gist: 290 Download_button fork
public
Public Clone URL: git://gist.github.com/290.git
gist.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
;; gist.el --- Emacs integration for gist.github.com
;; Copyright (C) 2008 Christian Neukirchen <purl.org/net/chneukirchen>
;; Licensed under the same terms as Emacs.
 
;; Version: 0.2
;; 21jul2008 +chris+
 
;; Ideas: fetch & fork
 
(defun gist-region (begin end)
  "Post the current region as a new paste at gist.github.com
Copies the URL into the kill ring."
  (interactive "r")
  (let* ((file (or (buffer-file-name) (buffer-name)))
         (name (file-name-nondirectory file))
         (ext (or (file-name-extension file) "txt"))
         (output (generate-new-buffer " *gist*")))
    (shell-command-on-region
     begin end
     (format (concat "curl -sS "
                     "-F 'file_ext[gistfile1]=.%s' "
                     "-F 'file_name[gistfile1]=%s' "
                     "-F 'file_contents[gistfile1]=<-' "
                     "http://gist.github.com/gists &") ext name)
     output)
    (with-current-buffer output
      (re-search-backward "href=\"\\(.*\\)\"")
      (message "Paste created: %s" (match-string 1))
      (kill-new (match-string 1)))
    (kill-buffer output)))
 
(defun gist-buffer ()
  "Post the current buffer as a new paste at gist.github.com.
Copies the URL into the kill ring."
  (interactive)
  (gist-region (point-min) (point-max)))
 
(provide 'gist)
;;; gist.el ends here.

Owner

Anonymous

Revisions

  • 2b5227 Mon Jul 21 14:36:08 -0700 2008