I'm trying to create a custom sublime-build file in MacOS Yosemite, that will execute ghci on console with my code preloaded. That will make my Haskell learning process faster and enjoyable. However, since I'm new to Haskell and Sublime Text, I have no idea what to write in the file.
I know that this code does the same for gnome-terminal:
{
"selector": "source.haskell",
"working_dir": "$file_path",
"cmd": ["gnome-terminal","-x","ghci", "$file"]
}
I found the code here.
check this: https://github.com/SublimeHaskell/SublimeHaskell
USAGE (From their Readme.md):
In short: Press Shift-Ctrl-P and type haskell to explore all commands.
When editing Haskell source files that are part of a Cabal project, automatic error highlighting and enhanced auto-completion are available.
Each time you save, any errors in your program will be listed at the bottom of the window and highlighted in the source code.
All source files in the project are scanned when the change. Any symbols that they export are provided in the auto-complete suggestions.
To use cabal-dev instead of cabal, set use_cabal_dev to true (or use command "Switch Cabal/Cabal-Dev") and specify cabal-dev absolute path. Completion list will be rescanned and build will use cabal-dev.
Stylish-haskell can be used to stylish file or selected text.
Use Ctrl-Shift-R to go to declaration and Ctrl-K-I to show symbol info with documentation. These command are also available through context menu with right-click.
Command 'SublimeHaskell: Browse module' is similar to ghci's browse command
To show inferred types use Show type (ctrl-k ctrl-h ctrl-t) command.
To insert inferred type use Insert type (ctrl-k ctrl-h ctrl-i).
You can jump between the errors and warnings with F4 and Shift-F4. To show hidden error output, use command Show error panel (ctrl-alt-e)
Related
How to use File : duplicate option from the palette using plugin in sublime text ?
In order to see which command is being run when a particular action is being performed, open the console (Ctrl`) and run
sublime.log_commands(True)
Next, open the Command Palette (command: show_overlay {"overlay": "command_palette"} will show up in the console) and select File: Duplicate. The console will close, but when you reopen it you will see that command: side_bar_duplicate {} has been logged. At this point, you can enter
sublime.log_commands(False)
to stop logging, as it tends to fill the console with unnecessary garbage.
As you can see from the name of the command, File: Duplicate is from the SideBarEnhancements plugin (defined here) and is not built-in to Sublime. Therefore, if you are making a plugin for public distribution, you users will need to have SideBarEnhancements installed first.
To call this (or any) command in your plugin, simply put
window.run_command("side_bar_duplicate")
into your code at the appropriate location.
As #OdatNurd reminded me, because SideBarDuplicateCommand is a subclass of sublime_plugin.WindowCommand, it can only be run on an instance of sublime.Window.
I would like to be able to map a keyboard shortcut to be able to open the settings and open the keybindings.
I would like it to behave the exact same as going to Menu > Preference > Settings \ Keybindings.
Is this possible?
If a command appears in a Menu or in the command palette, then it's possible to bind it to a key provided you can determine what the command is and what arguments it takes.
One way to determine that for a menu item is to use View Package File from the command palette and then open the appropriate menu resource. The main menu always comes from a Main.sublime-menu resource, so once you enter the command you can enter Main.sublime-menu in order to see all of the resources that match, then pick the one for the appropriate package.
For a command that appears in the command palette you can do the same by entering sublime-commands to see all of the files that are contributing commands to the command palette and then select the appropriate one to see what command it's executing.
For determining the command bound to a key (in case you want to go the other way and add it to a menu or the command palette) you would look for sublime-keymap files instead.
These options require you to either know the package that is contributing the command or be able to infer it based on what it does. The Default package is what contains the default Sublime behaviour; other files augment the files from that package.
Another method is to open the Sublime console with Ctrl+` or the menu item View > Show Console and then enter the command sublime.log_commands(True) to turn on command logging.
With that enabled you can take the action you want to know the command for and the console will tell you the command being executed and what arguments it's taking.
In your particular case, the output in the console would be:
command: edit_settings {"base_file": "${packages}/Default/Default ($platform).sublime-keymap", "default": "[\n\t$0\n]\n"}
command: new_window
The first of these is the appropriate command, and the second is that command executing a command of it's own to open a new window for the settings to be stored in.
Armed with that, you can make an appropriate key binding:
{
"keys": ["ctrl+alt+shift+k"],
"command": "edit_settings",
"args": {
"base_file": "${packages}/Default/Default ($platform).sublime-keymap",
"default": "[\n\t$0\n]\n"
}
},
Note that recent (as of the time of this answer) builds of Sublime have a bug in which commands executed from the command palette don't always get logged, in which case if that's how you want to determine the correct command you would have to look in the resource directly.
To add a more simple approach to OdatNurd's fantastic answer: I recently found myself wanting a shortcut to open my keybindings file and came across a slightly longer route using the Command Pallet that I was content with.
This doesn't answer the specific issue of creating a keyboard shortcut to open the user's .sublime-keymap file, but it does solve the general issue of getting to that file in a timely manner, without having to use the mouse.
The approach is:
Ctrl+Alt+P (Open Command Pallet)
Type: "keybind"
This gives:
Hit Enter and the user's .sublime-keymap file will be opened as it would be if you navigated to Menu > Preferences > Key Bindings.
I installed the toggle neo vintageous plugin for sublime text and set the key to ctrl+Alt+t, to toggle neovintageous. When I toggle it on it works, but when I toggle it of I get this error message:
Error loading syntax file
"Packages/NeoVintageous/res/Command-linemode.sublime-syntax":Unable to
read Packages/NeoVintageous/res/Command-linemode.sublime-syntax
Does any one know what it means, although it still toggles off after the error message, but I don't know why it keeps popping up whenever i try to do that
Error loading syntax file "Packages/NeoVintageous/res/Command-linemode.sublime-syntax":Unable to read Packages/NeoVintageous/res/Command-linemode.sublime-syntax
Generically speaking, this error message is telling you that there is something somewhere in Sublime (an open file or other widget) that thinks that it should be using a specific syntax definition, but that syntax definition can't be found. The syntax file named is the one that's causing the error.
If we examine the filename it mentions (Packages/NeoVintageous/res/Command-linemode.sublime-syntax) we can determine that the syntax file is in the NeoVintageous package itself.
In Sublime, any package that's installed is always "turned on" and active unless it's name appears in the ignored_packages setting, which tells Sublime that even though the package exists, it should pretend that it doesn't.
It's not explicitly stated anywhere in the README for this package, but all it's doing is modifying that setting on your behalf to either add or remove the NeoVintageous plugin to the setting.
When you add a package to the list of ignored packages when it's already loaded, Sublime responds by unloading the package from memory and acting like it does not exist.
So, taken all together, the problem that you're having here is that you have NeoVintageous turned on, something in Sublime is using a syntax definition from that package, and then when you toggle the package off, the syntax definition is unloaded and Sublime complains because the syntax it wants to use is no longer available.
I don't use either of those packages personally, but based on the name of the syntax being Command-linemode.sublime-syntax my guess would be that the syntax is being used in the ex command input that you can use to give ex commands to the package (probably to allow for auto complete or something like that).
If that's the case, you can probably stop the error from being displayed by closing the command window before you toggle the state of the package. I would imagine that the error popup would go away and not recur once the command input was closed, so the error is annoying but more or less harmless.
It may be worth raising an issue with the package author to let them know what's happening, if for no other reason than they can document that this will happen or modify this package to not be able to toggle the state of the package off while the syntax is currently in use.
Is there a way to add a keybind to reindent a highlighted block of code in Sublime Text 3?
I know there is a "reindent" option in Edit > Line > Reindent, but it has no keybind.
Also, that reindent funcion is not so "smart" and in some cases it gives weird results. Is there an addon that better solves this issue?
I mostly code in JavaScript if that helps.
Covering the first part of your question, it's possible to bind a key to anything that exists in the Menu or command palette, it's just a matter of finding out what command and arguments you need.
The easiest way to do that would be to open the Sublime console with Ctrl+` or View > Show Console, then enter the command sublime.log_commands(True), execute the command and see what it says:
>>> sublime.log_commands(True)
command: reindent {"single_line": true}
You can run the command command with False instead of True to turn off logging, or just restart Sublime.
With that knowledge, you can create a key binding using the command and arguments that were displayed by using Preferences > Key Bindings and adding the binding in the right hand pane.
In this case, that woulld look something like this (change the key as appropriate):
{
"keys": ["ctrl+alt+r"],
"command": "reindent",
"args": {
"single_line": true
}
},
Once you do this, not only is the key binding active but Sublime will also display the key that you selected in the menu next to the menu item as an extra reminder for you.
For the second part of your question, indeed the internal reindent and reformat of code is not ideal in Sublime; partially this is the result of its indentation system being powered by some simple regular expressions in the same manner as TextMate for compatibility reasons.
In any case, you can search Package Control for third party packages that might allow for better formatting/reformatting of code. In the case of JavaScript, something like JsFormat might be what you want.
Typically such a package only provides integration with an external tool that does the work and thus requires you to also install an external third party tool to function. In the specific case of JsFormat however, it bundles it's own formatter directly.
Is there way to have sublime text to build/compile real time as I type code so it can show my code errors if there's any? xcode has this feature.
for example, if i'm writing in a ruby file and in the first line i type:
print(hello)
and as i enter to the second line, sublime will tell me there's an undeclared variable "hello" in the first line?
This feature is not specific to the build/compilation process. What you're really looking for is linting.
You can use SublimeLinter coupled with SublimeLinter-ruby for ruby linting. There are also many more packages available for linting other languages at packagecontrol.io.