-
Notifications
You must be signed in to change notification settings - Fork 2
/
ctt-mode.el
100 lines (76 loc) · 2.78 KB
/
ctt-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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
;;; ctt.el --- Mode for the ctt programming language -*- lexical-binding: t -*-
;; Package-version: 1.0
;; Package-Requires: ((emacs "24.1") (cl-lib "0.5"))
;; Keywords: languages
;;; Commentary:
;; This package provides a major mode for editing proofs or programs in poset type theroy.
;; It is based on cctt.el by Andras Kovacs (https://github.com/AndrasKovacs/cctt)
(require 'comint)
(require 'cl-lib)
;;;; Customization options
(defgroup ctt nil "Options for ctt-mode"
:group 'languages
:prefix 'ctt-
:tag "ctt")
;;;; Syntax
(defvar ctt-keywords
'("inductive" "higher" "import" "let" "in" "where" "module" "lock" "unlock")
"Keywords.")
(defvar ctt-operations
'("Ext" "Path" "PathP" "hComp" "coe" "refl" "U" "I" "ap" "split" ".1" ".2")
"Operations.")
(defvar ctt-special
'("undefined")
"Special operators.")
(defvar ctt-keywords-regexp
(regexp-opt ctt-keywords 'words)
"Regexp that recognizes keywords.")
(defvar ctt-operations-regexp
(regexp-opt ctt-operations 'words)
"Regexp that recognizes operations.")
(defvar ctt-operators-regexp
(regexp-opt '("," ":" "->" "→" "∙" "=" "|" "\\" "λ" "*" "×" "_" "@" "." "⁻¹" "[" "]" "/\\" "\\/") t)
"Regexp that recognizes operators.")
(defvar ctt-special-regexp
(regexp-opt ctt-special 'words)
"Regexp that recognizes special operators.")
(defvar ctt-def-regexp "^[[:word:]'-/<>]+"
"Regexp that recognizes the beginning of a definition.")
(defvar ctt-font-lock-keywords
`((,ctt-keywords-regexp . font-lock-keyword-face)
(,ctt-def-regexp . font-lock-function-name-face)
(,ctt-operations-regexp . font-lock-builtin-face)
(,ctt-operators-regexp . font-lock-variable-name-face)
(,ctt-special-regexp . font-lock-warning-face))
"Font-lock information, assigning each class of keyword a face.")
(defvar ctt-syntax-table
(let ((st (make-syntax-table)))
(modify-syntax-entry ?\{ "(}1nb" st)
(modify-syntax-entry ?\} "){4nb" st)
(modify-syntax-entry ?- "_ 123" st)
(modify-syntax-entry ?\n ">" st)
(modify-syntax-entry ?\\ "." st)
st)
"Syntax table with Haskell-style comments.")
(defun ctt-indent-line ()
"Indent current line."
(insert-char ?\s 2))
;;;###autoload
(define-derived-mode ctt-mode prog-mode
"ctt"
"Major mode for editing ctt files."
:syntax-table ctt-syntax-table
;; Make comment-dwim do the right thing for Cubical
(set (make-local-variable 'comment-start) "--")
(set (make-local-variable 'comment-end) "")
;; Code for syntax highlighting
(setq font-lock-defaults '(ctt-font-lock-keywords))
;; Indentation
(setq indent-line-function 'ctt-indent-line)
;; Clear memory
(setq ctt-keywords-regexp nil)
(setq ctt-operators-regexp nil)
(setq ctt-special-regexp nil))
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.ctt\\'" . ctt-mode))
(provide 'ctt-mode)