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

calling a function on bufenter,bufnew,bufread

Expand Messages
  • Chris Lott
    I have the following in my .vimrc -- but the call to the function isn t working. If I call the function manually after it opens, it works fine. The filename is
    Message 1 of 8 , Dec 7, 2012
    • 0 Attachment
      I have the following in my .vimrc -- but the call to the function
      isn't working. If I call the function manually after it opens, it
      works fine. The filename is set to vimperator.txt. Do I have to do
      something different to call a function in this way?

      function! WW()
      :set showtabline=0
      :set noshowmode
      :set laststatus=0
      :set noruler
      :set noshowcmd
      :call VimWriteRoom()
      endfunction

      nnoremap WW :call WW()<CR>

      au BufNewFile,BufEnter,BufRead vimperator.txt :call WW()<cr>

      c
      --
      Chris Lott <chris@...>

      --
      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
    • Marcin Szamotulski
      ... Hi, Some time ago I used vimperator too, and I also had some additional settings for it. As far as I recall vimperator has its own file type, but I might
      Message 2 of 8 , Dec 7, 2012
      • 0 Attachment
        On 06:46 Fri 07 Dec , Chris Lott wrote:
        > I have the following in my .vimrc -- but the call to the function
        > isn't working. If I call the function manually after it opens, it
        > works fine. The filename is set to vimperator.txt. Do I have to do
        > something different to call a function in this way?
        >
        > function! WW()
        > :set showtabline=0
        > :set noshowmode
        > :set laststatus=0
        > :set noruler
        > :set noshowcmd
        > :call VimWriteRoom()
        > endfunction
        >
        > nnoremap WW :call WW()<CR>
        >
        > au BufNewFile,BufEnter,BufRead vimperator.txt :call WW()<cr>
        >
        > c
        > --
        > Chris Lott <chris@...>
        >
        > --
        > 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

        Hi,

        Some time ago I used vimperator too, and I also had some additional
        settings for it. As far as I recall vimperator has its own file type,
        but I might be wrong. If it has you could use FileType autocommand
        event.

        Best,
        Marcin

        --
        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
        ... Autocmds take ex commands, not normal mode mapping sequences. So, this code should be: au BufNewFile,BufEnter,BufRead vimperator.txt call WW() In the
        Message 3 of 8 , Dec 7, 2012
        • 0 Attachment
          On Friday, December 7, 2012 9:46:10 AM UTC-6, Chris Lott wrote:
          >
          > au BufNewFile,BufEnter,BufRead vimperator.txt :call WW()<cr>
          >

          Autocmds take ex commands, not normal mode mapping sequences. So, this code should be:

          au BufNewFile,BufEnter,BufRead vimperator.txt call WW()

          In the future, or if this doesn't solve your problem, "it isn't working" is not helpful at all to anybody trying to solve your problem. Tell us what happened, any error messages you see, and what you expected to happen instead.

          --
          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
        • Chris Lott
          ... Sorry, I will amend it to the complete problem: the call to the function in the autocommand did nothing. Happy? Thanks. c -- Chris Lott
          Message 4 of 8 , Dec 7, 2012
          • 0 Attachment
            On Fri, Dec 7, 2012 at 10:43 AM, Ben Fritz <fritzophrenic@...> wrote:
            >
            > au BufNewFile,BufEnter,BufRead vimperator.txt call WW()
            >
            > In the future, or if this doesn't solve your problem, "it isn't working" is not helpful at all

            Sorry, I will amend it to the complete problem:

            "the call to the function in the autocommand did nothing." Happy?

            Thanks.

            c
            --
            Chris Lott <chris@...>

            --
            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
          • Chris Lott
            ... The filetype is set to text. Using the proposed solution of: au BufNewFile,BufEnter,BufRead vimperator.txt call WW() almost works: instead of nothing
            Message 5 of 8 , Dec 7, 2012
            • 0 Attachment
              On Fri, Dec 7, 2012 at 10:32 AM, Marcin Szamotulski <mszamot@...> wrote:
              > On 06:46 Fri 07 Dec , Chris Lott wrote:
              >> function! WW()
              >> :set showtabline=0
              >> :set noshowmode
              >> :set laststatus=0
              >> :set noruler
              >> :set noshowcmd
              >> :call VimWriteRoom()
              >> endfunction
              >>
              >> nnoremap WW :call WW()<CR>

              > Some time ago I used vimperator too, and I also had some additional
              > settings for it. As far as I recall vimperator has its own file type,
              > but I might be wrong. If it has you could use FileType autocommand
              > event.

              The filetype is set to text. Using the proposed solution of:

              au BufNewFile,BufEnter,BufRead vimperator.txt call WW()

              almost works: instead of nothing happening when I invoke the
              vimperator file, the screen flashes and then it's as if nothing
              happened. So the function is now being called. But, as usual, if I
              call WW() manually at that point, things work as they are supposed to.
              I guess it must be something in the VimWriteRoom() function, which
              comes from a plugin. I'll dig around in there and see if I can find
              anything.

              c
              --
              Chris Lott <chris@...>

              --
              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
            • Gary Johnson
              ... After you ve opened vimperator.txt, you can determine how those ... That should tell you if your settings are being overridden by the later execution of an
              Message 6 of 8 , Dec 7, 2012
              • 0 Attachment
                On 2012-12-07, Chris Lott wrote:
                > On Fri, Dec 7, 2012 at 10:32 AM, Marcin Szamotulski wrote:
                > > On 06:46 Fri 07 Dec , Chris Lott wrote:
                > >> function! WW()
                > >> :set showtabline=0
                > >> :set noshowmode
                > >> :set laststatus=0
                > >> :set noruler
                > >> :set noshowcmd
                > >> :call VimWriteRoom()
                > >> endfunction
                > >>
                > >> nnoremap WW :call WW()<CR>
                >
                > > Some time ago I used vimperator too, and I also had some additional
                > > settings for it. As far as I recall vimperator has its own file type,
                > > but I might be wrong. If it has you could use FileType autocommand
                > > event.
                >
                > The filetype is set to text. Using the proposed solution of:
                >
                > au BufNewFile,BufEnter,BufRead vimperator.txt call WW()
                >
                > almost works: instead of nothing happening when I invoke the
                > vimperator file, the screen flashes and then it's as if nothing
                > happened. So the function is now being called. But, as usual, if I
                > call WW() manually at that point, things work as they are supposed to.
                > I guess it must be something in the VimWriteRoom() function, which
                > comes from a plugin. I'll dig around in there and see if I can find
                > anything.

                After you've opened vimperator.txt, you can determine how those
                options were set last with the :verbose command, like this:

                :verbose set ruler?

                That should tell you if your settings are being overridden by the
                later execution of an autocommand or filetype plugin.

                You can also record the execution of certain points in your code
                by embedding commands like this:

                echomsg "At point A"

                and seeing which ones were executed and in which order with

                :messages

                Regards,
                Gary

                --
                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
              • David Fishburn
                ... Once in the function use s for step into n for next or c for continue and see what it is doing. -- David Fishburn -- You received this message from
                Message 7 of 8 , Dec 7, 2012
                • 0 Attachment
                  On Dec 7, 2012, at 5:18 PM, Gary Johnson <garyjohn@...> wrote:

                  > On 2012-12-07, Chris Lott wrote:
                  >> On Fri, Dec 7, 2012 at 10:32 AM, Marcin Szamotulski wrote:
                  >>> On 06:46 Fri 07 Dec , Chris Lott wrote:
                  >>>> function! WW()
                  >>>> :set showtabline=0
                  >>>> :set noshowmode
                  >>>> :set laststatus=0
                  >>>> :set noruler
                  >>>> :set noshowcmd
                  >>>> :call VimWriteRoom()
                  >>>> endfunction
                  >>>>
                  >>>> nnoremap WW :call WW()<CR>
                  >>
                  >>> Some time ago I used vimperator too, and I also had some additional
                  >>> settings for it. As far as I recall vimperator has its own file type,
                  >>> but I might be wrong. If it has you could use FileType autocommand
                  >>> event.
                  >>
                  >> The filetype is set to text. Using the proposed solution of:
                  >>
                  >> au BufNewFile,BufEnter,BufRead vimperator.txt call WW()
                  >>
                  >
                  You could run:
                  :breakadd func *WW

                  Once in the function use "s" for step into "n" for next or "c" for continue and see what it is doing.



                  --
                  David Fishburn

                  --
                  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
                  ... Actually more precise would be even better. For example: After loading vimperator.txt from within Vim using :e vimperator.txt, the options set in the WW()
                  Message 8 of 8 , Dec 8, 2012
                  • 0 Attachment
                    On Friday, December 7, 2012 2:34:02 PM UTC-6, Chris Lott wrote:
                    > On Fri, Dec 7, 2012 at 10:43 AM, Ben Fritz <fritzophrenic@...> wrote:
                    >
                    > >
                    >
                    > > au BufNewFile,BufEnter,BufRead vimperator.txt call WW()
                    >
                    > >
                    >
                    > > In the future, or if this doesn't solve your problem, "it isn't working" is not helpful at all
                    >
                    >
                    >
                    > Sorry, I will amend it to the complete problem:
                    >
                    >
                    >
                    > "the call to the function in the autocommand did nothing." Happy?
                    >
                    >

                    Actually more precise would be even better. For example:

                    "After loading vimperator.txt from within Vim using :e vimperator.txt, the options set in the WW() function remain at their previous value. But, after invoking my mapping, the options set in the WW() function are set to the values from the function body."

                    Bonus points for using methods to determine whether your function is being called as suggested by Gary and David.

                    You mention the VimWriteRoom() function may be interfering. Have you tried moving it to the top of your function, or removing it entirely? You say it's from a plugin. Which one?

                    --
                    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.