Possible to set `foldexpr` using a function reference?Call function from string nameFunction that opens file for editingsystem function output with Chinese charsRunning python code in a functionIs it possible to create a function with the same name for different filetypes (and different implementations)?How do I use function to effect editing a file?Why is this function clearing screen output?How to use function returns?Add conceal in functionHow to set opfunc to a lambda function?

Verb "geeitet" in an old scientific text

What are the advantages of luxury car brands like Acura/Lexus over their sibling non-luxury brands Honda/Toyota?

What does a spell range of "25 ft. + 5 ft./2 levels" mean?

I drew a randomly colored grid of points with tikz, how do I force it to remember the first grid from then on?

Randomness of Python's random

What matters more when it comes to book covers? Is it ‘professional quality’ or relevancy?

As matter approaches a black hole, does it speed up?

Why do only some White Walkers shatter into ice chips?

What was the first instance of a "planet eater" in sci-fi?

Why didn't the check-in agent recognize my long term visa?

Why is [person X] visibly scared in the library in Game of Thrones S8E3?

Can my company stop me from working overtime?

Prove that the limit exists or does not exist

Why are prions in animal diets not destroyed by the digestive system?

Which module had more 'comfort' in terms of living space, the Lunar Module or the Command module?

Why wasn't the Night King naked in S08E03?

Can an isometry leave entropy invariant?

Using a microphone from the 1930s

String won't reverse using reverse_copy

How did Shepard's and Grissom's speeds compare with orbital velocity?

Getting a W on your transcript for grad school applications

Can there be a single technologically advanced nation, in a continent full of non-technologically advanced nations?

Out of scope work duties and resignation

What is the most remote airport from the center of the city it supposedly serves?



Possible to set `foldexpr` using a function reference?


Call function from string nameFunction that opens file for editingsystem function output with Chinese charsRunning python code in a functionIs it possible to create a function with the same name for different filetypes (and different implementations)?How do I use function to effect editing a file?Why is this function clearing screen output?How to use function returns?Add conceal in functionHow to set opfunc to a lambda function?













1















Got this:



let Func = function(folding_function) "folding_function is name of function
setlocal foldexpr=call(Func(v:lnum))


This is so user can set a custom function for folding in their config file. I can't get it to work, though.



Also tried:



call(Func, v:lnum)



and



call(Func, 'v:lnum')



Code in context



" Set settings which are local to a window. In a new tab they would be reset to
" Vim defaults. So we enforce our settings here when the cursor enters a
" Vimwiki buffer.
function! s:set_windowlocal_options()
if !&diff " if Vim is currently in diff mode, don't interfere with its folding
let foldmethod = vimwiki#vars#get_global('folding')
if foldmethod =~? '^expr.*'
setlocal foldmethod=expr
let custom = vimwiki#vars#get_global('custom_fold_func')
if custom
let Func = function('VimwikiFoldLevelCustom')
setlocal foldexpr=Func(v:lnum)
" setlocal foldexpr=VimwikiFoldLevelCustom(v:lnum)
else
setlocal foldexpr=VimwikiFoldLevel(v:lnum)
endif
setlocal foldtext=VimwikiFoldText()
elseif foldmethod =~? '^list.*' || foldmethod =~? '^lists.*'
setlocal foldmethod=expr
setlocal foldexpr=VimwikiFoldListLevel(v:lnum)
setlocal foldtext=VimwikiFoldText()
elseif foldmethod =~? '^syntax.*'
setlocal foldmethod=syntax
setlocal foldtext=VimwikiFoldText()
elseif foldmethod =~? '^custom.*'
" do nothing
else
setlocal foldmethod=manual
normal! zE
endif
endif

if vimwiki#vars#get_global('conceallevel') && exists("+conceallevel")
let &conceallevel = vimwiki#vars#get_global('conceallevel')
endif

if vimwiki#vars#get_global('auto_chdir')
exe 'lcd' vimwiki#vars#get_wikilocal('path')
endif
endfunction









