Coder Social home page Coder Social logo

Comments (5)

lifepillar avatar lifepillar commented on July 4, 2024

According to :help undojoin, calling getchar() should start a new change. That does not seem to be the case if the code using getchar() is in a callback.

from vim.

zeertzjq avatar zeertzjq commented on July 4, 2024

According to :help undojoin, calling getchar() should start a new change. That does not seem to be the case if the code using getchar() is in a callback.

I don't think that's the case. It just recommends that you use :undojoin before calling getchar().

from vim.

chrisbra avatar chrisbra commented on July 4, 2024

I agree with @zeertzjq reading of the help.

from vim.

lifepillar avatar lifepillar commented on July 4, 2024

I beg to disagree. The help describes a case where undojoin is necessary to merge two changes with a getchar() in between exactly because

the next key press will start a new change

In fact, that is what happens:

vim9script

def Foo()
  normal aX
  getchar()
  normal aY
  undo
enddef

Foo()

X remains in the buffer after the undo. But if the function is used as a callback, it behaves as if undojoin has been added. That is, in the following script:

vim9script

def Foo()
  normal aX
  getchar()
  normal aY
  undo
enddef

job_start(['ls'], {'close_cb': (_) => Foo()})

Foo() behaves the same as in:

vim9script

def Foo()
  normal aX
  getchar()
  undojoin
  normal aY
  undo
enddef

Foo()

I would like the function invoked as a job_start()'s callback to behave the same as if invoked directly.

[Edited for clarity]

from vim.

lifepillar avatar lifepillar commented on July 4, 2024

A workaround for this issue is to force a new change:

def Foo()
  normal aX
  getchar()
  execute "normal" "i\<c-g>u"
  normal aY
  undo
enddef

Similarly, my original example is fixed by adding execute "normal" "i\<c-g>u" before (or after) getcharstr().

from vim.

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.