dotemacs

My Emacs configuration
git clone git://git.entf.net/dotemacs
Log | Files | Refs | LICENSE

editorconfig-conf-mode.el (3190B)


      1 ;;; editorconfig-conf-mode.el --- Major mode for editing .editorconfig files  -*- lexical-binding: t -*-
      2 
      3 ;; Copyright (C) 2011-2023 EditorConfig Team
      4 
      5 ;; Author: EditorConfig Team <editorconfig@googlegroups.com>
      6 
      7 ;; See
      8 ;; https://github.com/editorconfig/editorconfig-emacs/graphs/contributors
      9 ;; or the CONTRIBUTORS file for the list of contributors.
     10 
     11 ;; This file is part of EditorConfig Emacs Plugin.
     12 
     13 ;; EditorConfig Emacs Plugin is free software: you can redistribute it and/or
     14 ;; modify it under the terms of the GNU General Public License as published by
     15 ;; the Free Software Foundation, either version 3 of the License, or (at your
     16 ;; option) any later version.
     17 
     18 ;; EditorConfig Emacs Plugin is distributed in the hope that it will be useful,
     19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
     20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
     21 ;; Public License for more details.
     22 
     23 ;; You should have received a copy of the GNU General Public License along with
     24 ;; EditorConfig Emacs Plugin. If not, see <https://www.gnu.org/licenses/>.
     25 
     26 ;;; Commentary:
     27 
     28 ;; Major mode for editing .editorconfig files.
     29 
     30 ;;; Code:
     31 
     32 (require 'conf-mode)
     33 
     34 (defvar editorconfig-conf-mode-syntax-table
     35   (let ((table (make-syntax-table conf-unix-mode-syntax-table)))
     36     (modify-syntax-entry ?\; "<" table)
     37     table)
     38   "Syntax table in use in `editorconfig-conf-mode' buffers.")
     39 
     40 (defvar editorconfig-conf-mode-abbrev-table nil
     41   "Abbrev table in use in `editorconfig-conf-mode' buffers.")
     42 (define-abbrev-table 'editorconfig-conf-mode-abbrev-table ())
     43 
     44 ;;;###autoload
     45 (define-derived-mode editorconfig-conf-mode conf-unix-mode "Conf[EditorConfig]"
     46   "Major mode for editing .editorconfig files."
     47   (set-variable 'indent-line-function 'indent-relative)
     48   (let ((key-property-list
     49          '("charset"
     50            "end_of_line"
     51            "file_type_emacs"
     52            "file_type_ext"
     53            "indent_size"
     54            "indent_style"
     55            "insert_final_newline"
     56            "max_line_length"
     57            "root"
     58            "tab_width"
     59            "trim_trailing_whitespace"))
     60         (key-value-list
     61          '("unset"
     62            "true"
     63            "false"
     64            "lf"
     65            "cr"
     66            "crlf"
     67            "space"
     68            "tab"
     69            "latin1"
     70            "utf-8"
     71            "utf-8-bom"
     72            "utf-16be"
     73            "utf-16le"))
     74         (font-lock-value
     75          '(("^[ \t]*\\[\\(.+?\\)\\]" 1 font-lock-type-face)
     76            ("^[ \t]*\\(.+?\\)[ \t]*[=:]" 1 font-lock-variable-name-face))))
     77 
     78     ;; Highlight all key values
     79     (dolist (key-value key-value-list)
     80       (push `(,(format "[=:][ \t]*\\(%s\\)\\([ \t]\\|$\\)" key-value)
     81               1 font-lock-constant-face)
     82             font-lock-value))
     83     ;; Highlight all key properties
     84     (dolist (key-property key-property-list)
     85       (push `(,(format "^[ \t]*\\(%s\\)[ \t]*[=:]" key-property)
     86               1 font-lock-builtin-face)
     87             font-lock-value))
     88 
     89     (conf-mode-initialize "#" font-lock-value)))
     90 
     91 ;;;###autoload
     92 (add-to-list 'auto-mode-alist '("\\.editorconfig\\'" . editorconfig-conf-mode))
     93 
     94 (provide 'editorconfig-conf-mode)
     95 ;;; editorconfig-conf-mode.el ends here