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

Re: How to get the start line and end line of a folding?

Expand Messages
  • anhnmncb
    ... Thank you, I m using usenet proxy to access this list, so if it got lost, I would not get the reply :) -- Regards, anhnmncb
    Message 1 of 10 , Dec 1, 2008
    • 0 Attachment
      On 2008-12-01, Tony Mechelynck wrote:
      >
      > Isn't it clear that I don't know how to help (and that Bram, Dr.Chip,
      > Bill, John and the rest are probably either too busy or equally nonplussed)?
      >
      > In case you didn't know, if you don't get a reply on this list, it
      > usually means that none of those who got your mail (and already got to
      > the point of opening it) knew a satisfatory answer. Lost mail may happen
      > too but it's rare, and with some mail providers including @...
      > it's even possible to get back the mail that "an over-diligent secretary
      > sent to the wastebasket" (and I don't mean a human secretary).
      >
      Thank you, I'm using usenet proxy to access this list, so if it got lost, I
      would not get the reply :)


      --
      Regards,
      anhnmncb


      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Tony Mechelynck
      ... I m using POP on my @gmail.com account (to which I have set the vim lists to send every message) and from time to time I use the webmail interface to
      Message 2 of 10 , Dec 1, 2008
      • 0 Attachment
        On 01/12/08 12:53, anhnmncb wrote:
        > On 2008-12-01, Tony Mechelynck wrote:
        >> Isn't it clear that I don't know how to help (and that Bram, Dr.Chip,
        >> Bill, John and the rest are probably either too busy or equally nonplussed)?
        >>
        >> In case you didn't know, if you don't get a reply on this list, it
        >> usually means that none of those who got your mail (and already got to
        >> the point of opening it) knew a satisfatory answer. Lost mail may happen
        >> too but it's rare, and with some mail providers including @...
        >> it's even possible to get back the mail that "an over-diligent secretary
        >> sent to the wastebasket" (and I don't mean a human secretary).
        >>
        > Thank you, I'm using usenet proxy to access this list, so if it got lost, I
        > would not get the reply :)
        >
        >

        I'm using POP on my @... account (to which I have set the vim
        lists to send every message) and from time to time I use the webmail
        interface to handle spam (recover false positives, report false
        negatives, and then clear the trash and spam folders until next time).
        Now and then there is a false positive at gmail but at least (thank ***)
        there's no firewall or proxy between it and me to delete my mail without
        my say-so.

        Best regards,
        Tony.
        --
        "I'd love to go out with you, but I've been scheduled for a karma
        transplant."

        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_use" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      • Charles Campbell
        ... Hello! I ve not messed with the foldtext option before; I suspect its one of the less common things people do, so your target audience is small. Also, I ve
        Message 3 of 10 , Dec 1, 2008
        • 0 Attachment
          anhnmncb wrote:
          > On 2008-11-30, anhnmncb wrote:
          >
          >> As title, I want to make a function for foldtext like this:
          >>
          >> function MY_TeX_BiBFoldText()
          >> let line = getline(v:foldstart, v:foldend)
          >> let matchlinea = match(line, '^\s*author.*{.*}.*') + 1
          >> let matchlinet = match(line, '^\s*title.*{.*}.*') + 1
          >> let matcha = substitute(getline(matchlinea), '^.*{\(.*\)}*.*$', '\1', 'g')
          >> let matcht = substitute(getline(matchlinet), '^.*{\(.*\)}*.*$', '\1', 'g')
          >> let matched = "title: " . matcht . " author: " . matcha
          >> return v:folddashes . matched
          >> endfunction
          >>
          >> So the folding will show the string "matched", but I find that v:foldstart and
          >> v:foldend have the same value in foldings, so all my foldings show the same
          >> string, why?
          >>
          >>
          > Isn't my description clear? If so, let me know please.
          >
          >
          Hello!

          I've not messed with the foldtext option before; I suspect its one of
          the less common things people do, so your target audience is small.
          Also, I've moved recently to a new email delivery mechanism (even though
          my email address itself hasn't changed), and its flagging your email as
          spam:


          Content analysis details: (5.9 points, 3.5 required)

          pts rule name description
          ---- ---------------------- --------------------------------------------------
          0.1 RDNS_NONE Delivered to trusted network by a host with no rDNS
          3.2 FROM_LOCAL_NOVOWEL From: localpart has series of non-vowel letters
          2.6 RCVD_NUMERIC_HELO Received: contains an IP address used for HELO

          The biggest item on the above list is your false "name". Rather discourages one from looking at your email, you know.

          Now, on to your problem -- I instrumented your function with Decho.vim calls (Dfunc, Decho, Dret). Since the foldtext option says its a no-no to change windows, I used DechoMsgOn which sends Decho output via echomsg.

          You can get the Decho plugin from:

          http://vim.sourceforge.net/scripts/script.php?script_id=120
          -or-
          http://mysite.verizon.net/astronaut/vim/index.html#DECHO
          (this latter one is always the most up-to-date)

          Here's the modified function/script:

          DechoMsgOn
          function! MY_TeX_BiBFoldText()
          call Dfunc("My_TeX_BiBFoldText() v:fold[".v:foldstart.",".v:foldend."]")
          let line = getline(v:foldstart, v:foldend)
          let matchlinea = match(line, '^\s*author.*{.*}.*') + 1
          let matchlinet = match(line, '^\s*title.*{.*}.*') + 1
          call Decho("matchlinea=".matchlinea." matchlinet=".matchlinet)
          let matcha = substitute(getline(matchlinea), '^.*{\(.*\)}*.*$', '\1', 'g')
          let matcht = substitute(getline(matchlinet), '^.*{\(.*\)}*.*$', '\1', 'g')
          let matched = "title: " . matcht . " author: " . matcha
          call Dret("My_TeX_BiBFoldText ".v:folddashes . matched)
          return v:folddashes . matched
          endfunction
          set foldtext=MY_TeX_BiBFoldText()

          With it, you'll see that v:foldstart and v:foldend do differ when MY_TeX_BiBFoldText() is called for each fold. An example of one of the calls (gotten by typing :mess):

          My_TeX_BiBFoldText() v:fold[30,35] {
          |matchlinea=0 matchlinet=0
          |return My_TeX_BiBFoldText -title: author: }

          The problem here is that your two match() calls which look for author and title don't match. None of my bib entries that I used for this test have {}s for author=... or title=... , so that's the proximate cause for me. You'd need to share some of your bib files for a better test, or better: get Decho.vim and try debugging this one yourself.

          Regards,
          Chip Campbell




          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_use" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        • Matt Wozniski
          ... Looks to me like your function is confused... ... Then you use those offsets as line numbers, instead of offsets into a list. Why are you using
          Message 4 of 10 , Dec 1, 2008
          • 0 Attachment
            On Sun, Nov 30, 2008 at 3:52 AM, anhnmncb wrote:
            >
            > As title, I want to make a function for foldtext like this:

            Looks to me like your function is confused...

            > function MY_TeX_BiBFoldText()

            You get a List containing the text of all lines in the fold:

            > let line = getline(v:foldstart, v:foldend)

            Then you find the offsets in that list of the matching lines:

            > let matchlinea = match(line, '^\s*author.*{.*}.*') + 1
            > let matchlinet = match(line, '^\s*title.*{.*}.*') + 1

            Then you use those offsets as line numbers, instead of offsets into a
            list. Why are you using getline(match()+1) here, instead of
            line[match()] ?

            > let matcha = substitute(getline(matchlinea), '^.*{\(.*\)}*.*$', '\1', 'g')
            > let matcht = substitute(getline(matchlinet), '^.*{\(.*\)}*.*$', '\1', 'g')

            Seems to me that those lines should be:

            let matchlinea = match(line, '^\s*author.*{.*}.*')
            let matchlinet = match(line, '^\s*title.*{.*}.*')
            let matcha = substitute(line[matchlinea], '^.*{\(.*\)}*.*$', '\1', 'g')
            let matcht = substitute(line[matchlinet], '^.*{\(.*\)}*.*$', '\1', 'g')

            > let matched = "title: " . matcht . " author: " . matcha
            > return v:folddashes . matched
            > endfunction

            Try that, see if it helps.

            ~Matt

            --~--~---------~--~----~------------~-------~--~----~
            You received this message from the "vim_use" maillist.
            For more information, visit http://www.vim.org/maillist.php
            -~----------~----~----~----~------~----~------~--~---
          • anhnmncb
            ... I use following lines for bib filetype: set fdm=syntax set foldtext=MY_TeX_BiBFoldText() syntax region bibentry start=/^ s*@.*$/ end=/^ s ?}.* n s*$/
            Message 5 of 10 , Dec 1, 2008
            • 0 Attachment
              Charles Campbell (2008-12-01 15:43 -0500) wrote:

              > anhnmncb wrote:
              >> On 2008-11-30, anhnmncb wrote:
              >>
              >>> As title, I want to make a function for foldtext like this:
              >>>
              >>> function MY_TeX_BiBFoldText()
              >>> let line = getline(v:foldstart, v:foldend)
              >>> let matchlinea = match(line, '^\s*author.*{.*}.*') + 1
              >>> let matchlinet = match(line, '^\s*title.*{.*}.*') + 1
              >>> let matcha = substitute(getline(matchlinea), '^.*{\(.*\)}*.*$', '\1', 'g')
              >>> let matcht = substitute(getline(matchlinet), '^.*{\(.*\)}*.*$', '\1', 'g')
              >>> let matched = "title: " . matcht . " author: " . matcha
              >>> return v:folddashes . matched
              >>> endfunction
              >>>
              >>> So the folding will show the string "matched", but I find that v:foldstart and
              >>> v:foldend have the same value in foldings, so all my foldings show the same
              >>> string, why?
              >>>
              >>>
              >> Isn't my description clear? If so, let me know please.
              >>
              >>
              > Hello!
              >
              > I've not messed with the foldtext option before; I suspect its one of
              > the less common things people do, so your target audience is small.
              > Also, I've moved recently to a new email delivery mechanism (even though
              > my email address itself hasn't changed), and its flagging your email as
              > spam:
              >
              >
              > Content analysis details: (5.9 points, 3.5 required)
              >
              > pts rule name description
              > ---- ---------------------- --------------------------------------------------
              > 0.1 RDNS_NONE Delivered to trusted network by a host with no rDNS
              > 3.2 FROM_LOCAL_NOVOWEL From: localpart has series of non-vowel letters
              > 2.6 RCVD_NUMERIC_HELO Received: contains an IP address used for HELO
              >
              > The biggest item on the above list is your false "name". Rather discourages one from looking at your email, you know.
              >
              > Now, on to your problem -- I instrumented your function with Decho.vim calls (Dfunc, Decho, Dret). Since the foldtext option says its a no-no to change windows, I used DechoMsgOn which sends Decho output via echomsg.
              >
              > You can get the Decho plugin from:
              >
              > http://vim.sourceforge.net/scripts/script.php?script_id=120
              > -or-
              > http://mysite.verizon.net/astronaut/vim/index.html#DECHO
              > (this latter one is always the most up-to-date)
              >
              > Here's the modified function/script:
              >
              > DechoMsgOn
              > function! MY_TeX_BiBFoldText()
              > call Dfunc("My_TeX_BiBFoldText() v:fold[".v:foldstart.",".v:foldend."]")
              > let line = getline(v:foldstart, v:foldend)
              > let matchlinea = match(line, '^\s*author.*{.*}.*') + 1
              > let matchlinet = match(line, '^\s*title.*{.*}.*') + 1
              > call Decho("matchlinea=".matchlinea." matchlinet=".matchlinet)
              > let matcha = substitute(getline(matchlinea), '^.*{\(.*\)}*.*$', '\1', 'g')
              > let matcht = substitute(getline(matchlinet), '^.*{\(.*\)}*.*$', '\1', 'g')
              > let matched = "title: " . matcht . " author: " . matcha
              > call Dret("My_TeX_BiBFoldText ".v:folddashes . matched)
              > return v:folddashes . matched
              > endfunction
              > set foldtext=MY_TeX_BiBFoldText()
              >
              > With it, you'll see that v:foldstart and v:foldend do differ when MY_TeX_BiBFoldText() is called for each fold. An example of one of the calls (gotten by typing :mess):
              >
              > My_TeX_BiBFoldText() v:fold[30,35] {
              > |matchlinea=0 matchlinet=0
              > |return My_TeX_BiBFoldText -title: author: }
              >
              > The problem here is that your two match() calls which look for author and title don't match. None of my bib entries that I used for this test have {}s for author=... or title=... , so that's the proximate cause for me. You'd need to share some of your bib files for a better test, or better: get Decho.vim and try debugging this one yourself.

              I use following lines for bib filetype:

              set fdm=syntax
              set foldtext=MY_TeX_BiBFoldText()
              syntax region bibentry start=/^\s*@.*$/ end=/^\s\?}.*\n\s*$/ contained contains=ALL fold

              and the bib example is following:

              @ARTICLE{foo1,
              author = {author1},
              title = {This is a long
              title.),
              journal = {journal1},
              year = 1980,
              volume = 18,
              pages = {55--67},
              TypeofLit = {J}
              }

              @ARTICLE{foo2,
              author = {author2 and author 3},
              title = {title 2},
              journal = {Throbosis Res},
              year = 1982,
              volume = 13,
              pages = {58--67},
              TypeofLit = {J}
              }


              >
              > Regards,
              > Chip Campbell
              >
              >
              >
              >
              >

              --~--~---------~--~----~------------~-------~--~----~
              You received this message from the "vim_use" maillist.
              For more information, visit http://www.vim.org/maillist.php
              -~----------~----~----~----~------~----~------~--~---
            • anhnmncb
              ... Hello, your version works! thanks :) I should use line[], not getline(). ... --~--~---------~--~----~------------~-------~--~----~ You received this
              Message 6 of 10 , Dec 1, 2008
              • 0 Attachment
                Matt Wozniski (2008-12-01 17:10 -0500) wrote:

                > On Sun, Nov 30, 2008 at 3:52 AM, anhnmncb wrote:
                >>
                >> As title, I want to make a function for foldtext like this:
                >
                > Looks to me like your function is confused...
                >
                >> function MY_TeX_BiBFoldText()
                >
                > You get a List containing the text of all lines in the fold:
                >
                >> let line = getline(v:foldstart, v:foldend)
                >
                > Then you find the offsets in that list of the matching lines:
                >
                >> let matchlinea = match(line, '^\s*author.*{.*}.*') + 1
                >> let matchlinet = match(line, '^\s*title.*{.*}.*') + 1
                >
                > Then you use those offsets as line numbers, instead of offsets into a
                > list. Why are you using getline(match()+1) here, instead of
                > line[match()] ?
                >
                >> let matcha = substitute(getline(matchlinea), '^.*{\(.*\)}*.*$', '\1', 'g')
                >> let matcht = substitute(getline(matchlinet), '^.*{\(.*\)}*.*$', '\1', 'g')
                >
                > Seems to me that those lines should be:
                >
                > let matchlinea = match(line, '^\s*author.*{.*}.*')
                > let matchlinet = match(line, '^\s*title.*{.*}.*')
                > let matcha = substitute(line[matchlinea], '^.*{\(.*\)}*.*$', '\1', 'g')
                > let matcht = substitute(line[matchlinet], '^.*{\(.*\)}*.*$', '\1', 'g')
                >
                >> let matched = "title: " . matcht . " author: " . matcha
                >> return v:folddashes . matched
                >> endfunction
                >
                > Try that, see if it helps.

                Hello, your version works! thanks :) I should use line[], not getline().

                >
                > ~Matt
                >
                >

                --~--~---------~--~----~------------~-------~--~----~
                You received this message from the "vim_use" maillist.
                For more information, visit http://www.vim.org/maillist.php
                -~----------~----~----~----~------~----~------~--~---
              • anhnmncb
                ... From my function and other stuff, you know I m not a programmer, and not get familiar with vimscript and regex, anyone can give me an improve version for
                Message 7 of 10 , Dec 1, 2008
                • 0 Attachment
                  On 2008-12-02, anhnmncb wrote:
                  >
                  >
                  > I use following lines for bib filetype:
                  >
                  > set fdm=syntax
                  > set foldtext=MY_TeX_BiBFoldText()
                  > syntax region bibentry start=/^\s*@.*$/ end=/^\s\?}.*\n\s*$/ contained contains=ALL fold

                  From my function and other stuff, you know I'm not a programmer, and not get
                  familiar with vimscript and regex, anyone can give me an improve version for
                  my syntax for bib? My version just can fold the bib entry like this:
                  @article{foo,
                  author = {author},
                  title = {title},
                  }

                  it doesn't support this one:
                  @article{foo,
                  author = {author},
                  title = {title},}

                  And my foldtext can support just one line of title, the splited long line will not
                  be regornized, so if title = {a long \n line title}, then the function just
                  returns "a long", not with the following line.

                  I know maybe there is already some plugins like latexsuit can do that, but I
                  don't get along well with them.

                  Any helpful info will be appreciated.

                  --
                  Regards,
                  anhnmncb


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