[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/rust-mode eaa332e 143/486: Add rust-playpen-buffer and rus
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/rust-mode eaa332e 143/486: Add rust-playpen-buffer and rust-playpen-region for sharing code. |
Date: |
Sat, 7 Aug 2021 09:25:06 -0400 (EDT) |
branch: elpa/rust-mode
commit eaa332ebcb60a724ec843d4a889c061b0e20aed4
Author: Huon Wilson <dbau.pp+github@gmail.com>
Commit: Huon Wilson <dbau.pp+github@gmail.com>
Add rust-playpen-buffer and rust-playpen-region for sharing code.
This will create (and shorten) a URL with the code on
play.rust-lang.org.
---
rust-mode.el | 53 ++++++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 48 insertions(+), 5 deletions(-)
diff --git a/rust-mode.el b/rust-mode.el
index 77fa349..b518c87 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -67,6 +67,15 @@
:type 'boolean
:group 'rust-mode)
+(defcustom rust-playpen-url-format "https://play.rust-lang.org/?code=%s"
+ "Format string to use when submitting code to the playpen"
+ :type 'string
+ :group 'rust-mode)
+(defcustom rust-shortener-url-format
"http://is.gd/create.php?format=simple&url=%s"
+ "Format string to use for creating the shortened link of a playpen
submission"
+ :type 'string
+ :group 'rust-mode)
+
(defun rust-paren-level () (nth 0 (syntax-ppss)))
(defun rust-in-str-or-cmnt () (nth 8 (syntax-ppss)))
(defun rust-rewind-past-str-cmnt () (goto-char (nth 8 (syntax-ppss))))
@@ -115,7 +124,7 @@
;; annoying to have to press tab again to align to a method chain
;; than to have an over-eager indent in all other cases which must
;; be undone via tab.
-
+
(when (looking-at (concat "\s*\." rust-re-ident))
(forward-line -1)
(end-of-line)
@@ -128,7 +137,7 @@
;; ^ ^
;; | |
;; | position of point
- ;; returned offset
+ ;; returned offset
;;
((skip-dot-identifier
(lambda ()
@@ -215,7 +224,7 @@
(goto-char end-of-prev-line-pos)
(back-to-indentation)
(current-column))))))
-
+
;; A function return type is indented to the corresponding
function arguments
((looking-at "->")
(save-excursion
@@ -225,7 +234,7 @@
;; A closing brace is 1 level unindended
((looking-at "}") (- baseline rust-indent-offset))
-
+
;; Doc comments in /** style with leading * indent to line up
the *s
((and (nth 4 (syntax-ppss)) (looking-at "*"))
(+ 1 baseline))
@@ -364,7 +373,7 @@
(defun rust-look-for-raw-string (bound)
;; Find a raw string, but only if it's not in the middle of another string or
;; a comment
-
+
(let* ((raw-str-regexp
(rx
(seq
@@ -745,6 +754,40 @@ See `compilation-error-regexp-alist for help on their
format.")
(cons 'rustc rustc-compilation-regexps))
(add-to-list 'compilation-error-regexp-alist 'rustc)))
+;;; Functions to submit (parts of) buffers to the rust playpen, for
+;;; sharing.
+(defun rust-playpen-region (begin end)
+ "Create a sharable URL for the contents of the current region
+ on the Rust playpen."
+ (interactive "r")
+ (let* ((data (buffer-substring begin end))
+ (escaped-data (url-hexify-string data))
+ (escaped-playpen-url (url-hexify-string (format
rust-playpen-url-format escaped-data))))
+ (if (> (length escaped-playpen-url) 5000)
+ (error "encoded playpen data exceeds 5000 character limit (length %s)"
+ (length escaped-playpen-url))
+ (let ((shortener-url (format rust-shortener-url-format
escaped-playpen-url))
+ (url-request-method "POST"))
+ (url-retrieve shortener-url
+ (lambda (state)
+ ; filter out the headers etc. included at the
+ ; start of the buffer: the relevant text
+ ; (shortened url or error message) is exactly
+ ; the last line.
+ (end-of-buffer)
+ (let ((last-line (thing-at-point 'line t))
+ (err (plist-get state :error)))
+ (kill-buffer)
+ (if err
+ (error "failed to shorten playpen url: %s"
last-line)
+ (message "%s" last-line)))))))))
+
+(defun rust-playpen-buffer ()
+ "Create a sharable URL for the contents of the current buffer
+ on the Rust playpen."
+ (interactive)
+ (rust-playpen-region (point-min) (point-max)))
+
(provide 'rust-mode)
;;; rust-mode.el ends here
- [nongnu] elpa/rust-mode 4659aee 098/486: rollup merge of #19913: KOMON/rust-mode-emacs-indentation, (continued)
- [nongnu] elpa/rust-mode 4659aee 098/486: rollup merge of #19913: KOMON/rust-mode-emacs-indentation, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode e6e16cc 102/486: Add test for closing braces in character literals, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 66438d4 108/486: Merge pull request #2 from MicahChalmer/fix-quotes-with-syntax-properties, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode f0d4c25 109/486: Fix aligning of method chains (more-or-less) and add various unit tests., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode fd92bfd 111/486: Merge pull request #17 from ramnes/master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 149cfdd 106/486: Merge pull request #20 from pnkfelix/fix-broken-tests, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 81d0680 118/486: Fix ERT section of README, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 2038365 120/486: Fix bug in rust-indent-method-chains, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode fea20e7 131/486: Include the last character in indentation tests, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 2e7c6dc 128/486: Add test for raw string with inner quote and hash, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode eaa332e 143/486: Add rust-playpen-buffer and rust-playpen-region for sharing code.,
ELPA Syncer <=
- [nongnu] elpa/rust-mode 054a11c 157/486: Update rust-mode URL in header, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 5d0fce5 149/486: Fix word and symbol syntax distinction, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode cb5781d 142/486: Merge pull request #46 from MicahChalmer/fix-fill-region, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 1be7a94 154/486: Merge pull request #57 from pnkfelix/regression-test-for-arrow-openbrace, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 493cc99 148/486: Merge pull request #52 from GBGamer/fix-indent, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode ded5ef7 155/486: Pass explicit second argument to looking-back, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 6d5b02e 153/486: Merge pull request #56 from pnkfelix/pr=fix-word-syntax, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 96f7f79 156/486: Fix free-variable warnings, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 8eb6029 165/486: handle case where blink-matching-paren-distance is nil, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 3798c7e 167/486: fix quoting in two doc strings, ELPA Syncer, 2021/08/07