I'm searching for a correct .sublime-build for ruby 1.9.3
so far i'm not been able to use gems with the ones i tried
a way to launch my .rb file with the terminal with a shortcut from ST2 should be great for me to
thank you
There are two possible ways, one involves editing the exec.py file that comes with ST2 so that the build process is not piped/captured but i had no luck in this, maybe someone with a python background can ?
The other method works for me, i edit the "c:\users\user\AppData\Roaming\Sublime Text 2\Packages\Ruby\Ruby.sublime-build" file that also comes with ST2 and change the contents to this.
I have no problem to use gems that are installed correctly like this.
{
"cmd": ["ruby", "$file"],
"shell": true,
"file_regex": "^(...*?):([0-9]*):?([0-9]*)",
"selector": "source.ruby, source.rb, source.rbw",
"variants":
[
{
"name": "Run",
"cmd": ["start", "ruby", "$file"],
"selector": "source.ruby, source.rb, source.rbw"
}
]
}
After that you can run Ruby scripts in two ways, the normal one with F7 and in the console with Ctrl-Shift-B (from Build). In order to avoid that the window closes after execution you need to end your script with a system 'pause'. In begin/rescue blocks it would also be best to put this command.
So a script would look like this
puts "test"
system 'pause'
EDIT: add the option "Open Command Window Here.." to the context-menu
First create and put the following in the file
c:\users\user\AppData\Roaming\Sublime Text 2 \Packages\User\opencommand.py
import sublime, sublime_plugin
import subprocess
import os
class OpenPromptCommand(sublime_plugin.TextCommand):
def run(self, edit):
dire = os.path.dirname(self.view.file_name())
retcode = subprocess.Popen(["cmd", "/K", "cd", dire])
def is_enabled(self):
return self.view.file_name() and len(self.view.file_name()) > 0
Then open C:\Users\user\AppData\Roaming\Sublime Text 2\Packages\Default\Context.sublime-menu and at the end add
{ "caption": "-", "id": "file" },
{ "command": "open_prompt", "caption": "Open Command Window Here…" },
{ "command": "open_dir", "caption": "Open Containing Folder…" },
{ "caption": "-", "id": "end" }
From now on you can right-click in a open script and open explorer or the command prompt in the folder where the script is saved.
in macOS the equivalent to windows start is open... ie:
Windows
start . (opens windows explorer at current path)
Mac
open . (opens finder at current path)
Related
I noticed that for node.js there's a debugger "auto attach" feature, which I would like to use if it was possible. However, I don't think I can use "auto attach" to automatically fire up the debugger after I've re-compiled my program. I compile my program using C/C++/Fortran using makefiles (and similar) so after running "make" I get a normal (linux) executable. I then execute that binary and often want to debug it right away, after this. I have the full binary path set to an environment variable "$myprog=/home/user/my-dev/bin/myApp".
So what I do is to run debug using "Attach to process" and every time I have to find the proper process in the dropdown list, but I do it too many times each day, each hour, it's becoming tedious and would like something smarter, "more automatically":
Instead of "auto attach" (only for node.js, as I understand it) I would like to modify my launch.json so it extracts the process-id automatically, using e.g. the shell command: 'pgrep -x "$myprog"' and maybe optionally bind it to a keyboard-shortcut... I'm guessing the line ""processId": "${command:pickProcess}"," needs to be modified, please see example configuration below:
{
"name": "(gdb) Attach (any)",
"type": "cppdbg",
"request": "attach",
"program": "/home/user/my-dev/bin/myApp",
"processId": "${command:pickProcess}",
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb"
},
Is it possible to modify the launch.json file so VS code understands that the variable "processId" should be substituted by the shell output from: 'pgrep -x "$myprog"' (obviously this PID changes, after every compilation and execution of the program to be debugged)? If so, I guess it is also possible to bind it to a keyboard-shortcut... Anyone knows how to achieve this?
Yes, it is possible with the use of the Tasks Shell Input Extension. It provides a vscode command that can return the result of a shell command.
The relevant parts of my workspace looks like this.
"launch": {
"configurations": [
{
...
"processId": "${input:FindVivadoPID}",
...
}
],
"inputs": [
{
"id": "FindVivadoPID",
"type": "command",
"command": "shellCommand.execute",
"args": {
"command": "pgrep 'ecold.*lnx64.g/vivado' -f",
"description": "Select your Vivado PID",
"useFirstResult": true,
}
}
]
}
Whenever I run Start Debugging, it automatically finds the relevent process and attaches.
This Stack Overflow question talks about the extension more generally.
If you can use LLDB and the Shell Input Extension doesn't work well for some reason, your program can also call Visual Studio Code with the debug information to ask it to connect as described here.
Rust:
#[cfg(debug_assertions)]
{
let url = format!("vscode://vadimcn.vscode-lldb/launch/config?{{'request':'attach','pid':{}}}", std::process::id());
std::process::Command::new("code").arg("--open-url").arg(url).output().unwrap();
std::thread::sleep_ms(1000); // Wait for debugger to attach
}
C:
char command[256];
snprintf(command, sizeof(command), "code --open-url \"vscode://vadimcn.vscode-lldb/launch/config?{'request':'attach','pid':%d}\"", getpid());
system(command);
sleep(1); // Wait for debugger to attach
Or add this to launch.json:
// This waits a second and calls VS code to attach lldb
"preLaunchTask": "Attach LLDB Later"
And then add this to tasks.json:
{
"label": "Attach LLDB Later",
"type": "shell",
"command": "/bin/bash",
// Called from a preLaunchTask. First wait for it to start up.
// Then call VS code and tell it to attach with the LLDB debugger.
"args": ["-c", "echo Waiting for launch...;sleep 2; code --open-url \"vscode://vadimcn.vscode-lldb/launch/config?{\\\"request\\\":\\\"attach\\\",\\\"pid\\\":$(pgrep --full --newest godot.\\*remote-debug)}\";echo LLDB attached."],
"isBackground": true,
// All this is needed so VSCode doesn't complain about the background task.
"problemMatcher": [
{
"pattern": [
{
"regexp": ".",
"file": 1,
"location": 2,
"message": 3
}
],
"background": {
"activeOnStart": true,
"beginsPattern": ".",
"endsPattern": ".",
}
}
]
},
But change "pgrep --full --newest godot.\*remote-debug" to search for your process. I used this to debug two languages simultaneously on the same Godot executable. A Compound Launch with the GDScript debugger and Tasks Shell Input Extension tried to start both debuggers simultaneously, and wouldn't even start the executable I wanted the PID until after the LLDB launch was configured. The background preLaunchTask fixed this catch-22.
eve : virtual box ubuntu16.04
I installed sublime text 3, and installed the plugin-in anaconda.
i configured the Anaconda.sublime-settings:
{
"anaconda_linting" : false,
"swallow_startup_errors": true,
"python_interpreter": "/home/cgy/soft/anaconda3/bin/python"
}
it's seem all ok, but when i make an .py file and build it ,such as that:
import pandas as pd
print("hello")
Can't find the build system, then i do that:tools->build system->new build system
create an file,and the content is that:
{
"shell_cmd": ["/home/cgy/soft/anaconda3/python", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
but the sublime console just out put:
File "/home/cgy/soft/sublime_text_3/sublime_plugin.py", line 795, in run_
return self.run(**args)
File "exec in /home/cgy/soft/sublime_text_3/Packages/Default.sublime-
package", line 238, in run
TypeError: Can't convert 'list' object to str implicitly
what's wrong it and how should i do to solve it?
thank you.
That error message is being generated because your build system is incorrectly using shell_cmd when you seem to have meant cmd instead.
If you use shell_cmd, the value should be a string that represents exactly what you would type into a command prompt, complete with things like redirection, && to chain commands, etc.
If you use cmd, the value should be an array of strings, where the first one is the name of the thing to run and the rest are the arguments.
To fix your problem you need to use cmd instead, or convert the list of strings into a complete string. If you go the latter route, be sure that you remember that you need to take care of quoting things like $file if your filename has spaces.
I am trying to give my Ruby program a different name. I am running this on OSx with Ruby version 2.1.2-p95. I am looking in the Activity Monitor which I believe uses top, but I am not 100% sure.
I have tried $0 = "My process name", $0 = "My process name\0", $PROGRAM_NAME = "My process name", $0 = "my_process_name". None of which seem to do the trick.
I have also tried:
require "fiddle"
def set_process_name(name)
Fiddle::Function.new(
DL::Handle["prctl"], [
Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP,
Fiddle::TYPE_LONG, Fiddle::TYPE_LONG,
Fiddle::TYPE_LONG
], Fiddle::TYPE_INT
).call(15, name, 0, 0, 0)
end
set_process_name("My process name")
I would love to have a cross-platform way to do this, but I'm mainly after an OSx way right now.
Similar question without satisfactory answer:
Change the ruby process name in top
I have not found a cross platform way to do it. The closest thing is using Process.setproctitle but on OSX it just works on the command line, not in the Activity Monitor app.
For OSX you will need bundling your script within an App and set the process name on the Info.plist file
https://www.sublimetext.com/docs/2/multiple_selection_with_the_keyboard.html
http://www.wdtutorials.com/2013/06/23/sublime-text-keyboard-shortcuts-cheat-sheet-win-os-x-and-linux#.U4SkQ5RdW8E
Both of those sites suggest that Ctrl + Shift + Up/Down will add another cursor. But my Mac OS X seems to have some behavior already set to that. It zooms all of the windows out or in depending on whether I use up or down.
Does anyone know a) how to disable this OS X functionality? or b) how to change the key binding for this in Sublime's "Default (OSX).sublime-keymap -User" file?
Happy trails!
-Pete
I figured it out after reading this: https://discussions.apple.com/thread/3331893?tstart=0
Basically, I just had to disable "Mission Control" and "Application Windows" in System Preferences >> Keyboard >> Shortcuts.
Add these lines to Key Bindings-User in Sublime settings
{ "keys": ["ctrl+alt+up"], "command": "select_lines", "args": {"forward": false} },
{ "keys": ["ctrl+alt+down"], "command": "select_lines", "args": {"forward": true} }
and you are good to go without changing anything in the preferences. now multicursors will work with
ctrl+alt(option)+up/down
You can use additional fn key to get pretty much the same key bindings usability: fn + up = pageup on mac.
{ "keys": ["ctrl+shift+pageup"], "command": "select_lines", "args": {"forward": false} },
{ "keys": ["ctrl+shift+pagedown"], "command": "select_lines", "args": {"forward": true} }
I found it quite usable for myself and there is no need to disable "Mission Control" and "Application Windows" in that case.
Another option is to use Karabiner (https://pqrs.org/osx/karabiner). It has a set of predefined examples but adding your own commands is a piece of cake.
Easy to install and to use and to customize.
Also available on github: https://github.com/tekezo/Karabiner.
I feel silly having to ask what seems like a basic question. I've Googled plenty, and I've examined the Default(OSX).sublime-keymap file, but I can't figure out:
How can I make the cursor jump to the beginning/end of the current buffer in Sublime2 on OSX?
Home/End scroll to the top/bottom respectively, but they do not position the cursor at the begin/end of the buffer.
Surely there is a way to do this. Some apps (e.g. Intellij) use CMD+Home/End for this, but that doesn't work either.
These work for me (Sublime Text 2 v2.0.1 on OS X 10.7.5)
⌘-↑: start of buffer
⌘-↓: end of buffer
The CMD-up and -down combos are the default shortcut for moving to the start and end of text buffers on OS X. They work in Safari text areas, too, for example. As such, they are not listed in the keymap file.
In windows you can use
Ctrl + Home -> to the beginning of the file
Ctrl + End -> to the end of the file
to customize short cut for "move to beginning of file" and "move to end of file"
{ "keys": ["ctrl+home"], "command": "move_to", "args": {"to": "bof"} },
{ "keys": ["ctrl+end"], "command": "move_to", "args": {"to": "eof"} },
{ "keys": ["ctrl+shift+end"], "command": "move_to", "args": {"to": "eof", "extend": true} },
{ "keys": ["ctrl+shift+home"], "command": "move_to", "args": {"to": "bof", "extend": true } },
An "almost" solution: as per standard OSX keybindings, shift + home/end will move the cursor from the current position to home/end, and select the text in-between. A side effect of this is that the cursor is positioned at home/end.
I would still like to know how to do this without selecting the intermediate text.
Darwin abcmacbook.local 14.3.0 Darwin Kernel Version 14.3.0: Mon Mar
23 11:59:06 PDT 2015; root:xnu-2782.20.48~5/DEVELOPMENT_X86_64 x86_64
OSX Yosemite Version: 10.10.3 (14D136)
In Sublime Text Stable Channel build 3083:
Command + down arrow takes me to end of buffer
Command + up arrow takes me to beginning of buffer
See if this works
beginning » CMD + left arrow
end » CMD + Right arrow