summaryrefslogtreecommitdiff
path: root/.emacs.d/lisp/rust-playpen.el
diff options
context:
space:
mode:
authorSimeon Simeonov2024-03-14 22:27:34 +0100
committerSimeon Simeonov2024-03-14 22:27:34 +0100
commit236114bdeab5edab09969e5ad398c32c2738dead (patch)
tree42b337b433de9ada45f2aa441833c5cde42c3a1e /.emacs.d/lisp/rust-playpen.el
parent9fffbc025f80ef22a77ccc62f53baa990568b214 (diff)
Upgrade markdown-mode, rust and yasnippet
Diffstat (limited to '.emacs.d/lisp/rust-playpen.el')
-rw-r--r--.emacs.d/lisp/rust-playpen.el42
1 files changed, 25 insertions, 17 deletions
diff --git a/.emacs.d/lisp/rust-playpen.el b/.emacs.d/lisp/rust-playpen.el
index 1a9e583..a80a184 100644
--- a/.emacs.d/lisp/rust-playpen.el
+++ b/.emacs.d/lisp/rust-playpen.el
@@ -16,6 +16,12 @@
16 :type 'string 16 :type 'string
17 :group 'rust-mode) 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(defcustom rust-shortener-url-format "https://is.gd/create.php?format=simple&url=%s" 25(defcustom rust-shortener-url-format "https://is.gd/create.php?format=simple&url=%s"
20 "Format string to use for creating the shortened link of a playpen submission." 26 "Format string to use for creating the shortened link of a playpen submission."
21 :type 'string 27 :type 'string
@@ -28,26 +34,28 @@
28 (interactive "r") 34 (interactive "r")
29 (let* ((data (buffer-substring begin end)) 35 (let* ((data (buffer-substring begin end))
30 (escaped-data (url-hexify-string data)) 36 (escaped-data (url-hexify-string data))
31 (escaped-playpen-url (url-hexify-string 37 (playpen-url (format rust-playpen-url-format escaped-data))
32 (format rust-playpen-url-format escaped-data)))) 38 (escaped-playpen-url (url-hexify-string playpen-url)))
33 (if (> (length escaped-playpen-url) 5000) 39 (if (> (length escaped-playpen-url) 5000)
34 (error "encoded playpen data exceeds 5000 character limit (length %s)" 40 (error "encoded playpen data exceeds 5000 character limit (length %s)"
35 (length escaped-playpen-url)) 41 (length escaped-playpen-url))
36 (let ((shortener-url (format rust-shortener-url-format escaped-playpen-url)) 42 (if (not rust-playpen-enable-shortener)
37 (url-request-method "POST")) 43 (message "%s" playpen-url)
38 (url-retrieve shortener-url 44 (let ((shortener-url (format rust-shortener-url-format escaped-playpen-url))
39 (lambda (state) 45 (url-request-method "POST"))
40 ;; filter out the headers etc. included at the 46 (url-retrieve shortener-url
41 ;; start of the buffer: the relevant text 47 (lambda (state)
42 ;; (shortened url or error message) is exactly 48 ;; filter out the headers etc. included at the
43 ;; the last line. 49 ;; start of the buffer: the relevant text
44 (goto-char (point-max)) 50 ;; (shortened url or error message) is exactly
45 (let ((last-line (thing-at-point 'line t)) 51 ;; the last line.
46 (err (plist-get state :error))) 52 (goto-char (point-max))
47 (kill-buffer) 53 (let ((last-line (thing-at-point 'line t))
48 (if err 54 (err (plist-get state :error)))
49 (error "failed to shorten playpen url: %s" last-line) 55 (kill-buffer)
50 (message "%s" last-line))))))))) 56 (if err
57 (error "failed to shorten playpen url: %s" last-line)
58 (message "%s" last-line))))))))))
51 59
52(defun rust-playpen-buffer () 60(defun rust-playpen-buffer ()
53 "Create a shareable URL for the contents of the buffer on the Rust playpen." 61 "Create a shareable URL for the contents of the buffer on the Rust playpen."