New Feature: Expand to cell
Hey there! A while ago, I implemented a feature to expand to the full containing block regardless of where in the block you are in (as opposed to current behavior which requires that you are on the first line of the block (with # %%) to run the full cell. This matches the behavior of R studio and (to some extent) jupyter notebooks.
Would you consider a pull request? Unfortunately, I made the change on an old version and so it's not trivial to integrate into master, which is why I'm asking before I put in the time.
Nice! I was thinking of doing the same thing!
I just had a quick look at the code ... and it seems relatively trivial to adapt the existing code base to do this.
The current process, as implemented in the block_expand method, is to search from the current line to the end of the file for the block ending comment (as defined in the settings, and by default presumed to be # %%).
To send code blocks while the cursor is somewhere within the block, rather than at the top, like you suggest, would simply require running this same search that is currently performed upward and downward when necessary.
If you've done something like this, I might be inclined to merge it in manually myself. It would definitely be a nice addition to the library!!
You can find my version here https://github.com/fredcallaway/SendCode but I noticed that master currently has a "block_start_pattern" preference and a corresponding block_expand method in getter... so i feel like this should already work. My hacked up version also has a bunch of extra stuff to emulate RStudio that probably won't be useful to you.
However, if you're into cells, you may find this little command useful: https://github.com/fredcallaway/Fredlime/blob/master/main.py#L94
{ "keys": ["alt+down"], "command": "jump_cell"},
{ "keys": ["alt+up"], "command": "jump_cell", "args": {"backward": true}},
I'm sorry, I just noticed that you're already aware of the block_expand method. I think it might actually be pretty easy to adapt block_expand to use my find_surround helper.
https://github.com/fredcallaway/SendCode/blob/master/code_getter/getter.py#L7
Hi, I'm looking for this behavior.
To send code blocks while the cursor is somewhere within the block, rather than at the top
Could you please guide me how I can do that if this is already done?
I don't think this is possible with the main package. I have it in my fork, which you could install by removing the standard one and cloning directly into your Packages folder.
https://github.com/fredcallaway/SendCode
Then add { "keys": ["ctrl+enter"], "command": "send_code", "args": {"cell": true} in your sublime-keymap file.
But beware, I've made lots of arbitrary changes to the code to suit my needs; not sure you will like all of them. The basic block expansion logic is implemented in commit d63a2987c269.
Thanks @fredcallaway
I removed the standard one and installed yours using Add Repository and Install Package. Now SendCode exists in this directory: Roaming\Sublime Text\Packages. Then, I updated the keymap file. But nothing happens. Any idea?
Can you show me the console output with sublime.log_commands(True)? (View > Show Console). For example, with the file
# %%
| # cursor location
x = 1
# %%
If I hit ctrl+enter, the console prints:
command: send_code {"cell": true}
command: terminus_send_string {"string": "\u001b[200~# %%\n\nx = 1\u001b[201~"}
This is the error:
command: send_code {"cell": true} Traceback (most recent call last): File "F:\Sublime Text\Lib\python33\sublime_plugin.py", line 1488, in run_ return self.run(edit, **args) File "C:\Users\mrr\AppData\Roaming\Sublime Text\Packages\SendCode\send_code.py", line 100, in run sender = CodeSender.initialize(self.view, prog=prog, from_view=cmd is None) File "C:\Users\mrr\AppData\Roaming\Sublime Text\Packages\SendCode\code_sender\sender.py", line 35, in initialize syntax = Settings(view).syntax() File "C:\Users\mrr\AppData\Roaming\Sublime Text\Packages\SendCode\settings.py", line 15, in init def init(self, view): AttributeError: 'NoneType' object has no attribute 'load_settings'
That line is self.s = sublime.load_settings("SendCode.sublime-settings"). I have no idea how sublime could be None. I assume you tried restarting Sublime Text?
Yes, I did. But this error was before that one:
reloading python 3.3 plugin SendCode.send_code
Traceback (most recent call last):
File "F:\Sublime Text\Lib\python33\sublime_plugin.py", line 308, in reload_plugin
m = importlib.import_module(modulename)
File "./python3.3/importlib/init.py", line 90, in import_module
File "
Ah weird, that folder somehow didn't make it into the git repo. I fixed it. Try pulling the updated repo?
Thanks @fredcallaway. It is loaded successfully and when I press ctrl+enter, the cursor moves to the next cell, but nothing moves to terminus. This error also appears in the console:
ConEmuC.exe not found. Specify the path to ConEmuC.exe in SendCode.sublime-settings.
Oh Sorry, my bad. I didn't adjust the settings. This is working as expected and I deeply appreciate that.
Is it possible to set the auto_advance in the args? So that users can create a keymap to "run" or "run and advance".
{ "keys": ["ctrl+shift+enter"], "command": "send_code", "args": {"cell": true, "advance": true}},
I also have commands to move up and down cells without running them here (you could rename the file and put it in the Packages/User/)
{ "keys": ["alt+down"], "command": "jump_cell"},
{ "keys": ["alt+up"], "command": "jump_cell", "args": {"backward": true}},
Oh, thank you so much. That's really great.