elisp/ini-mode.el
Jeremy Baxter 226cf35571 ini-mode.el: add reference font-locking
Highlight ${var}, {var} and %var% constructs.
2024-07-23 10:29:08 +12:00

57 lines
1.8 KiB
EmacsLisp

;;; ini-mode.el --- major mode for INI -*- lexical-binding:t -*-
;; Copyright (C) 2024 Jeremy Baxter
;; Author: Jeremy Baxter <jeremy@baxters.nz>
;; Maintainer: Jeremy Baxter <jeremy@baxters.nz>
;; Created: July 2024
;; Keywords: ini
;; This file is not part of GNU Emacs.
;; ini-mode.el is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; ini-mode.el is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with ini-mode.el. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; ini-mode.el provides `ini-mode', an implementation of a simple
;; font-locking major mode for INI.
;;; Code:
(require 'font-lock)
(defvar ini-mode-font-lock-keywords
'(("\\([#;].*$\\)" . font-lock-comment-face)
("\\[\\(.+\\)\\]" 1 'font-lock-type-face)
("\\(^.+\\)=" 1 'font-lock-variable-name-face)
("=\\(.+$\\)" 1 'font-lock-string-face)
("\\(\\$?{\\)\\(.+\\)\\(}\\)"
(1 'font-lock-bracket-face t)
(2 'font-lock-variable-use-face t)
(3 'font-lock-bracket-face t))
("\\(%\\)\\(.+\\)\\(%\\)"
(1 'font-lock-bracket-face t)
(2 'font-lock-variable-use-face t)
(3 'font-lock-bracket-face t)))
"Keywords for font locking in `ini-mode'.")
(define-derived-mode ini-mode nil "INI"
"Major mode for editing INI."
(font-lock-mode)
(font-lock-add-keywords nil ini-mode-font-lock-keywords))
(provide 'ini-mode)
;;; ini-mode.el ends here