Is there a Textmate equivalent of "Format indenting of selected code" in Sublime Text 2? - ide

In Textmate, the keyboard shortcut ⌘⌥[ properly indents all the nesting on selected code.
Is there a similar option in Sublime Text 2? It's the only thing holding me back from switching and I've checked all documentation to try and find something similar.

I'm not sure if Sublime Text 2 has a generic code formatter, but there are a lot of really good packages out there that will provide various formatting for different languages.
Take a look at Package Control (used to manage plugins for Sublime).
http://wbond.net/sublime_packages/community
For formatting Ruby there's a pretty good package called BeautifyRuby. https://github.com/CraigWilliams/BeautifyRuby

What you are actually looking for is "reindent". It's under the Edit -> Line -> Reindent option. Strangely enough it's not bound to a keystroke. Simply installing code syntax packages will not cause them to apply the formatting to existing code.

Related

How to disable lines around text and explanations in Sublime Text

I have these lines around text and explanations popping up annoyingly.
Is there a way to turn these off?
I tried to look in settings and to adjust them but nothing works out.
P.S. ignore the code, it's just for example
White lines surrounding code like that are generally indicative of something like a code linter or other similar tool giving you an indication that there might be something wrong with the code (such as not following a code convention of some sort). The code explanation is a popup showing you the arguments and documentation for whatever function or method you're working on.
Both of these things are something that Sublime doesn't do on its own; you have installed a package of some sort that provides this capability.
If you were looking in the regular Sublime settings (Preferences.sublime-settings) for options that control this, they won't be there. In order to configure these away you would need to determine the package that you installed that's doing this and then configure that package not to do it or, if that's not possible, remove it.
If you use Preferences > Package Settings > Package Control > Settings - User from the menu, you can inspect the installed_packages setting to see what third party packages you installed and investigate which one of them is doing this.
Possible packages that do something like this would be Jedi or one of the Anaconda packages; essentially anything that says that it provides code support and assistance for Python is a candidate here.
Once you find the package in question, you can look in it's settings directly to see if you can turn the features you don't want off; failing that only removing the package will stop it from displaying these things.
These lines are called linting. Linting is the process of running a program that will analyse code for potential errors.
In sublime text it occurs usually because of some packages that you have installed...
In your case, it is actually the anaconda package and some other packages. It can be removed easily in a few simple steps.
In the sublime text window press ctrl+shift+P to open a command pallete and then type the name of the package. I typed anaconda because it is the one giving me these lintings so there will be an option Disable linting on this file. Just click on it, as shown in this picture .

Having difficulty getting ZeroBrane to highlight code, autocomplete, etc

https://i.imgur.com/SlQ41BS.jpg
Here is an example. For some reason code is simply not being highlighted using the Lua 5.2 interpreter. Autocomplete doesn't appear to be working correctly either. Also whenever I declare a function it doesn't automatically add a space in the middle and the end at the bottom which I've seen. These would all be immensely helpful starting off. I have never coded before.
I don't see any issue with the highlighting, as the Lua code in your snapshot is highlighted. I'm not sure why auto-complete is not working in your case, but if you type "pr" and don't see "print" and "pairs" offered when Lua 5.2 interpreter is selected, you may want to open a ticket and we'll investigate.

Ignore whitespace changes in IntelliJ changebars

I have a file from our repository where I ran auto-indent (because it was a mess), and now the whole file is marked by blue changebars (down the right hand side of the editor window), making it difficult to find my changes.
I am already ignoring whitespace changes in the diff window (as described here: Intellij and changes tab), is there a way to also do this in the editor window?
I couldn't find a way to completely ignore whitespaces, but IntelliJ (I'm using version 2016) lets you set an option to color whitespace-only changes differentely:
Editor -> General -> Different color for lines with whitespace-only modifications
which helps tremendously.
At the moment [idea 13.5] it seems that is not possible to ignore spaces in the standard editor. You can open a support ticket
We also faced this in the company due the different codestyles used, at the end we settle for:
setting a common codestyle that everyone editing the code should [actually must] follow
reformat the whole codebase to the given codestyle
recommit the formatted code [without any addition or deletion, just the reformat]
It took just a bit of time, but at the end now we are working far better. In this way from that moment onward, we would have all the time the code that would aesthetically the same trough next versions.
You can completely disable the highlight of whitespace modified lines in :
Settings -> Editor -> Color Scheme -> VSC -> Editor Gutter -> Whitespace-modified lines
And then uncheck the background color :
Essentially, you want Intellij to use the --ignore-all-space or --ignore-space-change upon a merge.
My developer team also deals with this challenge because we have different code formatting preferences. The result is every merge is painful for no reason. The team loves being able to have their code formatting, but this negates it.
As of now there is no solution. Intellij has the technology to ignore whitespace, so fixing this is really just adding a check box on the merge diff screen or even in the version control settings.
There is a feature requests IDEA-107714
Please up vote it!
https://youtrack.jetbrains.com/issue/IDEA-107714
Try this,
View --> Active Editor --> Show whitespaces
this is guaranteed to solve your problem

Wrapping comments with line breaks in PyCharm

