[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/rust-mode 42730b1 144/486: Merge pull request #49 from huo
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/rust-mode 42730b1 144/486: Merge pull request #49 from huonw/playpen |
Date: |
Sat, 7 Aug 2021 09:25:07 -0400 (EDT) |
branch: elpa/rust-mode
commit 42730b1bdc5947ad2d5f50505221f1aadd84d792
Merge: cb5781d eaa332e
Author: Niko Matsakis <niko@alum.mit.edu>
Commit: Niko Matsakis <niko@alum.mit.edu>
Merge pull request #49 from huonw/playpen
Add rust-playpen-buffer and rust-playpen-region for sharing code.
---
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 0e58eb3 076/486: emacs: Add 'box' to keywords, (continued)
- [nongnu] elpa/rust-mode 0e58eb3 076/486: emacs: Add 'box' to keywords, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 226102c 086/486: emacs: Add shebang to test script, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 186583d 096/486: Mark _ as a word constituent to avoid highlighting parts of identifiers as keywords, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 04e4b49 103/486: Add .travis.yml, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode ec81a95 114/486: Merge pull request #22 from nikomatsakis/align-method-chain, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 351cc91 112/486: Merge pull request #16 from MicahChalmer/add-travis, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode b3f87b9 122/486: Make the test driver script a little more informative., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 19bc0e9 121/486: Merge pull request #30 from MicahChalmer/emacs23-fixup, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode bddc933 124/486: Fix typo in comment, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 97f6445 132/486: Merge pull request #38 from MicahChalmer/fix-issue-36, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 42730b1 144/486: Merge pull request #49 from huonw/playpen,
ELPA Syncer <=
- [nongnu] elpa/rust-mode 249e3ce 134/486: Merge pull request #40 from MicahChalmer/fix-comment-typos, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 31ceb60 135/486: Indent inside strings after ending backslash, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 22c8cfa 138/486: Merge pull request #43 from MicahChalmer/indent-backslash-strings, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode ce976b9 145/486: Fix "-> Type" on a single line indentation, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode f2f4d67 158/486: Merge pull request #59 from lunaryorn/fix-byte-compiler-warnings, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode ddf45ed 146/486: Use (goto-char (point-max)) instead of (end-of-buffer) to silence warning., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 0077bbf 160/486: Fix package.el URL, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 86db9bd 166/486: Merge pull request #65 from tromey/blink-matching-paren, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 53c558c 175/486: Factor out rust-conditional-re-search-forward, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 5231709 177/486: Speed up calls to "looking-back", ELPA Syncer, 2021/08/07