diff options
| -rw-r--r-- | rust-mode-tests.el | 23 | ||||
| -rw-r--r-- | rust-mode.el | 15 |
2 files changed, 37 insertions, 1 deletions
diff --git a/rust-mode-tests.el b/rust-mode-tests.el index cbfde96..e7a0429 100644 --- a/rust-mode-tests.el +++ b/rust-mode-tests.el @@ -2427,6 +2427,29 @@ Fontification needs to include this whole string or none of it. (should (<= font-lock-beg 1)) (should (>= font-lock-end 12))))) +(ert-deftest redo-syntax-after-change-far-from-point () + (let* + ((tmp-file-name (make-temp-file "rust-mdoe-test-issue104")) + (base-contents (apply 'concat (append '("fn foo() {\n\n}\n") (make-list 500 "// More stuff...\n") '("fn bar() {\n\n}\n"))))) + ;; Create the temp file... + (with-temp-file tmp-file-name + (insert base-contents)) + (with-temp-buffer + (insert-file-contents tmp-file-name 'VISIT nil nil 'REPLACE) + (rust-mode) + (goto-char (point-max)) + (should (= 0 (rust-paren-level))) + (with-temp-file tmp-file-name + (insert base-contents) + (goto-char 12) ;; On the blank line in the middle of fn foo + (insert " let z = 1 < 3;") + ) + (revert-buffer 'IGNORE-AUTO 'NOCONFIRM 'PRESERVE-MODES) + (should (= 0 (rust-paren-level))) + ) + ) + ) + ;; 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) diff --git a/rust-mode.el b/rust-mode.el index 1d39a54..a2c81f7 100644 --- a/rust-mode.el +++ b/rust-mode.el @@ -1229,7 +1229,9 @@ This is written mainly to be used as `end-of-defun-function' for Rust." (setq-local beginning-of-defun-function 'rust-beginning-of-defun) (setq-local end-of-defun-function 'rust-end-of-defun) (setq-local parse-sexp-lookup-properties t) - (setq-local electric-pair-inhibit-predicate 'rust-electric-pair-inhibit-predicate-wrap)) + (setq-local electric-pair-inhibit-predicate 'rust-electric-pair-inhibit-predicate-wrap) + (add-hook 'after-revert-hook 'rust--after-revert-hook 'LOCAL) + ) ;;;###autoload (add-to-list 'auto-mode-alist '("\\.rs\\'" . rust-mode)) @@ -1240,6 +1242,17 @@ This is written mainly to be used as `end-of-defun-function' for Rust." (require 'rust-mode) (rust-mode)) +;; Issue #104: When reverting the buffer, make sure all fontification is redone +;; so that we don't end up missing a non-angle-bracket '<' or '>' character. +(defun rust--after-revert-hook () + (let + ;; Newer emacs versions (25 and later) make `font-lock-fontify-buffer' + ;; interactive-only, and want lisp code to call `font-lock-flush' or + ;; `font-lock-ensure'. But those don't exist in emacs 24 and earlier. + ((font-lock-ensure-fn (if (fboundp 'font-lock-ensure) 'font-lock-ensure 'font-lock-fontify-buffer))) + (funcall font-lock-ensure-fn)) + ) + ;; Issue #6887: Rather than inheriting the 'gnu compilation error ;; regexp (which is broken on a few edge cases), add our own 'rust ;; compilation error regexp and use it instead. |
