PageRenderTime 36ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

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