Sublime Text 2 REPL run iPython file with a user Plug-in - sublimetext2

I am trying to run an iPython file in an interactive shell in Sublime Text 2. This is my first plugin I've written.
Here's what I have so far:
import sublime, sublime_plugin
class IpydevCommand(sublime_plugin.WindowCommand):
def run(self):
self.window.run_command('repl_open',{"type": "subprocess",
"encoding": "utf8",
"cmd": ["ipython", "-i", "$file_basename"],
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "ipython",
})
self.window.run_command('move_to_group', { "group": 1 })
The issue here is that I don't get an interactive environment after. The view is all messed up. Any ideas how to fix this?
Thanks

Instead of running a notebook, you can directly call ipython using following configuration at the keymap bindings:-
[
{ "keys": ["f9"], "command": "repl_open",
"caption": "Python - IPython",
"id": "repl_python_ipython",
"mnemonic": "p",
"args": {
"type": "subprocess",
"encoding": "utf8",
"autocomplete_server": true,
"cmd": {
"osx": ["python", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"],
"linux": ["python", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"],
"windows": ["python", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"]
},
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python",
"extend_env": {
"PYTHONIOENCODING": "utf-8",
"SUBLIMEREPL_EDITOR": "$editor"
}
}
}
]
So, By clicking F9, it will open ipython on new shell

Related

Visual Studio Code - Launching GDB in specific directory

I just have a quick question:
EDIT: This is run under Ubuntu 20.04 WSL2 using Visual Studio Code.
So I am debugging a kernel for gdb and the symbol files require that GDB is launched in the project directory, but the problem is GDB keep launching in the location of the program:
-exec pwd
Working directory /home/user/project-directory/obj/kern
I need GDB to stay in the project-directory:/home/user/project-directory
In the VSCode launch.json file, I made a workaround by adding a custom launch setup as shown below:
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Kernel",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/obj/kern/kernel",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"printCalls": true,
"showDevDebugOutput": true,
"setupCommands": [
{
"description": "Change back to the workspace folder",
"text": "cd ${workspaceRoot}",
"ignoreFailures": true
},
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
// "preLaunchTask": "Launch Qemu (no graphic)",
"miDebuggerPath": "/usr/bin/gdb",
"miDebuggerArgs": "",
"targetArchitecture": "x86_64",
"customLaunchSetupCommands": [
{
"text": "target remote localhost:1234",
"description": "Connect to QEMU remote debugger"
},
{
"text": "symbol-file obj/kern/kernel",
"description": "Get kernel symbols"
},
// {
// "text": "set architecture i8086",
// "description": "Sets the current architecture"
// }
],
"avoidWindowsConsoleRedirection": true
}
]
}
The ${workspaceFolder} and ${workspaceRoot} are located in the project's directory, but without the setup to change back into the workspace folder, it won't work. Any tips would be appreciated!

vscode launch.json configuration

I have an issue with launch a cpp project file with vscode, here is my error
launch program {workspace domain}\build\Debug\outDebug does not exist.
and that's true, but i want to know can I add a parameter to my launch.json file or edit it, to work like : if a there is no directory to put the build file into it, so make it!
is it possible to do that ?
here is my launch.json file source
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"cwd": "o:\\Developing\\Projects\\Training\\c++\\School",
"environment": [],
"program": "o:\\Developing\\Projects\\Training\\c++\\School\\build\\Debug\\outDebug",
"internalConsoleOptions": "openOnSessionStart",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"externalConsole": false,
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
See docs:
https://code.visualstudio.com/docs/cpp/launch-json-reference
May be there is solve.

g++ not detected in VS Code

I'm trying to compile c++ inside VS Code.
I have MinGW installed.
I've followed the steps in this video: https://www.youtube.com/watch?v=rFdJ68WbkdQ
And the steps at the "getting started" docs https://code.visualstudio.com/docs/languages/cpp
Actually, my config shows like this:
{
"configurations": [
{
"name": "Mac",
"includePath": [
"/usr/include",
"/usr/local/include",
"${workspaceRoot}"
],
"defines": [],
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"/usr/include",
"/usr/local/include",
"${workspaceRoot}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
},
"macFrameworkPath": [
"/System/Library/Frameworks",
"/Library/Frameworks"
]
},
{
"name": "Linux",
"includePath": [
"/usr/include",
"/usr/local/include",
"${workspaceRoot}"
],
"defines": [],
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"/usr/include",
"/usr/local/include",
"${workspaceRoot}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
},
{
"name": "Win32",
"includePath": [
"C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.11.25503/include/*",
"C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.11.25503/atlmfc/include/*",
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.16299.0/um",
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.16299.0/ucrt",
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.16299.0/shared",
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.16299.0/winrt",
"${workspaceRoot}"
],
"defines": [
"_DEBUG",
"UNICODE"
],
"intelliSenseMode": "msvc-x64",
"browse": {
"path": [
"${workspaceRoot}",
"C:\\MinGW\\lib\\gcc\\mingw32\\6.3.0\\include\\c++",
"C:\\MinGW\\bin"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 3
}
And the "tasks.json" file has the following:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "‪‪g++",
"args": [
"-g", "Calculator.cpp", "-o","Calculator"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher":"$gcc"
}
]
}
But when I hit "run main task" it prompts:
"> Executing task: ‪‪g++ -g Calculator.cpp -o Calculator <
'‪‪g++' is not recognized as an internal or external command,
operable program or batch file.
The terminal process terminated with exit code: 1"
How can I get gcc detected?
I'm using VS Code with Windows 10 machine BTW.
If you have not added the folder path to windows, try that first.
If that still does not work try adding the full path in "task.json" instead of just g++.
Something like this:
C:/MinGW/bin/g++

Enter Input to sublime text

I am using sublime text 2 as the editor for my programs and using this code
{ "cmd": ["g++", "$file", "-o", "$file_base_name"],
"selector": "source.c++", "working_dir": "$file_path",
"variants": [ { "name": "Run", "cmd": ["g++", "$file", "-o", "$file_base_name", "&&", "$file_path/$file_base_name"], "shell": true } ]
}
I am able to run the c++ programs but unable to use test inputs in it.
How do I do that...
P.S. I don't wanna take inputs from any file but give to the console itself.

Adding Custom Menus in Sublime Text

How to add a custom Menu item in SublimeText 2 .
Any Ideas ??
I see there is a Main.sublime-menu file but dont know how to edit it.
Thanks!
The *.sublime-menu file is simply JSON. You can create a Main.sublime-menu in your user directory and it will be merged with other menu entries. It may be beneficial to look through the Main.sublime-menu files third party plugins have. These are generally much shorter, so may be easier to understand some of the things you need to define in each entry.
edit
You can use the following as a plugin to open notepad with an arbitrary file.
import sublime
import sublime_plugin
import subprocess
import threading
class OpenNotepadCommand(sublime_plugin.TextCommand):
def run(self, edit, filename=None):
th = NotepadThread(filename)
th.start()
class NotepadThread(threading.Thread):
def __init__(self, filename=None):
self.filename = filename
threading.Thread.__init__(self)
def run(self):
if self.filename is not None:
subprocess.call("notepad.exe %s" % self.filename)
else:
subprocess.call("notepad.exe")
When you are creating a menu item use something like the following for the command and arguments.
{
"command": "open_notepad",
"args": { "filename": "<the absolute path here>"}
}
Easier option if what you want is just run a command. Create a file Context.sublime-menu inside your Packages/User directory, and add the following:
[
{ "caption": "<Your caption here>", "command": "exec", "args": {"cmd": ["<your cmd name>", "<arg1>", "<arg2>", <...>]} }
]
Exemple: Adding a menu item to the context menu that just run dir:
[
{ "caption": "List files in current dir", "command": "exec", "args": {"cmd": ["dir"]} }
]
I know this way too late to join the party and add my 2 cents. Anyway, Main.sublime-menu is a file that allows you to add menu items to the top menu i.e [File, Edit, Selection, Find, View, Goto, etc.]
I recently added a new section "Dev" just to figure it out. I also wanted a way to trigger browser previews for a specific browser. Check it out.
[
{
"caption": "Dev",
"mnemonic": "Z",
"id": "dev",
"children": [
{
"caption" : "Previews",
"children": [
{ "caption": "Markdown Live Preview", "command": "new_markdown_live_preview", "id": "markdown_live_preview" },
{ "caption": "Preview in Default Browser", "command": "view_in_browser", "id": "markdown_live_preview" },
{ "caption": "Preview in Firefox", "command": "view_in_browser", "args": { "browser": "firefox" }, "id": "markdown_live_preview" },
{ "caption": "Preview in Chrome","command": "view_in_browser", "args": { "browser": "chrome" }, "id": "markdown_live_preview" },
{ "caption": "Preview in Safari", "command": "view_in_browser", "args": { "browser": "safari" }, "id": "markdown_live_preview" },
]
},
]
}
]
Anyway, this still works in ST3. Just in case anyone stumbles around here.