Loading ...
Sorry, an error occurred while loading the content.

Re: Why doesn't the syntax file load the function from the ftplugin file?

Expand Messages
  • Suresh Govindachar
    AW On 6/16/2013 10:42 AM, Andy Wokula wrote: ... buffer ... AW I d define functions in an autoload script: AW vimfiles autoload mynotes.vim AW AW This
    Message 1 of 5 , Jun 16, 2013
    • 0 Attachment
      AW> On 6/16/2013 10:42 AM, Andy Wokula wrote:
      CB> On 6/16/2013 11:36 AM, Christian Brabandt wrote:

      > On So, 16 Jun 2013, Suresh Govindachar wrote:
      >
      > The file vimfiles/ftplugin/notes.vim starts as follows:
      >
      > if exists("b:did_ftplugin")
      > finish
      > endif
      > let b:did_ftplugin = 1 " Don't load another plugin for this
      buffer
      >
      > nmap <buffer> <localleader>u Yp$x^v$r-
      >
      > nmap <buffer> <F5> :syn off\|syn on<cr>
      >
      > setlocal spell
      > setlocal smartindent
      > setlocal textwidth=80
      > setlocal complete=.
      >
      > if !exists("*s:MyNotesFoldLevel")
      > function! MyNotesFoldLevel(acline)
      >
      > let cline = a:acline
      > <omitting rest of the function>
      > endfunction
      > endif
      > <omitting rest of the stuff in this file>
      >
      > The file vimfiles/syntax/notes.vim starts as follows:
      >
      > syn clear
      > if !exists("*s:MyNotesFoldLevel")
      > ru ftplugin/notes.vim
      > endif
      >
      > %g/^/let i = line('.') |
      > \ let level = MyNotesFoldLevel(i) |
      > <omitting rest of the stuff in this file>
      >
      > But the very first time a notes file is loaded, I get the error
      message:
      >
      > Error detected while processing
      C:\opt\vim\vimfiles\syntax\notes.vim:
      > line 35:
      > E117: Unknown function: MyNotesFoldLevel
      > E15: Invalid expression: MyNotesFoldLevel(i) | <omitting rest
      > of the stuff>
      >
      > After that, loading the same or different notes file is OK.
      >
      > How to fix the error message for the very first load?
      >

      AW> I'd define functions in an autoload script:
      AW> vimfiles\autoload\mynotes.vim
      AW>
      AW> This script should contain a function
      AW> function! mynotes#FoldLevel(acline)
      AW> ...
      AW> endfunction
      AW>
      AW> The script will only be loaded once, when invoking one of the
      AW> script's functions for the first time.

      CB> In your .vimrc, put the filetype plugin on command /before/
      CB> the :syntax on command. This makes sure, the filetype plugin
      CB> is loaded before the syntax script.

      I saw AW's suggestion before I saw CB's, and implemented the scheme
      based on autoload. It works as expected.

      Thanks,

      --Suresh


      --
      --
      You received this message from the "vim_use" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php

      ---
      You received this message because you are subscribed to the Google Groups "vim_use" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
      For more options, visit https://groups.google.com/groups/opt_out.
    • Suresh Govindachar
      ... So what s wrong with the test and the ru ftplugin/notes.vim line in the syntax file? --Suresh -- -- You received this message from the vim_use
      Message 2 of 5 , Jun 16, 2013
      • 0 Attachment
        On 6/16/2013 11:36 AM, Christian Brabandt wrote:
        > On So, 16 Jun 2013, Suresh Govindachar wrote:
        >
        >> The file vimfiles/ftplugin/notes.vim starts as follows:
        >>
        >> if exists("b:did_ftplugin")
        >> finish
        >> endif
        >> let b:did_ftplugin = 1 " Don't load another plugin for this buffer
        >>
        >> nmap <buffer> <localleader>u Yp$x^v$r-
        >>
        >> nmap <buffer> <F5> :syn off\|syn on<cr>
        >>
        >> setlocal spell
        >> setlocal smartindent
        >> setlocal textwidth=80
        >> setlocal complete=.
        >>
        >> if !exists("*s:MyNotesFoldLevel")
        >> function! MyNotesFoldLevel(acline)
        >>
        >> let cline = a:acline
        >> <omitting rest of the function>
        >> endfunction
        >> endif
        >> <omitting rest of the stuff in this file>
        >>
        >> The file vimfiles/syntax/notes.vim starts as follows:
        >>
        >> syn clear
        >> if !exists("*s:MyNotesFoldLevel")
        >> ru ftplugin/notes.vim
        >> endif
        >>
        >> %g/^/let i = line('.') |
        >> \ let level = MyNotesFoldLevel(i) |
        >> <omitting rest of the stuff in this file>
        >>
        >> But the very first time a notes file is loaded, I get the error message:
        >>
        >> Error detected while processing C:\opt\vim\vimfiles\syntax\notes.vim:
        >> line 35:
        >> E117: Unknown function: MyNotesFoldLevel
        >> E15: Invalid expression: MyNotesFoldLevel(i) | <omitting rest
        >> of the stuff>
        >>
        >> After that, loading the same or different notes file is OK.
        >>
        >> How to fix the error message for the very first load?
        > In your .vimrc, put the filetype plugin on command /before/ the :syntax
        > on command. This makes sure, the filetype plugin is loaded before the
        > syntax script.
        >

        So what's wrong with the test and the "ru ftplugin/notes.vim" line in
        the syntax file?

        --Suresh


        --
        --
        You received this message from the "vim_use" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php

        ---
        You received this message because you are subscribed to the Google Groups "vim_use" group.
        To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
        For more options, visit https://groups.google.com/groups/opt_out.
      Your message has been successfully submitted and would be delivered to recipients shortly.