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

Way to persist custom window-specific info with :mksession?

Expand Messages
  • dagfinn
    Hi all, This is an advanced scripting-related question. I m scripting Vim using Ruby as indicated in this blog post:
    Message 1 of 11 , Apr 1 1:07 PM
      Hi all,

      This is an advanced scripting-related question. I'm scripting Vim
      using Ruby as indicated in this blog post:

      http://www.reiersol.com/blog/index.php?op=ViewArticle&articleId=21&blogId=1

      To make it work, I keep Ruby objects that relate to each window (not
      buffer). I want to store a session and keep this information's
      relation to the windows. When I do :mksession, all the ruby variables
      die. Which is only natural, since :mksession only stores a specific
      set of Vim stuff. I can find a way to store the Ruby information (in
      separate files if necessary), but I do need at least an ID in to
      survive :mksession to make sure I can identify the link between the
      window and its Ruby data. Then I can re-connect the Ruby data with the
      windows after loading the Vim session. I've actually made it work
      using the equivalent of [tabpagenr(), winnr()] as the ID. But I'm not
      finding it robust enough, since these numbers change when tabpages and
      windows are created and deleted.

      I'm not a Vim guru (just a reasonably experienced user), so I'm not
      sure what is the best way to go about it. If there were a way in Vim
      to store window-local variables with the session, that would do it,
      but it seems impossible. The only alternative I've been able to find
      is the ugly one of using a window local option such as foldtext and
      abusing it to store the ID. To make matters worse, this approach to
      identify a window might require storing and restoring the original
      value of the option to avoid interfering with folding (or whatever the
      option controls).

      Is there a better way?
      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • A.Politz
      ... Create the nessescary code yourself, like pseudofun MkSaveWinVarsCode() let res = [] for w in range(1,winn( $ )) let cmd = w. wincmd w|let w:foo= .GetID(w)
      Message 2 of 11 , Apr 1 2:13 PM
        dagfinn wrote:

        > If there were a way in Vim
        >to store window-local variables with the session, that would do it,
        >but it seems impossible.
        >
        >
        Create the nessescary code yourself, like

        pseudofun MkSaveWinVarsCode()
        let res = []
        for w in range(1,winn('$'))
        let cmd = w.'wincmd w|let w:foo='.GetID(w)
        let res+=[cmd]
        endfor
        return res
        endfun

        And than either stuff it at some reasonable place in the created
        sessionfile. Or use the extension mechanism described at point 10
        in':h :mks'.

        Of course this assumes, that the sessionfile restores windows.
        (Otherwise it wouldn't make sense anyway.)

        -ap

        --
        :wq


        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_use" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      • Charles Campbell
        ... Make a List; each element of the List holds a List of window-based variables. Save the whole thing into a DAG_RUBY (global) variable. The viminfo !
        Message 3 of 11 , Apr 1 5:56 PM
          Dagfinn Reiersøl wrote:
          > Charles E Campbell Jr wrote:
          >
          >>
          >> Look into viminfo's "!" option -- with it, variables that start with an
          >> upper case character and don't contain a lower case character are
          >> retained (:help 'viminfo'). You could save quite a bit that way, I'd
          >> assume. For example, DAG_RUBY_GONEIT could be used... :)
          >>
          >>
          > Thanks, that could be helpful for doing part of what I need to do, but
          > as I read the documentation, it doesn't solve the essence of my issue.
          > Global variables are not specific to a window; I would need to save
          > window-local variables to do what I'm trying to do in a reasonably clean
          > way.
          >
          Make a List; each element of the List holds a List of window-based
          variables. Save the whole thing into a DAG_RUBY (global) variable.
          The viminfo '!' option will then save it into .viminfo for you.
          Restoration to window variables seems straightforward to me (windo).

          Regards,
          Chip Campbell


          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_use" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        • Tony Mechelynck
          ... Or even, make a Dictionary, where the key is the window name or number. If you have several such variables per window, the Value could even be a further
          Message 4 of 11 , Apr 2 12:19 AM
            Charles Campbell wrote:
            > Dagfinn Reiersøl wrote:
            >> Charles E Campbell Jr wrote:
            >>
            >>> Look into viminfo's "!" option -- with it, variables that start with an
            >>> upper case character and don't contain a lower case character are
            >>> retained (:help 'viminfo'). You could save quite a bit that way, I'd
            >>> assume. For example, DAG_RUBY_GONEIT could be used... :)
            >>>
            >>>
            >> Thanks, that could be helpful for doing part of what I need to do, but
            >> as I read the documentation, it doesn't solve the essence of my issue.
            >> Global variables are not specific to a window; I would need to save
            >> window-local variables to do what I'm trying to do in a reasonably clean
            >> way.
            >>
            > Make a List; each element of the List holds a List of window-based
            > variables. Save the whole thing into a DAG_RUBY (global) variable.
            > The viminfo '!' option will then save it into .viminfo for you.
            > Restoration to window variables seems straightforward to me (windo).
            >
            > Regards,
            > Chip Campbell

            Or even, make a Dictionary, where the key is the window name or number.
            If you have several such variables per window, the Value could even be a
            further Dictionary with the variable-name as the key and its value as
            the value for each entry. The outer dictionary would of course be a
            global variable with a name in ALL_CAPITALS_AND_SYMBOLS. How to keep it
            in sync when you add, remove, or split windows might require some
            careful thought, but I believe it ought to be possible.

            See ":help Dictionary"

            --~--~---------~--~----~------------~-------~--~----~
            You received this message from the "vim_use" maillist.
            For more information, visit http://www.vim.org/maillist.php
            -~----------~----~----~----~------~----~------~--~---
          • Yegappan Lakshmanan
            Hi, On Wed, Apr 2, 2008 at 12:19 AM, Tony Mechelynck ... There is an item in the todo list for supporting storing persistent variables in the viminfo and
            Message 5 of 11 , Apr 2 7:21 AM
              Hi,

              On Wed, Apr 2, 2008 at 12:19 AM, Tony Mechelynck
              <antoine.mechelynck@...> wrote:
              >
              > Charles Campbell wrote:
              > > Dagfinn Reiersøl wrote:
              > >> Charles E Campbell Jr wrote:
              > >>
              > >>> Look into viminfo's "!" option -- with it, variables that start with an
              > >>> upper case character and don't contain a lower case character are
              > >>> retained (:help 'viminfo'). You could save quite a bit that way, I'd
              > >>> assume. For example, DAG_RUBY_GONEIT could be used... :)
              > >>>
              > >>>
              > >> Thanks, that could be helpful for doing part of what I need to do, but
              > >> as I read the documentation, it doesn't solve the essence of my issue.
              > >> Global variables are not specific to a window; I would need to save
              > >> window-local variables to do what I'm trying to do in a reasonably clean
              > >> way.
              > >>
              > > Make a List; each element of the List holds a List of window-based
              > > variables. Save the whole thing into a DAG_RUBY (global) variable.
              > > The viminfo '!' option will then save it into .viminfo for you.
              > > Restoration to window variables seems straightforward to me (windo).
              > >
              > > Regards,
              > > Chip Campbell
              >
              > Or even, make a Dictionary, where the key is the window name or number.
              > If you have several such variables per window, the Value could even be a
              > further Dictionary with the variable-name as the key and its value as
              > the value for each entry. The outer dictionary would of course be a
              > global variable with a name in ALL_CAPITALS_AND_SYMBOLS. How to keep it
              > in sync when you add, remove, or split windows might require some
              > careful thought, but I believe it ought to be possible.
              >
              > See ":help Dictionary"
              >

              There is an item in the todo list for supporting storing persistent
              variables in the
              viminfo and session files:

              7 Persistent variables: "p:var"; stored in viminfo file and sessions files.

              This feature will help the plugins to remember state across Vim sessions.
              Maybe this can be implemented as part of one of the GSoC projects?

              - Yegappan

              --~--~---------~--~----~------------~-------~--~----~
              You received this message from the "vim_use" maillist.
              For more information, visit http://www.vim.org/maillist.php
              -~----------~----~----~----~------~----~------~--~---
            • dagfinn
              ... I know I can save global variables. It seems I can achieve the same thing by having sessionoptions contain globals . I can see that I m having a hard time
              Message 6 of 11 , Apr 2 1:08 PM
                On Apr 2, 2:56 am, Charles Campbell <drc...@...> wrote:
                > Dagfinn Reiersøl wrote:
                > > Charles E Campbell Jr wrote:
                >
                > >> Look into viminfo's "!" option -- with it, variables that start with an
                > >> upper case character and don't contain a lower case character are
                > >> retained (:help 'viminfo'). You could save quite a bit that way, I'd
                > >> assume. For example, DAG_RUBY_GONEIT could be used... :)
                >
                > > Thanks, that could be helpful for doing part of what I need to do, but
                > > as I read the documentation, it doesn't solve the essence of my issue.
                > > Global variables are not specific to a window; I would need to save
                > > window-local variables to do what I'm trying to do in a reasonably clean
                > > way.
                >
                > Make a List; each element of the List holds a List of window-based
                > variables. Save the whole thing into a DAG_RUBY (global) variable.
                > The viminfo '!' option will then save it into .viminfo for you.
                > Restoration to window variables seems straightforward to me (windo).

                I know I can save global variables. It seems I can achieve the same
                thing by having sessionoptions contain 'globals'.

                I can see that I'm having a hard time explaining what I'm really
                after. The problem is re-connecting the information I've saved to the
                right windows. The function posted by A.Politz uses winnr() to achieve
                this (if I've understood it correctly). I've found that approach
                insufficiently reliable. I would like each window to be marked with an
                ID that will stay constant even when windows are opened and closed.
                And I would like that to be saved when :mksession is run. As I
                mentioned, it can be done with an option, but not without interfering
                with something else in Vim.
                --~--~---------~--~----~------------~-------~--~----~
                You received this message from the "vim_use" maillist.
                For more information, visit http://www.vim.org/maillist.php
                -~----------~----~----~----~------~----~------~--~---
              • dagfinn
                ... My problem is remembering state related to a specific window. --~--~---------~--~----~------------~-------~--~----~ You received this message from the
                Message 7 of 11 , Apr 2 1:12 PM
                  > 7 Persistent variables: "p:var"; stored in viminfo file and sessions files.
                  >
                  > This feature will help the plugins to remember state across Vim sessions.

                  My problem is remembering state related to a specific window.
                  --~--~---------~--~----~------------~-------~--~----~
                  You received this message from the "vim_use" maillist.
                  For more information, visit http://www.vim.org/maillist.php
                  -~----------~----~----~----~------~----~------~--~---
                • A.Politz
                  ... Windows have no identity, unless they are visible. If you close the window, it s gone, all local variables are deleted. You can open a new window, with the
                  Message 8 of 11 , Apr 2 2:31 PM
                    dagfinn wrote:

                    >I can see that I'm having a hard time explaining what I'm really
                    >after. The problem is re-connecting the information I've saved to the
                    >right windows. The function posted by A.Politz uses winnr() to achieve
                    >this (if I've understood it correctly). I've found that approach
                    >insufficiently reliable. I would like each window to be marked with an
                    >ID that will stay constant even when windows are opened and closed.
                    >And I would like that to be saved when :mksession is run. As I
                    >mentioned, it can be done with an option, but not without interfering
                    >with something else in Vim.
                    >
                    >
                    >

                    Windows have no identity, unless they are visible.

                    If you close the window, it's gone, all local variables are deleted.
                    You can open a new window, with the same dimensions, position and
                    buffer, but it's not the same window. Anything else would be news to
                    me.
                    What you experience with window-local options, are the effects of how
                    vim handles this situations. If you spit a window, it inherits the
                    setting of the other window.

                    Are you talking about buffers instead ?

                    -ap


                    --
                    :wq


                    --~--~---------~--~----~------------~-------~--~----~
                    You received this message from the "vim_use" maillist.
                    For more information, visit http://www.vim.org/maillist.php
                    -~----------~----~----~----~------~----~------~--~---
                  • dagfinn
                    ... I know. That s not the problem. The problem is that the identification of the remaining windows change . winnr(), that is. ... When you close a window, the
                    Message 9 of 11 , Apr 2 2:39 PM
                      On Apr 2, 11:31 pm, "A.Politz" <poli...@...> wrote:
                      > dagfinn wrote:
                      > >I can see that I'm having a hard time explaining what I'm really
                      > >after. The problem is re-connecting the information I've saved to the
                      > >right windows. The function posted by A.Politz uses winnr() to achieve
                      > >this (if I've understood it correctly). I've found that approach
                      > >insufficiently reliable. I would like each window to be marked with an
                      > >ID that will stay constant even when windows are opened and closed.
                      > >And I would like that to be saved when :mksession is run. As I
                      > >mentioned, it can be done with an option, but not without interfering
                      > >with something else in Vim.
                      >
                      > Windows have no identity, unless they are visible.
                      >
                      > If you close the window, it's gone, all local variables are deleted.

                      I know. That's not the problem. The problem is that the identification
                      of the remaining windows change . winnr(), that is.

                      > You can open a new window, with the same dimensions, position and
                      > buffer, but it's not the same window. Anything else would be news to
                      > me.

                      When you close a window, the only available ID of another window
                      changes. So windows are not stably identifiable even when they're not
                      explicitly changed. Somehow the window concept in Vim seems
                      incomplete. But when re-loading a session, Vim re-creates windows that
                      appear to the user as the same set of windows. And I'm trying to work
                      with that. That may be the root cause of the problem.

                      > What you experience with window-local options, are the effects of how
                      > vim handles this situations. If you spit a window, it inherits the
                      > setting of the other window.

                      That's a weakness of my idea that I hadn't considered. It's still a
                      more reliable way of identifying windows, though.

                      >
                      > Are you talking about buffers instead ?

                      No.
                      --~--~---------~--~----~------------~-------~--~----~
                      You received this message from the "vim_use" maillist.
                      For more information, visit http://www.vim.org/maillist.php
                      -~----------~----~----~----~------~----~------~--~---
                    Your message has been successfully submitted and would be delivered to recipients shortly.