tyler (owner)

Revisions

gist: 139902 Download_button fork
public
Description:
Really basic major mode for Potion
Public Clone URL: git://gist.github.com/139902.git
Emacs Lisp
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
; 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)