I have comments that gets balloon (PEP 8: Line too long ... > 120)
I wish there was a command that will wrap the lines with few keystrokes.
Right now, even if I type Alt+Enter and press enter on Reformat file, nothing actually changes. Is there a setting or plugin I could use to accomplish the formatting easily?
Under the Edit menu, there is a Fill Paragraph option, which does what I believe you want. You can assign a key command to this in Preferences, under Appearance & Behavior -> Keymap (search for "fill").
Personally, I choose first stroke Esc, second stroke Q, because that's what I've always used in Emacs...
Firstly, reformatting won't work, not in Python at least, where whitespace is important. PyCharm's "Wrap when typing reaches right margin" option is what you're looking for. Now this will not work when you copy and paste code, but in the places where it gives you trouble, just press enter, and it will work.
To be able to auto-reformat comments (and code, for that matter) to honor a right margin after the fact, go into Project Settings under Code Style and then further under Python. Click the Wrapping and Braces tab, and check the "Ensure right margin is not exceeded" checkbox.
Now if you select a region of lines and then run the Code/Reformat Code... command, PyCharm will do its best to wrap the comments or code appropriately.
You will probably have to do some tweaking of the results to suit your stylistic taste. For example, I wish PyCharm would do aggressive filling of text in block comments, at least optionally so.
PyCharm will not reformat code such that it becomes invalid Python, so sometimes it will still leave a line longer than the margin (120 or whatever you set under Project Settings/Code Style/General).
With recent PyCharm this now is located at "Editor -> Code Style", with the checkbox named "Wrap on typing"
The Screenshot shows PyCharm version 2016.2.1 Professional.
Updated Answer:
Use "soft wraps." You can search for it in the help bar.
View > Active Editor > Use Soft Wraps
It won't work for existing text or text that's copied in, but will for any newly typed text.

Keyboard shortcut to Un/Comment out code in Mathematica 7?

A keyboard shortcut to comment/uncomment out a piece of code is common in other programming IDE's for languages like Java, .Net. I find it a very useful technique when experimenting through trial and error to temporarily comment out and uncomment lines, words and parts of the code to find out what is and isn't working.
I cannot find any such keyboard shortcut on the Mathematica front end in version 7. I know that it is possible to comment out code by selecting the code, right mouse click and select Un/Comment from the menu that appears but this is too slow while coding.
I tried to access this using the menu key Menu on the keyboard but Mathematica frontend doesn't respond to or recognise this key unlike other applications, this could have allowed a key combination for commenting. Can someone else verify that this isn't unique to my machine and that the key isn't recognised by mathematica. I looked at this question and looked in the KeyEventTranslations.tr file but I don't think there is any way to create a shortcut to do this(?). Should I just live with it?
Any other suggestions?
(I have seen there is an Emacs version of mathematica, I have never tried Emacs or this Mma version and imagine that it would have this ability but would prefer not to go to the trouble and uncertainty of installing it. Also I would guess that the Wolfram Workbench could do this, but that may not be worth the investment just for this.)
You can install the shortcut in Mathematica 7.0.x if you are willing to edit the Mathematica system file MenuSetup.tr. You can find it in the same location as the KeyEventTranslations.tr file (i.e. in the installation under "SystemFiles/FrontEnd/TextResources/platform"). In MenuSetup.tr, locate the following line under the definition of the Edit menu:
MenuItem["Check &Balance", "Balance", MenuKey["B", Modifiers->{"Control", "Shift"}]],
Immediately below that line, insert the following:
MenuItem["Un/C&omment Selection", KernelExecute[FE`toggleComment[]], MenuKey["/", Modifiers->{"Command"}], MenuEvaluator -> Automatic, Method -> "Queued"],
The Un/Comment Selection command is now available under the Edit menu, with the keyboard shortcut Cmd-/ or Alt-/ depending on your platform -- just like in Mathematica 8 where this command comes pre-installed.
Please take as read the usual disclaimers about hacking the Mathematica installation files -- no warranty is offered :)
I do not know of any way to map this function to some shortcut involving the Menu key.
Shortcut Key, No Menu
The preceding steps mimic what Mathematica 8 does by installing a new menu item. If you prefer to leave the menus unchanged, then you can install the shortcut in KeyEventTranslations.tr instead. Add the following line:
Item[KeyEvent["/", Modifiers->{Command}], KernelExecute[ToExpression["FE`toggleComment[]"]], MenuEvaluator -> Automatic, Method -> "Queued"]
You'll need a comma on the end of that line if it is not the last item in the list.
Select the code and press one of the following:
Alt+/
Alt-E-O
Alt+E+O
Notes:
Tested only on Windows, using Mathematica 8.
On my non-US keyboard (ABNT Brazil), the shortcut Alt+/ doesn't work, instead I use Alt+E+O.
Here is code for your KeyEventTranslations.tr file that will comment out code. I am still working on the other half.
Item[KeyEvent["/", Modifiers -> {Command}],
FrontEndExecute[{
NotebookApply[FrontEnd`InputNotebook[],
"(*\[SelectionPlaceholder]*)"
]
}]
],
This binds it to Alt+/ as it is in Mathematica 8.