summaryrefslogtreecommitdiff
path: root/lisp/textmodes/conf-mode.el
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2017-08-26 16:23:34 -0600
committerTom Tromey <tom@tromey.com>2017-08-26 20:36:51 -0600
commit1be689fbc4df1ca9883f5bdeb5dd3ccc00eae3aa (patch)
tree14e9b026b9da861b23494ac9fd5a76f6ac956b04 /lisp/textmodes/conf-mode.el
parente8001d4c27e1e33c83b9994aac4d5fc3feada2da (diff)
downloademacs-1be689fbc4df1ca9883f5bdeb5dd3ccc00eae3aa.tar.gz
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.
Diffstat (limited to 'lisp/textmodes/conf-mode.el')
-rw-r--r--lisp/textmodes/conf-mode.el30
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
(defvar conf-toml-font-lock-keywords
'(;; [section] (do this first because it may look like a parameter)
- ("^[ \t]*\\[\\(.+\\)\\]" 1 'font-lock-type-face)
+ (conf-toml-recognize-section 0 'font-lock-type-face prepend)
;; var=val or var[index]=val
- ("^[ \t]*\\(.+?\\)\\(?:\\[\\(.*?\\)\\]\\)?[ \t]*="
+ ("^\\s-*\\(.+?\\)\\(?:\\[\\(.*?\\)\\]\\)?\\s-*="
(1 'font-lock-variable-name-face)
(2 'font-lock-constant-face nil t))
("\\_<false\\|true\\_>" 0 'font-lock-keyword-face))
@@ -637,6 +637,32 @@ For details see `conf-mode'. Example:
*foreground: black"
(conf-mode-initialize "!"))
+(defun conf-toml-recognize-section (limit)
+ "Font-lock helper function for conf-toml-mode.
+Handles recognizing TOML section names, like [section],
+\[[section]], or [something.\"else\".section]."
+ (save-excursion
+ ;; Skip any number of "[" to handle things like [[section]].
+ (when (re-search-forward "^\\s-*\\[+" limit t)
+ (let ((start (point)))
+ (backward-char)
+ (let ((end (min limit
+ (condition-case nil
+ (progn
+ (forward-list)
+ (1- (point)))
+ (scan-error
+ (end-of-line)
+ (point))))))
+ ;; If there is a comma in the text, then we assume this is
+ ;; an array and not a section. (This could be refined to
+ ;; look only for unquoted commas if necessary.)
+ (save-excursion
+ (goto-char start)
+ (unless (search-forward "," end t)
+ (set-match-data (list start end))
+ t)))))))
+
;;;###autoload
(define-derived-mode conf-toml-mode conf-mode "Conf[TOML]"
"Conf Mode starter for TOML files.