-
Notifications
You must be signed in to change notification settings - Fork 1
/
ron-mode.el
86 lines (64 loc) · 2.32 KB
/
ron-mode.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
;;; ron-mode.el --- Rusty Object Notation (RON) mode -*- lexical-binding: t; -*-
;; Copyright (C) 2019 Devin Schwab
;; Author: Devin Schwab <digidevin@gmail.com>
;; URL: TODO
;; Version: 0.1-pre
;; Package-Requires: ((emacs "26.1"))
;; Keywords: rust
;;; Commentary:
;; Provide syntax highlighting for Rusty Object Notation (RON) files
;; See https://github.com/ron-rs/ron for information on the file format
;;
;; These files are used by the Amethyst project:
;; https://www.amethyst.rs/
;;; Code:
;;;; Requirements
;;;; Customization
(defvar ron-mode-indent-offset 4
"Indentation offset for `ron-mode'.")
(defvar ron-mode-hook '())
;;;; Variables
(setq ron-constants '("true" "false"))
(setq ron-keywords '("Some"))
(setq ron-comment-regexp "//.*")
(setq ron-extension-regexp "\\(#[[:space:]]*\\![[:space:]]*\\[[[:space:]]*enable[[:space:]]*\\)(\\([[:alpha:]]\\|[[:digit:]]\\|_\\)+\\(,[[:space:]]*\\([[:alpha:]]\\|[[:digit:]]\\|_\\)+\\)*[[:space:]]*)\\]")
(setq ron-constants-regexp (regexp-opt ron-constants 'words))
(setq ron-keywords-regexp (regexp-opt ron-keywords 'words))
(setq ron-font-lock-keywords
`(
(,ron-extension-regexp (1 font-lock-preprocessor-face))
(,ron-constants-regexp . font-lock-constant-face)
(,ron-keywords-regexp . font-lock-keyword-face)
(,ron-comment-regexp . font-lock-comment-face)))
;;;; Keymaps
;;;; Functions
(defun ron-indent-line ()
"Indent current line for `ron-mode'."
(interactive)
(let ((indent-col 0))
(save-excursion
(beginning-of-line)
(condition-case nil
(while t
(backward-up-list 1)
(when (looking-at "[[{\\(]")
(setq indent-col (+ indent-col ron-mode-indent-offset))))
(error nil)))
(save-excursion
(back-to-indentation)
(when (and (looking-at "[]}\\)]") (>= indent-col ron-mode-indent-offset))
(setq indent-col (- indent-col ron-mode-indent-offset))))
(indent-line-to indent-col)))
;;;; Commands
;;;; Support
;;;; Footer
(define-derived-mode ron-mode prog-mode "ron-mode"
"Major mode for editing RON files"
(setq font-lock-defaults '((ron-font-lock-keywords)))
(setq comment-start "//")
(setq comment-end "")
(setq tab-width ron-mode-indent-offset)
(setq indent-line-function 'ron-indent-line)
(setq indent-tabs-mode nil))
(provide 'ron-mode)
;;; ron-mode.el ends here