Commits (17)
elpa-rust-mode (0.3.0-1) unstable; urgency=medium
* New upstream release.
-- Matt Kraai <kraai@debian.org> Tue, 01 Nov 2016 07:17:50 -0700
elpa-rust-mode (0.2.0~git20160721.1.b3b0f78-1) unstable; urgency=medium
* New upstream commits.
......@@ -1162,6 +1162,23 @@ All positions are position symbols found in `rust-test-positions-alist'."
(ert-deftest no-stack-overflow-in-rust-rewind-irrelevant ()
(insert "fn main() {\n let x = 1;")
;; Insert 150 separate comments on the same line
(dotimes (i 150)
(insert "/* foo */ "))
;; Rewinding from the last commment to the end of the let needs at least
;; 150 iterations, but if we limit the stack depth to 100 (this appears to
;; be some minimum), a recursive function would overflow, throwing an
;; error.
(let ((max-lisp-eval-depth 100))
;; Only a non-stack overflowing function would make it this far. Also
;; check that we rewound till after the ;
(should (= (char-before) ?\;)))))
(defun rust-test-fontify-string (str)
......@@ -1582,6 +1599,19 @@ fn main() {
(ert-deftest indent-method-chains-look-over-comment ()
(let ((rust-indent-method-chain t)) (test-indent
fn main() {
// A comment
// Another comment
(ert-deftest indent-method-chains-comment ()
(let ((rust-indent-method-chain t)) (test-indent
......@@ -1610,6 +1640,17 @@ fn main() { // comment here should not push next line out
(ert-deftest indent-method-chains-after-comment2 ()
(let ((rust-indent-method-chain t)) (test-indent
fn main() {
// Lorem ipsum lorem ipsum lorem ipsum lorem.ipsum
(ert-deftest test-for-issue-36-syntax-corrupted-state ()
"This is a test for a issue #36, which involved emacs's
internal state getting corrupted when actions were done in a
......@@ -2561,6 +2602,18 @@ Fontification needs to include this whole string or none of it.
(ert-deftest rust-test-revert-hook-preserves-point ()
;; Insert some code, and put point in the middle.
(insert "fn foo() {}\n")
(insert "fn bar() {}\n")
(insert "fn baz() {}\n")
(goto-char (point-min))
(forward-line 1)
(let ((initial-point (point)))
(should (equal initial-point (point))))))
;; If electric-pair-mode is available, load it and run the tests that use it. If not,
;; no error--the tests will be skipped.
(require 'elec-pair nil t)
;;; rust-mode.el --- A major emacs mode for editing Rust source code -*-lexical-binding: t-*-
;; Version: 0.2.0
;; Version: 0.3.0
;; Author: Mozilla
;; Url: https://github.com/rust-lang/rust-mode
;; Keywords: languages
......@@ -201,14 +201,20 @@ function or trait. When nil, where will be aligned with fn or trait."
(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))))
(defun rust-rewind-irrelevant ()
(let ((starting (point)))
(skip-chars-backward "[:space:]\n")
(if (rust-looking-back-str "*/") (backward-char))
(if (rust-in-str-or-cmnt)
(if (/= starting (point))
(let ((continue t))
(while continue
(let ((starting (point)))
(skip-chars-backward "[:space:]\n")
(when (rust-looking-back-str "*/")
(when (rust-in-str-or-cmnt)
;; Rewind until the point no longer moves
(setq continue (/= starting (point)))))))
(defun rust-in-macro ()
(when (> (rust-paren-level) 0)
......@@ -295,6 +301,17 @@ buffer."
(when (looking-at (concat "\s*\." rust-re-ident))
(forward-line -1)
;; Keep going up (looking for a line that could contain a method chain)
;; while we're in a comment or on a blank line. Stop when the paren
;; level changes.
(let ((level (rust-paren-level)))
(while (and (or (rust-in-str-or-cmnt)
;; Only whitespace (or nothing) from the beginning to
;; the end of the line.
(looking-back "^\s*" (point-at-bol)))
(= (rust-paren-level) level))
(forward-line -1)
;; skip-dot-identifier is used to position the point at the
......@@ -1258,8 +1275,10 @@ This is written mainly to be used as `end-of-defun-function' for Rust."
(insert-buffer-substring buf)
(if (zerop (call-process-region (point-min) (point-max) rust-rustfmt-bin t t nil))
(progn (copy-to-buffer buf (point-min) (point-max))
(if (not (string= (buffer-string) (with-current-buffer buf (buffer-string))))
(copy-to-buffer buf (point-min) (point-max)))
(error "Rustfmt failed, see *rustfmt* buffer for details"))))
(defun rust-format-buffer ()
......@@ -1268,10 +1287,16 @@ This is written mainly to be used as `end-of-defun-function' for Rust."
(unless (executable-find rust-rustfmt-bin)
(error "Could not locate executable \"%s\"" rust-rustfmt-bin))
(let ((cur-point (point))
(let ((cur-line (line-number-at-pos))
(cur-column (current-column))
(cur-win-start (window-start)))
(rust--format-call (current-buffer))
(goto-char cur-point)
;; Move to the same line and column as before. This is best
;; effort: if rustfmt inserted lines before point, we end up in
;; the wrong place. See issue #162.
(goto-char (point-min))
(forward-line (1- cur-line))
(forward-char cur-column)
(set-window-start (selected-window) cur-win-start))
;; Issue #127: Running this on a buffer acts like a revert, and could cause
......@@ -1363,9 +1388,10 @@ This is written mainly to be used as `end-of-defun-function' for Rust."
;; to use `font-lock-ensure', which doesn't exist in Emacs 24 and earlier.
;; If it's not available, fall back to calling `font-lock-fontify-region'
;; on the whole buffer.
(if (fboundp 'font-lock-ensure)
(font-lock-fontify-region (point-min) (point-max))))
(if (fboundp 'font-lock-ensure)
(font-lock-fontify-region (point-min) (point-max)))))
(defun rust--before-save-hook ()
(when rust-format-on-save (rust-format-buffer)))
......@@ -1419,7 +1445,7 @@ See `compilation-error-regexp-alist' for help on their format.")
(let ((start-of-error
(while (not (looking-at "^[a-z]+:"))
(while (not (looking-at "^[a-z]+:\\|^[a-z]+\\[E[0-9]+\\]:"))
(forward-line -1))
(set-window-start (selected-window) start-of-error))))))