unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Improvement for conf-mode
@ 2020-07-05  0:17 Vinicius Latorre
  0 siblings, 0 replies; only message in thread
From: Vinicius Latorre @ 2020-07-05  0:17 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 3822 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 4632 bytes --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-07-05  0:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-05  0:17 Improvement for conf-mode Vinicius Latorre

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).