Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

First commit.

  • Loading branch information...
commit d83f96fd29285a03b6303a5b85f14d59d0a66025 0 parents
@Raynes authored
Showing with 111 additions and 0 deletions.
  1. +3 −0  README.markdown
  2. +108 −0 refheap.el
3  README.markdown
@@ -0,0 +1,3 @@
+# refheap.el
+
+This is a little library for pasting to [RefHeap](https://refheap.com). It is currently under development and not useful to the general public.
108 refheap.el
@@ -0,0 +1,108 @@
+(require 'json)
+(require 'url)
+
+(defvar refheap-supported-modes '((clojure-mode . "Clojure")
+ ;(dontknow . "Factor")
+ (fancy-mode . "Fancy")
+ (groovy-mode . "Groovy")
+ (grails-mode . "Groovy")
+ (io-mode . "Io")
+ (ioke-mode . "Ioke")
+ (lua-mode . "Lua")
+ (perl-mode . "Perl")
+ (python-mode . "Python")
+ (ruby-mode . "Ruby")
+ (c-mode . "C")
+ (c++-mode . "C++")
+ (tcl-mode . "Tcl")
+ (ada-mode . "Ada")
+ (d-mode . "D")
+ (delphi-mode . "Delphi")
+ (dylan-mode . "Dylan")
+ (fortran-mode . "Fortran")
+ (go-mode . "Go")
+ (java-mode . "Java")
+ (nimrod-mode . "Nimrod")
+ (objc-mode . "Objective C")
+ (ooc-mode . "ooc")
+ (prolog-mode . "Prolog")
+ (scala-mode . "Scala")
+ (vala-mode . "Vala")
+ (boo-mode . "Boo")
+ (csharp-mode . "C#")
+ (fsharp-mode . "F#")
+ (vbnet-mode . "VB.NET")
+ (common-lisp-mode . "Common Lisp")
+ (erlang . "Erlang")
+ (haskell-mode . "Haskell")
+ (tuareg-mode . "OCaml")
+ (scheme-mode . "Scheme")
+ (emacs-lisp-mode . "Scheme")
+ (r-mode . "R")
+ (applescript-mode "AppleScript")
+ (sh-mode . "Bash")
+ (batch-mode . "Batch")
+ (newspeak-mode . "NewSpeak")
+ (protobuf-mode . "Protobuf")
+ (rebol-mode . "REBOL")
+ (latex-mode . "LaTeX")
+ (actionscript-mode . "ActionScript")
+ (yaml-mode . "YAML")
+ (coffeescript-mode . "CoffeeScript")
+ (css-mode . "CSS")
+ (html-mode . "HTML")
+ (haml-mode . "HAML")
+ (js-mode . "Javascript")
+ (php-mode . "PHP")
+ (text-mode . "Plain Text")
+ (sass-mode . "SASS")
+ (xml-mode . "XML")))
+
+(defcustom refheap-user nil
+ "Your RefHeap username.")
+
+(defcustom refheap-token nil
+ "Your RefHeap API token.")
+
+(defun read-url (status)
+ (search-forward "\n\n")
+ (let ((location (cdr (assoc 'url
+ (json-read-from-string
+ (buffer-substring (point)
+ (point-max)))))))
+ (message "Paste created: %s" location)
+ (kill-new location)
+ (kill-buffer (current-buffer))))
+
+(defun refheap-paste (text mode private)
+ (let ((url-request-method "POST")
+ (url-request-extra-headers
+ '(("Content-Type" . "application/x-www-form-urlencoded")))
+ (url-request-data
+ (concat "private=" (if private "true" "false") "&"
+ "language=" (url-hexify-string mode) "&"
+ "contents=" (url-hexify-string text)
+ (when (and refheap-user refheap-token)
+ (concat "&username=" refheap-user "&"
+ "token=" (url-hexify-string refheap-token))))))
+ (url-retrieve "http://localhost:8080/api/paste" 'read-url)))
+
+(defun refheap-paste-region (begin end &optional private)
+ (interactive "r\nP")
+ (let ((hl (or (cdr (assoc major-mode refheap-supported-modes))
+ "Plain Text")))
+ (refheap-paste (buffer-substring begin end) hl private)))
+
+(defun refheap-paste-region-private (begin end)
+ (interactive "r")
+ (refheap-paste-region begin end t))
+
+(defun refheap-paste-buffer (&optional private)
+ (interactive "P")
+ (refheap-paste-region (point-min) (point-max) private))
+
+(defun refheap-paste-buffer-private ()
+ (interactive)
+ (refheap-paste-buffer t))
+
+(provide 'refheap)
Please sign in to comment.
Something went wrong with that request. Please try again.