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

Limiting ftplugins to relevant buffers

Expand Messages
  • neilhwatson@...
    Greetings, I set custom ftplugin like this: au BufRead,BufNewFile *.cf set ft=cf3 I edit a .cf file the plugin works correctly. If I start a new buffer, say
    Message 1 of 13 , Jan 21, 2013
    • 0 Attachment
      Greetings,

      I set custom ftplugin like this:
      au BufRead,BufNewFile *.cf set ft=cf3

      I edit a .cf file the plugin works correctly. If I start a new buffer, say *.html, the settings from the .cf plugin are active in this buffer. How can I prevent this?

      --
      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
    • sc
      ... have you tried using setl instead of set ? sc -- You received this message from the vim_use maillist. Do not top-post! Type your reply below the text
      Message 2 of 13 , Jan 21, 2013
      • 0 Attachment
        On Mon, Jan 21, 2013 at 01:03:59PM -0800, neilhwatson@... wrote:
        > Greetings,

        > I set custom ftplugin like this:
        > au BufRead,BufNewFile *.cf set ft=cf3

        > I edit a .cf file the plugin works correctly. If I start a new buffer, say *.html, the settings from the .cf plugin are active in this buffer. How can I prevent this?

        have you tried using "setl" instead of "set"?

        sc

        --
        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
      • neilhwatson@...
        I tried this: au BufRead,BufNewFile *.cf setlocal ft=cf3 The maps from the cf plugin still worked if my buffer was *.html. -- You received this message from
        Message 3 of 13 , Jan 21, 2013
        • 0 Attachment
          I tried this:
          au BufRead,BufNewFile *.cf setlocal ft=cf3

          The maps from the cf plugin still worked if my buffer was *.html.

          --
          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
        • Ben Fritz
          ... You need to set up buffer-local mappings if you don t want them to be defined globally to all of Vim. ... If you want to be extra careful you can undo them
          Message 4 of 13 , Jan 21, 2013
          • 0 Attachment
            On Monday, January 21, 2013 3:24:33 PM UTC-6, neilh...@... wrote:
            > I tried this:
            > au BufRead,BufNewFile *.cf setlocal ft=cf3
            >
            > The maps from the cf plugin still worked if my buffer was *.html.

            You need to set up buffer-local mappings if you don't want them to be defined globally to all of Vim.

            :help :map-local

            If you want to be extra careful you can undo them in the b:undo_ftplugin variable but if you're loading a new buffer this should not be necessary for your purposes. :he undo_ftplugin.

            --
            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
          • neilhwatson@...
            Success with maps. Thank you. nmap limits the map to that file type. I tried the same with abbreviations using iab . This works too well.
            Message 5 of 13 , Jan 22, 2013
            • 0 Attachment
              Success with maps. Thank you. nmap <buffer> limits the map to that file type. I tried the same with abbreviations using iab <buffer>. This works too well. If I open another buffer of the same file type, the maps work but the abbreviations do not. What did I do wrong?

              --
              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
            • Ben Fritz
              ... Where did you define the abbreviations? How did you edit the new buffer (specific command sequence)? -- You received this message from the vim_use
              Message 6 of 13 , Jan 22, 2013
              • 0 Attachment
                On Tuesday, January 22, 2013 8:40:25 AM UTC-6, neilh...@... wrote:
                > Success with maps. Thank you. nmap <buffer> limits the map to that file type. I tried the same with abbreviations using iab <buffer>. This works too well. If I open another buffer of the same file type, the maps work but the abbreviations do not. What did I do wrong?

                Where did you define the abbreviations? How did you edit the new buffer (specific command sequence)?

                --
                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
              • neilhwatson@...
                ... (specific command sequence)? The abbreviations are on the ftplugin. New buffer: :e newfile.cf The plugin is here:
                Message 7 of 13 , Jan 22, 2013
                • 0 Attachment
                  On Tuesday, 22 January 2013 15:30:23 UTC-5, Ben Fritz wrote:
                  > Where did you define the abbreviations? How did you edit the new buffer
                  (specific command sequence)?

                  The abbreviations are on the ftplugin. New buffer: :e newfile.cf

                  The plugin is here:
                  https://github.com/neilhwatson/vim_cf3/blob/dev/ftplugin/cf3.vim

                  --
                  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
                • Charles Campbell
                  ... In your code: once you have g:DisableCF3Ftplugin existing, the ftplugin won t be loaded again. Buffers are not filetypes; so you need to allow reloading
                  Message 8 of 13 , Jan 22, 2013
                  • 0 Attachment
                    neilhwatson@... wrote:
                    > On Tuesday, 22 January 2013 15:30:23 UTC-5, Ben Fritz wrote:
                    >> Where did you define the abbreviations? How did you edit the new buffer
                    > (specific command sequence)?
                    >
                    > The abbreviations are on the ftplugin. New buffer: :e newfile.cf
                    >
                    > The plugin is here:
                    > https://github.com/neilhwatson/vim_cf3/blob/dev/ftplugin/cf3.vim
                    >
                    In your code: once you have

                    g:DisableCF3Ftplugin

                    existing, the ftplugin won't be loaded again. Buffers are not filetypes; so you need to allow reloading of the ftplugin each time a buffer of the appropriate filetype is edited.

                    Regards,
                    C Campbell

                    --
                    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
                  • neilhwatson@...
                    I have this: if exists( g:DisableCF3Ftplugin ) finish endif But I do not have let g:DisableCF3Ftplugin=1 or anything similar in .vimrc or elsewhere. How can
                    Message 9 of 13 , Jan 22, 2013
                    • 0 Attachment
                      I have this:

                      if exists("g:DisableCF3Ftplugin")
                      finish
                      endif

                      But I do not have 'let g:DisableCF3Ftplugin=1' or anything similar in .vimrc or elsewhere. How can this affect it? If this is the cause I would expect the maps to not work, but they do. Only abbreviations do not work in a new buffer.

                      --
                      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
                    • Ben Fritz
                      ... I saw that too, but the plugin file never sets g:DisableCF3Ftplugin, it looks like it is simply a way to disable the ftplugin from taking effect if the
                      Message 10 of 13 , Jan 22, 2013
                      • 0 Attachment
                        On Tuesday, January 22, 2013 3:25:06 PM UTC-6, Charles Campbell wrote:
                        > neilhwatson@... wrote:
                        >
                        > > On Tuesday, 22 January 2013 15:30:23 UTC-5, Ben Fritz wrote:
                        >
                        > >> Where did you define the abbreviations? How did you edit the new buffer
                        >
                        > > (specific command sequence)?
                        >
                        > >
                        >
                        > > The abbreviations are on the ftplugin. New buffer: :e newfile.cf
                        >
                        > >
                        >
                        > > The plugin is here:
                        >
                        > > https://github.com/neilhwatson/vim_cf3/blob/dev/ftplugin/cf3.vim
                        >
                        > >
                        >
                        > In your code: once you have
                        >
                        >
                        >
                        > g:DisableCF3Ftplugin
                        >
                        >
                        >
                        > existing, the ftplugin won't be loaded again. Buffers are not filetypes; so you need to allow reloading of the ftplugin each time a buffer of the appropriate filetype is edited.
                        >

                        I saw that too, but the plugin file never sets g:DisableCF3Ftplugin, it looks like it is simply a way to disable the ftplugin from taking effect if the user has it installed but doesn't want it to load for some reason, on any buffer.

                        I think the problem is actually here:

                        if !exists('g:DisableCFE3KeywordAbbreviations')
                        let g:DisableCFE3KeywordAbbreviations=1
                        call EnableCFE3KeywordAbbreviations()
                        endif

                        That should be a buffer-local variable, not a global variable, otherwise the abbreviations will only load on the first buffer.

                        --
                        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
                      • Ben Fritz
                        ... Or if it s supposed to be a global disable, don t set it to true inside the plugin file; it would still be ok to check its existence. -- You received this
                        Message 11 of 13 , Jan 22, 2013
                        • 0 Attachment
                          On Tuesday, January 22, 2013 3:41:27 PM UTC-6, Ben Fritz wrote:
                          >
                          > I think the problem is actually here:
                          >
                          > if !exists('g:DisableCFE3KeywordAbbreviations')
                          > let g:DisableCFE3KeywordAbbreviations=1
                          > call EnableCFE3KeywordAbbreviations()
                          > endif
                          >
                          > That should be a buffer-local variable, not a global variable, otherwise the abbreviations will only load on the first buffer.

                          Or if it's supposed to be a global disable, don't set it to true inside the plugin file; it would still be ok to check its existence.

                          --
                          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
                        • Tony Mechelynck
                          ... One possible way to do it to test for both already-loaded and user-disabled would be (near the start of the ftplugin) if exists
                          Message 12 of 13 , Jan 22, 2013
                          • 0 Attachment
                            On 22/01/13 22:48, Ben Fritz wrote:
                            > On Tuesday, January 22, 2013 3:41:27 PM UTC-6, Ben Fritz wrote:
                            >>
                            >> I think the problem is actually here:
                            >>
                            >> if !exists('g:DisableCFE3KeywordAbbreviations')
                            >> let g:DisableCFE3KeywordAbbreviations=1
                            >> call EnableCFE3KeywordAbbreviations()
                            >> endif
                            >>
                            >> That should be a buffer-local variable, not a global variable, otherwise the abbreviations will only load on the first buffer.
                            >
                            > Or if it's supposed to be a global disable, don't set it to true inside the plugin file; it would still be ok to check its existence.
                            >
                            One possible way to do it to test for both already-loaded and
                            user-disabled would be (near the start of the ftplugin)

                            if exists ('g:DisableCFE3KeywordAbbreviations') ||
                            exists('b:DisableCFE3KeywordAbbreviations')
                            finish
                            endif
                            let b:DisableCFE3KeywordAbbreviations = 1


                            Best regards,
                            Tony.
                            --
                            Children seldom misquote you. In fact, they usually repeat word for
                            word what you shouldn't have said.

                            --
                            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
                          • neilhwatson@...
                            Thanks for the help everyone. I think I have it sorted out. -- You received this message from the vim_use maillist. Do not top-post! Type your reply below
                            Message 13 of 13 , Jan 23, 2013
                            • 0 Attachment
                              Thanks for the help everyone. I think I have it sorted out.

                              --
                              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
                            Your message has been successfully submitted and would be delivered to recipients shortly.