Download
(defgroup pastebin nil
"Pastebin -- pastebin.com client"
:tag "Pastebin"
:group 'tools)
(defcustom pastebin-unique-developer-api-key "INSERT_YOURS"
"Everybody using our API is required to use a valid Developer
API Key. You automaticly get a key when you become a member of
Pastebin. http://pastebin.com/api"
:type 'string
:group 'pastebin)
(defcustom pastebin-user-name "guest"
"Username of the user you want to login."
:type 'string
:group 'pastebin)
(defcustom pastebin-password "guest"
"Password of the user you want to login."
:type 'string
:group 'pastebin)
(defcustom pastebin-post-request-login-url "http://pastebin.com/api/api_login.php"
"Login url"
:type 'string
:group 'pastebin)
(defcustom pastebin-post-request-paste-url "http://pastebin.com/api/api_post.php"
"Paste url"
:type 'string
:group 'pastebin)
(defcustom pastebin-user-api-key "INSERT_YOURS"
"Key for pastebin members"
:type 'string
:group 'pastebin)
(defun pastebin-login ()
(let* ((params (concat "api_dev_key=" pastebin-unique-developer-api-key
"&api_user_name=" (url-hexify-string pastebin-user-name)
"&api_user_password=" (url-hexify-string pastebin-password)))
(url-request-method "POST")
(url-request-extra-headers
'(("Content-Type" . "application/x-www-form-urlencoded")))
(url-request-data params)
(content-buf (url-retrieve
pastebin-post-request-login-url
(lambda (arg)
(cond
((equal :error (car arg))
(signal 'pastebin-error (cdr arg)))
(t
(re-search-forward "\n\n")
(setq pastebin-user-api-key (buffer-substring (point) (point-max)))))))))))
(defcustom pastebin-type-assoc
'((actionscript-mode . " actionscript")
(ada-mode . "ada")
(asm-mode . "asm")
(autoconf-mode . "bash")
(bibtex-mode . "bibtex")
(cmake-mode . "cmake")
(c-mode . "c")
(c++-mode . "cpp")
(cobol-mode . "cobol")
(conf-colon-mode . "properties")
(conf-javaprop-mode . "properties")
(conf-mode . "ini")
(conf-space-mode . "properties")
(conf-unix-mode . "ini")
(conf-windows-mode . "ini")
(cperl-mode . "perl")
(csharp-mode . "csharp")
(css-mode . "css")
(delphi-mode . "delphi")
(diff-mode . "dff")
(ebuild-mode . "bash")
(eiffel-mode . "eiffel")
(emacs-lisp-mode . "lisp")
(erlang-mode . "erlang")
(erlang-shell-mode . "erlang")
(espresso-mode . "javascript")
(fortran-mode . "fortran")
(glsl-mode . "glsl")
(gnuplot-mode . "gnuplot")
(graphviz-dot-mode . "dot")
(haskell-mode . "haskell")
(html-mode . "html4strict")
(idl-mode . "idl")
(inferior-haskell-mode . "haskell")
(inferior-octave-mode . "octave")
(inferior-python-mode . "python")
(inferior-ruby-mode . "ruby")
(java-mode . "java")
(js2-mode . "javascript")
(jython-mode . "python")
(latex-mode . "latex")
(lisp-mode . "lisp")
(lua-mode . "lua")
(makefile-mode . "make")
(makefile-automake-mode . "make")
(makefile-gmake-mode . "make")
(makefile-makepp-mode . "make")
(makefile-bsdmake-mode . "make")
(makefile-imake-mode . "make")
(matlab-mode . "matlab")
(nxml-mode . "xml")
(oberon-mode . "oberon2")
(objc-mode . "objc")
(ocaml-mode . "ocaml")
(octave-mode . "matlab")
(pascal-mode . "pascal")
(perl-mode . "perl")
(php-mode . "php")
(plsql-mode . "plsql")
(po-mode . "gettext")
(prolog-mode . "prolog")
(python-2-mode . "python")
(python-3-mode . "python")
(python-basic-mode . "python")
(python-mode . "python")
(ruby-mode . "ruby")
(scheme-mode . "lisp")
(shell-mode . "bash")
(sh-mode . "bash")
(smalltalk-mode . "smalltalk")
(sql-mode . "sql")
(tcl-mode . "tcl")
(visual-basic-mode . "vb")
(xml-mode . "xml")
(yaml-mode . "properties")
(text-mode . "text"))
"Alist composed of major-mode names and corresponding pastebin highlight formats."
:type '(alist :key-type symbol :value-tupe string)
:group 'pastebin)
(defcustom pastebin-type-assoc
'((never . "N")
(ten-minutes . "10M")
(one-hour . "1H")
(one-day . "1D")
(one-month . "1M"))
"We have 5 valid values available which you can use with the 'api_paste_expire_date' parameter."
:type '(alist :key-type symbol :value-tupe string)
:group 'pastebin)
(defvar pastebin-domain-history '())
(defun pastebin (start end &optional name)
"Send the region to the pastebin service specified.
See pastebin.com for more information about pastebin.
Called interactively pastebin uses the current region for
preference for sending... if the mark is NOT set then the entire
buffer is sent.
Argument START is the start of region.
Argument END is the end of region.
If domain is used pastebin prompts for a domain defaulting to
'pastebin-default-domain' so you can send requests or use a
different domain.
"
(interactive
(if (region-active-p)
(list (region-beginning) (region-end) nil)
(list (point-min) (point-max) nil)))
(print (buffer-substring-no-properties start end))
(let* ((data (buffer-substring-no-properties start end))
(params (concat "api_dev_key=" pastebin-unique-developer-api-key
"&api_user_key=" pastebin-user-api-key
"&api_option=" "paste"
"&api_paste_code=" (url-hexify-string data)
"&api_paste_format=" (or
(assoc-default major-mode pastebin-type-assoc nil "text")
"text")
(if name
(concat "&api_paste_name=" (url-hexify-string name))
(concat "&api_paste_name=" (url-hexify-string (buffer-name))))
))
(url-request-method "POST")
(url-request-extra-headers
'(("Content-Type" . "application/x-www-form-urlencoded")))
(url-request-data
params)
(content-buf (url-retrieve
pastebin-post-request-paste-url
(lambda (arg)
(cond
((equal :error (car arg))
(signal 'pastebin-error (cdr arg)))
(t
(re-search-forward "\n\n")
(clipboard-kill-ring-save (point) (point-max))
(message "Pastebin URL: %s" (buffer-substring (point) (point-max)))))))))))
(provide 'pastebin)