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

Question about b:did_ftplugin

Expand Messages
  • Thomas
    Hi, When I set a filetype for a buffer the variable b:did_ftplugin is set. ... Now, when I do set ft=X from the command line, it happens that the ftplugin X
    Message 1 of 4 , Apr 2, 2007
    • 0 Attachment
      Hi,

      When I set a filetype for a buffer the variable b:did_ftplugin is set.

      The help says:

      > If you are writing a filetype plugin to be used by many people, they need a
      > chance to disable loading it. Put this at the top of the plugin: >
      >
      > " Only do this when not done yet for this buffer
      > if exists("b:did_ftplugin")
      > finish
      > endif
      > let b:did_ftplugin = 1

      Now, when I do set ft=X from the command line, it happens that the
      ftplugin X doesn't get loaded because it finishes when b:did_ftplugin is
      set.

      When is b:did_ftplugin ever unset? What's the rationale of setting
      b:did_ftplugin and not b:did_ftplugin_X?

      Regards,
      Thomas.
    • Andy Wokula
      ... ftplugins should define b:undo_ftplugin . ... If this var exists and its commands get executed then (only then) also b:did_ftplugin will be unset.
      Message 2 of 4 , Apr 2, 2007
      • 0 Attachment
        Thomas schrieb:
        > Hi,
        >
        > When I set a filetype for a buffer the variable b:did_ftplugin is set.
        >
        > The help says:
        >
        >> If you are writing a filetype plugin to be used by many people, they
        >> need a
        >> chance to disable loading it. Put this at the top of the plugin: >
        >>
        >> " Only do this when not done yet for this buffer
        >> if exists("b:did_ftplugin")
        >> finish
        >> endif
        >> let b:did_ftplugin = 1
        >
        > Now, when I do set ft=X from the command line, it happens that the
        > ftplugin X doesn't get loaded because it finishes when b:did_ftplugin is
        > set.
        >
        > When is b:did_ftplugin ever unset? What's the rationale of setting
        > b:did_ftplugin and not b:did_ftplugin_X?
        >
        > Regards,
        > Thomas.

        ftplugins should define b:undo_ftplugin .
        :h undo_ftplugin
        If this var exists and its commands get executed then (only then) also
        b:did_ftplugin will be unset.

        Executing b:undo_ftplugin is one of the first things :setf X tries
        to do.

        --
        Regards,
        Andy

        EOM
      • Thomas
        ... What I actually meant by this was: the ftplugin X doesn t get loaded when a filetype was already set before, i.e. when a filetype plugin already defined
        Message 3 of 4 , Apr 2, 2007
        • 0 Attachment
          >> Now, when I do set ft=X from the command line, it happens that the
          >> ftplugin X doesn't get loaded because it finishes when b:did_ftplugin
          >> is set.
          What I actually meant by this was: the ftplugin X doesn't get loaded
          when a filetype was already set before, i.e. when a filetype plugin
          already defined b:did_ftplugin.

          > ftplugins should define b:undo_ftplugin .
          > :h undo_ftplugin
          > If this var exists and its commands get executed then (only then) also
          > b:did_ftplugin will be unset.
          >
          > Executing b:undo_ftplugin is one of the first things :setf X tries
          > to do.
          Thanks, in the meantime I already found this help page. But it doesn't
          seem to solve the problem.

          Here's what I do (vim is 7.0-204):

          in ~/.vim/ftplugin/test.vim

          if &cp || exists("b:did_ftplugin")
          echom 'b:did_ftplugin already set!'
          finish
          endif
          let b:did_ftplugin = 1

          echom "Test ftplugin!"

          on the command line:
          gvim -u NONE

          in vim:
          :set nocompatible
          :syntax on
          :filetype plugin on
          :help
          :set ft=test

          Result: 'b:did_ftplugin already set!' is printed in the echo area.
          b:did_ftplugin obviously is set by the help ftplugin (b:undo_ftplugin is
          set to "setl fo< tw<") but is never unset.

          Is this really the intended behaviour? Is the user meant to manually
          unlet b:did_ftplugin in such a situation? Do I misunderstand here
          something quite fundamentally?

          Regards,
          Thomas.
        • Andy Wokula
          ... Ok. There has been an error in the earlier help ftplugin (from 2006-04-19). Are you sure your help ftplugin sets ... and not ... (?) In the latter case,
          Message 4 of 4 , Apr 2, 2007
          • 0 Attachment
            Thomas schrieb:
            >
            >>> Now, when I do set ft=X from the command line, it happens that the
            >>> ftplugin X doesn't get loaded because it finishes when
            >>> b:did_ftplugin is set.
            > What I actually meant by this was: the ftplugin X doesn't get loaded
            > when a filetype was already set before, i.e. when a filetype plugin
            > already defined b:did_ftplugin.
            >
            >> ftplugins should define b:undo_ftplugin .
            >> :h undo_ftplugin
            >> If this var exists and its commands get executed then (only then)
            >> also b:did_ftplugin will be unset.
            >>
            >> Executing b:undo_ftplugin is one of the first things :setf X tries
            >> to do.
            > Thanks, in the meantime I already found this help page. But it doesn't
            > seem to solve the problem.
            >
            > Here's what I do (vim is 7.0-204):
            >
            > in ~/.vim/ftplugin/test.vim
            >
            > if &cp || exists("b:did_ftplugin")
            > echom 'b:did_ftplugin already set!'
            > finish
            > endif
            > let b:did_ftplugin = 1
            >
            > echom "Test ftplugin!"
            >
            > on the command line:
            > gvim -u NONE
            >
            > in vim:
            > :set nocompatible
            > :syntax on
            > :filetype plugin on
            > :help
            > :set ft=test
            >
            > Result: 'b:did_ftplugin already set!' is printed in the echo area.
            > b:did_ftplugin obviously is set by the help ftplugin (b:undo_ftplugin
            > is set to "setl fo< tw<") but is never unset.

            Ok. There has been an error in the earlier help ftplugin (from
            2006-04-19). Are you sure your help ftplugin sets

            :let b:undo_ftplugin = "setl fo< tw<"

            and not

            :let b:undo_plugin = "setl fo< tw<"

            (?) In the latter case, update your runtime file(s) and try again.

            > Is this really the intended behaviour? Is the user meant to manually
            > unlet b:did_ftplugin in such a situation? Do I misunderstand here
            > something quite fundamentally?
            >
            > Regards,
            > Thomas.

            No, no, no :-)

            --
            Regards,
            Andy

            EOM
          Your message has been successfully submitted and would be delivered to recipients shortly.