diff options
| author | Tom Tromey | 2017-08-26 16:23:34 -0600 |
|---|---|---|
| committer | Tom Tromey | 2017-08-26 20:36:51 -0600 |
| commit | 1be689fbc4df1ca9883f5bdeb5dd3ccc00eae3aa (patch) | |
| tree | 14e9b026b9da861b23494ac9fd5a76f6ac956b04 | |
| parent | e8001d4c27e1e33c83b9994aac4d5fc3feada2da (diff) | |
| download | emacs-1be689fbc4df1ca9883f5bdeb5dd3ccc00eae3aa.tar.gz emacs-1be689fbc4df1ca9883f5bdeb5dd3ccc00eae3aa.zip | |
Refine conf-toml-mode font-lock
Bug#28218
* lisp/textmodes/conf-mode.el (conf-toml-font-lock-keywords): Use
conf-toml-recognize-section. Use \s- in variable regexp.
(conf-toml-recognize-section): New function.
| -rw-r--r-- | lisp/textmodes/conf-mode.el | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/lisp/textmodes/conf-mode.el b/lisp/textmodes/conf-mode.el index 7bcc69572d2..b420aaa2467 100644 --- a/lisp/textmodes/conf-mode.el +++ b/lisp/textmodes/conf-mode.el | |||
| @@ -254,9 +254,9 @@ This variable is best set in the file local variables, or through | |||
| 254 | 254 | ||
| 255 | (defvar conf-toml-font-lock-keywords | 255 | (defvar conf-toml-font-lock-keywords |
| 256 | '(;; [section] (do this first because it may look like a parameter) | 256 | '(;; [section] (do this first because it may look like a parameter) |
| 257 | ("^[ \t]*\\[\\(.+\\)\\]" 1 'font-lock-type-face) | 257 | (conf-toml-recognize-section 0 'font-lock-type-face prepend) |
| 258 | ;; var=val or var[index]=val | 258 | ;; var=val or var[index]=val |
| 259 | ("^[ \t]*\\(.+?\\)\\(?:\\[\\(.*?\\)\\]\\)?[ \t]*=" | 259 | ("^\\s-*\\(.+?\\)\\(?:\\[\\(.*?\\)\\]\\)?\\s-*=" |
| 260 | (1 'font-lock-variable-name-face) | 260 | (1 'font-lock-variable-name-face) |
| 261 | (2 'font-lock-constant-face nil t)) | 261 | (2 'font-lock-constant-face nil t)) |
| 262 | ("\\_<false\\|true\\_>" 0 'font-lock-keyword-face)) | 262 | ("\\_<false\\|true\\_>" 0 'font-lock-keyword-face)) |
| @@ -637,6 +637,32 @@ For details see `conf-mode'. Example: | |||
| 637 | *foreground: black" | 637 | *foreground: black" |
| 638 | (conf-mode-initialize "!")) | 638 | (conf-mode-initialize "!")) |
| 639 | 639 | ||
| 640 | (defun conf-toml-recognize-section (limit) | ||
| 641 | "Font-lock helper function for conf-toml-mode. | ||
| 642 | Handles recognizing TOML section names, like [section], | ||
| 643 | \[[section]], or [something.\"else\".section]." | ||
| 644 | (save-excursion | ||
| 645 | ;; Skip any number of "[" to handle things like [[section]]. | ||
| 646 | (when (re-search-forward "^\\s-*\\[+" limit t) | ||
| 647 | (let ((start (point))) | ||
| 648 | (backward-char) | ||
| 649 | (let ((end (min limit | ||
| 650 | (condition-case nil | ||
| 651 | (progn | ||
| 652 | (forward-list) | ||
| 653 | (1- (point))) | ||
| 654 | (scan-error | ||
| 655 | (end-of-line) | ||
| 656 | (point)))))) | ||
| 657 | ;; If there is a comma in the text, then we assume this is | ||
| 658 | ;; an array and not a section. (This could be refined to | ||
| 659 | ;; look only for unquoted commas if necessary.) | ||
| 660 | (save-excursion | ||
| 661 | (goto-char start) | ||
| 662 | (unless (search-forward "," end t) | ||
| 663 | (set-match-data (list start end)) | ||
| 664 | t))))))) | ||
| 665 | |||
| 640 | ;;;###autoload | 666 | ;;;###autoload |
| 641 | (define-derived-mode conf-toml-mode conf-mode "Conf[TOML]" | 667 | (define-derived-mode conf-toml-mode conf-mode "Conf[TOML]" |
| 642 | "Conf Mode starter for TOML files. | 668 | "Conf Mode starter for TOML files. |