I'm learning Ruby and I'm using Sublime Text 3 but I find the syntax highlighting really strange.
For example :
Ugly syntax
Even after setting the syntax to ruby.
Ruby syntax set
I'd like to know if this is normal, or if I need to change something on the users
settings or something like that.
The syntax file for Ruby (Ruby.sublime-syntax) contains a list of unresolved issues. Among them is:
text:
"p << end
print me!
end"
symptoms:
not recognized as a heredoc
solution:
there is no way to distinguish perfectly between the << operator and the start
of a heredoc. Currently, we require assignment to recognize a heredoc. More
refinement is possible.
• Heredocs with indented terminators (<<-) are always distinguishable, however.
• Nested heredocs are not really supportable at present
So yeah, it's normal.
You could visit https://packagecontrol.io/ and use something like Railscast Colour Scheme
The basic syntax highlighting that comes w/ sublime is pretty sparse - these packages usually do a better job. Also this is just one example. There's plenty of themes and color schemes.
To install package control ctrl+ and past in the snippet according to your version of sublime from this page https://packagecontrol.io/installation#st3
Related
How can I fix ruby 2.0 symbol array syntax in Emacs?
In standard ruby-mode, it displays symbol arrays in default color. In enh-ruby-mode, a definition of symbol array breaks my color theme entirely.
ruby-mode is currently not capable of rendering the array syntax correctly.
If you really are concerned about that, consider using the highlight-escape-sequences package, available through MELPA.
Edit The same author (Dmitry Gutov) seems to have made a commit on ruby-mode, fixing the syntax-highlighting for array of symbols, as we can see here. But that change is not available yet, so I guess we need to wait for Emacs 24.4...
Emacs 24 ruby-mode insists on indenting if expressions the following way:
before1 = if params[:before]
Time.zone.at(params[:before].to_i)
end
Which i find just plain wrong. The expected behavior should be:
before1 = if params[:before]
Time.zone.at(params[:before].to_i)
end
That is - the if block should be indented by exactly one level relative to the line in which the if expression starts. Is there any way to achieve this?
If your Emacs is recent enough (24.4+) and you're using the SMIE indentation engine (ruby-use-smie is non-nil), you can use ruby-align-to-stmt-keywords:
(add-to-list 'ruby-align-to-stmt-keywords 'if)
I guess you actually meant to say that Emacs aligns the if with the end, which is actually pretty idiomatic in Ruby (and the style enforced by tools like RuboCop). The second indentation style is popular for method class with blocks, but not for expressions like if/unless/case.
Currently there is now way to change this behaviour. There are plans to introduce a more flexible indentation scheme in ruby-mode in the future, but that's not going to happen in the next Emacs release.
At any rate - it's not a bug, it's a feature :-)
Sometimes, parsing done by text editors for syntax highlighting is not accurate. It often happens that introducing a heredoc in ruby-mode messes up syntax highlighting on emacs as in this question. I am having problem with such case:
<<_
some here doc content
...
last line of the intended heredoc
_
this_ruby_code_line_and_any_line_after_it_is_highlightened_as_part_of_heredoc
I do not expect a fix on emacs ruby-mode for this, but is there some kind of a commented string that I can generally put between the heredoc and the following Ruby code in order to reset the highlighting problem? When I have problems not with heredoc but with funky string literals (especially those including quotes), sometimes, putting a commented string like
#"'`
at the end of the line fixes the problem. Is there such thing to fix the problem for heredoc, and further, is there a string that can be used more generally?
Works fine for me in an Emacs trunk build.
Try a more recent Emacs version (I'm quite certain that this works in the upcoming 24.3 version, but maybe in the current release, too) and/or make sure that you are using ruby-mode bundled with Emacs, not installed through ELPA, etc:
ELISP> (require 'which-func)
which-func
ELISP> (find-library-name "ruby-mode")
"/home/gutov/emacs-bzr/trunk/lisp/progmodes/ruby-mode.el"
I'm sure we're all familiar with the "unexpected kEnd" problem. They are always (to me) a lot of trouble to track down, because Vim doesn't match "do"s and "end"s. (And, obviously, other elements that end with "end", like "if")
Is there a way to configure Vim to show these matches to help make debugging easier?
If you are using a recent vim (I'm using 7.4), the built-in matchit macro works well with ruby code.
Simply enable it by adding the following to your .vimrc
runtime macros/matchit.vim
Hit % to match do/end combos and many others in ruby files.
I use this macro and then add this to my vimrc to enable it:
" % to bounce from do to end etc.
runtime! macros/matchit.vim
When I want to find the matching end for a do, I cursor over the do and hit %.
"endwise" is a pretty nice vim extension that adds them automatically, which I found greatly reduces the amount of missing ends. etc:
http://www.vim.org/scripts/script.php?script_id=2386
I use this matchit clone, that can be installed easily with vundle.
I'm really used to auto-completion coming from Netbeans.
In Netbeans, when I type a 'string' and then hit a 'dot' it will print out a list of methods for the String class.
TextMate doesn't seem to have that function.
Is it something you could add?
Would save A LOT of time instead of using the ri/irb/online doc all the time.
Install the Ruby TextMate bundle, open a Ruby file and type alt+esc to get the autocompletion.
You have discovered the fundamental difference between a text editor and an IDE: a text editor edits text (duh!), i.e. an unstructured stream of characters. It doesn't know anything about objects, messages, methods, mixins, modules, classes, namespaces, types, strings, arrays, hashes, numbers, literals etc. This is great, because it means that you can edit anything with a text editor, but it also means that editing any particular thing is harder than it were with a specialized editor.
A Ruby IDE edits Ruby programs, i.e. a highly structured semantic graph of objects, methods, classes etc. This is great, because the IDE knows about the rules that make up legal Ruby programs and thus will e.g. make it impossible for you to write illegal Ruby programs and it can offer you automated transformations that guarantee that if you start out with a legal Ruby program, you end up with a legal Ruby program (e.g. automated refactorings). But it also means that you can only edit Ruby programs.
In short: it's simply impossible to do what you ask with a text editor. You need an IDE. (Note: you can of course build an IDE on top of a text editor. Emacs is a good example of this. But from what I have read, the TextMate plugin API is simply not powerful enough to do this. I could be wrong, though – since I don't have a Mac, I'm mostly dependent on hearsay.)
TM's "equivalent" is hitting escape, I believe.
You can make escape "go across files" for completion if you use the ruby amp TM bundle http://code.google.com/p/ruby-amp/
GL.
-r