emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Improvement for conf-mode


From: Vinicius Latorre
Subject: Improvement for conf-mode
Date: Sat, 4 Jul 2020 21:17:22 -0300

Hi,

Below is an improvement for conf-mode to deal with libconfig files.

Maybe this code could be added to the conf-mode.

Best regards,

Vinicius


=================================================================
;;; conf-config-mode.el --- Simple major mode for editing libconfig files  -*- lexical-binding: t; -*-

;; Copyright (C) 2020 Vinicius José Latorre

;; Author: Vinicius José Latorre <viniciusjl.gnu@gmail.com>
;; Keywords: libconfig

;; This file is NOT part of GNU Emacs.

;; GNU Emacs 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.

;; GNU Emacs 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 GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:
;;
;; This mode is designed to edit libconfig files.
;; It derives from Daniel Pfeiffer's conf-mode (conf-toml-*).
;;
;; Follow the link below to see the libconfig documentation:
;; https://hyperrealm.github.io/libconfig/
;;
;; Libconfig is a simple library for processing structured configuration files.
;; This file format is more compact and more readable than XML. And unlike XML,
;; it is type-aware, so it is not necessary to do string parsing in application
;; code.
;;
;; Libconfig is very compact – a fraction of the size of the expat XML parser
;; library.  This makes it well-suited for memory-constrained systems like
;; handheld devices.
;;
;; The library includes bindings for both the C and C++ languages.  It works on
;; POSIX-compliant UNIX and UNIX-like systems (GNU/Linux, Mac OS X, FreeBSD),
;; Android, and Windows (2000, XP and later).

;;; Code:

(require 'conf-mode)


(defvar conf-config-mode-syntax-table
  (let ((table (make-syntax-table conf-mode-syntax-table)))
    ;; string: " \t "
    (modify-syntax-entry ?\" "\"" table)
    (modify-syntax-entry ?\\ "\\" table)
    ;; script comment: # \n
    (modify-syntax-entry ?#  "<"  table)
    ;; C++ comment style: /* */, // \n
    (modify-syntax-entry ?/  ". 124" table)
    (modify-syntax-entry ?*  ". 23b" table)
    ;; override
    (modify-syntax-entry ?\; "." table)
    (modify-syntax-entry ?'  "." table)
    table)
  "Syntax table in use in CONFIG style `conf-mode' buffers.")


(defvar conf-config-font-lock-keywords
  '(;; setting: name = value, name : value
    ("\\_<\\([*A-Za-z][*A-Za-z0-9_-]*\\)\\_>\\s-*[=:]"
     (1 'font-lock-variable-name-face nil t))
    ;; directive: @include "path"
    ("@include\\_>" 0 'font-lock-preprocessor-face)
    ;; optional: ;
    (";" 0 'font-lock-builtin-face)
    ;; array: [ ], list: ( ), group: { }
    ("[][(){}]" 0 'font-lock-regexp-grouping-construct)
    ;; boolean values: true, false
    ("\\_<false\\|true\\_>" 0 'font-lock-keyword-face))
  "Keywords to highlight in Conf CONFIG mode.")


;;;###autoload
(define-derived-mode conf-config-mode conf-mode "Conf[CONFIG]"
  "Conf Mode starter for CONFIG files.
Comments start with `#' and \"assignments\" are with `=' or `:'.
For details see `conf-mode'.  Example:

# Conf mode font-locks this right with \\[conf-config-mode]

value = \"some string\";
value : \"string\";"
  (conf-mode-initialize "#" 'conf-config-font-lock-keywords)
  (setq-local conf-assignment-column 0)
  (setq-local conf-assignment-sign ?=))


(provide 'conf-config-mode)


;;; conf-config-mode.el ends here

reply via email to

[Prev in Thread] Current Thread [Next in Thread]