jpellerin / emacs-crystal-mode Goto Github PK
View Code? Open in Web Editor NEWA minimal crystal mode for emacs, based on ruby-mode (of course)
License: GNU General Public License v3.0
A minimal crystal mode for emacs, based on ruby-mode (of course)
License: GNU General Public License v3.0
Highlighting of delimiters works ok, but the contents of macro templates don't highlight or indent properly, because the lexer can't tokenize {%...%}
correctly and even if it could, the indentation engine is not set up to handle macro tokens.
struct
as a proper scope.abstract
as a modifier. Currently, indentation is incorrect thereafter.I tried modifying the mode a little, with a little success. Here is the diff.
--- crystal-mode.el.orig 2015-09-11 22:12:51.921843474 +0530
+++ crystal-mode.el 2015-09-21 11:59:49.652919958 +0530
@@ -55,7 +55,7 @@
:group 'languages)
(defconst crystal-block-beg-keywords
- '("class" "module" "def" "if" "unless" "case" "while" "until" "for" "begin" "do" "macro")
+ '("class" "struct" "module" "def" "if" "unless" "case" "while" "until" "for" "begin" "do" "macro" "abstract")
"Keywords at the beginning of blocks.")
(defconst crystal-block-beg-re
@@ -67,7 +67,7 @@
"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" "struct" "module" "def" "macro" "abstract")) "\\|"
(regexp-opt '("if" "unless" "case" "while" "until" "for" "begin"))
"\\)\\_>")
"Regexp to match where the indentation gets deeper.")
@@ -103,7 +103,7 @@
(defconst crystal-block-end-re "\\_<end\\_>")
(defconst crystal-defun-beg-re
- '"\\(def\\|class\\|module\\|macro\\)"
+ '"\\(def\\|class\\|struct\\|module\\|macro\\|abstract\\)"
"Regexp to match the beginning of a defun, in the general sense.")
(defconst crystal-singleton-class-re
@@ -381,7 +381,10 @@
(exp3 ("def" insts "end")
("begin" insts-rescue-insts "end")
("do" insts "end")
- ("class" insts "end") ("module" insts "end")
+ ("abstract class" insts "end")
+ ("class" insts "end")
+ ("struct" insts "end")
+ ("module" insts "end")
("[" expseq "]")
("{" hashvals "}")
("{" insts "}")
@@ -719,8 +722,8 @@
(`(:before . ";")
(message "Before ;")
(cond
- ((smie-rule-parent-p "def" "begin" "do" "class" "module" "{%for%}"
- "while" "until" "unless" "macro"
+ ((smie-rule-parent-p "def" "begin" "do" "class" "struct" "module" "abstract"
+ "{%for%}" "while" "until" "unless" "macro"
"if" "then" "elsif" "else" "when" "{%if%}"
"{%elsif%}" "{%else%}" "{%unless%}"
"rescue" "ensure" "{")
@@ -820,7 +823,7 @@
(let ((index-alist '()) (case-fold-search nil)
name next pos decl sing)
(goto-char beg)
- (while (re-search-forward "^\\s *\\(\\(class\\s +\\|\\(class\\s *<<\\s *\\)\\|module\\s +\\)\\([^\(<\n ]+\\)\\|\\(def\\|alias\\)\\s +\\([^\(\n ]+\\)\\)" end t)
+ (while (re-search-forward "^\\s *\\(\\(class\\s +\\|\\(class\\s *<<\\s *\\)\\|module\\s +\\|struct\\s +\\)\\([^\(<\n ]+\\)\\|\\(def\\|alias\\)\\s +\\([^\(\n ]+\\)\\)" end t)
(setq sing (match-beginning 3))
(setq decl (match-string 5))
(setq next (match-end 0))
@@ -1750,7 +1753,7 @@
"\\([A-Za-z_]" crystal-symbol-re "*\\|\\.\\|::" "\\)"
"+\\)")))
(definition-re (funcall make-definition-re crystal-defun-beg-re))
- (module-re (funcall make-definition-re "\\(class\\|module\\)")))
+ (module-re (funcall make-definition-re "\\(class\\|struct\\|module\\)")))
;; Get the current method definition (or class/module).
(when (re-search-backward definition-re nil t)
(goto-char (match-beginning 1))
@@ -2161,6 +2164,7 @@
crystal-font-lock-keyword-beg-re
(regexp-opt
'("->"
+ "abstract"
"alias"
"and"
"begin"
@@ -2189,6 +2193,7 @@
"retry"
"return"
"then"
+ "struct"
"super"
"unless"
"undef"
However, I am no good at Emacs Lisp, and could not make much progress in the time that I had on hand.
In macros, when we have two adjacent if
blocks, the indentation of (the contents of) the second one is incorrect.
...
{% if cond %}
...
{% end %}
{% if cond %}
...
{% end %}
...
I've installed crystal-mode via el-get by specifying GitHub repository directly.
It would be useful to be able to install crystal-mode via package.el
๐ก
With the new crystal the arguments passed should be probably be compile --no-color --no-codegen
instead of compile build --no-build --no-color
However, probably one should use the json output together with json.el
or so to get accurate error information
Actually, as a quick hack the following might work
(require 'json)
(flycheck-define-checker crystal-build
"A Crystal syntax checker using crystal build"
:command ("crystal"
"compile"
"--no-codegen"
"--no-color"
"--format" "json"
source-inplace)
:error-parser
(lambda (output checker buffer)
(mapcar (lambda (err)
(flycheck-error-new :buffer buffer
:checker checker
:filename (cdr-safe (assoc 'file err))
:line (cdr-safe (assoc 'line err))
:column (cdr-safe (assoc 'column err))
:level 'error
:message (cdr-safe (assoc 'message err))))
(append nil (json-read-from-string output))))
:modes crystal-mode
)
I love emacs and crystal.
I really disappointed when I knew this repository is not updated recently since there are still bugs especially when I write macros.
Here is a wrong indenting pattern which I faced.
{% if ok = true %}
{{ok}} # should be indented
{% end %}
{% if true %}
func0
{% else %}
func1 # should be indented
{% end %}
{% if true %}
{% end %}
{% if true %} # wrong indenting
{% end %}
It seems that @dotmilk and @TechMagister are still developing in forked repository.
But the bugs above are still remaining.
Have anyone solved this bugs?
(The lisp syntax is not readable for me...)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.