|
67 | 67 | :type 'boolean
|
68 | 68 | :group 'rust-mode)
|
69 | 69 |
|
| 70 | +(defcustom rust-playpen-url-format "https://play.rust-lang.org/?code=%s" |
| 71 | + "Format string to use when submitting code to the playpen" |
| 72 | + :type 'string |
| 73 | + :group 'rust-mode) |
| 74 | +(defcustom rust-shortener-url-format "http://is.gd/create.php?format=simple&url=%s" |
| 75 | + "Format string to use for creating the shortened link of a playpen submission" |
| 76 | + :type 'string |
| 77 | + :group 'rust-mode) |
| 78 | + |
70 | 79 | (defun rust-paren-level () (nth 0 (syntax-ppss)))
|
71 | 80 | (defun rust-in-str-or-cmnt () (nth 8 (syntax-ppss)))
|
72 | 81 | (defun rust-rewind-past-str-cmnt () (goto-char (nth 8 (syntax-ppss))))
|
|
115 | 124 | ;; annoying to have to press tab again to align to a method chain
|
116 | 125 | ;; than to have an over-eager indent in all other cases which must
|
117 | 126 | ;; be undone via tab.
|
118 |
| - |
| 127 | + |
119 | 128 | (when (looking-at (concat "\s*\." rust-re-ident))
|
120 | 129 | (forward-line -1)
|
121 | 130 | (end-of-line)
|
|
128 | 137 | ;; ^ ^
|
129 | 138 | ;; | |
|
130 | 139 | ;; | position of point
|
131 |
| - ;; returned offset |
| 140 | + ;; returned offset |
132 | 141 | ;;
|
133 | 142 | ((skip-dot-identifier
|
134 | 143 | (lambda ()
|
|
215 | 224 | (goto-char end-of-prev-line-pos)
|
216 | 225 | (back-to-indentation)
|
217 | 226 | (current-column))))))
|
218 |
| - |
| 227 | + |
219 | 228 | ;; A function return type is indented to the corresponding function arguments
|
220 | 229 | ((looking-at "->")
|
221 | 230 | (save-excursion
|
|
225 | 234 |
|
226 | 235 | ;; A closing brace is 1 level unindended
|
227 | 236 | ((looking-at "}") (- baseline rust-indent-offset))
|
228 |
| - |
| 237 | + |
229 | 238 | ;; Doc comments in /** style with leading * indent to line up the *s
|
230 | 239 | ((and (nth 4 (syntax-ppss)) (looking-at "*"))
|
231 | 240 | (+ 1 baseline))
|
|
364 | 373 | (defun rust-look-for-raw-string (bound)
|
365 | 374 | ;; Find a raw string, but only if it's not in the middle of another string or
|
366 | 375 | ;; a comment
|
367 |
| - |
| 376 | + |
368 | 377 | (let* ((raw-str-regexp
|
369 | 378 | (rx
|
370 | 379 | (seq
|
@@ -745,6 +754,40 @@ See `compilation-error-regexp-alist for help on their format.")
|
745 | 754 | (cons 'rustc rustc-compilation-regexps))
|
746 | 755 | (add-to-list 'compilation-error-regexp-alist 'rustc)))
|
747 | 756 |
|
| 757 | +;;; Functions to submit (parts of) buffers to the rust playpen, for |
| 758 | +;;; sharing. |
| 759 | +(defun rust-playpen-region (begin end) |
| 760 | + "Create a sharable URL for the contents of the current region |
| 761 | + on the Rust playpen." |
| 762 | + (interactive "r") |
| 763 | + (let* ((data (buffer-substring begin end)) |
| 764 | + (escaped-data (url-hexify-string data)) |
| 765 | + (escaped-playpen-url (url-hexify-string (format rust-playpen-url-format escaped-data)))) |
| 766 | + (if (> (length escaped-playpen-url) 5000) |
| 767 | + (error "encoded playpen data exceeds 5000 character limit (length %s)" |
| 768 | + (length escaped-playpen-url)) |
| 769 | + (let ((shortener-url (format rust-shortener-url-format escaped-playpen-url)) |
| 770 | + (url-request-method "POST")) |
| 771 | + (url-retrieve shortener-url |
| 772 | + (lambda (state) |
| 773 | + ; filter out the headers etc. included at the |
| 774 | + ; start of the buffer: the relevant text |
| 775 | + ; (shortened url or error message) is exactly |
| 776 | + ; the last line. |
| 777 | + (end-of-buffer) |
| 778 | + (let ((last-line (thing-at-point 'line t)) |
| 779 | + (err (plist-get state :error))) |
| 780 | + (kill-buffer) |
| 781 | + (if err |
| 782 | + (error "failed to shorten playpen url: %s" last-line) |
| 783 | + (message "%s" last-line))))))))) |
| 784 | + |
| 785 | +(defun rust-playpen-buffer () |
| 786 | + "Create a sharable URL for the contents of the current buffer |
| 787 | + on the Rust playpen." |
| 788 | + (interactive) |
| 789 | + (rust-playpen-region (point-min) (point-max))) |
| 790 | + |
748 | 791 | (provide 'rust-mode)
|
749 | 792 |
|
750 | 793 | ;;; rust-mode.el ends here
|
0 commit comments