Created
September 10, 2013 09:39
-
-
Save jfdm/6507161 to your computer and use it in GitHub Desktop.
A derived mode for OTT.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; ott-mode.el -- A Derived mode for writing OTT files | |
;; | |
;;; DESCRIPTION | |
;; | |
;; A derived mode to highlight OTT input files. | |
;; | |
;;; INSTALLATION | |
;; | |
;; 1. Place ott-mode.el in your .emacs.d directory | |
;; 2. Ensure that .emacs.d is on your load path. | |
;; 3. Add the following to your emacs setup file: | |
;; (require 'ott-mode) | |
;; (add-to-list 'auto-mode-alist (quote ("\\.ott$" . ott-mode))) | |
;; or augment your setup accordingly. | |
;; ------------------------------------------------------------------- | |
;;; CODE | |
(defvar ott-keywords '( | |
"metavar" "indexvar" "grammar" "embed" "subrules" "contextrules" | |
"substitutions" "single" "multiple" "freevars" "defns" "defn" | |
"by" "homs" "funs" "fun" "parsing" "begincoqsection" | |
"endcoqsection" "coqvariable" "left" "right" "terminals" | |
"formula" "judgement" | |
)) | |
;; -------------------------------------------------- [ Assign Faces ] | |
(defvar ott-font-lock-defaults | |
`(( | |
( ,(regexp-opt ott-keywords 'words) . font-lock-keyword-face) | |
( "(\\+.+\\+)\\|-->\\|{{\\|}}\\|;\\|<::\\|_::\\|::=\\|::\\|<=\\|<<.*\\|>>\\|</\\|//\\|/>\\|\|" . font-lock-constant-face) | |
))) | |
;; --------------------------------------------------- [ Clear memory ] | |
(setq ott-keywords nil | |
) | |
;; ------------------------------------------------------------------- | |
;; SIF Definition | |
;; ------------------------------------------------------------------- | |
(define-derived-mode ott-mode fundamental-mode "OTT" | |
"Major mode for editing OTT files." | |
(defgroup ott-mode nil | |
"Derived mode for OTT Files" :group 'languages) | |
(defvar ott-mode-hook nil "Hook for ott-mode") | |
(modify-syntax-entry ?% "<" ott-mode-syntax-table) | |
(modify-syntax-entry ?\n ">" ott-mode-syntax-table) | |
;; (mapcar (lambda (x) | |
;; (modify-syntax-entry x "_" ott-mode-syntax-table)) | |
;; ;; Some of these are actually OK by default. | |
;; "!#$%&*+./:<=>?@^|~") | |
(make-local-variable 'ott-font-lock-defaults) | |
(make-local-variable 'comment-start) | |
(make-local-variable 'comment-end) | |
(make-local-variable 'comment-start-skip) | |
(make-local-variable 'comment-column) | |
(make-local-variable 'comment-padding) | |
(make-local-variable 'comment-multi-line) | |
(make-local-variable 'comment-indent-function) | |
(setq font-lock-defaults ott-font-lock-defaults | |
comment-start "% " | |
comment-end "" | |
comment-start-skip "+ %+ \n" | |
comment-column 60 | |
comment-padding 0 | |
comment-multi-line nil | |
comment-indent-function 'java-comment-indent | |
indent-tabs-mode t | |
) | |
(run-hooks 'ott-mode-hook) | |
) | |
(provide 'ott-mode) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Multi-line comments and inserts i.e. between {{ }} are not properly handled. There is trouble getting the regex for comment-start-skip and comment-end-skip to recognise comments.