Coder Social home page Coder Social logo

emacs-crystal-mode's People

Contributors

jhp-stripe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

emacs-crystal-mode's Issues

Highlight and indent macro templates properly

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.

[Enhancement] Support `struct`, `abstract`, etc.

  • Enhance to support struct as a proper scope.
  • Enhance to support 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.

Make crystal-mode available on MELPA

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 ๐Ÿ’ก

Fix flycheck arguments

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
  )

Won't this be updated anymore?

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...)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.