forked from alex-eg/sex
108 lines
3.4 KiB
EmacsLisp
108 lines
3.4 KiB
EmacsLisp
(require 'scheme)
|
|
|
|
(defgroup sex-mode nil
|
|
"Major mode for Sex code."
|
|
:prefix 'sex-
|
|
:group 'languages)
|
|
|
|
(define-abbrev-table 'sex-mode-abbrev-table ()
|
|
"Abbrev table for Sex mode.
|
|
It has `scheme-mode-abbrev-table' as its parent."
|
|
:parents (list scheme-mode-abbrev-table))
|
|
|
|
(defvar sex-mode-syntax-table
|
|
(let ((table (make-syntax-table lisp-data-mode-syntax-table)))
|
|
table))
|
|
|
|
(defvar sex-mode-map
|
|
(let ((map (make-sparse-keymap)))
|
|
(set-keymap-parent map lisp-mode-shared-map)
|
|
map)
|
|
"Keymap for Sex mode.
|
|
All commands in `lisp-mode-shared-map' are inherited by this map.")
|
|
|
|
(defvar sex-mode-line-process "")
|
|
|
|
(defconst sex-font-lock-keywords
|
|
(eval-when-compile
|
|
(list
|
|
;; Declarations
|
|
(list (concat "("
|
|
(regexp-opt '("chicken-define"
|
|
"chicken-define-syntax"
|
|
"chicken-import"
|
|
"chicken-load"
|
|
"define"
|
|
"defmacro"
|
|
"extern"
|
|
"impl"
|
|
"import"
|
|
"include"
|
|
"fn"
|
|
"pub"
|
|
"struct"
|
|
"trait"
|
|
"var"
|
|
"union")
|
|
'word)
|
|
"\\>"
|
|
"[[:space:]]*"
|
|
"\\([[:word:]]*\\)")
|
|
'(1 font-lock-keyword-face)
|
|
'(2 font-lock-function-name-face))
|
|
;; Keywords
|
|
(list (concat "("
|
|
(regexp-opt '(
|
|
"case"
|
|
"do"
|
|
"if"
|
|
"for"
|
|
"goto"
|
|
"return"
|
|
"self"
|
|
"switch"
|
|
"var"
|
|
"while")
|
|
'word)
|
|
"\\>")
|
|
'(1 'font-lock-builtin-face)))))
|
|
|
|
(defun sex-mode-set-variables ()
|
|
(set-syntax-table sex-mode-syntax-table)
|
|
(setq local-abbrev-table sex-mode-abbrev-table)
|
|
(setq mode-line-process '("" sex-mode-line-process))
|
|
(setq font-lock-defaults
|
|
'((sex-font-lock-keywords)
|
|
nil nil
|
|
(("+-*/.<>=!?$%_&:" . "w"))
|
|
nil
|
|
(font-lock-mark-block-function . mark-defun)))
|
|
(setq-local prettify-symbols-alist lisp-prettify-symbols-alist))
|
|
|
|
(put 'fn 'lisp-indent-function 'defun)
|
|
(put 'pub 'lisp-indent-function 'defun)
|
|
(put 'defmacro 'lisp-indent-function 'defun)
|
|
(put 'struct 'lisp-indent-function 'defun)
|
|
(put 'union 'lisp-indent-function 'defun)
|
|
(put 'trait 'lisp-indent-function 'defun)
|
|
(put 'impl 'lisp-indent-function 'defun)
|
|
(put 'var 'lisp-indent-function 0)
|
|
(put 'import 'lisp-indent-function 1)
|
|
|
|
;;;###autoload
|
|
(define-derived-mode sex-mode lisp-data-mode "Sex"
|
|
"Major mode for editing Sex code.
|
|
Editing commands are similar to those of `lisp-mode'.
|
|
|
|
Commands:
|
|
Delete converts tabs to spaces as it moves back.
|
|
Blank lines separate paragraphs. Semicolons start comments.
|
|
\\{sex-mode-map}"
|
|
:group 'sex-mode
|
|
(sex-mode-set-variables))
|
|
|
|
;;;###autoload
|
|
(add-to-list 'auto-mode-alist '("\\.\\(sex\\|hsex\\)\\'" . sex-mode))
|
|
|
|
(provide 'sex-mode)
|