Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More font lock & basic struct/enum/lib support #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions crystal-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
:group 'languages)

(defconst crystal-block-beg-keywords
'("class" "module" "def" "if" "unless" "case" "while" "until" "for" "begin" "do" "macro")
'("class" "module" "def" "if" "unless" "case" "while" "until" "for" "begin" "do"
"macro" "lib" "enum" "struct")
"Keywords at the beginning of blocks.")

(defconst crystal-block-beg-re
Expand All @@ -67,7 +68,8 @@
"Regexp to match keywords that nest without blocks.")

(defconst crystal-indent-beg-re
(concat "^\\(\\s *" (regexp-opt '("class" "module" "def" "macro")) "\\|"
(concat "^\\(\\s *" (regexp-opt '("class" "module" "def" "macro" "lib" "enum" "struct"))
"\\|"
(regexp-opt '("if" "unless" "case" "while" "until" "for" "begin"))
"\\)\\_>")
"Regexp to match where the indentation gets deeper.")
Expand Down Expand Up @@ -103,9 +105,13 @@
(defconst crystal-block-end-re "\\_<end\\_>")

(defconst crystal-defun-beg-re
'"\\(def\\|class\\|module\\|macro\\)"
'"\\(def\\|class\\|module\\|macro\\|lib\\|struct\\|enum\\)"
"Regexp to match the beginning of a defun, in the general sense.")

(defconst crystal-attr-re
'"\\(@\\[\\)\\(.*\\)\\(\\]\\)"
"Regexp to match attributes preceding a method or type")

(defconst crystal-singleton-class-re
"class\\s *<<"
"Regexp to match the beginning of a singleton class context.")
Expand Down Expand Up @@ -381,7 +387,8 @@ It is used when `crystal-encoding-magic-comment-style' is set to `custom'."
(exp3 ("def" insts "end")
("begin" insts-rescue-insts "end")
("do" insts "end")
("class" insts "end") ("module" insts "end")
("class" insts "end") ("module" insts "end") ("struct" insts "end")
("lib" insts "end") ("enum" insts "end")
("[" expseq "]")
("{" hashvals "}")
("{" insts "}")
Expand Down Expand Up @@ -720,7 +727,7 @@ It is used when `crystal-encoding-magic-comment-style' is set to `custom'."
(message "Before ;")
(cond
((smie-rule-parent-p "def" "begin" "do" "class" "module" "{%for%}"
"while" "until" "unless" "macro"
"while" "until" "unless" "macro" "lib" "enum" "struct"
"if" "then" "elsif" "else" "when" "{%if%}"
"{%elsif%}" "{%else%}" "{%unless%}"
"rescue" "ensure" "{")
Expand Down Expand Up @@ -2174,10 +2181,12 @@ See `font-lock-syntax-table'.")
"else"
"fail"
"ensure"
"enum"
"for"
"end"
"if"
"in"
"lib"
"macro"
"module"
"next"
Expand All @@ -2189,6 +2198,7 @@ See `font-lock-syntax-table'.")
"retry"
"return"
"then"
"struct"
"super"
"unless"
"undef"
Expand Down Expand Up @@ -2312,6 +2322,10 @@ See `font-lock-syntax-table'.")
0 font-lock-builtin-face)
("\\(\\$\\|@\\|@@\\)\\(\\w\\|_\\)+"
0 font-lock-variable-name-face)
;; Attributes
(, crystal-attr-re
(1 font-lock-preprocessor-face)
(3 font-lock-preprocessor-face))
;; Constants.
("\\(?:\\_<\\|::\\|\\s+:\\s+\\)\\([A-Z]+\\(\\w\\|_\\)*\\)"
1 (unless (eq ?\( (char-after)) font-lock-type-face))
Expand Down