Highlighting rspec in sublime text 2 - ruby-on-rails

The amount of DO END in my test files are getting confusing.
Is there a way to highlight the matching pairs of a DO or END in sublime text 2?
Bracket Highlighter doesn't have this functionality (although the developer is looking into it)

Edit
~/Library/Application Support/Sublime Text 2/Packages/BracketHighlighter/bh_core.sublime-settings
Add "RSpec" to the language list.
// Ruby conditional statements
{
"name": "ruby",
"open": "(^\\s*\\b(?:if|case|until|unless|while|begin|class|module|def\\b\\s*[a-zA-Z_\\d]+)|do)\\b",
"close": "\\b(end)\\b",
"style": "default",
"scope_exclude": ["string", "comment"],
"plugin_library": "bh_modules.rubykeywords",
"language_filter": "whitelist",
"language_list": ["RSpec", "Ruby", "Ruby on Rails", "HTML (Rails)"],
"enabled": true
},
The result
EDIT
Installing the Bracket Highliter "BH2" branch via package control:
Open
~/Library/Application Support/Sublime Text 2/Packages/User/Package Control.sublime-settings
and add
"repositories":
[
"https://github.com/facelessuser/BracketHighlighter/tree/BH2"
]
Then from the package control drop down menu: Package Control: Upgrade Package and select Bracket Highlighter.

I needed only to install the BracketHighlighter package (using the default repository in Package Control) and restart Sublime (important!). The answer by AGS is out of date.

Related

VS Code Windows 10: LaTeX Workshop will not compile

On Windows 10, I have MiKTex (as admin) installed and updated. Within VS Code, I have installed the LaTeX Workshop extension, but my document will not compile. I require lualatex, so I have moved that "recipe" to the "first" position in LaTeX Workshop's .json file, but compiling throws the message Recipe terminated with error. Looking at the console shows Undefined control sequence with my document's file path c:\Users\...etc... -- this is relating to the first line of the document [1,1] where I have the typical \documentclass[12pt]{article}.
It seems that the extension isn't able to locate the Path to the LaTeX executables...does this sound right? It is almost like it is looking in my files own directory for the LaTeX classes and packages, etc. In my Windows System Environment Variables, the path to C:\Program Files\MiKTeX 2.9\miktex\bin\x64\ seems to be correctly configured. Oddly, if I try to compile using pdflatex, it does not seem to encounter this specific issue (rather showing the error that I need to use lualatex, which I am trying to do).
Has anyone had this issue, or knows a way to fix it?
1: It might be some problem related to "pdftex vs pdflatex"... Now I have the same but looking for the solution... (Win10; VSCode + Latex Workshop extension; WSL2; TexLive 2020 on Ubuntu 20.04;)
2: I've found something... in: "latex-workshop.latex.tools"
{
"name": "pdflatex",
"command": "pdftex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOC%"
],
"env": {}
},
I changed "command": "pdftex" to "command": "pdflatex"
Now it is working.
Make sure you got TeX Live installed. The installation takes some time, but as you've installed it, it should work.

Typescript beautify in brackets IDE

I have problem with adding new format to beautify plugin. According to this instruction, point .5, I Have open defaultPreferences.json in notepad, added new lines and save file. Next when I open(or refresh) brackets IDE and open defaultPreferences, there's no that new lines, also beautify dont detect typescript. How to fix it?
Install Typescript support on Brackets Extensions Typescript extension
Install beautify Beautify Extension
Install Typescript and Typescript-formatter globally to have them accessible across all your projects npm install -g typescript typescript-formatter
Open Brackets.json, by selecting Debug > Open Preferences File
Note that this will split your Brackets window, make changes in brackets.json, as defaultPreferences.json is a read-only for your reference.
Append the following code block to the end of your JSON object.
"bb.beautify.beautifiers": {
"tsfmt": {
"command": "tsfmt"
}
},
"bb.beautify.languages": {
"css": "css",
"ejs": "html",
"handlebars": "html",
"html": "html",
"javascript": "js",
"json": "js",
"less": "css",
"php": "html",
"scss": "css",
"svg": "html",
"vue": "html",
"xml": "html",
"typescript": "tsfmt"
}
*Had technical issues formatting the JSON, please look at this image for the formatted block

