Vagrantfile opening in SublimeText by default as Ruby extended file - vagrant

On top of my Vagrantfile I have:
# -*- mode: ruby -*-
# vi: set ft=ruby :
But every time when I open the file, I have to select manually in SublimeText 3 that I wanna set the syntax to Ruby, so it'll be readable.
How can you set a filename to be opened as a ruby-file in this example. Because the file has no extension.

Your use case is exactly what ApplySyntax is written to address. In fact, I believe Vagrantfile is one of the default "samples", so you might not have to do anything. Also, comments that are handled in some special way on some editors does not apply to all editors (in this case, ST).

Related

What does the dash star dash (-*-) do in a Ruby file?

I've noticed some Ruby files have a section at the very top like the following:
# -*- mode: ruby -*-
An example is a Vagrantfile generated by Vagrant.
What does that section actually do?
It's a file mode specification for emacs
When you visit a file, Emacs chooses a major mode automatically. Normally, it makes the choice based on the file name—for example, files whose names end in ‘.c’ are normally edited in C mode—but sometimes it chooses the major mode based on special text in the file. This special text can also be used to enable buffer-local minor modes.
It basically tells Emacs to use ruby mode

PyCharm debug always goes to cp1252.py

I am using the Community Edition of PyCharm.
When I put a break point in my python file and try to debug, always file cp1252.py opens and it goes to this line:
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
Do I need to do any specific setting for debugger in PyCharm?
Thanks for the help.
It turned out that I needed to force the source file to be opened as UTF-8 by adding this at the first line of my code:
# -*- coding: UTF-8 -*-

File.exist? not working when directory name has special characters

File.exist? in not working with directory name having special characters. for something like given below
path = "/home/cis/Desktop/'El%20POP%20que%20llevas%20dentro%20Vol.%202'/*.mp3"
it works fine but if it has letters like ñ its returns false.
Plz help with this.
Try the following:
Make sure you're running 1.9.2 or greater and put # encoding: UTF-8 at the top of your file (which must be in UTF-8 and your editor must support it).
If you're running MRI(i.e. not JRuby or other implementation) you can add environment variable RUBYOPT=-Ku instead of # encoding: UTF-8 to the top of each file.

Tell Netbeans it's a Ruby file

I've got a file named Vagrantfile and it's a ruby file but it cannot have the .rb at the end of the filename.
Is there a way to tell Netbeans that it's Ruby file?
Right-click the file in Files view (Ctrl-Shift-2 or ⌘-Shift-2) and look for "Open As...". When the context menu opens, select "text/x-ruby". Note that this works only when a file type is not detected automatically.
There is a caveat with this: Once a file w/o extension is opened as Ruby file, it treats all files w/o extension as Ruby files.
I was wondering this myself today, and came up with this:
# Vagrantfile.rb
Vagrant::Config.run do |config|
config.vm.box = "base"
# ...
end
and
# Vagrantfile
require "Vagrantfile.rb"
It's just Ruby after all!

ruby: unknown encoding name: undecided

I've actually figured out what causes this error, but Googling for it was unsuccessful so I thought I'd write it down here to help out other people. This error pops up when you've got an # -*- coding: undecided -*- comment at the top of one of your files. Emacs added this automatically for me, but re-saving the file caused it to be changed to the correct # -*- coding: utf-8 -*-.
This error pops up when you've got an # -*- coding: undecided -*- comment at the top of one of your files. Emacs added this automatically for me, but re-saving the file caused it to be changed to the correct # -*- coding: utf-8 -*-.

Resources