How to run AStyle from inside Sublime? - sublimetext3

I already tried using the SublimeAStyle Package, but it didn't work. When I pressed the keys, the command would not fire (I checked in the console). Now I am trying to write my own key-shortcut to run the program on my source code. I have this:
{ "keys": ["ctrl+alt+f"], "command": "exec", "args": { "cmd": ["C:\\Program Files\\AStyle\\bin\\astyle.exe", "${file_name}"]} }
but the ${file_name} is not expanding to pass the file name to the command. Is there anything I am doing wrong?

Related

Visual Studio Code - how to add a vim editor command?

I'm trying to bind ":W" editor command to save the file just like ":w". I make a lot of this typos.
The vim plugin is: https://marketplace.visualstudio.com/items?itemName=vscodevim.vim
This settings.json code doesn't work:
"vim.normalModeKeyBindingsNonRecursive": [
{
"before": [":","W"],
"commands": [
"workbench.action.files.save"
]
}
]
Unfortunately this is not possible in vs code vim, but I ended up doing what bsaf suggested here and rebound : to ; so that I wouldn't accidentally be holding shift down while pressing w, which doesn't solve the problem you asked but it does solve the problem you mentioned in your post. You can do this by adding this to your settings.json file:
"vim.normalModeKeyBindings": [
{
"before": [";"],
"after": [":"]
}
]
You can still use : as normal, but now ; will also allow you to run editor commands.

"$file" variable nor working with exec command

I want to set a shortcut to open my current file using an external program (in my case, Visual Studio).
I thought I could use the $file variable, available in the build system. So it I write:
{ "keys": ["ctrl+o"], "command": "exec", "args": {"shell_cmd": "\"C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\Common7\\IDE\\devenv.exe\" $file"} }
I get in the Sublime console prompt:
Running "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe" $file
As you can see, the $file variable isn't expanded to the pull path of the open file. Does anyone know what's the problem here?
Working solution for (but for OS X) was to use it like this:
{ "keys": ["super+shift+option+o"], "command": "exec", "args": {"cmd": ["open", "-a", "ForkLift", ""]}}

Keep Gnuplot window open when building from Sublime Text

I am using the gnuplot package from PackageControl in Sublime Text 3 on Windows. My gnuplot code successfully builds when run from Sublime Text, but if using a terminal that outputs the plot to a graphics window (such as the default wxt), the window appears and closes immediately.
Presumably there is a way to edit the gnuplot.sublime-build file to keep the plot window from closing, but I have been unsuccessful so far.
My Sublime Text build file for gnuplot currently looks like this:
{
"cmd": ["gnuplot", "$file"],
"working_dir": "${project_path:${folder}}",
"selector": "source.gnuplot",
"variants": [
{
"cmd": ["start", "gnuplot", "-persist", "$file"],
"shell": true
}
]
}
Unfortunately, the -persist has no effect.
I had this problem as well... I ended up just adding:
pause -1
To the end of my script.

bash permission denied on C++ build&run chain keybiding

Through steps found:
Is it possible to chain key binding commands in sublime text 2?
Using the following Build System:
{
"cmd": ["g++", "$file", "-o", "${file_path}/${file_base_name}"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++, source.cxx, source.cpp",
"variants": [{
"name": "Run",
"shell": true,
"cmd": ["gnome-terminal -e 'bash -c \"${file_path}/${file_base_name};echo;read line;exit; exec bash\"'"]
}]
}
I created the following .py extension:
import sublime, sublime_plugin
class BuildAndRun(sublime_plugin.WindowCommand):
def run(self):
self.window.run_command("build")
self.window.run_command("build", {"variant": "Run"})
And keybiding:
{ "keys": ["ctrl+b"], "command": "build_and_run"},
The keybiding activates the extension correctly, but then in terminal it returns:
bash: /home/hadrian/Documents/new: Permission denied
'new' is the name of of .cpp file.
The problem is also that, if it only has (in the .py extension) build, it builds, if it only has run, it runs, but if it has both it returns that bash error.
I'm not being able to find out where this 'permission error' is created through the whole process.

Key binding. How to run a external script (external command/program) in sublime text 2 when pressing a key?

I would like to run a external python script (or external command/program) when I press a key on Sublime Text 2.
How can I do this?
Here is a solution:
Preferences->Key Bindings - User and put this in the file (overriding the [,] inside):
[
{ "keys": ["<your shortucut>"], "command": "exec", "args": { "cmd": ["<path to your script>"]} }
]
Where <your shortcut> as the name says is the shortcut (examples: F1, ctrl+shift+F1, etc.) and <path to your command> is the location of your command (examples: echo, /home/user/scripts/my_script.py, ls, etc.)

Resources