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

Re: Restoring statusline

Expand Messages
  • ashres
    Figured it out: function! MyPlugin#Shutdown()    let &statusline=s:saved_statusline endfunction Now statusline can be restored! :) Reference:
    Message 1 of 3 , Jan 1, 2012
    • 0 Attachment
      Figured it out:

      function! MyPlugin#Shutdown()
         let &statusline=s:saved_statusline
      endfunction

      Now statusline can be restored! :)

      Reference: http://www.adp-gmbh.ch/vim/let_vs_set.html

      On Jan 1, 8:45 pm, ashres <ash...@...> wrote:
      > Hey all,
      > I'm working on my first vimscript plugin.  One of the things I want to
      > do in the plugin is to customize the statusline, but then, at a later
      > time, be able to restore it.
      >
      > I've a function called Startup that saves the current statusline:
      >
      > function! MyPlugin#Startup()
      >    let s:saved_statusline = &statusline
      >    " modify the statusline for plugin purposes here
      >    " ....
      > endfunction
      >
      > And, I've got a function called Shutdown, that reverts the statusline
      > back:
      >
      > function! MyPlugin#Shutdown()
      >    set statusline=%{s:saved_statusline}
      > endfunction
      >
      > I call Startup first, then Shutdown next.  I get these errors:
      >
      > E121: Undefined variable: s:saved_statusline
      > E15: Invalid expression: s:saved_statusline
      >
      > Any help would be greatly appreciated!

      --
      You received this message from the "vim_mac" 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
      ... When restoring, use let &statusline = s:saved_statusline instead. If the restoring function is defined in the same script as the saving function, they will
      Message 2 of 3 , Jan 2, 2012
      • 0 Attachment
        On Jan 2, 3:45 am, ashres <ash...@...> wrote:
        > Hey all,
        > I'm working on my first vimscript plugin.  One of the things I want to
        > do in the plugin is to customize the statusline, but then, at a later
        > time, be able to restore it.
        >
        > I've a function called Startup that saves the current statusline:
        >
        > function! MyPlugin#Startup()
        >    let s:saved_statusline = &statusline
        >    " modify the statusline for plugin purposes here
        >    " ....
        > endfunction
        >
        > And, I've got a function called Shutdown, that reverts the statusline
        > back:
        >
        > function! MyPlugin#Shutdown()
        >    set statusline=%{s:saved_statusline}
        > endfunction
        >
        > I call Startup first, then Shutdown next.  I get these errors:
        >
        > E121: Undefined variable: s:saved_statusline
        > E15: Invalid expression: s:saved_statusline
        >
        > Any help would be greatly appreciated!

        When restoring, use

        let &statusline = s:saved_statusline

        instead. If the restoring function is defined in the same script as
        the saving function, they will both have access to the script-local
        variables of that script; but the 'statusline' and its %{} expression
        are evaluated outside of any script context, and, when *evaluating*
        the statusline in order to display it for a particular window,
        s:saved_statusline is indeed not defined.

        --
        You received this message from the "vim_mac" 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.