From: Stefan Kangas Date: Tue, 1 Aug 2023 10:18:12 +0000 (+0200) Subject: Fix font locking of booleans in conf-toml-mode X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=742104abd7b0b9c417e4bbf3fcda684595375c27;p=emacs.git Fix font locking of booleans in conf-toml-mode * lisp/textmodes/conf-mode.el (conf-toml-mode): Do not use case folding when font locking. * test/lisp/textmodes/conf-mode-tests.el (conf-test-toml-mode): Expand test. --- diff --git a/lisp/textmodes/conf-mode.el b/lisp/textmodes/conf-mode.el index d15fba9c43a..ff41dcdf000 100644 --- a/lisp/textmodes/conf-mode.el +++ b/lisp/textmodes/conf-mode.el @@ -245,6 +245,7 @@ This variable is best set in the file local variables, or through ("^\\s-*\\(.+?\\)\\(?:\\[\\(.*?\\)\\]\\)?\\s-*=" (1 'font-lock-variable-name-face) (2 'font-lock-constant-face nil t)) + ;; Must be lower-case according to the TOML spec. ("\\_" 0 'font-lock-keyword-face)) "Keywords to highlight in Conf TOML mode.") @@ -643,7 +644,10 @@ For details see `conf-mode'. Example: \[entry] value = \"some string\"" - (conf-mode-initialize "#" 'conf-toml-font-lock-keywords) + (conf-mode-initialize "#") + ;; Booleans are "always lowercase", so we must *not* use case + ;; folding. Therefore, we can't set it using `conf-mode-initialize´. + (setq-local font-lock-defaults `(,conf-toml-font-lock-keywords nil nil nil nil)) (setq-local conf-assignment-column 0) (setq-local conf-assignment-sign ?=)) diff --git a/test/lisp/textmodes/conf-mode-tests.el b/test/lisp/textmodes/conf-mode-tests.el index 1f6d9b6b587..677a6d35d66 100644 --- a/test/lisp/textmodes/conf-mode-tests.el +++ b/test/lisp/textmodes/conf-mode-tests.el @@ -158,7 +158,6 @@ image/tiff tiff tif (should-not (face-at-point)))) (ert-deftest conf-test-toml-mode () - ;; From `conf-toml-mode' docstring. (with-temp-buffer (insert "[entry] value = \"some string\"") @@ -174,6 +173,22 @@ value = \"some string\"") (search-forward "som") (should (equal (face-at-point) 'font-lock-string-face)))) +(ert-deftest conf-test-toml-mode/boolean () + ;; https://toml.io/en/v1.0.0#boolean + (with-temp-buffer + (insert "[entry] +a = true +b = True") + (goto-char (point-min)) + (conf-toml-mode) + (font-lock-mode) + (font-lock-ensure) + (search-forward "tru") + (should (equal (face-at-point) 'font-lock-keyword-face)) + ;; Do not fontify upper-case "True". + (search-forward "Tru") + (should (equal (face-at-point) nil)))) + (ert-deftest conf-test-desktop-mode () ;; From `conf-desktop-mode' dostring. (with-temp-buffer