Merge branch 'alphapapa-without-eval'

master
Elis Axelsson 9 years ago
commit f206653419
No known key found for this signature in database
GPG Key ID: D57EFA625C9A925F
  1. 146
      webpaste.el

@ -1,4 +1,4 @@
;;; webpaste.el --- Paste to pastebin-like services ;;; webpaste.el --- Paste to pastebin-like services -*- lexical-binding: t; -*-
;; Copyright (c) 2016 Elis Axelsson ;; Copyright (c) 2016 Elis Axelsson
@ -59,13 +59,7 @@ if that variable is nil, it will use the list of names from ‘webpaste-provider
each run.") each run.")
(cl-defmacro webpaste-provider (cl-defun webpaste-provider (&key domain (type "POST") parser post-data post-field success)
(&key (domain)
(type "POST")
(parser)
(post-data ())
(post-field)
(success))
"Macro to create the lambda function for a provider. "Macro to create the lambda function for a provider.
This macro accepts the parameters :domain, :type, :parser, :post-data, This macro accepts the parameters :domain, :type, :parser, :post-data,
@ -83,78 +77,76 @@ Usage:
:post-field Name of the field to insert the code into. :post-field Name of the field to insert the code into.
:success Callback sent to `request`, look up how to write these in the :success Callback sent to `request`, look up how to write these in the
documentation for `request`" documentation for `request`"
`(lambda (text) (lambda (text)
"Paste TEXT to provider" "Paste TEXT to provider"
;; Local variable post-data ;; Local variable post-data
(let ((post-data ,post-data)) (cl-pushnew (cons post-field text) post-data)
;; Push field with text to post-data
(cl-pushnew (cons ,post-field text) post-data) ;; Do request
(request domain
;; Do request :type type
(request ,domain :data post-data
:type ,type :parser parser
:data post-data :success success
:parser ,parser :error
:success ,success (cl-function (lambda (&key error-thrown &allow-other-keys)
:error (message "Got error: %S" error-thrown)
(cl-function (lambda (&key error-thrown &allow-other-keys) (webpaste-paste-text text))))
(message "Got error: %S" error-thrown) nil))
(webpaste-paste-text text))))
nil)))
;;; Define providers ;;; Define providers
(defcustom webpaste-providers-alist (defcustom webpaste-providers-alist
'(("ix.io" . (list (list "ix.io"
(webpaste-provider (webpaste-provider
:domain "http://ix.io/" :domain "http://ix.io/"
:parser 'buffer-string :parser 'buffer-string
:post-field "f:1" :post-field "f:1"
:success :success
(cl-function (lambda (&key data &allow-other-keys) (cl-function (lambda (&key data &allow-other-keys)
(when data (when data
(webpaste-return-url (webpaste-return-url
(replace-regexp-in-string "\n$" "" data))))))) (replace-regexp-in-string "\n$" "" data)))))))
("sprunge.us" . (list "sprunge.us"
(webpaste-provider (webpaste-provider
:domain "http://sprunge.us/" :domain "http://sprunge.us/"
:parser 'buffer-string :parser 'buffer-string
:post-field "sprunge" :post-field "sprunge"
:success :success
(cl-function (lambda (&key data &allow-other-keys) (cl-function (lambda (&key data &allow-other-keys)
(when data (when data
(webpaste-return-url (webpaste-return-url
(replace-regexp-in-string "\n$" "" data))))))) (replace-regexp-in-string "\n$" "" data)))))))
("dpaste.com" . (list "dpaste.com"
(webpaste-provider (webpaste-provider
:domain "http://dpaste.com/api/v2/" :domain "http://dpaste.com/api/v2/"
:parser 'buffer-string :parser 'buffer-string
:post-data '(("syntax" . "text") :post-data '(("syntax" . "text")
("title" . "") ("title" . "")
("poster" . "") ("poster" . "")
("expiry_days" . 1)) ("expiry_days" . 1))
:post-field "content" :post-field "content"
:success :success
(cl-function (lambda (&key response &allow-other-keys) (cl-function (lambda (&key response &allow-other-keys)
(webpaste-return-url (webpaste-return-url
(request-response-header response "Location")))))) (request-response-header response "Location"))))))
("dpaste.de" . (list "dpaste.de"
(webpaste-provider (webpaste-provider
:domain "https://dpaste.de/api/" :domain "https://dpaste.de/api/"
:parser 'buffer-string :parser 'buffer-string
:post-data '(("lexer" . "text") :post-data '(("lexer" . "text")
("format" . "url") ("format" . "url")
("expires" . 86400)) ("expires" . 86400))
:post-field "content" :post-field "content"
:success :success
(cl-function (lambda (&key data &allow-other-keys) (cl-function (lambda (&key data &allow-other-keys)
(when data (when data
(webpaste-return-url (webpaste-return-url
(replace-regexp-in-string "\n$" "" data)))))))) (replace-regexp-in-string "\n$" "" data))))))))
"Define all webpaste.el providers. "Define all webpaste.el providers.
Consists of provider name and lambda function to do the actuall call to the Consists of provider name and lambda function to do the actuall call to the
@ -216,7 +208,7 @@ When we run out of providers to try, it will restart since
(setq webpaste-tested-providers (cdr webpaste-tested-providers)) (setq webpaste-tested-providers (cdr webpaste-tested-providers))
;; Run pasting function ;; Run pasting function
(funcall (eval (cdr (assoc provider-name webpaste-providers-alist))) text))) (funcall (cadr (assoc provider-name webpaste-providers-alist)) text)))
;;;###autoload ;;;###autoload

Loading…
Cancel
Save