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

folding: some questions and comments (long)

Expand Messages
  • Paul Robins
    (Please forgive me if a second, similar post to the one below appears on this list. I lost up my original posting but I m still not sure if it survived
    Message 1 of 5 , Jul 1, 2002
    • 0 Attachment
      (Please forgive me if a second, similar post to the one below appears on
      this list. I lost up my original posting but I'm still not sure if it
      survived somewhere in the posting process).

      I'm a brand new vim user, quite excited to find a powerful, supported
      text editor with a good implementation of "folding". I have however,
      several comments and questions related to vims implementation of
      folding. For info, I'm using exclusively foldmethod=marker.

      As an ex-Inmos person, where folding was almost a religion I'm a keen
      "folder". The "style" of folding used in some of those long gone editors
      that I used in my youth was (IMHO) elegant and powerful. I'd like to
      make vim look and behave a little more like that, if possible. For
      starters, there are a couple of things I'd like to be able to do. Maybe
      others may also like some of these ideas...

      1) Indent folded lines to the same level as the fold's contents:

      eg:

      if (some test) {
      ... this stuff is folded
      ... so is this

      if (some other test) {
      ... also folded
      }
      }

      reads much nicer than :

      if (some test) {
      +-- 3 lines folded: this stuff is folded --------------------------
      +-- 6 lines folded: so is this ------------------------------------

      if (some other test) {
      +-- 6 lines folded: also folded -----------------------------------
      }
      }

      is this possible ?

      2) enter/exit fold commands?

      These don't seem to exist, or have I just not found them perhaps? I
      found umpteen ways to open/close folds, but none to actually "enter" a
      fold - where "enter" means to see only the contents of that fold in a
      window, as if it is a seperate file/buffer. This is very useful when you
      want to concentrate your work on a single fold and ignore everything
      else in the file. All commands like search/replace and movement issued
      when in this fold take effect on the contents only. The "exit fold"
      command goes up a level and closes the fold.

      Does this exist. If not are there any plans to implement it?

      3) General style of folded lines

      As seen in (1) above, apart from the indentation I'd like a cleaner look
      to the folded lines. I don't like dashes filling up the entire line, and
      I'd like the information about how may lines are within the fold to be
      an optional component of the line (maybe it already is?), or perhaps put
      in the foldcolumn window and not in the buffers main window. Can this be
      done ?

      4) Fold lines with markers are comments

      This one may be a little hard to swallow for some folks: I'd like all
      the text in a folds first line to be a comment. The philosophy we had
      was that if a block was folded then it merited at the very least a
      comment about what was inside. The closed fold line could not contain
      code or content, only foldmarker and comment. This was accomplished by
      the following behaviour:

      When a block is folded an empty fold line is created and the fold is
      closed. The cursor is placed on the closed fold line, where the user may
      add a comment: eg:

      here's some stuff
      here's some stuff
      here's some stuff

      (now I fold it)

      ... ^
      the cursor goes^ here
      ... and now I type my comment

      I can also go back at any time and edit the comment directly on the
      closed fold line. This behaviour forces me to at least think about what
      I'm hiding in a fold and type a line of comment about it, now and again ;-)

      I'm not suggesting that any of the stuff above should become the default
      behaviour for vim. Thanks in advance for any suggestions, comments,
      help, etc.

      Best regards

      Paul
    • Bram Moolenaar
      ... Yes, you can set foldtext to suit your need. ... You can close all other folds: zMzv . But this doesn t display the open fold in another window. That
      Message 2 of 5 , Jul 1, 2002
      • 0 Attachment
        Paul Robins wrote:

        > 1) Indent folded lines to the same level as the fold's contents:
        >
        > eg:
        >
        > if (some test) {
        > ... this stuff is folded
        > ... so is this
        >
        > if (some other test) {
        > ... also folded
        > }
        > }
        >
        > reads much nicer than :
        >
        > if (some test) {
        > +-- 3 lines folded: this stuff is folded --------------------------
        > +-- 6 lines folded: so is this ------------------------------------
        >
        > if (some other test) {
        > +-- 6 lines folded: also folded -----------------------------------
        > }
        > }
        >
        > is this possible ?

        Yes, you can set 'foldtext' to suit your need.

        > 2) enter/exit fold commands?
        >
        > These don't seem to exist, or have I just not found them perhaps? I
        > found umpteen ways to open/close folds, but none to actually "enter" a
        > fold - where "enter" means to see only the contents of that fold in a
        > window, as if it is a seperate file/buffer. This is very useful when you
        > want to concentrate your work on a single fold and ignore everything
        > else in the file. All commands like search/replace and movement issued
        > when in this fold take effect on the contents only. The "exit fold"
        > command goes up a level and closes the fold.
        >
        > Does this exist. If not are there any plans to implement it?

        You can close all other folds: "zMzv". But this doesn't display the
        open fold in another window. That is not planned to be added. You
        could write a script that yanks the text, opens a new window and puts it
        there, putting back the changed text when you close the window. It's a
        bit tricky, but should work.

        There currently are no commands that only work on the open fold(s).
        These are planned, but I have no idea when they get implemented.

        > 3) General style of folded lines
        >
        > As seen in (1) above, apart from the indentation I'd like a cleaner look
        > to the folded lines. I don't like dashes filling up the entire line, and
        > I'd like the information about how may lines are within the fold to be
        > an optional component of the line (maybe it already is?), or perhaps put
        > in the foldcolumn window and not in the buffers main window. Can this be
        > done ?

        Can also be done by tweaking 'foldtext'.

        > 4) Fold lines with markers are comments
        >
        > This one may be a little hard to swallow for some folks: I'd like all
        > the text in a folds first line to be a comment. The philosophy we had
        > was that if a block was folded then it merited at the very least a
        > comment about what was inside. The closed fold line could not contain
        > code or content, only foldmarker and comment. This was accomplished by
        > the following behaviour:
        >
        > When a block is folded an empty fold line is created and the fold is
        > closed. The cursor is placed on the closed fold line, where the user may
        > add a comment: eg:
        >
        > here's some stuff
        > here's some stuff
        > here's some stuff
        >
        > (now I fold it)
        >
        > ... ^
        > the cursor goes^ here
        > ... and now I type my comment
        >
        > I can also go back at any time and edit the comment directly on the
        > closed fold line. This behaviour forces me to at least think about what
        > I'm hiding in a fold and type a line of comment about it, now and again ;-)

        In Vim the text before the marker is used in the closed fold line. You
        can edit it when the fold is open. That's not too different from what
        you want and avoids another editing mode.

        --
        MESKIMEN'S LAW
        There's never time to do it right, but always time to do it over.

        /// Bram Moolenaar -- Bram@... -- http://www.moolenaar.net \\\
        /// Creator of Vim -- http://vim.sf.net -- ftp://ftp.vim.org/pub/vim \\\
        \\\ Project leader for A-A-P -- http://www.a-a-p.org ///
        \\\ Help me helping AIDS orphans in Uganda - http://iccf-holland.org ///
      • Mario Schweigler
        Hi Paul, I can see, you are an origami guy! ;) I am currently writing some scripts to improve the look and feel of vim folding, so that it looks more like
        Message 3 of 5 , Jul 1, 2002
        • 0 Attachment
          Hi Paul,

          I can see, you are an origami guy! ;)

          I am currently writing some scripts to improve the look and feel of vim
          folding, so that it looks more like origami. (This includes the famous 3
          dots! :) )

          Also, I am writing scripts to enter and exit folds. And I'm writing
          syntax and indent files for occam (maybe you are interested in that as
          well).

          All that will soon be in beta stage and I will post a link to the
          mailing list, so that interested people can test it too.

          Mario

          Paul Robins wrote:
          >
          > (Please forgive me if a second, similar post to the one below appears on
          > this list. I lost up my original posting but I'm still not sure if it
          > survived somewhere in the posting process).
          >
          > I'm a brand new vim user, quite excited to find a powerful, supported
          > text editor with a good implementation of "folding". I have however,
          > several comments and questions related to vims implementation of
          > folding. For info, I'm using exclusively foldmethod=marker.
          >
          > As an ex-Inmos person, where folding was almost a religion I'm a keen
          > "folder". The "style" of folding used in some of those long gone editors
          > that I used in my youth was (IMHO) elegant and powerful. I'd like to
          > make vim look and behave a little more like that, if possible. For
          > starters, there are a couple of things I'd like to be able to do. Maybe
          > others may also like some of these ideas...
          >
          > 1) Indent folded lines to the same level as the fold's contents:
          >
          > eg:
          >
          > if (some test) {
          > ... this stuff is folded
          > ... so is this
          >
          > if (some other test) {
          > ... also folded
          > }
          > }
          >
          > reads much nicer than :
          >
          > if (some test) {
          > +-- 3 lines folded: this stuff is folded --------------------------
          > +-- 6 lines folded: so is this ------------------------------------
          >
          > if (some other test) {
          > +-- 6 lines folded: also folded -----------------------------------
          > }
          > }
          >
          > is this possible ?
          >
          > 2) enter/exit fold commands?
          >
          > These don't seem to exist, or have I just not found them perhaps? I
          > found umpteen ways to open/close folds, but none to actually "enter" a
          > fold - where "enter" means to see only the contents of that fold in a
          > window, as if it is a seperate file/buffer. This is very useful when you
          > want to concentrate your work on a single fold and ignore everything
          > else in the file. All commands like search/replace and movement issued
          > when in this fold take effect on the contents only. The "exit fold"
          > command goes up a level and closes the fold.
          >
          > Does this exist. If not are there any plans to implement it?
          >
          > 3) General style of folded lines
          >
          > As seen in (1) above, apart from the indentation I'd like a cleaner look
          > to the folded lines. I don't like dashes filling up the entire line, and
          > I'd like the information about how may lines are within the fold to be
          > an optional component of the line (maybe it already is?), or perhaps put
          > in the foldcolumn window and not in the buffers main window. Can this be
          > done ?
          >
          > 4) Fold lines with markers are comments
          >
          > This one may be a little hard to swallow for some folks: I'd like all
          > the text in a folds first line to be a comment. The philosophy we had
          > was that if a block was folded then it merited at the very least a
          > comment about what was inside. The closed fold line could not contain
          > code or content, only foldmarker and comment. This was accomplished by
          > the following behaviour:
          >
          > When a block is folded an empty fold line is created and the fold is
          > closed. The cursor is placed on the closed fold line, where the user may
          > add a comment: eg:
          >
          > here's some stuff
          > here's some stuff
          > here's some stuff
          >
          > (now I fold it)
          >
          > ... ^
          > the cursor goes^ here
          > ... and now I type my comment
          >
          > I can also go back at any time and edit the comment directly on the
          > closed fold line. This behaviour forces me to at least think about what
          > I'm hiding in a fold and type a line of comment about it, now and again ;-)
          >
          > I'm not suggesting that any of the stuff above should become the default
          > behaviour for vim. Thanks in advance for any suggestions, comments,
          > help, etc.
          >
          > Best regards
          >
          > Paul
        • Bram Moolenaar
          ... Something like this should work: yank the text in the fold, remember the line numbers ... put the text [... do your edits ...] yank all the text ... put
          Message 4 of 5 , Jul 1, 2002
          • 0 Attachment
            Paul Robins wrote:

            > >You could write a script that yanks the text, opens a new window and
            > >puts it there, putting back the changed text when you close the
            > >window. It's a bit tricky, but should work.
            >
            > Sounds messy. It really needs to work in the same window.

            Something like this should work:

            yank the text in the fold, remember the line numbers
            :hide enew
            put the text

            [... do your edits ...]

            yank all the text
            :buf! <previous buffer>
            put the edited text in place of the remembered lines

            The tricky part is that the original buffer must not be edited in
            another way in between, the line numbers could be messed up.

            > > Can also be done by tweaking 'foldtext'.
            >
            > I'm a bit puzzled by this foldtext option, surely because I don't know
            > enough about vim and setting options. Even when I set foldtext to "" I
            > still seem get a line full of dashes and the number of lines as info.

            I'm sure someone on the vim list can help you with this.

            --
            There are three kinds of people: Those who can count & those who can't.

            /// Bram Moolenaar -- Bram@... -- http://www.moolenaar.net \\\
            /// Creator of Vim -- http://vim.sf.net -- ftp://ftp.vim.org/pub/vim \\\
            \\\ Project leader for A-A-P -- http://www.a-a-p.org ///
            \\\ Help me helping AIDS orphans in Uganda - http://iccf-holland.org ///
          • Mario Schweigler
            ... I do it differently in my script (soon available): I first thought of doing it like you described, but it seemed too messy and too dangerous to me. Now I
            Message 5 of 5 , Jul 1, 2002
            • 0 Attachment
              > > >You could write a script that yanks the text, opens a new window
              > > >and puts it there, putting back the changed text when you close the
              > > >window. It's a bit tricky, but should work.
              > >
              > > Sounds messy. It really needs to work in the same window.
              >
              > Something like this should work:
              >
              > yank the text in the fold, remember the line numbers
              > :hide enew
              > put the text
              >
              > [... do your edits ...]
              >
              > yank all the text
              > :buf! <previous buffer>
              > put the edited text in place of the remembered lines
              >
              > The tricky part is that the original buffer must not be edited in
              > another way in between, the line numbers could be messed up.

              I do it differently in my script (soon available): I first thought of
              doing it like you described, but it seemed too messy and too dangerous
              to me. Now I "simply" (it ain't that simple, but it is very stable) put
              the text before and after the folds in special swap files and remove it
              from the buffer so that just the fold will be left. Then I shift it to
              the left so that the indent is 0. (Just as origami does.) Exiting a fold
              works exactly the other way round.

              This way, even if vim crashes, we can still recover the text from the
              swap files, and this is something which is very important for me.

              Please be a bit patient, by the end of the week it will be available.

              > > I'm a bit puzzled by this foldtext option, surely because I don't
              > > know enough about vim and setting options. Even when I set foldtext
              > > to "" I still seem get a line full of dashes and the number of lines
              > > as info.
              >
              > I'm sure someone on the vim list can help you with this.

              OK, Paul: I can send you the famous 3 dots even now, as this is already
              finished and it doesn't affect the other stuff. Add the content of the
              attached file to a configuration file (.vimrc should do it for now,
              later on you should think of putting your own configuration stuff into
              separate *.vim files and calling them from .vimrc).

              Mario
            Your message has been successfully submitted and would be delivered to recipients shortly.