share|improve this question
























  • try Func(v:lnum)

    – dedowsdi
    Apr 29 at 0:20











  • with or without call?

    – StevieD
    Apr 29 at 0:23











  • without call, don't need it.

    – dedowsdi
    Apr 29 at 0:26











  • Hmm, no dice. Also tried to simplify things: let Func = function('VimwikiFoldLevelCustom') setlocal foldexpr=Func(v:lnum)

    – StevieD
    Apr 29 at 0:32






  • 2





    try let g:Func = function('VimwikiFoldLevelCustom')

    – dedowsdi
    Apr 29 at 2:42















1















Got this:



let Func = function(folding_function) "folding_function is name of function
setlocal foldexpr=call(Func(v:lnum))


This is so user can set a custom function for folding in their config file. I can't get it to work, though.



Also tried:



call(Func, v:lnum)



and



call(Func, 'v:lnum')



Code in context



" Set settings which are local to a window. In a new tab they would be reset to
" Vim defaults. So we enforce our settings here when the cursor enters a
" Vimwiki buffer.
function! s:set_windowlocal_options()
if !&diff " if Vim is currently in diff mode, don't interfere with its folding
let foldmethod = vimwiki#vars#get_global('folding')
if foldmethod =~? '^expr.*'
setlocal foldmethod=expr
let custom = vimwiki#vars#get_global('custom_fold_func')
if custom
let Func = function('VimwikiFoldLevelCustom')
setlocal foldexpr=Func(v:lnum)
" setlocal foldexpr=VimwikiFoldLevelCustom(v:lnum)
else
setlocal foldexpr=VimwikiFoldLevel(v:lnum)
endif
setlocal foldtext=VimwikiFoldText()
elseif foldmethod =~? '^list.*' || foldmethod =~? '^lists.*'
setlocal foldmethod=expr
setlocal foldexpr=VimwikiFoldListLevel(v:lnum)
setlocal foldtext=VimwikiFoldText()
elseif foldmethod =~? '^syntax.*'
setlocal foldmethod=syntax
setlocal foldtext=VimwikiFoldText()
elseif foldmethod =~? '^custom.*'
" do nothing
else
setlocal foldmethod=manual
normal! zE
endif
endif

if vimwiki#vars#get_global('conceallevel') && exists("+conceallevel")
let &conceallevel = vimwiki#vars#get_global('conceallevel')
endif

if vimwiki#vars#get_global('auto_chdir')
exe 'lcd' vimwiki#vars#get_wikilocal('path')
endif
endfunction









share|improve this question
























  • try Func(v:lnum)

    – dedowsdi
    Apr 29 at 0:20











  • with or without call?

    – StevieD
    Apr 29 at 0:23











  • without call, don't need it.

    – dedowsdi
    Apr 29 at 0:26











  • Hmm, no dice. Also tried to simplify things: let Func = function('VimwikiFoldLevelCustom') setlocal foldexpr=Func(v:lnum)

    – StevieD
    Apr 29 at 0:32






  • 2





    try let g:Func = function('VimwikiFoldLevelCustom')

    – dedowsdi
    Apr 29 at 2:42













1












1








1








Got this:



let Func = function(folding_function) "folding_function is name of function
setlocal foldexpr=call(Func(v:lnum))


This is so user can set a custom function for folding in their config file. I can't get it to work, though.



Also tried:



call(Func, v:lnum)



and



call(Func, 'v:lnum')



Code in context



" Set settings which are local to a window. In a new tab they would be reset to
" Vim defaults. So we enforce our settings here when the cursor enters a
" Vimwiki buffer.
function! s:set_windowlocal_options()
if !&diff " if Vim is currently in diff mode, don't interfere with its folding
let foldmethod = vimwiki#vars#get_global('folding')
if foldmethod =~? '^expr.*'
setlocal foldmethod=expr
let custom = vimwiki#vars#get_global('custom_fold_func')
if custom
let Func = function('VimwikiFoldLevelCustom')
setlocal foldexpr=Func(v:lnum)
" setlocal foldexpr=VimwikiFoldLevelCustom(v:lnum)
else
setlocal foldexpr=VimwikiFoldLevel(v:lnum)
endif
setlocal foldtext=VimwikiFoldText()
elseif foldmethod =~? '^list.*' || foldmethod =~? '^lists.*'
setlocal foldmethod=expr
setlocal foldexpr=VimwikiFoldListLevel(v:lnum)
setlocal foldtext=VimwikiFoldText()
elseif foldmethod =~? '^syntax.*'
setlocal foldmethod=syntax
setlocal foldtext=VimwikiFoldText()
elseif foldmethod =~? '^custom.*'
" do nothing
else
setlocal foldmethod=manual
normal! zE
endif
endif

