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

Re: Custom Paragraph Formatting with gq

Expand Messages
  • Andy Wokula
    ... Here on Win32, I checked with gVim 7.0 and gVim7.2.218, and I get almost the same: [headline1] Some Text (ere. Some more text Even more text [headline2]
    Message 1 of 9 , Dec 1, 2009
    • 0 Attachment
      Christian Brabandt schrieb:
      > Hi Andy!
      >
      > On Di, 01 Dez 2009, Andy Wokula wrote:
      >
      >> Andy Wokula schrieb:
      >> setlocal formatexpr=FexLogBook()
      >>
      >> func! FexLogBook()
      >> if mode() =~# '[iR]'
      >> return 1
      >> endif
      >> exec v:lnum. "mark ["
      >> exec (v:lnum + v:count - 1). "mark ]"
      >> '[,']s/^\[.*]$/&\r/
      >> setl fex=
      >> normal! '[gq']
      >> setl fex=FexLogBook()
      >> '[,']s/^\[.*]\zs\n$//
      >> return
      >> endfunc
      >>
      > Nice. But there seems to be a bug somewhere.
      >
      > With this file

      > [headline1]
      > Some Text here.
      > Some more text
      > Even more text
      >
      >
      > [headline2]
      > Some Text here.
      > Some more text
      > Even more text

      > Now executing vim on Windows (this does not happen on Linux):
      >
      > vim -u NONE file.txt
      > :so fex.vim
      > :norm! gqG
      > :norm! u
      >
      > Now the file looks like this:

      > [headline1]
      > Some Text here.
      > Some more (ext
      > Even more text
      >
      >
      > [headline2]
      > Some Text here.
      > Some more text
      > Even more text

      > Notice the ( in the first paragraph. The position of the parenthesis
      > changes, but the buffer stays modified and only :e! reloaded it
      > correctly. This happened with vim 7.2.284 on Windows, same Version under
      > Linux is not affected. Can any Windows user confirm this bahaviour?

      Here on Win32, I checked with gVim 7.0 and gVim7.2.218, and I get almost
      the same:


      [headline1]
      Some Text (ere.
      Some more text
      Even more text


      [headline2]
      Some Text here.
      Some more text
      Even more text


      After undoing, the buffer is not left modified.
      And I typed the commands in (not using :normal).

      Maybe the recursive gq is a problem?

      --
      Andy

      --
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
    • Christian Brabandt
      Fullquote, cause copying this message to vim_dev Hi Andy! ... Sorry, I meant my buffer was not left modified either. Here is an minimal example: func!
      Message 2 of 9 , Dec 1, 2009
      • 0 Attachment
        Fullquote, 'cause copying this message to vim_dev

        Hi Andy!

        On Di, 01 Dez 2009, Andy Wokula wrote:

        > Christian Brabandt schrieb:
        > > Hi Andy!
        > >
        > > On Di, 01 Dez 2009, Andy Wokula wrote:
        > >
        > >> Andy Wokula schrieb:
        > >> setlocal formatexpr=FexLogBook()
        > >>
        > >> func! FexLogBook()
        > >> if mode() =~# '[iR]'
        > >> return 1
        > >> endif
        > >> exec v:lnum. "mark ["
        > >> exec (v:lnum + v:count - 1). "mark ]"
        > >> '[,']s/^\[.*]$/&\r/
        > >> setl fex=
        > >> normal! '[gq']
        > >> setl fex=FexLogBook()
        > >> '[,']s/^\[.*]\zs\n$//
        > >> return
        > >> endfunc
        > >>
        > > Nice. But there seems to be a bug somewhere.
        > >
        > > With this file
        >
        > > [headline1]
        > > Some Text here.
        > > Some more text
        > > Even more text
        > >
        > >
        > > [headline2]
        > > Some Text here.
        > > Some more text
        > > Even more text
        >
        > > Now executing vim on Windows (this does not happen on Linux):
        > >
        > > vim -u NONE file.txt
        > > :so fex.vim
        > > :norm! gqG
        > > :norm! u
        > >
        > > Now the file looks like this:
        >
        > > [headline1]
        > > Some Text here.
        > > Some more (ext
        > > Even more text
        > >
        > >
        > > [headline2]
        > > Some Text here.
        > > Some more text
        > > Even more text
        >
        > > Notice the ( in the first paragraph. The position of the parenthesis
        > > changes, but the buffer stays modified and only :e! reloaded it
        > > correctly. This happened with vim 7.2.284 on Windows, same Version under
        > > Linux is not affected. Can any Windows user confirm this bahaviour?
        >
        > Here on Win32, I checked with gVim 7.0 and gVim7.2.218, and I get almost
        > the same:
        >
        >
        > [headline1]
        > Some Text (ere.
        > Some more text
        > Even more text
        >
        >
        > [headline2]
        > Some Text here.
        > Some more text
        > Even more text
        >
        >
        > After undoing, the buffer is not left modified.
        > And I typed the commands in (not using :normal).
        >
        > Maybe the recursive gq is a problem?
        >

        Sorry, I meant my buffer was not left modified either.

        Here is an minimal example:
        func! FexLogBook()
        set fex=
        exe 'normal! gqap'
        endfunc
        setlocal formatexpr=FexLogBook()
        call feedkeys('gqapu', 't')

        Open vim with the sample text file from above:
        ~$ vim -u NONE -N fex.txt
        and source the file:
        :so fex.vim

        Note the change. BTW: this does not happen, when you call vim like this:
        ~$ vim -u NONE -N -S fex.vim fex.txt

        Try sourcing it several times, the change does not always occur and
        looks differently sometimes. e.g. I get this result:
        [headline1]()

        However changing the function to this, does not result in the bug:
        func! FexLogBook()
        let &l:fex=''
        exe 'normal! gqap'
        endfunc
        setlocal formatexpr=FexLogBook()
        call feedkeys('gqapu', 't')


        regards,
        Christian
        --
        :wq

        --
        You received this message from the "vim_use" maillist.
        For more information, visit http://www.vim.org/maillist.php
      • Chris Jones
        ... [..] ... If you re in a rush, or just lazy, another option is to record a macro: qr record macro name r
        Message 3 of 9 , Dec 1, 2009
        • 0 Attachment
          On Tue, Dec 01, 2009 at 01:05:32AM EST, Robert Chan wrote:
          > I have logbook entries that have the following structure:
          >
          > [entry title 1]
          > Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse blandit
          > ipsum vel elit ultrices pharetra rhoncus tellus aliquam. Donec quis dolor ac
          > elit vestibulum rhoncus. Quisque adipiscing dolor vitae urna molestie in
          > vulputate arcu mattis. Donec felis augue, aliquam dictum mattis vitae,
          > pretium in massa.
          >
          > What I would like to do is apply 'gq' command to format all the paragraphs
          > in the file, but the [entry title 1] header also gets formatted (which I
          > don't want.) So it turns out something like this:

          [..]

          > Any ideas?
          >
          > (I've been reading 'formatoptions' and fo-table but could not find anything
          > of related to custom paragraph settings.)

          If you're in a rush, or just lazy, another option is to record a macro:

          qr record macro name 'r'
          o^[/[^MO^[?]^Mjjgqipjdd?]^Mjdd/[^M format one entry
          q end recording
          ugg undo and move to line 1

          999@r replay 999 times

          The macro actually works to some extent, and is a variation on adding blank lines
          temporarily.

          CJ

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