Zend Framework 2 Autoload Third Party library using composer

I am trying to use composer to autoload a third party library into my ZF2 application - specifically Google api.
I followed the answer in this post on SO, edited my composer.json
"autoload": {
"psr-0": {"Googleanalytics\\": "vendor/google-api-php-client/src/"}
}
and ran update.
I can see the entry in composer/autoload_namespaces.php
'Googleanalytics\\' => array($vendorDir . '/google-api-php-client/src'),
but i still get a fatal error class not found when trying to instantiate a class in that directory (Google_Client.php).
Any ideas what i am missing?
I am including the file in the class i am trying to use it:
use Googleanalytics\Google_Client;
I have tried renaming the directory in case the - was the problem and also creating a simple test.php file in that dir in case the underscore in the class name (Google_Client.php) was the problem, but still the same error.
Is there anything else i need to add to my ZF2 application to autoload this library?
Also note i decided not to use ZendGdata as this component does not seem to be maintained anymore.
Thanks in advance
The autoload definition of your software should not include the autoload definition of any vendor module. Move that to the package definition you use to include the software.
And in other news: If it does not work with PSR-0, the classmap autoloader should take care of it.
Update
How to create the package for a repository not offering a composer.json
Essentially you'd need only a couple of pieces of information:
The version number and where it's located in that repository.
A name of the software you are trying to use - you'd probably only want to add a vendor name and not be too creative with the module.
Know how to autoload the package, i.e. know which path is used for the software and apply the classmap autoloader to it.
At least one of the following, preferredly both:
The URL of the repository that hosts the code
The URL of a download of a published version
In case of the "google-api-php-client", the a) URL of the repository is http://google-api-php-client.googlecode.com/svn/, the b) most current version number is 0.6.7, the A) download URL of that package is http://google-api-php-client.googlecode.com/files/google-api-php-client-0.6.7.tar.gz.
And now you fill it into this "template":
"repositories": [
{
"type": "package",
"package": {
"name": "name from (2)",
"version": "version from (1)",
"dist": {
"url": "URL from (4/2)",
"type": "tar or zip according to download"
},
"source": {
"url": "URL from (4/1)",
"type": "svn",
"reference": "tags/version from (1)"
},
"autoload": {
"classmap": ["path from (3)"]
}
}
}
]
And then you can require that exact package in your requirements: "require": { "name from (2)": "version from (1)" }
For the google package you are using this would essentially get you to use this:
"require": {
"google/google-api-php-client":"*"
},
"repositories": [
{
"type": "package",
"package": {
"name": "google/google-api-php-client",
"version": "0.6.7",
"dist": {
"url": "http://google-api-php-client.googlecode.com/files/google-api-php-client-0.6.7.tar.gz",
"type": "tar"
},
"source": {
"url": "http://google-api-php-client.googlecode.com/svn/",
"type": "svn",
"reference": "tags/0.6.7"
},
"autoload": {
"classmap": ["src/"]
}
}
}
]
The benefit of adding this mostly boilerplate stuff is that you get the downloading of the software for free now. You don't have to care about how to manually download, unpack and install the package. You did add the autoloading information for this software to your own composer.json, but it is contained in the package definition of the software you want to use, it is not contained in the autoloading area of your own software.
You also do not have to worry about Composer removing your manually downloaded package accidentally.
For anyone else looking to add a third party library to ZF2 using composer, here are the steps that worked for me.
Copy third party library to vendor folder
Add following line to composer.json
"autoload": {
"classmap": ["vendor/PATH TO LIBRARY"]
}
Run php composer.phar update
Then you should see all the classes that were in the 3rd party library in the file in the composer folder: composer/autoload_classmap.php
When instantiating any class from the library in your zf2 application, dont forget to prefix the class name with a \.
For example:
$client = new \Google_Client();

sublime text : open containing folder