if vimwiki#vars#get_global('conceallevel') && exists("+conceallevel")
let &conceallevel = vimwiki#vars#get_global('conceallevel')
endif

if vimwiki#vars#get_global('auto_chdir')
exe 'lcd' vimwiki#vars#get_wikilocal('path')
endif
endfunction









share|improve this question
















Got this:



let Func = function(folding_function) "folding_function is name of function
setlocal foldexpr=call(Func(v:lnum))


This is so user can set a custom function for folding in their config file. I can't get it to work, though.



Also tried:



call(Func, v:lnum)



and



call(Func, 'v:lnum')



Code in context



" Set settings which are local to a window. In a new tab they would be reset to
" Vim defaults. So we enforce our settings here when the cursor enters a
" Vimwiki buffer.
function! s:set_windowlocal_options()
if !&diff " if Vim is currently in diff mode, don't interfere with its folding
let foldmethod = vimwiki#vars#get_global('folding')
if foldmethod =~? '^expr.*'
setlocal foldmethod=expr
let custom = vimwiki#vars#get_global('custom_fold_func')
if custom
let Func = function('VimwikiFoldLevelCustom')
setlocal foldexpr=Func(v:lnum)
" setlocal foldexpr=VimwikiFoldLevelCustom(v:lnum)
else
setlocal foldexpr=VimwikiFoldLevel(v:lnum)
endif
setlocal foldtext=VimwikiFoldText()
elseif foldmethod =~? '^list.*' || foldmethod =~? '^lists.*'
setlocal foldmethod=expr
setlocal foldexpr=VimwikiFoldListLevel(v:lnum)
setlocal foldtext=VimwikiFoldText()
elseif foldmethod =~? '^syntax.*'
setlocal foldmethod=syntax
setlocal foldtext=VimwikiFoldText()
elseif foldmethod =~? '^custom.*'
" do nothing
else
setlocal foldmethod=manual
normal! zE
endif
endif

if vimwiki#vars#get_global('conceallevel') && exists("+conceallevel")
let &conceallevel = vimwiki#vars#get_global('conceallevel')
endif

if vimwiki#vars#get_global('auto_chdir')
exe 'lcd' vimwiki#vars#get_wikilocal('path')
endif
endfunction






functions






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 29 at 2:38







StevieD

















asked Apr 28 at 23:20









StevieDStevieD

500313




500313












  • try Func(v:lnum)

    – dedowsdi
    Apr 29 at 0:20











  • with or without call?

    – StevieD
    Apr 29 at 0:23











  • without call, don't need it.

    – dedowsdi
    Apr 29 at 0:26











  • Hmm, no dice. Also tried to simplify things: let Func = function('VimwikiFoldLevelCustom') setlocal foldexpr=Func(v:lnum)

    – StevieD
    Apr 29 at 0:32






  • 2





    try let g:Func = function('VimwikiFoldLevelCustom')

    – dedowsdi
    Apr 29 at 2:42

















  • try Func(v:lnum)

    – dedowsdi
    Apr 29 at 0:20











  • with or without call?

    – StevieD
    Apr 29 at 0:23











  • without call, don't need it.

    – dedowsdi
    Apr 29 at 0:26











  • Hmm, no dice. Also tried to simplify things: let Func = function('VimwikiFoldLevelCustom') setlocal foldexpr=Func(v:lnum)

    – StevieD
    Apr 29 at 0:32






  • 2





    try let g:Func = function('VimwikiFoldLevelCustom')

    – dedowsdi
    Apr 29 at 2:42
















try Func(v:lnum)

– dedowsdi
Apr 29 at 0:20





try Func(v:lnum)

– dedowsdi
Apr 29 at 0:20













with or without call?

– StevieD
Apr 29 at 0:23





with or without call?

– StevieD
Apr 29 at 0:23













without call, don't need it.

– dedowsdi
Apr 29 at 0:26





