deelang/dee-mode.el
2024-11-16 13:44:04 -06:00

54 lines
1.5 KiB
EmacsLisp

;; A major mode for editing scripts written in Deelang
(add-to-list 'auto-mode-alist '("\\.dee\\'" . dee-mode))
(defcustom dee-indent-offset 4
"Default indentation offset for Deelang."
:group 'dee
:type 'integer
:safe 'integerp)
(defvar dee-mode-map
(let ((map (make-sparse-keymap)))
map)
"Keymap for Deelang files")
(defvar dee-mode-syntax-table
(let ((table (make-syntax-table)))
(modify-syntax-entry ?# "<" table)
(modify-syntax-entry ?\n ">" table)
(modify-syntax-entry ?- "w" table)
(modify-syntax-entry ?? "w" table)
table)
"Syntax table for Deelang files")
(defvar dee-font-lock-id-re
(rx (seq alpha (* (any alnum ?- ??)))))
(defvar dee-font-lock-keywords
`(,(rx symbol-start
(or
"if" "elif" "else" "loop" "until" "over" "in" "")
symbol-end)
(,(rx (group (regexp dee-font-lock-id-re)) (* space) "<-")
(1 font-lock-variable-name-face))
(,(rx (group (regexp dee-font-lock-id-re)) (* space) "(")
(1 font-lock-function-name-face))
(,(rx (group (regexp dee-font-lock-id-re)) (* space) "->")
(1 font-lock-constant-face))))
(defun dee-indent-line-function ()
'noindent) ;TODO
(define-derived-mode dee-mode prog-mode "Dee"
"Major mode for editing scripts written in Deelang.
\\{dee-mode-map}"
(set (make-local-variable 'indent-line-function)
#'dee-indent-line-function)
(set (make-local-variable 'font-lock-defaults)
`(,dee-font-lock-keywords
nil nil nil nil)))
(provide 'dee)