I'm working on some file in my sublime text 2 editor, and I want to open a folder in which that file resides.
I know there is a 2 step procedure to do this already
step 1: right click and reveal in sidebar (ctrl+shift+r)
step 2: right click on the same file in sidebar and click open containing folder.
I would like to know if there is only one shortcut key to do the same. This is something that I use quite often.
You can add the line below to your Default (Windows).sublime-keymap:
{ "keys": ["ctrl+alt+e"], "command": "open_dir",
"args": {"dir": "$file_path", "file": "$file_name"} }
By default the editor has this item in context menu. If you need this feature on tabs you have to create a file with name "Tab Context.sublime-menu" in "\Data\Packages\User\" (if does not exist yet) and add this code:
[
{
"caption": "-"
},
{
"command": "open_dir",
"args": {"dir": "$file_path", "file": "$file_name"},
"caption": "Open Containing Folder…"
}
]
Do not forget formatting lines as a JSON file! If you do not need a separator before this menu item you need to delete first block with caption "-"! You can add any other menu in this file. For example:
{
"command": "copy_path",
"caption": "Copy File Path"
},
Install Open project path by shortcut. Then setup keybindings in your User keymap file
{
"keys": ["f10"],
"command": "open_project_folder"
},
{
"keys": ["ctrl+f10"],
"command": "open_file_folder"
}
Initiate the key bindings on a open file (f10 to open the directory you have set as the project folder, ctrl+f10 to open the folder of the current file.)
This worked for me: assuming you have opened the file whose enclosing folder you want to open, use the Menu > Project > Add Folder To Project command.
A new window should open with the enclosing folder. Just click 'Open' and you're done!
I found this plugin: https://github.com/kallepersson/Sublime-Finder
The instructions are pretty simple and straightforward. Now I just use CMD+SHIFT+P and type "finder" and press enter and it opens a finder window.
I think this might only work on macs though.
In sublimetext3 there is a package to sync current open file with the sidebar explorer.
SyncedSidebar

How do I setup/use ruby on rails snippets and autocomplete in sublime text 2?

I would appreciate if someone could direct me to a website that shows how to do this..
Can't seem to find anything decent enough via google.
This will be the first time I'm doing this kind of thing with a text editor.. It has got to the stage where typing out things like <%= %> is getting old and slow.
I've got a rails snippet package and also ryan-on-rails package installed. Just confused with how to start using them.
I'm on max osx - snow leopard
Kind regards
Update
This helped me out. http://webtempest.com/sublime-text-2-how-to-create-snippets/ but I still need a little practice.
I have a package "rails" can't remember where I got it but the triggering of snippets is working. I'd just like to find a nice list of the commands rather than have to go to each snippet and look for myself. I can find the by clicking on snippets but isn't there a way I can create a shortcut for that?
Also would like some auto indentation.. and also complete.
I'm puzzled that this isn't part of the default Rails package, but I found this to be just what I was looking for:
https://github.com/eddorre/SublimeERB
Since you're new to Sublime Text, I highly recommend you check out: ST2's Unofficial Documentation. If includes a ton of getting started info plus tons of info for extendibility and plugin development.
Another great "Getting Started" guide can be found here on Nettuts+.
If you're looking a list of your snippets and their associated shortcuts, go to "Tools > Snippets..." from your menu.
To expand <% into <%| %> (where | is the cursor), add the following you to your User-keybindings (Preferences > Keybindings - User):
{
"args": {
"contents": "% $0 %>"
},
"command": "insert_snippet",
"context": [
{
"key": "selector",
"match_all": true,
"operand": "source.ruby",
"operator": "equal"
},
{ "key": "preceding_text", "operator": "regex_match", "operand": ".*<", "match_all": true }
],
"keys": [
"%"
]
}
The latest beta includes improved auto-indentation, so if you don't have that installed, try that out.
As for autocompletion, Sublime Text 2 by default offers autocompletion of words in the current document (plus all of your snippets/completions from packages). However, if you're looking for IDE-like autocompletion, there is the SublimeCodeIntel plugin. I am reluctant to mention it because it has not been updated in months and the bug reports keep flowing in.
Hope that helps.
I use ERB Snippets
https://github.com/matthewrobertson/ERB-Sublime-Snippets
You can install via Sublime Package control
Cmd+Shift+P
Go to Package Control: Install Package.
Type ERB Snippets. Let it roll.
Then you can use tab autocomplete for lots of snippets such as:
print ERB tags = pe which auto completes to <%= %>
if block = if which auto completes to <% if %>...<% end %>
If you are looking for autocomplete suggest, change the auto_complete_selector in Preference like:
"auto_complete_selector": "text, source - comment",

Resources