In IPython, typing a variable name at the command line will automatically print the contents of the variable.
In [75]: x = 1
In [76]: x
Out[76]: 1
However, when passing code from a file into IPython via the SublimeREPL plugin in Sublime Text, I have to run print(x) if I want to see anything (I'm using Windows in case it matters). To be explicit, my code is in a separate file, and I'm passing the line of code into IPython for execution via SublimeREPL's Ctrl+,l shortcut. Is there a way I can just pass x instead of print(x) and see the contents of x?
Related
Just as the title says, How do you do multiple line entry in the command line REPL of SuperCollider? For example, in Haskell, you use :{ and :} to open and close multiple line entry in ghci.
If you're using sclang with the -i flag (meaning e.g. sclang -i something), the keycode to execute previously entered text is esc, followed by a newline. For example:
~a = {
"test".postln;
}^[
~a.();^[
outputs: test
This works file if you're driving sclang from an IDE or another scripting context (this is used for sclang's unit tests). If you're using the repl, it appears that there ISN'T a way to do multiline entries - the repl uses readline which doesn't have multiline support out of the box. This should probably be filed as a bug.
I just installed Rascal and Eclipse (4.7.2) on Windows 10.
I've imported CLaiR (C Language Analysis in Rascal) and am trying to parse an existing C program
rascal>import lang::cpp::AST;
ok
rascal>parseCpp(|file:///c:/users/user/testme.cpp|)
I get a little over a screenful of information. The last line looks truncated and the last 3 characters are ...
Am I right? How do I increase how much is shown?
I've tried:
1. Windows, Preferences, Terminal, Terminal Buffer Lines = 1000000
2. Windows, Preferences, Run/Debug, Console, Console Buffer Size = 1000000
Any other ideas?
We indeed truncate the output of the result of an REPL command.
If you pass the value into iprintln (i for indented), you will get the full value. There is also iprintToFile to write it to a file. Another option is to use the functions util::ValueUI to view the value as either a collapsable tree, indented text, or a graph.
I know subl myfile.txt:5 would open “myfile.txt” on line 5. I however want to be able to, from the command line, open a file with say lines 5,9,15 highlighted or selected. I know adding –command should enable me to do that, but how? What would the command be?
There's no built-in command that I know of that can do this, but one can easily create one.
(Technically, it could be done using the bookmarks functionality from the Default package, and the built-in "Expand Selection to Line" functionality. However, experience shows that it would be better and more reliable to write a command in ST specifically for this purpose.)
In ST:
from the Tools menu -> Developer -> New Plugin...
select all and replace with the following
import sublime
import sublime_plugin
class SelectSpecificLinesCommand(sublime_plugin.TextCommand):
def run(self, edit, lines):
self.view.sel().clear()
for line in lines:
position = self.view.text_point(int(line) - 1, 0) # internally, line numbers start from 0
self.view.sel().add(self.view.line(position))
save it, in the folder ST recommends (Packages/User/) as something like select_lines.py (file extension is important).
subl myfile.txt
subl --command "select_specific_lines { \"lines\": [5, 9, 15] }" (this style of escaping the quotes for JSON strings works from the Windows Command Prompt and Linux's Bash)
Why did I specify the command on a separate line / call to subl? Because of these 2 caveats:
ST must already be running, otherwise commands specified on the command line may not get executed, because the plugins haven't loaded yet.
the command could get executed before the file is loaded.
Arguably, point 2 could still happen with multiple invocations of subl, but hopefully it is less likely. There is an open issue on the ST bug tracker for better command line command handling: https://github.com/SublimeTextIssues/Core/issues/1457.
I want to use gvim as the standard editor for Matlab. It used to work on Linux but now I am forced to use windows and I can't seem to figure out how to set the editor such that files are opened in gvim in a new tab.
In the preferences there is a field which allows to pass a command that points to the prefered text editor. That works, but things fail when I try to give additional options, in my case that would be "--remote-tab-silent" to tell gvim to open the file in a running instance in a new tab. More specifically, the following line in the matlab preferences works:
C:\pathtovim\gvim.exe
while this one fails
C:\pathtovim\gvim.exe --remote-tab-silent
A command line opens with the following error message (my own translation from German):
The command ""C:\pathtovim\gvim.exe --remote-tab-silent"" is either spelled incorrectly or could not be found.
My guess is that it has something to do with the additional quotes, I have no idea why the command is issued with quotes, even though in the field I put it without. The follwing commands work when typed into the command line directly:
"C:\pathtovim\gvim.exe"
C:\pathtovim\gvim.exe --remote-tab-silent file.m
and this one fails:
"C:\pathtovim\gvim.exe --remote-tab-silent file.m"
I'd really appreciate any help! Thanks!
I can't find a good way to hack around it through the MATLAB settings; it looks like MATLAB is stupidly expecting the text editor to take only file names as arguments.
I think your best option, is to create a .bat script that simply passes any arguments it receives on to Vim, inserting the --remote-tab-silent.
I.e. create a .bat file with these contents:
"C:\pathtovim\gvim.exe" --remote-tab-silent %*
Then set up your MATLAB preferences to invoke the .bat file rather than Vim.
In iPython, when using the command shell command (the exclamation point operator), is there a way to do line continuation of long string literals?
E.g.
t = !echo "Hello"\
"World"
t
produces ['Hello'] as the value for t instead of the expected ['HelloWorld'].
You can use a "cell magic" (which is basically a multi-line version of other magics like !). If you enter %%bash at the command prompt, it will give you a new line with ..., meaning that you should type your command. Press enter again, and you get another ..., until you just hit enter twice in a row, and it runs your commands. For example, you can type just the following.
%%bash --out t
echo "Hello "\
"World"
(and hit enter twice at the end). It works as expected. In particular, note the --out t, which stores the standard output in the variable t. If you evaluate that now, you get 'Hello World\n'. You can also get the standard error output with --err, as described nicely on this page.
In the ipython notebook, you just put the whole thing in one cell and evaluate it all together. (If you haven't tried the notebook, I highly recommend it.)