Created
August 26, 2011 07:27
-
-
Save jfdm/1172906 to your computer and use it in GitHub Desktop.
An EMACS derived mode for the MINION constraint solver.
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
;; minion-mode.el -- Derived mode for writing MINION input files. | |
;; Copyright (C) 2011 by Jan de Muijnck-Hughes | |
;; Author: Jan de Muijnck-Hughes | |
;; | |
;;; DESCRIPTION | |
;; | |
;; A derived mode to highlight MINION input files. Currently this | |
;; mode only provides syntax highlighting, and comment support. | |
;; Future work will seek to add support for smart indentation. | |
;; | |
;;; INSTALLATION | |
;; | |
;; 1. Place minion-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: | |
;; (add-to-list 'auto-mode-alist (quote ("\\.minion$" . minion-mode))) | |
;; ------------------------------------------------------------------- | |
;;; CODE | |
;; --------------------------------------------------- [ Constraints ] | |
(defvar minion-constraints '( | |
"abs" "alldiff" "difference" "diseq" "div" "element" | |
"element_one" "eq" "gacalldiff" "gaclexleq" "gaclexless" | |
"gcc" "gccweak" "hamming" "ineq" "lexleq" "lexless" | |
"lighttable" "litsumgeq" "max" "min" "minuseq" "modulo" | |
"negativetable" "occurrence" "occurrencegeq" "occurrenceleq" | |
"pow" "product" "reification" "reify" "reifyimply" "sumgeq" | |
"sumleq" "table" "watched-and" "watched-or" "watchelement" | |
"watchelement_one" "watchless" "watchsumgeq" "watchsumleq" | |
"watchvecneq" "weightedsumgeq" "weightedsumleq" "w-inrange" | |
"w-inset" "w-literal" "w-notinrange" "w-notinset" | |
"w-notliteral" "table" | |
)) | |
;; ------------------------------------------------------ [ Keywords ] | |
(defvar minion-keywords '( | |
"PRINT" "VARORDER" "MAXIMISING" "MINIMISING" "MAX" "MIN" "ALIAS" | |
)) | |
;; --------------------------------------------------------- [ Types ] | |
(defvar minion-types '( | |
"BOOL" "DISCRETE" "BOUND" "SPARSEBOUND" | |
)) | |
;; ----------------------------------------------------- [ Constants ] | |
(defvar minion-constants '( | |
"NONE" "ALL" "STATIC" | |
)) | |
;; ----------------------------------------------------- [ Structure ] | |
(defvar minion-preprocessor '( | |
"MINION" "VARIABLES" "TUPLELIST" "SEARCH" "CONSTRAINTS" "EOF" | |
)) | |
;; -------------------------------------------------- [ Assign Faces ] | |
(defvar minion-font-lock-defaults | |
`(( | |
( ,(regexp-opt minion-constraints 'words) . font-lock-function-name-face) | |
( ,(regexp-opt minion-keywords 'words) . font-lock-keyword-face) | |
( ,(regexp-opt minion-types 'words) . font-lock-type-face) | |
( ,(regexp-opt minion-constants 'words) . font-lock-constant-face) | |
( ,(regexp-opt minion-preprocessor 'words) . font-lock-preprocessor-face) | |
))) | |
;; --------------------------------------------------- [ Clear memory ] | |
(setq minion-constraints nil | |
minion-keywords nil | |
minion-types nil | |
minion-constants nil | |
minion-preprocessor nil | |
) | |
;; ------------------------------------------------------------------- | |
;; MINION Definition | |
;; ------------------------------------------------------------------- | |
(define-derived-mode minion-mode fundamental-mode "MINION" | |
"Major mode for editing MINION files." | |
(defgroup minion-mode nil | |
"Derived mode for MINION Files" :group 'languages) | |
(defvar minion-mode-hook nil "Hook for minion-mode") | |
(modify-syntax-entry ?# "<" minion-mode-syntax-table) | |
(modify-syntax-entry ?\n ">" minion-mode-syntax-table) | |
(make-local-variable 'minion-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-multi-line) | |
(make-local-variable 'comment-indent-function) | |
(setq font-lock-defaults minion-font-lock-defaults | |
comment-start "# " | |
comment-end "" | |
comment-start-skip "+ #+ \n" | |
comment-column 60 | |
comment-multi-line nil | |
comment-indent-function 'java-comment-indent | |
indent-tabs-mode t | |
) | |
(run-hooks 'minion-mode-hook) | |
) | |
(provide 'minion-mode) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment