/
fancy-mode.el
63 lines (54 loc) · 2.23 KB
/
fancy-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
(require 'generic-x)
(define-generic-mode
'fancy-mode
'("#") ;; comments
'("def" "class" "try" "catch"
"finally" "retry" "return"
"return_local" "require:"
"match" "case" "->" "=>") ;; keywords
'(;; symbols
("\\('\\(\\([^\s\n\(\)\{\}]+\\|\\]+\\)\\)\\)" 1 font-lock-reference-face)
;; fixnums
("[0-9]+" . 'font-lock-variable-name-face)
;; floats
("[0-9]+\.[0-9]+" 'font-lock-variable-name-face)
;; variables & pseudo variables
("\\(^\\|[^_:.@$]\\|\\.\\.\\)\\b\\(super\\|nil\\|self\\|true\\|false\\)\\>" 2 font-lock-variable-name-face)
;; variable names
("\\(\\$\\([^a-zA-Z0-9 \n]\\|[0-9]\\)\\)\\W" 1 font-lock-variable-name-face)
;; instance & class vars
("\\(\\$\\|@\\|@@\\)\\(\\w\\|_\\)+" 0 font-lock-variable-name-face)
;; method definitions
("^\\s *def\\s +\\([^( \t\n]+\\)" 1 font-lock-function-name-face)
;; message selectors
(" \\<[A-z][A-z0-9_-+?!=*/^><%]*:" . font-lock-function-name-face)
;; operators
("\\([-+*/~,<>=&!?%^]+ \\)" 1 'font-lock-function-name-face)
;; general delimited string
("\\(^\\|[[ \t\n<+(,=]\\)\\(%[xrqQwW]?\\([^<[{(a-zA-Z0-9 \n]\\)[^\n\\\\]*\\(\\\\.[^\n\\\\]*\\)*\\(\\3\\)\\)" (2 font-lock-string-face))
;; constants
("\\(^\\|[^_]\\)\\b\\([A-Z]+\\(\\w\\|_\\)*\\)" 2 font-lock-type-face))
'("\\.fy$") ;; files for which to activate this mode
nil ;; other functions to call
"A mode for fancy files" ;; doc string for this mode
)
(add-to-list 'auto-mode-alist '("\\.fy\\'" . fancy-mode))
(add-to-list 'auto-mode-alist '("\\.fancypack\\'" . fancy-mode))
;; Ignore .fyc (compiled fancy bytecode) files
(add-to-list 'completion-ignored-extensions ".fyc")
(setq-default indent-tabs-mode nil)
(setq-default tab-width 2)
(setq indent-line-function 'insert-tab)
(setq do-indent nil)
(defun fancy-indent-line ()
;(indent-line-to (+ (current-indentation) 2)))
(progn
(if (= (current-indentation) 0)
(setq do-indent nil))
(if do-indent
(indent-line-to (+ (current-indentation) 2))
(progn
(indent-relative)
(setq do-indent t)))))
(setq indent-line-function 'fancy-indent-line)
(provide 'fancy-mode)