Code Monkey home page Code Monkey logo

Comments (16)

jpalardy avatar jpalardy commented on July 24, 2024

Hmmmm… does that just mean not turning on ipython mode? Or is there more to it?

from vim-slime.

alok avatar alok commented on July 24, 2024

I took a 200 line python script, copied it to the system clipboard, and then just hit Cmd-V to paste it and it pasted with the correct indentation. I'm not sure how they implement it. I'd try not turning it on and see if that works.

from vim-slime.

aicherc avatar aicherc commented on July 24, 2024

I was able to get this to partially work by turning on "bracked paste mode" (https://cirw.in/blog/bracketed-paste), instead of using %cpaste. Specifically in ftplugin/python/slime.vim I changed

if exists('g:slime_python_ipython') && len(split(a:text,"\n")) > 1
   return ["%cpaste -q\n", a:text, "--\n"]

to

if exists('g:slime_python_ipython') && len(split(a:text,"\n")) > 1
   return ["\e[200~", a:text, "\e[201~\n"]

where \e[200~ and \e[201~ are the bracketed paste escape sequences.
As far as I can tell, this prevents ipython 5.0+ from only reading the first line.
See also (ipython/ipython#9948)

I don't know enough about vimscript to make it check the current version of ipython (as multi-line pasting is version 5.0+).

from vim-slime.

dlovell avatar dlovell commented on July 24, 2024

@jpalardy , "not turning on ipython mode" doesn't work because you need to send something special for "non-executing-newline"

We need to bind a shortcut that adds a new line without executing, if you are scripting you can use C-o Down to force a newline and Escape Enter to force execution.

See also: ENH: enable multiline send for ipython
(I think I like "bracketed paste mode" better)

from vim-slime.

jpalardy avatar jpalardy commented on July 24, 2024

Based on what I'm reading, this is related to #142 ?

from vim-slime.

NedWestern avatar NedWestern commented on July 24, 2024

For IPython 7.2, I managed to get it working with the following changes:

if exists('g:slime_python_ipython') && len(split(a:text,"\n")) > 1
  return ["%cpaste -q\n", g:slime_dispatch_ipython_pause, a:text, "--\n"]

to

if exists('g:slime_python_ipython')
  return [a:text, g:slime_dispatch_ipython_pause, "\n"]

when vim-slime pastes the text, IPython 5.0+ will run the code with no problems, but it will not auto-execute. Adding the pause and the newline character makes IPython execute the code after pasting.

Note that for large blocks of code with empty lines, there is still a problem with IPython executing at some of these empty lines, which seems to occur randomly, indicating a timing issue. This will be a problem for indented code. I'm not sure how to address this.

from vim-slime.

jpalardy avatar jpalardy commented on July 24, 2024

I'll have to defer to an iPython user for a solution.

from vim-slime.

NedWestern avatar NedWestern commented on July 24, 2024

If I replace empty lines with a comment character, it suppresses early execution and somewhat preserves the layout of the code. A bit hacky, but it seems to work.

from vim-slime.

NedWestern avatar NedWestern commented on July 24, 2024

So... should I submit a pull request for testing perhaps? Or no?

from vim-slime.

jpalardy avatar jpalardy commented on July 24, 2024

I'm up for it.

If you send a PR, I'll merge it. If it doesn't work, we'll revert?

from vim-slime.

NedWestern avatar NedWestern commented on July 24, 2024

New to this... hopefully it's OK.

from vim-slime.

aicherc avatar aicherc commented on July 24, 2024

@NedWestern
For the problem with IPython executing at empty lines somewhat randomly (treating one code chunk as multiple chunks), have you tried adding the "bracketed paste mode" characters around a.text? (see #123 (comment))

I've been using it (for the last two years) to send code from vim to ipython using tmux and it's removed the issue of ipython thinking I'm sending multiple chunks (as far as I can tell).

Specifically replacing

if exists('g:slime_python_ipython')
  return [a:text, g:slime_dispatch_ipython_pause, "\n"]

with

if exists('g:slime_python_ipython')
  return ["\e[200~", a:text, "\e[201~", g:slime_dispatch_ipython_pause, "\n"]

It might let you avoid having to suppress empty lines with comment characters.

from vim-slime.

NedWestern avatar NedWestern commented on July 24, 2024

@aicherc
Hi Christopher, yes I read your blog post. Sounds interesting, but I can not get it to work for my setup (IPython 7.2 in vimterminal in gVim). It sends the escape sequence, minus the "\e", and does not execute.

In [1]: [200~print('foo')
        : ^[[201~
        :

Does it require specific settings in vim?

from vim-slime.

aicherc avatar aicherc commented on July 24, 2024

@NedWestern
Thanks for trying it out.
After re-reading the blog post, it sounds like "bracketed paste mode" is only intended to work in terminals that support it (my setup is gnome-terminal + tmux). I'm not very familiar with vimterminal (or terminal emulation in vim/neovim) to know if they support it.

Based on this, I like your current solution (empty lines -> #), since it works more generally.

from vim-slime.

NedWestern avatar NedWestern commented on July 24, 2024

True, but it seems to break for some people... ugh.

from vim-slime.

stale avatar stale commented on July 24, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

from vim-slime.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.