How to run existing Clojure programme in Sublime REPL - clojure

I have setup sublime REPL(Sublime 2, MAC) and able to run small Clojure programs like (+ 2 2). I have created a small project using lein lein new app clojure-noob and I am able to run it via lein repl. And it loads the main class defined inside the project. How can I load the same main class in Sublime REPL.

All you need to do is open your project's project.clj file in Sublime, make sure it has focus, then select Tools → SublimeREPL → Clojure → Clojure. This runs lein repl in project.clj's folder.
If you'd prefer to not have to go through so many submenus to open the REPL, you can do this:
Select Preferences → Browse Packages… to open the Packages folder (~/Library/Application Support/Sublime Text 3/Packages) in Finder.
Go to the User folder and create the following hierarchy: Packages/User/SublimeREPL/config/Clojure.
Create a new file in Clojure called Main.sublime-menu and open it in Sublime with the JSON syntax.
Add the following to the file:
[
{
"id": "tools",
"children":
[
{"command": "repl_open",
"caption": "Clojure",
"id": "repl_clojure",
"args": {
"type": "subprocess",
"encoding": "utf8",
"cmd": {"windows": ["lein.bat", "repl"],
"linux": ["lein", "repl"],
"osx": ["lein", "repl"]},
"soft_quit": "\n(. System exit 0)\n",
"cwd": {"windows":"c:/Clojure",
"linux": "$file_path",
"osx": "$file_path"},
"syntax": "Packages/Clojure/Clojure.tmLanguage",
"external_id": "clojure",
"extend_env": {"INSIDE_EMACS": "1"}
}
}
]
}
]
Once you save the file, you will now have a Tools → Clojure menu option.

Related

How to hit Vscode breakpoints in unit tests from within a docker-compose setup running Django

What I'm trying to do seems simple enough, but it's been crazy hard to actually get there. I have a Django application that runs in a docker-compose environment, and I want to run and debug the unit tests with breakpoints in Vscode.
Since this is a big project with a team that doesn't necessarily use vscode, I can't add libraries willy-nilly (like ptvsd, for example). I'm hoping there's a magic configuration for tasks.json and launch.json that will makes things work.
I have a container for a postgres database, one for django, and one for redis, all defined in docker-compose.yml. There's a command that I can run in the terminal that will run the tests, it's:
docker-compose run --rm app python manage.py test
where app is the django app container. I'd love to be able to run this command in such a way that it can hit breakpoints in vscode.
My incomplete stab at the launch.json file looks like this:
{
"configurations": [{
"name": "Docker: Python - Django",
"type": "docker",
"request": "launch",
"preLaunchTask": "compose-for-debug",
"python": {
"pathMappings": [{
"localRoot": "${workspaceFolder}",
"remoteRoot": "/app"
}],
"projectType": "django"
}
}]
}
And my tasks.json:
{
"version": "2.0.0",
"tasks": [{
"type": "docker-build",
"label": "docker-build",
"platform": "python",
"dockerBuild": {
"tag": "dockerdebugging:latest",
"dockerfile": "${workspaceFolder}/Dockerfile",
"context": "${workspaceFolder}",
"pull": true
}
},
{
"type": "docker-run",
"label": "docker-run: debug",
"dependsOn": [
"docker-build"
],
"python": {
"args": [
"test",
"--nothreading",
"--noreload"
],
"file": "manage.py"
}
}
]
}
I think I need to convert the build task to a docker compose task somehow, but I just can't figure out how its done. It may also make sense to run the containers in the terminal, and somehow make vscode attach to them with breakpoints enabled.
Even some help with how to approach this would be great. I know it's a tricky one.
This question became somewhat popular, but a direct answer never came. If you've landed here looking for a way to hit breakpoints inside vscode using docker, my suggestion is to use the Remote Container extension.
When the container is up, right click it and open a vscode window inside of the container itself. Then everything will just work.

How to run C++ in command prompt from Sublime Text?

The build systems bundled with Sublime Text run the program in the small window below the text editor pane. This is inconvenient to some as user input cannot be taken in such a case.
What is the build system script to execute the program in a separate cmd window directly from Sublime Text?
Go to Tools > Build System > New Build System...' and paste the following in the file:
{
"cmd": ["g++.exe", "-std=c++11", "-o", "$file_base_name", "$file", "&&", "start", "cmd", "/c", "$file_base_name & echo. & echo. & pause"],
"shell": true,
"selector": "source.c++"
}
Save the file, and while compiling your C++ code from Sublime, choose the newly created build system from Tools > Build System

Sass build issue for sublime text 2 : no file is generated

I've downloaded Ruby and installed Sass. I then installed Sass Build for Sublime Text 2 through the package manager but when I try to build my css file, nothing happens.
It says :
[Decode error - output not utf-8]
[Finished in 0.1s with exit code 1]
Does anyone know how to fix this ?
By default, the output encoding in a sublime build is utf-8. This will cause an error if there are non-utf-8 characters in your sass or scss.
You can create a custom sass .sublime-build along the lines of the following by going to Tools > Build System > New Build System.
{
"cmd": ["sass", "--update", "$file:${file_path}/${file_base_name}.css", "--stop-on-error", "--no-cache"],
"selector": "source.sass, source.scss",
"line_regex": "Line ([0-9]+):",
"osx":
{
"path": "/usr/local/bin:$PATH"
},
"windows":
{
"shell": "true"
}
"encoding": "cp1252"
}
Note the key (the only one that'll be surplus from the installed package) "encoding": "cp1252". Its value will have to match that of your source or be a superset thereof. There's a fairly comprehensive list of codecs in the Python docs.

Run program in cmd mode after building from Sublime Text 2

I'm using Sublime Text 2 with MinGW as a build system to compile my c++ programs. I have the following build added to my Sublime:
{
"cmd": ["mingw32-g++.exe", "-o", "$file_base_name", "$file"],
"path": "C:\\Program Files (x86)\\MinGWStudio\\MinGW\\bin\\"
}
Now I want to run the program that I've just compiled in a cmd window (not in the Sublime console) What should I add to that command ?
Thank you.
A build system like the following will run your program in a new cmd window after you build it:
{
"cmd": ["mingw32-g++.exe", "-o", "$file_base_name", "$file"],
"path": "C:\\Program Files (x86)\\MinGWStudio\\MinGW\\bin\\",
"variants": [
{
"cmd": ["start", "cmd", "/k", "$file_base_name"],
"shell": true,
"name": "Run"
}
]
}
The "Run" name has special significance, it means that when you select this build system as your default, hitting CtrlB will compile your program, and then hitting CtrlShiftB will execute it. start is the command to start running a separate process, cmd is short for cmd.exe, the Windows command line program, and the /k option keeps the resulting window open after your program exits so you can see its output, run additional commands, or what have you.
For those trying this on MacOs (High Sierra) and Sublime 2, you might want to consider the next string in your build system:
{
"cmd": ["make", "${file_base_name}"],
"selector" : "source.c",
"variants": [
{
"cmd": ["/Applications/vice/x64sc.app/Contents/MacOS/x64sc $file_base_name"],
"shell": true,
"name": "Run"
}
]
}
This example will start Vice (the C64 emulator) installed in its specific location, which takes the file base name as an argument. Please note that I do not use "start", "cmd" or "/k".

Build and run with arguments in Sublime Text 2

I'm running on MacOS X and I'm using Sublime Text 2 to code.
I've found the command + B option to build and command + shift + B to build and run.
Is it possible to run a program (or script) and pass arguments. Exemple:
myProg arg1 arg2
Note: I'm using multiple languages (C++, Java, Python), so I hope there is a way to set the arguments for each project and not for all build.
Edit
I want to set the parameters for a program call, a little bit like in eclipse where you can set the arguments when you run your program.
For each project you can create a .sublime-project file with your specific build_system on it:
{
"folders":
[{
"path": "src"
}],
"build_systems":
[{
"name": "Run with args",
"cmd": ["python", "$file", "some", "args"]
}]
}
This way you don't pollute the global Build System menu and won't have to worry about switching build system as you switch projects. This file is also easy to access when you need to change the arguments:
Cmd-Shift-P > Edit Project
InputArgs does precisely what you're looking for. It shows an input dialog every time you run build(ctrl+b) and you can supply it with space separated arguments from within sublime text.
I found a simple solution is create a python file in the same directory:
import os
os.system("python filename.py some args")