-
-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggestion for a better python support #274
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the proposal.
I would like to avoid creating more ways to send text to REPL instances, also, the goal o the PR is to fix the python REPL integration, so new ways of sending text to the REPL should be in another proposal. I would also rather to have as little options as possible, so let's try to fix that without adding more options to the code.
I did a few suggestions there, let me know what you think.
Thank's for your explanation. I already suspected that it was a bit too much for a single pull request. Can absolutely understand your point of view regarding maintainability. In some places it may make more sense to simply expand the documentation instead of new functions. I like the idea with filetype specific script. I could also imagine to write and maintain a python-plugin based on neoterm myself. Would have some more ideas such as interactive debugging. |
That's an option, but I think with the filetype-specific REPL code most of the default behavior could be easily done. I'm looking forward to see this PR updated. 😄 |
Everything works for python and ipython like in my first screen video. In addition, I have embedded the function of jkroes @ d6c5098. A python specific file was added.
I will continue to test this on occasion, but so far it seems to be working quite well. |
autoload/neoterm/repl/python.vim
Outdated
@@ -0,0 +1,57 @@ | |||
"init python specific settings | |||
if !exists('g:neoterm_repl_ipy_magic') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it magic
a term used in the python community? Is the name of this variable is meaningful to someone starting in the python community?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it is. Read here. The currently used command use is the ipython-paste-magic. I should probably insert the full name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! That's good to know, thanks for sharing the reference.
So, I think we should the full qualified name here, just to be more clear:
if !exists('g:neoterm_repl_enable_ipython_paste_magic')
It's better to be a long name that it's more clear than a short one.
I've been thinking for a while how to cover cell mode with the existing commands such as the g-x movement. Generally it's possible to search for the marker I have already considered using the sign column to set graphical markers instead of the text markers. I*ve currently read the docs to understand how |
@@ -24,12 +24,11 @@ function! neoterm#repl#term(id) | |||
if has_key(g:neoterm.instances, a:id) | |||
let g:neoterm.repl.instance_id = a:id | |||
let g:neoterm.repl.loaded = 1 | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's keep the diff with the minimum. Avoid unnecessary changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, sry.
autoload/neoterm/repl/python.vim
Outdated
if a:value[i] =~ 'python' | ||
let l:pyCmd = 1 | ||
if a:value[i] == 'ipython' | ||
let g:neoterm_repl_python[i] = 'ipython --no-autoindent' | ||
endif | ||
endif | ||
if executable(split(a:value[i])[0]) == 0 | ||
let l:invalid = 1 | ||
endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In python i would create a function to handle the list item and the string. Do you know if it is possible here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I don't understand your intention. What do you mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Has already cleared up.
endif | ||
endfunction | ||
|
||
function! neoterm#repl#python#exec(command) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think to make things a bit more explicit in here, as well, like:
function! neoterm#repl#python#exec(command)
if g:neoterm_repl_ipy_magic == 1 && join(g:neoterm_repl_command) =~ "ipython"
let l:cmd = s:ipython_magic_command_for(a:command)
elseif join(g:neoterm_repl_command) !~ 'ipython'
let l:cmd = s:ipython_command_for(a:command)
else
let l:cmd = s:python_command_for(a:command)
end
call g:neoterm.repl.instance().exec(add(l:cmd, g:neoterm_eof))
endfunction
This way we'd have one private function for each way neoterm can send python commands to the REPL, it'd be easier to debug and easier to maintain. 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, of course.
How do you debug vim scripts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When needed, yes, but usually only with echo
🙈
doc/neoterm.txt
Outdated
Both a string and a list can be passed to. Defaults to an empty string, | ||
in which case NeoTerm will fall back to IPython followed by Python. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both a string and a list can be passed to. Defaults to an empty string, | |
in which case NeoTerm will fall back to IPython followed by Python. | |
This option accepts either a String or a list of commands. Its default | |
value is an empty string, which will try to use `ipython` or `python`, | |
in this order, to execute the REPL. |
doc/neoterm.txt
Outdated
Default value: (empty) | ||
|
||
Example for a valid command list: | ||
|g:neoterm_repl_python| = `['conda activate venv', 'clear', 'ipython']`` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's write the example in a way that users can copy'n'paste:
|g:neoterm_repl_python| = `['conda activate venv', 'clear', 'ipython']`` | |
`let g:neoterm_repl = ['conda activate venv', 'clear', 'ipython']` |
autoload/neoterm/repl/python.vim
Outdated
return get(l:, 'ipycommand', pycommand) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return get(l:, 'ipycommand', pycommand) | |
return get(l:, 'ipycommand', pycommand) |
end | ||
endfunction | ||
|
||
function! s:ipython_magic_command_for(command) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you put the private functions after the public function that call them? In this case, after the neoterm#repl#python#exec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a changelog as well, please?
can you also remove that sample.gif file, please? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the great contribution! ❤️💛💚💜💙🖤🧡
Thank you for your support. |
I've tried to optimize the python support depending on this issues:
#273
#270
Related:
#74, #89, #114, #233, #234
Branch demo:
![1](https://raw.githubusercontent.com/incoggnito/neoterm/master/assets/sample.gif)
I've added:
My settings: