emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/webpaste 1114813 017/298: Move providers to customizable l


From: ELPA Syncer
Subject: [nongnu] elpa/webpaste 1114813 017/298: Move providers to customizable list with lambdas
Date: Thu, 9 Dec 2021 18:59:36 -0500 (EST)

branch: elpa/webpaste
commit 11148135ce49f866409293ddb2455a7bdc7529ea
Author: Elis Axelsson <elis.axelsson@gmail.com>
Commit: Elis Axelsson <elis.axelsson@gmail.com>

    Move providers to customizable list with lambdas
    instead of having loose functions.
---
 webpaste.el | 86 ++++++++++++++++++++++++++++++-------------------------------
 1 file changed, 43 insertions(+), 43 deletions(-)

diff --git a/webpaste.el b/webpaste.el
index f80dc29..3a4d94b 100644
--- a/webpaste.el
+++ b/webpaste.el
@@ -48,7 +48,7 @@
   (interactive)
 
   (let ((text (buffer-substring (mark) (point))))
-    (webpaste-providers-ix.io text)))
+    (funcall (cdr (car webpaste-providers)) text)))
 
 
 ;;;###autoload
@@ -63,49 +63,49 @@
 
 
 ;;; Define providers
+(defcustom webpaste-providers
+  '(("ix.io" .
+     (lambda (text)
+       "Paste TEXT to http://ix.io/.";
+
+       (let ((post-data '()))
+         ;; Construct post data
+         (add-to-list 'post-data (cons "f:1" text))
+
+         ;; Use request.el to do request to ix.io to submit data
+         (request "http://ix.io/";
+                  :type "POST"
+                  :data post-data
+                  :parser 'buffer-string
+                  :success (function* (lambda (&key data &allow-other-keys)
+                                        (when data
+                                          (webpaste-return-url data))))))
+       nil))
+    ("dpaste.com" .
+     (lambda (text)
+       "Paste TEXT to http://dpaste.com/.";
+
+       ;; Prepare post fields
+       (let ((post-data '(("syntax" . "text")
+                          ("title" . "")
+                          ("poster" . "")
+                          ("expiry_days" . "1"))))
+
+         ;; Add TEXT as content
+         (add-to-list 'post-data (cons "content" text))
+
+         ;; Use request.el to do request to dpaste.com to submit data
+         (request "http://dpaste.com/api/v2/";
+                  :type "POST"
+                  :data post-data
+                  :parser 'buffer-string
+                  :success
+                  (function* (lambda (&key response &allow-other-keys)
+                               (webpaste-return-url
+                                (request-response-header response 
"Location"))))))
+       nil)))
+  "Define all webpaste.el providers.")
 
-;; Provider for http://ix.io/
-(defun webpaste-providers-ix.io (text)
-  "Paste TEXT to http://ix.io/.";
-
-  (let ((post-data '()))
-    ;; Construct post data
-    (add-to-list 'post-data (cons "f:1" text))
-
-    ;; Use request.el to do request to ix.io to submit data
-    (request "http://ix.io/";
-             :type "POST"
-             :data post-data
-             :parser 'buffer-string
-             :success (function* (lambda (&key data &allow-other-keys)
-                                   (when data
-                                     (webpaste-return-url data))))))
-  nil)
-
-
-;; Provider for http://dpaste.com/
-(defun webpaste-providers-dpaste.com (text)
-  "Paste TEXT to http://dpaste.com/.";
-
-  ;; Prepare post fields
-  (let ((post-data '(("syntax" . "text")
-                     ("title" . "")
-                     ("poster" . "")
-                     ("expiry_days" . "1"))))
-
-    ;; Add TEXT as content
-    (add-to-list 'post-data (cons "content" text))
-
-    ;; Use request.el to do request to dpaste.com to submit data
-    (request "http://dpaste.com/api/v2/";
-             :type "POST"
-             :data post-data
-             :parser 'buffer-string
-             :success
-             (function* (lambda (&key response &allow-other-keys)
-                          (webpaste-return-url
-                           (request-response-header response "Location"))))))
-  nil)
 
 (provide 'webpaste)
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]