Skip to content

Commit ee7043b

Browse files
committed
Use syntax-propertize-function, not font-lock-syntactic-keywords
font-lock-syntactic-keywords have been obsolete since Emacs 24.1, the earliest version supported by rust-mode. Instead, modes are encouraged to use syntax-propertize-function. syntax-propertize-function provides a generally better experience. Syntax propertization is not tied to font lock,so angle bracket matching will still work when font-lock is disabled. There's no longer a need to call font-lock-fontify-buffer or font-lock-ensure (you can see this in the tests). The resulting code is also shorter. I removed a few tests: * font-lock-raw-string-constant was written assuming font-lock based syntax propertization, but that's no longer the case. * font-lock-extend-region-in-string and rust-test-revert-hook-preserves-point both called functions that no longer exist. There's a fix for a hidden bug in rust-is-in-expression-context. This previously could signal in some situations, but the signal was hidden by font-lock. It was visible now when running tests, hence the new call to condition-case. I suspect this might fix #192, but I haven't tried it.
1 parent 35298ed commit ee7043b

File tree

2 files changed

+107
-285
lines changed

2 files changed

+107
-285
lines changed

rust-mode-tests.el

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,6 @@ very very very long string
309309
deindented
310310
1
311311
(lambda ()
312-
;; The indentation will fail in some cases if the syntax properties are
313-
;; not set. This only happens when font-lock fontifies the buffer.
314-
(font-lock-fontify-buffer)
315312
(indent-region 1 (+ 1 (buffer-size))))
316313
indented)))
317314

@@ -960,7 +957,6 @@ INIT-POS, FINAL-POS are position symbols found in `rust-test-positions-alist'."
960957
(with-temp-buffer
961958
(rust-mode)
962959
(insert source-code)
963-
(font-lock-fontify-buffer)
964960
(goto-char (rust-get-buffer-pos init-pos))
965961
(apply manip-func args)
966962
(should (equal (point) (rust-get-buffer-pos final-pos)))))
@@ -974,7 +970,6 @@ All positions are position symbols found in `rust-test-positions-alist'."
974970
(with-temp-buffer
975971
(rust-mode)
976972
(insert source-code)
977-
(font-lock-fontify-buffer)
978973
(goto-char (rust-get-buffer-pos init-pos))
979974
(apply manip-func args)
980975
(should (equal (list (region-beginning) (region-end))
@@ -1377,24 +1372,6 @@ this_is_not_a_string();)"
13771372
"r\" this is a comment\n" font-lock-comment-face
13781373
"\"this is a string\"" font-lock-string-face)))
13791374

1380-
(ert-deftest font-lock-raw-string-constant ()
1381-
;; There was an issue in which a multi-line raw string would be fontified
1382-
;; correctly if inserted, but then incorrectly if one of the lines was then
1383-
;; edited. This test replicates how font-lock responds when text in the
1384-
;; buffer is modified in order to reproduce it.
1385-
(with-temp-buffer
1386-
(rust-mode)
1387-
(font-lock-fontify-buffer)
1388-
(insert "const BOO:&str = r#\"\nBOO\"#;")
1389-
(beginning-of-buffer)
1390-
(insert " ")
1391-
(font-lock-after-change-function 1 2 0)
1392-
1393-
(should (equal 'font-lock-string-face (get-text-property 19 'face))) ;; Opening "r" of raw string
1394-
(should (equal 'font-lock-string-face (get-text-property 27 'face))) ;; Closing "#" of raw string
1395-
(should (equal nil (get-text-property 28 'face))) ;; Semicolon--should not be part of the string
1396-
))
1397-
13981375
(ert-deftest font-lock-runaway-raw-string ()
13991376
(rust-test-font-lock
14001377
"const Z = r#\"my raw string\";\n// oops this is still in the string"
@@ -2552,34 +2529,6 @@ type Foo<T> where T: Copy = Box<T>;
25522529
'(7 9))))
25532530

25542531

2555-
(ert-deftest font-lock-extend-region-in-string ()
2556-
2557-
(with-temp-buffer
2558-
(rust-mode)
2559-
(insert "
2560-
fn foo() {
2561-
let x = r\"
2562-
Fontification needs to include this whole string or none of it.
2563-
\"
2564-
}")
2565-
(font-lock-fontify-buffer)
2566-
(let ((font-lock-beg 13)
2567-
(font-lock-end 42))
2568-
(rust-font-lock-extend-region)
2569-
(should (<= font-lock-beg 13))
2570-
(should (>= font-lock-end 106))
2571-
)
2572-
(let ((font-lock-beg 42)
2573-
(font-lock-end 108))
2574-
(rust-font-lock-extend-region)
2575-
(should (<= font-lock-beg 25))
2576-
(should (>= font-lock-end 108)))
2577-
(let ((font-lock-beg 1)
2578-
(font-lock-end 12))
2579-
(rust-font-lock-extend-region)
2580-
(should (<= font-lock-beg 1))
2581-
(should (>= font-lock-end 12)))))
2582-
25832532
(ert-deftest redo-syntax-after-change-far-from-point ()
25842533
(let*
25852534
((tmp-file-name (make-temp-file "rust-mdoe-test-issue104"))
@@ -2603,18 +2552,6 @@ Fontification needs to include this whole string or none of it.
26032552
)
26042553
)
26052554

2606-
(ert-deftest rust-test-revert-hook-preserves-point ()
2607-
(with-temp-buffer
2608-
;; Insert some code, and put point in the middle.
2609-
(insert "fn foo() {}\n")
2610-
(insert "fn bar() {}\n")
2611-
(insert "fn baz() {}\n")
2612-
(goto-char (point-min))
2613-
(forward-line 1)
2614-
(let ((initial-point (point)))
2615-
(rust--after-revert-hook)
2616-
(should (equal initial-point (point))))))
2617-
26182555
(defun test-imenu (code expected-items)
26192556
(with-temp-buffer
26202557
(rust-mode)

0 commit comments

Comments
 (0)