Skip to content
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

Add support for sourcing a Vim9 script from a buffer #9974

Closed
wants to merge 1 commit into from

Conversation

yegappan
Copy link
Member

No description provided.

@codecov
Copy link

codecov bot commented Mar 19, 2022

Codecov Report

Merging #9974 (fbb2eaf) into master (397a87a) will decrease coverage by 0.17%.
The diff coverage is 66.66%.

❗ Current head fbb2eaf differs from pull request most recent head 0800017. Consider uploading reports for the commit 0800017 to get more accurate results

@@            Coverage Diff             @@
##           master    #9974      +/-   ##
==========================================
- Coverage   81.91%   81.74%   -0.18%     
==========================================
  Files         167      167              
  Lines      187269   187229      -40     
  Branches    42201    42202       +1     
==========================================
- Hits       153409   153044     -365     
- Misses      21516    21813     +297     
- Partials    12344    12372      +28     
Flag Coverage Δ
huge-clang-none 82.31% <67.64%> (-0.02%) ⬇️
huge-gcc-none 82.65% <66.17%> (-0.02%) ⬇️
huge-gcc-testgui ?
huge-gcc-unittests 2.01% <0.00%> (+<0.01%) ⬆️
linux 83.58% <66.66%> (-0.33%) ⬇️
mingw-x64-HUGE 0.00% <0.00%> (ø)
mingw-x64-HUGE-gui 77.15% <70.17%> (-0.01%) ⬇️
windows 75.93% <68.96%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/scriptfile.c 83.10% <66.17%> (-0.38%) ⬇️
src/ex_docmd.c 91.47% <100.00%> (-0.13%) ⬇️
src/gui_gtk_x11.c 51.59% <0.00%> (-5.39%) ⬇️
src/gui_gtk.c 24.23% <0.00%> (-3.62%) ⬇️
src/sound.c 64.57% <0.00%> (-1.72%) ⬇️
src/hardcopy.c 77.49% <0.00%> (-1.62%) ⬇️
src/gui_xim.c 22.38% <0.00%> (-1.20%) ⬇️
src/os_unix.c 67.35% <0.00%> (-1.08%) ⬇️
src/gui.c 73.16% <0.00%> (-0.88%) ⬇️
src/highlight.c 81.25% <0.00%> (-0.83%) ⬇️
... and 33 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 397a87a...0800017. Read the comment docs.

@habamax
Copy link
Contributor

habamax commented Mar 20, 2022

Can it source the following:

vim9script

def Hello()
   var myList = ['multi',
            'lined',
            'list'
            ]
   echo myList[0]
enddef

nnoremap <F5> <ScriptCmd>Hello()<CR>
  • :4,7source
  • :11source -- would proper script context be used here?
    ?

@brammool
Copy link
Contributor

We can keep using sourcing_a_script(), hide the details of how that is decided.

I don't think we should try to be clever and detect the kind of script. If someone sources some sequence of buffer lines we can't really know whether they are legacy or Vim9 script. They could even be some lines in a help file. We can require using "vim9cmd source". Unless "vim9script" is the first command in the range of lines.

We also need to define what happens when sourcing from the same buffer again. I suppose this would work like "vim9script noclear". That way you could, for example, source a function again after modifying it.

@yegappan yegappan force-pushed the wildopt branch 2 times, most recently from 823a6a1 to fa01bdb Compare March 20, 2022 14:53
@vim-ml
Copy link

vim-ml commented Mar 20, 2022 via email

@brammool
Copy link
Contributor

There is a remark in the help about using the same SID when sourcing multiple times.
It would be good to say a few things about what happens when redefining a function. I suppose that works.
But other items from the script are still there, thus it would work like "vim9script noclear".
As is explained at "vim9-reload".

When sourcing just a few lines, e.g. from a help buffer, "vim9cmd source" should work.
Please add a test for that.

@Shane-XB-Qian
Copy link
Contributor

Shane-XB-Qian commented Mar 20, 2022 via email

@yegappan yegappan force-pushed the wildopt branch 4 times, most recently from a70a87d to 17d2229 Compare March 21, 2022 02:39
@vim-ml
Copy link

vim-ml commented Oct 11, 2022 via email

@habamax
Copy link
Contributor

habamax commented Oct 11, 2022

To source a Vim9 script from a buffer, it must start with "vim9script" as the first line. For a legacy script, you can source any range of lines.

I have this operator to run both vimscript and vim9script ranges:

# source vimscript (operator)
def SourceVim(...args: list<any>): any
    if len(args) == 0
        &opfunc = matchstr(expand('<stack>'), '[^. ]*\ze[')
        return 'g@'
    endif
    if getline(1) =~ '^vim9script$'
        vim9cmd :'[,']source
    else
        :'[,']source
    endif
    return ''
enddef
nnoremap <silent> <expr> <space>v SourceVim()
xnoremap <silent> <expr> <space>v SourceVim()
nnoremap <silent> <expr> <space>vv SourceVim() .. '_'

So <space>vv to eval current line, <space>vip to eval current para, etc.

zeertzjq added a commit to zeertzjq/neovim that referenced this pull request Apr 24, 2024
Problem:    Sourcing buffer lines is too complicated.
Solution:   Simplify the code. Make it possible to source Vim9 script lines.
            (Yegappan Lakshmanan, closes vim/vim#9974)

vim/vim@85b43c6

Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
zeertzjq added a commit to zeertzjq/neovim that referenced this pull request Apr 25, 2024
Problem:    Sourcing buffer lines is too complicated.
Solution:   Simplify the code. Make it possible to source Vim9 script lines.
            (Yegappan Lakshmanan, closes vim/vim#9974)

vim/vim@85b43c6

Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
zeertzjq added a commit to zeertzjq/neovim that referenced this pull request Apr 25, 2024
Problem:    Sourcing buffer lines is too complicated.
Solution:   Simplify the code. Make it possible to source Vim9 script lines.
            (Yegappan Lakshmanan, closes vim/vim#9974)

vim/vim@85b43c6

vim-patch:9.1.0372: Calling CLEAR_FIELD() on the same struct twice

Problem:  Calling CLEAR_FIELD() on the same struct twice.
Solution: Remove the second CLEAR_FIELD().  Move the assignment of
          cookie.sourceing_lnum (zeertzjq).

closes: vim/vim#14627

vim/vim@f68517c

Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants