aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Tromey2017-08-23 16:06:48 -0600
committerTom Tromey2017-08-23 16:06:48 -0600
commitad3cd227aa915ac1e671c27aa642da49bac5c463 (patch)
treea9d41df74d4420745cf4bf2db6c1b7de510368e0
parent9538ba6a0f7b906fed3bb7d10b9b98244469047b (diff)
downloademacs-ad3cd227aa915ac1e671c27aa642da49bac5c463.tar.gz
emacs-ad3cd227aa915ac1e671c27aa642da49bac5c463.zip
Add conf-toml-mode
* etc/NEWS: Mention conf-toml-mode. * lisp/files.el (auto-mode-alist): Add entry for .toml. * lisp/textmodes/conf-mode.el (conf-toml-mode-syntax-table) (conf-toml-font-lock-keywords): New defvars. (conf-toml-mode): New mode.
-rw-r--r--etc/NEWS3
-rw-r--r--lisp/files.el1
-rw-r--r--lisp/textmodes/conf-mode.el34
3 files changed, 38 insertions, 0 deletions
diff --git a/etc/NEWS b/etc/NEWS
index 09390333ae6..a9e2f5ae3f1 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1115,6 +1115,9 @@ processes on exit.
1115mode for *.html files. This mode handles indentation, 1115mode for *.html files. This mode handles indentation,
1116fontification, and commenting for embedded JavaScript and CSS. 1116fontification, and commenting for embedded JavaScript and CSS.
1117 1117
1118** New mode 'conf-toml-mode' is a sub-mode of conf-mode, specialized
1119 for editing TOML files.
1120
1118** New minor mode 'pixel-scroll-mode' provides smooth pixel-level scrolling. 1121** New minor mode 'pixel-scroll-mode' provides smooth pixel-level scrolling.
1119 1122
1120** New major mode 'less-css-mode' (a minor variant of 'css-mode') for 1123** New major mode 'less-css-mode' (a minor variant of 'css-mode') for
diff --git a/lisp/files.el b/lisp/files.el
index 0311cc6d210..bc347c1d7df 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -2653,6 +2653,7 @@ ARC\\|ZIP\\|LZH\\|LHA\\|ZOO\\|[JEW]AR\\|XPI\\|RAR\\|CBR\\|7Z\\)\\'" . archive-mo
2653 ("\\.ppd\\'" . conf-ppd-mode) 2653 ("\\.ppd\\'" . conf-ppd-mode)
2654 ("java.+\\.conf\\'" . conf-javaprop-mode) 2654 ("java.+\\.conf\\'" . conf-javaprop-mode)
2655 ("\\.properties\\(?:\\.[a-zA-Z0-9._-]+\\)?\\'" . conf-javaprop-mode) 2655 ("\\.properties\\(?:\\.[a-zA-Z0-9._-]+\\)?\\'" . conf-javaprop-mode)
2656 ("\\.toml\\'" . conf-toml-mode)
2656 ("\\`/etc/\\(?:DIR_COLORS\\|ethers\\|.?fstab\\|.*hosts\\|lesskey\\|login\\.?de\\(?:fs\\|vperm\\)\\|magic\\|mtab\\|pam\\.d/.*\\|permissions\\(?:\\.d/.+\\)?\\|protocols\\|rpc\\|services\\)\\'" . conf-space-mode) 2657 ("\\`/etc/\\(?:DIR_COLORS\\|ethers\\|.?fstab\\|.*hosts\\|lesskey\\|login\\.?de\\(?:fs\\|vperm\\)\\|magic\\|mtab\\|pam\\.d/.*\\|permissions\\(?:\\.d/.+\\)?\\|protocols\\|rpc\\|services\\)\\'" . conf-space-mode)
2657 ("\\`/etc/\\(?:acpid?/.+\\|aliases\\(?:\\.d/.+\\)?\\|default/.+\\|group-?\\|hosts\\..+\\|inittab\\|ksysguarddrc\\|opera6rc\\|passwd-?\\|shadow-?\\|sysconfig/.+\\)\\'" . conf-mode) 2658 ("\\`/etc/\\(?:acpid?/.+\\|aliases\\(?:\\.d/.+\\)?\\|default/.+\\|group-?\\|hosts\\..+\\|inittab\\|ksysguarddrc\\|opera6rc\\|passwd-?\\|shadow-?\\|sysconfig/.+\\)\\'" . conf-mode)
2658 ;; ChangeLog.old etc. Other change-log-mode entries are above; 2659 ;; ChangeLog.old etc. Other change-log-mode entries are above;
diff --git a/lisp/textmodes/conf-mode.el b/lisp/textmodes/conf-mode.el
index 054d8dbb8b2..7bcc69572d2 100644
--- a/lisp/textmodes/conf-mode.el
+++ b/lisp/textmodes/conf-mode.el
@@ -175,6 +175,16 @@ not align (only setting space according to `conf-assignment-space')."
175 table) 175 table)
176 "Syntax table in use in Xdefaults style `conf-mode' buffers.") 176 "Syntax table in use in Xdefaults style `conf-mode' buffers.")
177 177
178(defvar conf-toml-mode-syntax-table
179 (let ((table (make-syntax-table conf-mode-syntax-table)))
180 (modify-syntax-entry ?\" "\"" table)
181 (modify-syntax-entry ?' "\"" table)
182 (modify-syntax-entry ?\\ "\\" table)
183 (modify-syntax-entry ?# "<" table)
184 ;; override
185 (modify-syntax-entry ?\; "." table)
186 table)
187 "Syntax table in use in TOML style `conf-mode' buffers.")
178 188
179(defvar conf-font-lock-keywords 189(defvar conf-font-lock-keywords
180 '(;; [section] (do this first because it may look like a parameter) 190 '(;; [section] (do this first because it may look like a parameter)
@@ -242,6 +252,16 @@ This variable is best set in the file local variables, or through
242 ("^[ \t]*\\([^:\n]+\\)[ \t\n]*{[^{}]*?$" 1 'font-lock-type-face prepend)) 252 ("^[ \t]*\\([^:\n]+\\)[ \t\n]*{[^{}]*?$" 1 'font-lock-type-face prepend))
243 "Keywords to highlight in Conf Colon mode.") 253 "Keywords to highlight in Conf Colon mode.")
244 254
255(defvar conf-toml-font-lock-keywords
256 '(;; [section] (do this first because it may look like a parameter)
257 ("^[ \t]*\\[\\(.+\\)\\]" 1 'font-lock-type-face)
258 ;; var=val or var[index]=val
259 ("^[ \t]*\\(.+?\\)\\(?:\\[\\(.*?\\)\\]\\)?[ \t]*="
260 (1 'font-lock-variable-name-face)
261 (2 'font-lock-constant-face nil t))
262 ("\\_<false\\|true\\_>" 0 'font-lock-keyword-face))
263 "Keywords to highlight in Conf TOML mode.")
264
245(defvar conf-assignment-sign ?= 265(defvar conf-assignment-sign ?=
246 "Sign used for assignments (char or string).") 266 "Sign used for assignments (char or string).")
247 267
@@ -617,6 +637,20 @@ For details see `conf-mode'. Example:
617*foreground: black" 637*foreground: black"
618 (conf-mode-initialize "!")) 638 (conf-mode-initialize "!"))
619 639
640;;;###autoload
641(define-derived-mode conf-toml-mode conf-mode "Conf[TOML]"
642 "Conf Mode starter for TOML files.
643Comments start with `#' and \"assignments\" are with `='.
644For details see `conf-mode'. Example:
645
646# Conf mode font-locks this right with \\[conf-toml-mode]
647
648\[entry]
649value = \"some string\""
650 (conf-mode-initialize "#" 'conf-toml-font-lock-keywords)
651 (setq-local conf-assignment-column 0)
652 (setq-local conf-assignment-sign ?=))
653
620(provide 'conf-mode) 654(provide 'conf-mode)
621 655
622;;; conf-mode.el ends here 656;;; conf-mode.el ends here