Created
July 3, 2009 04:25
-
-
Save tyler/139902 to your computer and use it in GitHub Desktop.
Really basic major mode for Potion
This file contains 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
; Potion Mode | |
(defconst potion-indent-offset 2 "Offset for indentation.") | |
; Stolen from Ioke Mode | |
(defconst potion-operator-symbols | |
'("?" "..." "=>" "++" "--" "*" "/" "%" "+" "-" "<<" ">>" ">" "<" "<=" ">=" "<=>" "==" "!=" "=~" "!~" "&" "^" "|" "&&" "||" ".." "=" "+=" "-=" "*=" "/=" "%=" "&=" "^=" "|=" "<<=" ">>=" "<-" "<->" "->") | |
"Potion mode operator symbols") | |
(defgroup potion-font-lock-faces nil | |
"Specific Potion faces for highlighting Potion sources." | |
:prefix "potion-font-lock-" | |
:group (if (featurep 'xemacs) | |
'font-lock-faces | |
'font-lock-highlighting-faces)) | |
(defface potion-font-lock-integer-face | |
'((((class grayscale)) (:foreground "LightGray")) | |
(((class color)) (:foreground "LightSalmon")) | |
(t (:bold t))) | |
"Font Lock Mode face used to highlight ." | |
:group 'potion-font-lock-faces) | |
(defconst potion-font-lock-integer-face 'potion-font-lock-integer-face) | |
(defface potion-font-lock-operator-face | |
'((((class grayscale)) (:foreground "DimGray")) | |
(((class color)) (:foreground "SteelBlue1")) | |
(t (:bold t))) | |
"Font Lock Mode face used to highlight ." | |
:group 'potion-font-lock-faces) | |
(defconst potion-font-lock-operator-face 'potion-font-lock-operator-face) | |
(defface potion-font-lock-variable-name-face | |
'((((class grayscale)) (:foreground "DimGray")) | |
(((class color)) (:foreground "LightSkyBlue2")) | |
(t (:bold t))) | |
"Font Lock Mode face used to highlight ." | |
:group 'potion-font-lock-faces) | |
(defconst potion-font-lock-variable-name-face 'font-lock-reference-face) | |
(defface potion-font-lock-function-name-face | |
'((((class grayscale)) (:foreground "LightGray")) | |
(((class color)) (:foreground "light goldenrod")) | |
(t (:bold t))) | |
"Font Lock Mode face used to highlight ." | |
:group 'potion-font-lock-faces) | |
(defconst potion-font-lock-function-name-face 'potion-font-lock-function-name-face) | |
(defface potion-font-lock-punctuation-face | |
'((((class grayscale)) (:foreground "DimGray")) | |
(((class color)) (:foreground "RosyBrown2")) | |
(t (:bold t))) | |
"Font Lock Mode face used to highlight ." | |
:group 'potion-font-lock-faces) | |
(defconst potion-font-lock-punctuation-face 'potion-font-lock-punctuation-face) | |
(defconst potion-font-lock-builtin-face font-lock-keyword-face) | |
(defface potion-font-lock-boolean-face | |
'((((class grayscale)) (:foreground "Gray50")) | |
(((class color)) (:foreground "Aquamarine")) | |
(t (:bold t))) | |
"Font Lock Mode face used to highlight ." | |
:group 'potion-font-lock-faces) | |
(defconst potion-font-lock-boolean-face 'potion-font-lock-boolean-face) | |
(defconst potion-font-lock-class-name-face font-lock-type-face) | |
(defface potion-font-lock-path-face | |
'((((class grayscale)) (:foreground "Gray50")) | |
(((class color)) (:foreground "plum3")) | |
(t (:bold t))) | |
"Font Lock Mode face used to highlight ." | |
:group 'potion-font-lock-faces) | |
(defconst potion-font-lock-path-face 'potion-font-lock-path-face) | |
(defface potion-font-lock-closure-face | |
'((((class grayscale)) (:foreground "Gray50")) | |
(((class color)) (:foreground "SlateGray3")) | |
(t (:bold t))) | |
"Font Lock Mode face used to highlight ." | |
:group 'potion-font-lock-faces) | |
(defconst potion-font-lock-closure-face 'potion-font-lock-closure-face) | |
(defvar potion-font-lock-keywords | |
(list | |
'("\\([0-9]+\\)" 1 potion-font-lock-integer-face) | |
'("\\([A-Z]+\\S-+\\)" 1 potion-font-lock-class-name-face) | |
'("\\(/\\S-+\\)" 1 potion-font-lock-path-face) | |
'("\\([()]\\)" 1 potion-font-lock-closure-face) | |
`(,(format "\\(%s\\)" (regexp-opt potion-operator-symbols)) 1 potion-font-lock-operator-face) | |
'("\\(\\S-+\\)\\s-+=\\s-+(" 1 potion-font-lock-function-name-face) | |
'("\\(\\S-+\\)\\s-+=" 1 potion-font-lock-variable-name-face) | |
'("\\([:,\\.]\\)" 1 potion-font-lock-punctuation-face) | |
'("\\(loop\\|elsif\\|if\\|class\\|while\\|to\\|return\\|else\\)" 1 potion-font-lock-builtin-face) | |
'("\\(true\\|false\\|nil\\)" 1 potion-font-boolean-face) | |
) | |
"Highlighting for Potion mode") | |
(defvar potion-mode-hook nil) | |
(defvar potion-mode-syntax-table | |
(let ((st (make-syntax-table))) | |
(modify-syntax-entry ?# "<" st) | |
(modify-syntax-entry ?\' "\"" st) | |
st)) | |
(defun potion-indent-line () | |
"Indentation for Potion" | |
(interactive) | |
(beginning-of-line) | |
(if (bobp) | |
(indent-line-to 0) | |
(let ((not-indented t) cur-indent) | |
(if (looking-at "^[ \t]*\\.") | |
(progn | |
(save-excursion | |
(forward-line -1) | |
(setq cur-indent (- (current-indentation) potion-indent-offset)))) | |
(save-excursion | |
(while not-indented | |
(forward-line -1) | |
(end-of-line) | |
(if (looking-back ":[ \t]*") | |
(progn | |
(setq cur-indent (+ (current-indentation) potion-indent-offset)) | |
(setq not-indented nil)) | |
(if (looking-back "\\.[ \t]*") | |
(progn | |
(setq cur-indent (- (current-indentation) potion-indent-offset)) | |
(setq not-indented nil)) | |
(if (progn | |
(beginning-of-line) | |
(bobp)) | |
(setq not-indented nil))))))) | |
(if cur-indent | |
(indent-line-to (max 0 cur-indent)) | |
(indent-line-to 0))))) | |
(define-derived-mode potion-mode fundamental-mode "Potion" | |
"A major mode for editing Potion files." | |
:syntax-table potion-mode-syntax-table | |
(set (make-local-variable 'comment-start) "# ") | |
(set (make-local-variable 'font-lock-defaults) '(potion-font-lock-keywords)) | |
(set (make-local-variable 'indent-line-function) 'potion-indent-line)) | |
(run-hooks 'potion-mode-hook) | |
(provide 'potion-mode) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment