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

sourcing functions in file with has gui_running from .vimrc

Expand Messages
  • Chris Lott
    Currently running: VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Sep 1 2012 18:08:47) MacOS X (unix) version Included patches: 1-646 Compiled by Bjorn Winckler
    Message 1 of 6 , Nov 4, 2012
    • 0 Attachment
      Currently running:

      VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Sep 1 2012 18:08:47)
      MacOS X (unix) version
      Included patches: 1-646
      Compiled by Bjorn Winckler <bjorn.winckler@...>

      I have these lines in my .vimrc

      if has("gui_macvim")
      source ~/.vim/vimrc/mygfuncs.vim
      endif

      In the mygfuncs file are some functions that set the `guitablabel` and
      `guitabtooltip` based on two custom functions. The file is being
      sourced (because the functions are defined), but the lines that set
      those variables using those functions aren't working:

      set guitabtooltip=%{GuiTabToolTip()}
      set guitablabel=%{GuiTabLabel()}

      At this point, the variables are set properly, because if I

      :set guitabtooltip

      Vim responds with

      guitabtooltip=%{GuiTabToolTip()}

      But it isn't actually being applied.

      **But** if I then `:so ~/.vimrc`, the tab label and tooltips *are* applied.

      What is going on here?

      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
      ... The way to set an option from a value returned by a function is: let &guitabltooltip=GuiTabToolTip() if you want to set local value (like setlocal does)
      Message 2 of 6 , Nov 4, 2012
      • 0 Attachment
        On 23:40 Sat 03 Nov , Chris Lott wrote:
        > Currently running:
        >
        > VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Sep 1 2012 18:08:47)
        > MacOS X (unix) version
        > Included patches: 1-646
        > Compiled by Bjorn Winckler <bjorn.winckler@...>
        >
        > I have these lines in my .vimrc
        >
        > if has("gui_macvim")
        > source ~/.vim/vimrc/mygfuncs.vim
        > endif
        >
        > In the mygfuncs file are some functions that set the `guitablabel` and
        > `guitabtooltip` based on two custom functions. The file is being
        > sourced (because the functions are defined), but the lines that set
        > those variables using those functions aren't working:
        >
        > set guitabtooltip=%{GuiTabToolTip()}
        > set guitablabel=%{GuiTabLabel()}
        >
        > At this point, the variables are set properly, because if I
        >
        > :set guitabtooltip
        >
        > Vim responds with
        >
        > guitabtooltip=%{GuiTabToolTip()}
        >
        > But it isn't actually being applied.
        >
        > **But** if I then `:so ~/.vimrc`, the tab label and tooltips *are* applied.
        >
        > What is going on here?
        >
        > 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

        The way to set an option from a value returned by a function is:

        let &guitabltooltip=GuiTabToolTip()

        if you want to set local value (like setlocal does) you could use:

        let &l:guitabtooltip=GuiTabToolTip()

        You can read about it in ":help :let-&". You can also use the short
        name of an option. &guitabtooltip is just a VimL variable. There is
        also &g:guitabtooltip which will work like using the :setglobal command.

        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
      • Chris Lott
        ... Thanks, but I m still not understanding. If I use let &guitablabel=GuiTabTabLabel() in my mygfuncs.vim file, I get an error: E714: list required If I use
        Message 3 of 6 , Nov 4, 2012
        • 0 Attachment
          On Sun, Nov 4, 2012 at 1:06 AM, Marcin Szamotulski <mszamot@...> wrote:
          > On 23:40 Sat 03 Nov , Chris Lott wrote:
          >
          > The way to set an option from a value returned by a function is:
          >
          > let &guitabltooltip=GuiTabToolTip()
          >
          > if you want to set local value (like setlocal does) you could use:
          >
          > let &l:guitabtooltip=GuiTabToolTip()
          >
          > You can read about it in ":help :let-&". You can also use the short
          > name of an option. &guitabtooltip is just a VimL variable. There is
          > also &g:guitabtooltip which will work like using the :setglobal command.

          Thanks, but I'm still not understanding. If I use

          let &guitablabel=GuiTabTabLabel()

          in my mygfuncs.vim file, I get an error:

          E714: list required

          If I use
          let &guitabtooltip=%{GuiTabToolTip()}

          I get an invalid expression error.

          So I guess I don't understand how I use your suggestions in the
          included mygfuncs.vim file so that it will work without having to
          source my .vimrc a second time.

          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
        • Tony Mechelynck
          ... No, :set guitablabel=%{GuiTabLabel()} is actually the example given under :help guitablabel so that the function is calculated every time Vim tries to
          Message 4 of 6 , Nov 4, 2012
          • 0 Attachment
            On 04/11/12 11:06, Marcin Szamotulski wrote:
            > On 23:40 Sat 03 Nov , Chris Lott wrote:
            >> Currently running:
            >>
            >> VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Sep 1 2012 18:08:47)
            >> MacOS X (unix) version
            >> Included patches: 1-646
            >> Compiled by Bjorn Winckler <bjorn.winckler@...>
            >>
            >> I have these lines in my .vimrc
            >>
            >> if has("gui_macvim")
            >> source ~/.vim/vimrc/mygfuncs.vim
            >> endif
            >>
            >> In the mygfuncs file are some functions that set the `guitablabel` and
            >> `guitabtooltip` based on two custom functions. The file is being
            >> sourced (because the functions are defined), but the lines that set
            >> those variables using those functions aren't working:
            >>
            >> set guitabtooltip=%{GuiTabToolTip()}
            >> set guitablabel=%{GuiTabLabel()}
            >>
            >> At this point, the variables are set properly, because if I
            >>
            >> :set guitabtooltip
            >>
            >> Vim responds with
            >>
            >> guitabtooltip=%{GuiTabToolTip()}
            >>
            >> But it isn't actually being applied.
            >>
            >> **But** if I then `:so ~/.vimrc`, the tab label and tooltips *are* applied.
            >>
            >> What is going on here?
            >>
            >> 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
            >
            > The way to set an option from a value returned by a function is:
            >
            > let &guitabltooltip=GuiTabToolTip()
            >
            > if you want to set local value (like setlocal does) you could use:
            >
            > let &l:guitabtooltip=GuiTabToolTip()
            >
            > You can read about it in ":help :let-&". You can also use the short
            > name of an option. &guitabtooltip is just a VimL variable. There is
            > also &g:guitabtooltip which will work like using the :setglobal command.
            >
            > Best,
            > Marcin
            >
            No, :set guitablabel=%{GuiTabLabel()} is actually the example given
            under :help 'guitablabel' so that the function is calculated every time
            Vim tries to display the GUI tabs. Using :let &guitablabel =
            GuiTabLabel() would calculate the function just once, when setting the
            option.

            For GUI tabs to be displayed, you need the e flag in 'guioptions'. Also,
            the value of 'showtabline' is relevant:
            0 Never
            1 (default) Only if there are two or more tab pages
            2 Always

            If 'showtabline' is nonzero and 'guioptions' does not contain e you'll
            get text-style tabs as defined by the 'tabline' option, even in GUI mode.

            If these options are set correctly and you still don't see the tabs,
            then another possibility is that Vim would set 'guitablabel' and
            'guitabtooltip' to some default (or empty) value at GUI startup. To
            counteract this, you can set them at the GUIEnter autocommand event:

            if has('gui') && has('autocmd') && has('windows')
            au GUIEnter * set gtl=%{GuiTabLabel()} gtt=%{GuiTabTooltip()}
            endif


            Best regards,
            Tony.
            --
            Mother told me to be good, but she's been wrong before.

            --
            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
            On Sun, Nov 4, 2012 at 7:56 AM, Tony Mechelynck ... Thanks. It s interesting that, as originally written, if the code was in the .vimrc it worked, but if
            Message 5 of 6 , Nov 4, 2012
            • 0 Attachment
              On Sun, Nov 4, 2012 at 7:56 AM, Tony Mechelynck
              >
              > If these options are set correctly and you still don't see the tabs, then
              > another possibility is that Vim would set 'guitablabel' and 'guitabtooltip'
              > to some default (or empty) value at GUI startup. To counteract this, you can
              > set them at the GUIEnter autocommand event:
              >
              > if has('gui') && has('autocmd') && has('windows')
              > au GUIEnter * set gtl=%{GuiTabLabel()} gtt=%{GuiTabTooltip()}
              > endif

              Thanks. It's interesting that, as originally written, if the code was
              in the .vimrc it worked, but if included in a separate file it did not
              unless I use the GUIEnter command...

              But it worked! 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
            • Tony Mechelynck
              ... A script sourced from your vimrc does the same as it would if it replaced the :source statement (except that it runs in a different script context, and
              Message 6 of 6 , Nov 4, 2012
              • 0 Attachment
                On 04/11/12 19:00, Chris Lott wrote:
                > On Sun, Nov 4, 2012 at 7:56 AM, Tony Mechelynck
                >>
                >> If these options are set correctly and you still don't see the tabs, then
                >> another possibility is that Vim would set 'guitablabel' and 'guitabtooltip'
                >> to some default (or empty) value at GUI startup. To counteract this, you can
                >> set them at the GUIEnter autocommand event:
                >>
                >> if has('gui') && has('autocmd') && has('windows')
                >> au GUIEnter * set gtl=%{GuiTabLabel()} gtt=%{GuiTabTooltip()}
                >> endif
                >
                > Thanks. It's interesting that, as originally written, if the code was
                > in the .vimrc it worked, but if included in a separate file it did not
                > unless I use the GUIEnter command...
                >
                > But it worked! Thanks!
                >
                > c
                > --
                > Chris Lott <chris@...>
                >

                A script sourced from your vimrc does the same as it would if it
                replaced the :source statement (except that it runs in a different
                script context, and anything defined with s: or <SID> in one of the
                scripts cannot be accessed from the other).

                OTOH, autocommands for the GUIEnter event are run at the end of
                initialization, after opening the GUI but before the VimEnter event, and
                of course not when running in Console mode.

                Check your vimrc for overriding the other file's 'guitablabel' and
                'guitabtooltip' settings after the :source statement. In cases such as
                this, the last one wins. Since the GUIEnter event is near the end of
                initialization, it overrides anything that is done at startup without an
                autocommand.


                Best regards,
                Tony.
                --
                If the weather is extremely bad, church attendance will be down. If
                the weather is extremely good, church attendance will be down. If the
                bulletin covers are in short supply, however, church attendance will
                exceed all expectations.
                -- Reverend Chichester

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