without call, don't need it.

– dedowsdi
Apr 29 at 0:26













Hmm, no dice. Also tried to simplify things: let Func = function('VimwikiFoldLevelCustom') setlocal foldexpr=Func(v:lnum)

– StevieD
Apr 29 at 0:32





Hmm, no dice. Also tried to simplify things: let Func = function('VimwikiFoldLevelCustom') setlocal foldexpr=Func(v:lnum)

– StevieD
Apr 29 at 0:32




2




2





try let g:Func = function('VimwikiFoldLevelCustom')

– dedowsdi
Apr 29 at 2:42





try let g:Func = function('VimwikiFoldLevelCustom')

– dedowsdi
Apr 29 at 2:42










1 Answer
1






active

oldest

votes


















2














The value of the foldexpr option is evaluated to get the foldlevel of a line. You don't need to add extra call to it. You can copy following code in a new file and source it to check how it works.



" vim:set foldmethod=expr noexpandtab:

function! FoldingFunction(lnum)
return getline(v:lnum)[0]==#"t"
endfunction
let Func = function('FoldingFunction') "FoldingFunction is name of function
setlocal foldexpr=Func(v:lnum)

finish

fold
fold
fold
fold
fold


update



Your code doesn't work because your Func is a function local variable, change it to g:Func fix the problem.






share|improve this answer

























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "599"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fvi.stackexchange.com%2fquestions%2f19782%2fpossible-to-set-foldexpr-using-a-function-reference%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    The value of the foldexpr option is evaluated to get the foldlevel of a line. You don't need to add extra call to it. You can copy following code in a new file and source it to check how it works.



    " vim:set foldmethod=expr noexpandtab:

    function! FoldingFunction(lnum)
    return getline(v:lnum)[0]==#"t"
    endfunction
    let Func = function('FoldingFunction') "FoldingFunction is name of function
    setlocal foldexpr=Func(v:lnum)

    finish

    fold
    fold
    fold
    fold
    fold


    update



    Your code doesn't work because your Func is a function local variable, change it to g:Func fix the problem.






    share|improve this answer





























      2














      The value of the foldexpr option is evaluated to get the foldlevel of a line. You don't need to add extra call to it. You can copy following code in a new file and source it to check how it works.



      " vim:set foldmethod=expr noexpandtab:

      function! FoldingFunction(lnum)
      return getline(v:lnum)[0]==#"t"
      endfunction
      let Func = function('FoldingFunction') "FoldingFunction is name of function
      setlocal foldexpr=Func(v:lnum)

      finish

      fold
      fold
      fold
      fold
      fold


      update



      Your code doesn't work because your Func is a function local variable, change it to g:Func fix the problem.






      share|improve this answer



























        2












        2








        2







        The value of the foldexpr option is evaluated to get the foldlevel of a line. You don't need to add extra call to it. You can copy following code in a new file and source it to check how it works.



        " vim:set foldmethod=expr noexpandtab:

        function! FoldingFunction(lnum)
        return getline(v:lnum)[0]==#"t"
        endfunction
        let Func = function('FoldingFunction') "FoldingFunction is name of function
        setlocal foldexpr=Func(v:lnum)

        finish

        fold
        fold
        fold
        fold
        fold


        update



        Your code doesn't work because your Func is a function local variable, change it to g:Func fix the problem.






        share|improve this answer















        The value of the foldexpr option is evaluated to get the foldlevel of a line. You don't need to add extra call to it. You can copy following code in a new file and source it to check how it works.



        " vim:set foldmethod=expr noexpandtab:

        function! FoldingFunction(lnum)
        return getline(v:lnum)[0]==#"t"
        endfunction
        let Func = function('FoldingFunction') "FoldingFunction is name of function
        setlocal foldexpr=Func(v:lnum)

        finish

        fold
        fold
        fold
        fold
        fold


        update



        Your code doesn't work because your Func is a function local variable, change it to g:Func fix the problem.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Apr 29 at 2:51

























        answered Apr 29 at 0:46









        dedowsdidedowsdi

        78849




        78849



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Vi and Vim Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fvi.stackexchange.com%2fquestions%2f19782%2fpossible-to-set-foldexpr-using-a-function-reference%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

            Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

            Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form