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

Unable to use :setf from $VIMRUNTIME/ftdetect/*.vim

Expand Messages
  • Alexey I. Froloff
    filetype.vim looks like: augroup filetypedetect ... Generic configuration file (check this last, it s just guessing!) au BufNewFile,BufRead,StdinReadPost *
    Message 1 of 10 , Aug 30, 2006
    • 0 Attachment
      filetype.vim looks like:

      augroup filetypedetect

      ...

      " Generic configuration file (check this last, it's just guessing!)
      au BufNewFile,BufRead,StdinReadPost *
      \ ... some files are being setf'ed to "conf"

      " Use the plugin-filetype checks last, they may overrule any of the previously
      " detected filetypes.
      runtime! ftdetect/*.vim

      augroup END


      So, if Vim sets filetype to "conf", it is not possible to use
      :setf from ftdetect/*.vim, because of "but only if not done yet
      in a sequence of (nested) autocommands." setf feature.

      Solution is simple - source ftdetect/*.vim before "conf"
      fallback.

      --
      Regards,
      Sir Raorn.
    • Alexey I. Froloff
      ... Also, it would be nice to use StarSetf() from ftdetect/*.vim... -- Regards, Sir Raorn.
      Message 2 of 10 , Aug 30, 2006
      • 0 Attachment
        * Alexey I. Froloff <raorn@> [060830 21:21]:
        > Solution is simple - source ftdetect/*.vim before "conf"
        > fallback.
        Also, it would be nice to use StarSetf() from ftdetect/*.vim...

        --
        Regards,
        Sir Raorn.
      • Ilya
        ... You can do set filetype=... if you want unconditionally set file type.
        Message 3 of 10 , Aug 30, 2006
        • 0 Attachment
          Alexey I. Froloff wrote:
          > filetype.vim looks like:
          >
          > augroup filetypedetect
          >
          > ...
          >
          > " Generic configuration file (check this last, it's just guessing!)
          > au BufNewFile,BufRead,StdinReadPost *
          > \ ... some files are being setf'ed to "conf"
          >
          > " Use the plugin-filetype checks last, they may overrule any of the previously
          > " detected filetypes.
          > runtime! ftdetect/*.vim
          >
          > augroup END
          >
          >
          > So, if Vim sets filetype to "conf", it is not possible to use
          > :setf from ftdetect/*.vim, because of "but only if not done yet
          > in a sequence of (nested) autocommands." setf feature.
          >
          > Solution is simple - source ftdetect/*.vim before "conf"
          > fallback.
          >
          You can do "set filetype=..." if you want unconditionally set file type.
        • A.J.Mechelynck
          ... 1. You should never create, delete or modify any file in the $VIMRUNTIME directory tree, because any upgrade or bugfix may at any time silently overwrite
          Message 4 of 10 , Aug 30, 2006
          • 0 Attachment
            Alexey I. Froloff wrote:
            > filetype.vim looks like:
            >
            > augroup filetypedetect
            >
            > ...
            >
            > " Generic configuration file (check this last, it's just guessing!)
            > au BufNewFile,BufRead,StdinReadPost *
            > \ ... some files are being setf'ed to "conf"
            >
            > " Use the plugin-filetype checks last, they may overrule any of the previously
            > " detected filetypes.
            > runtime! ftdetect/*.vim
            >
            > augroup END
            >
            >
            > So, if Vim sets filetype to "conf", it is not possible to use
            > :setf from ftdetect/*.vim, because of "but only if not done yet
            > in a sequence of (nested) autocommands." setf feature.
            >
            > Solution is simple - source ftdetect/*.vim before "conf"
            > fallback.
            >

            1. You should never create, delete or modify any file in the $VIMRUNTIME
            directory tree, because any upgrade or bugfix may at any time silently
            overwrite anything there, and a point release (such as 7.1) will
            certainly re-create everything there from scratch (under another name,
            such as .../vim/vim71/ instead of .../vim/vim70/). User customizations
            to Vim should go in the _other_ directory trees mentioned in the
            'runtimepath' option, usually as follows:

            ~/.vim/
            single-user full-fledged scripts on Unix

            ~/vimfiles/
            single-user full-fledged scripts on Windows

            $VIM/vimfiles/
            system-wide full-fledged scripts on all platforms

            $VIM/vimfiles/after/
            small system-wide tweaks to scripts under $VIMRUNTIME or any
            of the above

            ~/vimfiles/after/
            on Windows, small single-user tweaks to any of the above

            ~/.vim/after/
            on Unix, small single-user tweaks to any of the above.

            2. The files detected as "conf" are the following:

            auto.master

            anything not yet detected which has a # in column 1 of one or more of
            the first 5 lines, unless the filepathname has a match in
            g:ft_ignore_pat (this is done after all other tests except
            ftdetect/*.vim and any filetype.vim in an |after-directory| )

            3. If you know that a filetype may already have been assigned and you're
            dead sure you want to change it, use ":set filetype=foobar" rather than
            ":setfiletype foobar". You may even let Vim do part of the detection for
            you by using

            if &filetype == "conf"
            if ...
            set filetype=foobar
            endif
            endif

            Using "set filetype=something" rather than "setfiletype something" in
            ftdetect/*vim scripts is what is explicitly shown in the example in
            paragraph 2 under ":help ftdetect". At the end of the same help topic,
            just above paragraph B, |:setfiletype| is mentioned with the words: "if
            you want to keep a previously detected filetype". I'm not inventing
            anything. If you want to _override_ a previously detected filetype
            instead, don't use it.

            4. You may also set g:ft_ignore_pat to force non-detection of some
            files. The default (which will be set by $VIMRUNTIME/filetype.vim the
            first time it is run, unless the user has already set something before)
            is '\.\(Z\|gz\|bz2\|zip\|tgz\)$' which means "anything ending in one of
            .Z .gz .bz2 .zip or .tgz". (see ":help filetype-ignore").


            Best regards,
            Tony.
          • Bram Moolenaar
            ... The current method is correct. In the ftdetect scripts you can check for filetype being equal to conf and then do :set ft=anything to overrule it.
            Message 5 of 10 , Aug 30, 2006
            • 0 Attachment
              Alexey I. Froloff wrote:

              > filetype.vim looks like:
              >
              > augroup filetypedetect
              >
              > ...
              >
              > " Generic configuration file (check this last, it's just guessing!)
              > au BufNewFile,BufRead,StdinReadPost *
              > \ ... some files are being setf'ed to "conf"
              >
              > " Use the plugin-filetype checks last, they may overrule any of the previously
              > " detected filetypes.
              > runtime! ftdetect/*.vim
              >
              > augroup END
              >
              >
              > So, if Vim sets filetype to "conf", it is not possible to use
              > :setf from ftdetect/*.vim, because of "but only if not done yet
              > in a sequence of (nested) autocommands." setf feature.
              >
              > Solution is simple - source ftdetect/*.vim before "conf"
              > fallback.

              The current method is correct. In the ftdetect scripts you can check
              for 'filetype' being equal to "conf" and then do ":set ft=anything" to
              overrule it. Use ":setf" only when you don't want to overrule the
              default filetype.

              The idea is that you can also do something like:

              if &ft == 'python' && SomeCheck()
              set ft=notpython
              elseif &ft == 'conf' && SomeOtherCheck()
              set ft=myconf
              endif

              --
              MAN: Fetchez la vache!
              GUARD: Quoi?
              MAN: Fetchez la vache!
              "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

              /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
              /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
              \\\ download, build and distribute -- http://www.A-A-P.org ///
              \\\ help me help AIDS victims -- http://ICCF-Holland.org ///
            • Alexey I. Froloff
              ... By $VIMRUNTIME I mean &rtp. Those file comes modified from vim-* rpm packages and I just want to _package_ system-specific settings in separate file
              Message 6 of 10 , Aug 30, 2006
              • 0 Attachment
                * A.J.Mechelynck <antoine.mechelynck@> [060830 23:53]:
                > 1. You should never create, delete or modify any file in the $VIMRUNTIME
                By "$VIMRUNTIME" I mean &rtp. Those file comes modified from
                vim-* rpm packages and I just want to _package_ system-specific
                settings in separate file instead of rediff'ing patch for every
                filetype.vim changes.

                --
                Regards,
                Sir Raorn.
              • Alexey I. Froloff
                ... I want these files act as default and I don t want to patch filetype.vim. Will :setf work after :set filetype ? -- Regards, Sir Raorn.
                Message 7 of 10 , Aug 30, 2006
                • 0 Attachment
                  * Bram Moolenaar <Bram@> [060831 00:14]:
                  > The current method is correct. In the ftdetect scripts you can check
                  > for 'filetype' being equal to "conf" and then do ":set ft=anything" to
                  > overrule it. Use ":setf" only when you don't want to overrule the
                  > default filetype.
                  I want these files act as "default" and I don't want to patch
                  filetype.vim. Will :setf work after :set filetype ?

                  --
                  Regards,
                  Sir Raorn.
                • A.J.Mechelynck
                  ... :setf bar will not work after :set filetype=foo , neither will it work after :setfiletype foo ; it will (IIUC) work after :set filetype= (setting it
                  Message 8 of 10 , Aug 30, 2006
                  • 0 Attachment
                    Alexey I. Froloff wrote:
                    > * Bram Moolenaar <Bram@> [060831 00:14]:
                    >> The current method is correct. In the ftdetect scripts you can check
                    >> for 'filetype' being equal to "conf" and then do ":set ft=anything" to
                    >> overrule it. Use ":setf" only when you don't want to overrule the
                    >> default filetype.
                    > I want these files act as "default" and I don't want to patch
                    > filetype.vim. Will :setf work after :set filetype ?
                    >

                    ":setf bar" will not work after ":set filetype=foo", neither will it
                    work after ":setfiletype foo"; it will (IIUC) work after ":set
                    filetype=" (setting it forcibly to empty). But if you want your settings
                    to act as defaults, you can use the ":setf" command -- anything else
                    will already have been detected. Filetype "conf" itself is only set
                    after all other tests (except ftdetect/*.vim) have been run, be they
                    defined by Vim in $VIMRUNTIME/filetype.vim, by the sysadmin in
                    $VIM/vimfiles/filetype.vim (which is run before that) or by the
                    individual user in ~/.vim/filetype.vim (which is run before them both).

                    Or you may use the following in ftdetect/*.vim

                    if &ft == "" || &ft == "conf"
                    set filetype=blahblahblah
                    endif

                    if you want to override "conf" filetype but leave any other nonempty
                    filetype unchanged.

                    If I misunderstood, please be more specific: do you or don't you want to
                    override the filetype detected by filetype.vim ? If you do, use ":set
                    filetype=something". If you don't, use the ":setf" command. If sometimes
                    you do and other times you don't, you must ascertain which is which.

                    You should not patch $VIMRUNTIME/filetype.vim, but you can set up a
                    $VIM/vimfiles/filetype.vim (to be sourced before it) or a
                    $VIM/vimfiles/after/filetype.vim (to be sourced after it, and after
                    ftdetect/*.vim). Don't set did_load_filetypes yourself if you want the
                    default mechanism to run.


                    Best regards,
                    Tony.
                  • Alexey I. Froloff
                    ... No. Not override, but extend as if it was done in filetype.vim. What user scripts can break with this changes? -- Regards, Sir Raorn.
                    Message 9 of 10 , Aug 30, 2006
                    • 0 Attachment
                      * A.J.Mechelynck <antoine.mechelynck@> [060831 01:48]:
                      > If I misunderstood, please be more specific: do you or don't you want to
                      > override the filetype detected by filetype.vim ?
                      No. Not override, but extend as if it was done in filetype.vim.

                      What user scripts can break with this changes?

                      --
                      Regards,
                      Sir Raorn.
                    • A.J.Mechelynck
                      ... I don t think il will break anything; but you may want to run it and try. :scriptnames gives you at any time the name of all scripts that have been
                      Message 10 of 10 , Aug 30, 2006
                      • 0 Attachment
                        Alexey I. Froloff wrote:
                        > * A.J.Mechelynck <antoine.mechelynck@> [060831 01:48]:
                        >> If I misunderstood, please be more specific: do you or don't you want to
                        >> override the filetype detected by filetype.vim ?
                        > No. Not override, but extend as if it was done in filetype.vim.
                        >
                        > What user scripts can break with this changes?
                        >

                        I don't "think" il will break anything; but you may want to run it and
                        try. ":scriptnames" gives you at any time the name of all scripts that
                        have been sourced so far in the present Vim session, each of them listed
                        once, in the order they were first sourced.

                        ":setf[iletype]" sets a filetype if none is set

                        ":set filetype=<value>" or ":set ft=<value>" set a filetype unconditionally.

                        You can always test the variable &ft to see if any filetype (and which
                        one) has already been set. Thus

                        setf foo

                        is equivalent to

                        if &ft == ""
                        set filetype=foo
                        endif

                        or even (IIUC) to

                        let &ft = (&ft == "" ? "foo" : &ft)


                        Best regards,
                        Tony.
                      Your message has been successfully submitted and would be delivered to recipients shortly.