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

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

[nongnu] elpa/webpaste e892ef2 277/298: webpaste: Add custom to limit am


From: ELPA Syncer
Subject: [nongnu] elpa/webpaste e892ef2 277/298: webpaste: Add custom to limit amount of retries
Date: Thu, 9 Dec 2021 19:00:29 -0500 (EST)

branch: elpa/webpaste
commit e892ef243fb7bcf786d0994a59465868a6fb392e
Author: Elis Hirwing <elis@hirwing.se>
Commit: Elis Hirwing <elis@hirwing.se>

    webpaste: Add custom to limit amount of retries
---
 webpaste.el | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/webpaste.el b/webpaste.el
index 83649f9..42a9595 100644
--- a/webpaste.el
+++ b/webpaste.el
@@ -86,6 +86,12 @@ This uses `browse-url-generic' to open URLs."
   :type 'hook)
 
 
+(defcustom webpaste-max-retries 10
+  "Max retries before we give up on pasting, say if network is down or so."
+  :group 'webpaste
+  :type 'number)
+
+
 (defcustom webpaste-providers-alist
   '(("ix.io"
      :uri "http://ix.io/";
@@ -191,6 +197,12 @@ This list will be populated when you add providers to have 
the languages
 precalculated, and also available both for pre and post request access.")
 
 
+(defvar webpaste--current-retries 0
+  "Variable for storing the current amount of retries.
+This shouldn't go biffer than `webpaste-max-retries' to avoid infinite
+loops.  This variable is reset on each new paste.")
+
+
 (defvar webpaste--default-lang-alist
   '((c-mode . "c")
     (c++-mode . "cpp")
@@ -513,6 +525,12 @@ When we run out of providers to try, it will restart since
   (unless webpaste--tested-providers
     (setq webpaste--tested-providers (webpaste--get-provider-priority)))
 
+  ;; If we have too many retries, empty the provider list.
+  (if (>= webpaste--current-retries webpaste-max-retries)
+      (setq webpaste--tested-providers nil)
+    ;; Otherwise increment the retry counter.
+    (setq webpaste--current-retries (+ 1 webpaste--current-retries)))
+
   ;; Get name of provider at the top of the list
   (let ((provider-name (car webpaste--tested-providers)))
     ;; Drop the name at the top of the list
@@ -530,6 +548,9 @@ Argument POINT Current point.
 Argument MARK Current mark."
   (interactive "r")
 
+  ;; Set retry counter to zero before we start.
+  (setq webpaste--current-retries 0)
+
   ;; unless we wanted a paste confirmation and declined
   (unless (and webpaste-paste-confirmation
                (not (yes-or-no-p "paste entire region?")))
@@ -542,6 +563,9 @@ Argument MARK Current mark."
   "Paste current buffer to some paste service."
   (interactive)
 
+  ;; Set retry counter to zero before we start.
+  (setq webpaste--current-retries 0)
+
   ;; unless we wanted a paste confirmation and declined
   (unless (and webpaste-paste-confirmation
                (not (yes-or-no-p "paste entire buffer?")))



reply via email to

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