PageRenderTime 18ms CodeModel.GetById 5ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 1ms

/tools/fancy-mode.el

http://github.com/nuclearsandwich/fancy
Emacs Lisp | 67 lines | 44 code | 10 blank | 13 comment | 1 complexity | 4dfff1af83abbeee3f1a22bd5055ce25 MD5 | raw file
 1(require 'generic-x)
 2
 3(define-generic-mode
 4  'fancy-mode
 5  '("#")                              ;; comments
 6  '("def" "class" "try" "catch"
 7    "finally" "retry" "return"
 8    "return_local" "require:"
 9    "match" "case" "->" "=>")             ;; keywords
10
11  '(;; symbols
12    ("\\('\\(\\([^\s\n\(\)\{\}\,]+\\|\\]+\\)\\)\\)" 1 font-lock-reference-face)
13    ;; fixnums
14    ("[0-9]+" . 'font-lock-variable-name-face)
15    ;; floats
16    ("[0-9]+\.[0-9]+" 'font-lock-variable-name-face)
17    ;; dynamic vars
18    ("\*[a-zA-Z0-9_-]+\*" . font-lock-reference-face)
19    ;; variables & pseudo variables
20    ("\\(^\\|[^_:.@$]\\|\\.\\.\\)\\b\\(super\\|nil\\|self\\|true\\|false\\)\\>" 2 font-lock-variable-name-face)
21    ;; variable names
22    ("\\(\\$\\([^a-zA-Z0-9 \n]\\|[0-9]\\)\\)\\W" 1 font-lock-variable-name-face)
23    ;; instance & class vars
24    ("\\(\\$\\|@\\|@@\\)\\(\\w\\|_\\)+" 0 font-lock-variable-name-face)
25    ;; method definitions
26    ("^\\s *def\\s +\\([^( \t\n]+\\)" 1 font-lock-function-name-face)
27    ;; message selectors
28    ("\\<[A-z][A-z0-9_-+?!=*/^><%]*:" . font-lock-function-name-face)
29    ;; operators
30    ("\\([-+*/~,<>=&!?%^]+ \\)" 1 'font-lock-function-name-face)
31     ;; general delimited string
32    ("\\(^\\|[[ \t\n<+(,=]\\)\\(%[xrqQwW]?\\([^<[{(a-zA-Z0-9 \n]\\)[^\n\\\\]*\\(\\\\.[^\n\\\\]*\\)*\\(\\3\\)\\)" (2 font-lock-string-face))
33    ;; constants
34    ("\\(^\\|[^_]\\)\\b\\([A-Z]+\\(\\w\\|_\\)*\\)" 2 font-lock-type-face))
35
36  '("\\.fy$")                      ;; files for which to activate this mode
37   nil                             ;; other functions to call
38  "A mode for fancy files"         ;; doc string for this mode
39)
40
41(add-to-list 'auto-mode-alist '("\\.fy\\'" . fancy-mode))
42(add-to-list 'auto-mode-alist '("\\.fancypack\\'" . fancy-mode))
43
44(add-to-list 'interpreter-mode-alist '("fancy" . fancy-mode))
45
46;; Ignore .fyc (compiled fancy bytecode) files
47(add-to-list 'completion-ignored-extensions ".fyc")
48
49(setq-default indent-tabs-mode nil)
50(setq-default tab-width 2)
51(setq indent-line-function 'insert-tab)
52
53(setq do-indent nil)
54(defun fancy-indent-line ()
55  ;(indent-line-to (+ (current-indentation) 2)))
56  (progn
57    (if (= (current-indentation) 0)
58        (setq do-indent nil))
59    (if do-indent
60        (indent-line-to (+ (current-indentation) 2))
61      (progn
62        (indent-relative)
63        (setq do-indent t)))))
64
65(setq indent-line-function 'fancy-indent-line)
66
67(provide 'fancy-mode)