Skip to content

Commit 47e7c84

Browse files
psibijimblandy
authored andcommitted
Abilty to customize the enabling of URL shortener for playpen
This makes me share the Playpen URL directly. And this is kind of necessary for me since the region I'm out of currently, the URL shortener domain itself is blocked. Snapshot here: https://imgur.com/a/ugLLVwP
1 parent 1f421fb commit 47e7c84

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

rust-playpen.el

+25-17
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
:type 'string
1717
:group 'rust-mode)
1818

19+
(defcustom rust-playpen-enable-shortener t
20+
"Enable shortended URL for playpen links."
21+
:type 'boolean
22+
:safe #'booleanp
23+
:group 'rust-mode)
24+
1925
(defcustom rust-shortener-url-format "https://is.gd/create.php?format=simple&url=%s"
2026
"Format string to use for creating the shortened link of a playpen submission."
2127
:type 'string
@@ -28,26 +34,28 @@
2834
(interactive "r")
2935
(let* ((data (buffer-substring begin end))
3036
(escaped-data (url-hexify-string data))
31-
(escaped-playpen-url (url-hexify-string
32-
(format rust-playpen-url-format escaped-data))))
37+
(playpen-url (format rust-playpen-url-format escaped-data))
38+
(escaped-playpen-url (url-hexify-string playpen-url)))
3339
(if (> (length escaped-playpen-url) 5000)
3440
(error "encoded playpen data exceeds 5000 character limit (length %s)"
3541
(length escaped-playpen-url))
36-
(let ((shortener-url (format rust-shortener-url-format escaped-playpen-url))
37-
(url-request-method "POST"))
38-
(url-retrieve shortener-url
39-
(lambda (state)
40-
;; filter out the headers etc. included at the
41-
;; start of the buffer: the relevant text
42-
;; (shortened url or error message) is exactly
43-
;; the last line.
44-
(goto-char (point-max))
45-
(let ((last-line (thing-at-point 'line t))
46-
(err (plist-get state :error)))
47-
(kill-buffer)
48-
(if err
49-
(error "failed to shorten playpen url: %s" last-line)
50-
(message "%s" last-line)))))))))
42+
(if (not rust-playpen-enable-shortener)
43+
(message "%s" playpen-url)
44+
(let ((shortener-url (format rust-shortener-url-format escaped-playpen-url))
45+
(url-request-method "POST"))
46+
(url-retrieve shortener-url
47+
(lambda (state)
48+
;; filter out the headers etc. included at the
49+
;; start of the buffer: the relevant text
50+
;; (shortened url or error message) is exactly
51+
;; the last line.
52+
(goto-char (point-max))
53+
(let ((last-line (thing-at-point 'line t))
54+
(err (plist-get state :error)))
55+
(kill-buffer)
56+
(if err
57+
(error "failed to shorten playpen url: %s" last-line)
58+
(message "%s" last-line))))))))))
5159

5260
(defun rust-playpen-buffer ()
5361
"Create a shareable URL for the contents of the buffer on the Rust playpen."

0 commit comments

Comments
 (0)