|
16 | 16 | :type 'string
|
17 | 17 | :group 'rust-mode)
|
18 | 18 |
|
| 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 | + |
19 | 25 | (defcustom rust-shortener-url-format "https://is.gd/create.php?format=simple&url=%s"
|
20 | 26 | "Format string to use for creating the shortened link of a playpen submission."
|
21 | 27 | :type 'string
|
|
28 | 34 | (interactive "r")
|
29 | 35 | (let* ((data (buffer-substring begin end))
|
30 | 36 | (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))) |
33 | 39 | (if (> (length escaped-playpen-url) 5000)
|
34 | 40 | (error "encoded playpen data exceeds 5000 character limit (length %s)"
|
35 | 41 | (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)))))))))) |
51 | 59 |
|
52 | 60 | (defun rust-playpen-buffer ()
|
53 | 61 | "Create a shareable URL for the contents of the buffer on the Rust playpen."
|
|
0 commit comments