[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/webpaste 78651c9 073/298: Avoid using eval
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/webpaste 78651c9 073/298: Avoid using eval |
Date: |
Thu, 9 Dec 2021 18:59:47 -0500 (EST) |
branch: elpa/webpaste
commit 78651c982a820807028f9a4309dcc672fbed0441
Author: alphapapa <adam@alphapapa.net>
Commit: GitHub <noreply@github.com>
Avoid using eval
Enable lexical-binding and use a function instead of a macro for
webpaste-provider
---
webpaste.el | 146 ++++++++++++++++++++++++++++--------------------------------
1 file changed, 69 insertions(+), 77 deletions(-)
diff --git a/webpaste.el b/webpaste.el
index 2f2ce55..96ce305 100644
--- a/webpaste.el
+++ b/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
@@ -59,13 +59,7 @@ if that variable is nil, it will use the list of names from
‘webpaste-provider
each run.")
-(cl-defmacro webpaste-provider
- (&key (domain)
- (type "POST")
- (parser)
- (post-data ())
- (post-field)
- (success))
+(cl-defun webpaste-provider (&key domain (type "POST") parser post-data
post-field success)
"Macro to create the lambda function for a provider.
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.
:success Callback sent to `request`, look up how to write these in the
documentation for `request`"
- `(lambda (text)
- "Paste TEXT to provider"
-
- ;; Local variable post-data
- (let ((post-data ,post-data))
- ;; Push field with text to post-data
- (cl-pushnew (cons ,post-field text) post-data)
-
- ;; Do request
- (request ,domain
- :type ,type
- :data post-data
- :parser ,parser
- :success ,success
- :error
- (cl-function (lambda (&key error-thrown &allow-other-keys)
- (message "Got error: %S" error-thrown)
- (webpaste-paste-text text))))
- nil)))
+ (lambda (text)
+ "Paste TEXT to provider"
+
+ ;; Local variable post-data
+ (cl-pushnew (cons post-field text) post-data)
+
+ ;; Do request
+ (request domain
+ :type type
+ :data post-data
+ :parser parser
+ :success success
+ :error
+ (cl-function (lambda (&key error-thrown &allow-other-keys)
+ (message "Got error: %S" error-thrown)
+ (webpaste-paste-text text))))
+ nil))
;;; Define providers
(defcustom webpaste-providers-alist
- '(("ix.io" .
- (webpaste-provider
- :domain "http://ix.io/"
- :parser 'buffer-string
- :post-field "f:1"
- :success
- (cl-function (lambda (&key data &allow-other-keys)
- (when data
- (webpaste-return-url
- (replace-regexp-in-string "\n$" "" data)))))))
-
- ("sprunge.us" .
- (webpaste-provider
- :domain "http://sprunge.us/"
- :parser 'buffer-string
- :post-field "sprunge"
- :success
- (cl-function (lambda (&key data &allow-other-keys)
- (when data
- (webpaste-return-url
- (replace-regexp-in-string "\n$" "" data)))))))
-
- ("dpaste.com" .
- (webpaste-provider
- :domain "http://dpaste.com/api/v2/"
- :parser 'buffer-string
- :post-data '(("syntax" . "text")
- ("title" . "")
- ("poster" . "")
- ("expiry_days" . 1))
- :post-field "content"
- :success
- (cl-function (lambda (&key response &allow-other-keys)
- (webpaste-return-url
- (request-response-header response "Location"))))))
-
- ("dpaste.de" .
- (webpaste-provider
- :domain "https://dpaste.de/api/"
- :parser 'buffer-string
- :post-data '(("lexer" . "text")
- ("format" . "url")
- ("expires" . 86400))
- :post-field "content"
- :success
- (cl-function (lambda (&key data &allow-other-keys)
- (when data
- (webpaste-return-url
- (replace-regexp-in-string "\n$" "" data))))))))
+ (list (list "ix.io"
+ (webpaste-provider
+ :domain "http://ix.io/"
+ :parser 'buffer-string
+ :post-field "f:1"
+ :success
+ (cl-function (lambda (&key data &allow-other-keys)
+ (when data
+ (webpaste-return-url
+ (replace-regexp-in-string "\n$" "" data)))))))
+
+ (list "sprunge.us"
+ (webpaste-provider
+ :domain "http://sprunge.us/"
+ :parser 'buffer-string
+ :post-field "sprunge"
+ :success
+ (cl-function (lambda (&key data &allow-other-keys)
+ (when data
+ (webpaste-return-url
+ (replace-regexp-in-string "\n$" "" data)))))))
+
+ (list "dpaste.com"
+ (webpaste-provider
+ :domain "http://dpaste.com/api/v2/"
+ :parser 'buffer-string
+ :post-data '(("syntax" . "text")
+ ("title" . "")
+ ("poster" . "")
+ ("expiry_days" . 1))
+ :post-field "content"
+ :success
+ (cl-function (lambda (&key response &allow-other-keys)
+ (webpaste-return-url
+ (request-response-header response
"Location"))))))
+
+ (list "dpaste.de"
+ (webpaste-provider
+ :domain "https://dpaste.de/api/"
+ :parser 'buffer-string
+ :post-data '(("lexer" . "text")
+ ("format" . "url")
+ ("expires" . 86400))
+ :post-field "content"
+ :success
+ (cl-function (lambda (&key data &allow-other-keys)
+ (when data
+ (webpaste-return-url
+ (replace-regexp-in-string "\n$" ""
data))))))))
"Define all webpaste.el providers.
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))
;; Run pasting function
- (funcall (eval (cdr (assoc provider-name webpaste-providers-alist)))
text)))
+ (funcall (cadr (assoc provider-name webpaste-providers-alist)) text)))
;;;###autoload
- [nongnu] elpa/webpaste d7700eb 050/298: Merge pull request #2 from syohex/cl-lib, (continued)
- [nongnu] elpa/webpaste d7700eb 050/298: Merge pull request #2 from syohex/cl-lib, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste c33f341 019/298: Added custom for provider priority, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste cc05738 025/298: Added some TODO notes, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste 729e277 030/298: Paste to selected paste provider at the top of the list, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste 80f0afe 051/298: Added provider to todo-list, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste cb9cca7 054/298: Stop moving point and remove usage of save-excursion and therefore, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste 2250993 061/298: Fix eval of macros, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste c60c712 062/298: Checkdoc, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste 39809d8 063/298: Update documentation, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste c57cd53 071/298: Changed string to number, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste 78651c9 073/298: Avoid using eval,
ELPA Syncer <=
- [nongnu] elpa/webpaste c9d1de0 076/298: Added Makefile for running tests, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste 7770c88 080/298: Added first unit test to detect a working provider, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste 20760ac 097/298: Set default value of :parser to provider, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste e998ee4 099/298: Simplify one unit test, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste e905bbc 066/298: Change value-type to catch-all sexp since it's not functions anymore, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste b4c08a5 070/298: Spelling in docs, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste dc11b51 078/298: Added code for helper for unit tests, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste 8e9f4e0 094/298: Bump required version for webpaste.el because I can't install older, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste 0b7ba72 098/298: Added coveralls for file coverage testing, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste 25ea405 103/298: Added ERT test for message when returning URL, ELPA Syncer, 2021/12/09