how to redefine paragraphs?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

how to redefine paragraphs?

Jose Caballero
I have searched on google using the same words as the subject, but
didn't get too much information. Or didn't understand what I found.
Maybe people in this list can provide for hints on how to google it
more precisely.


So this is what I would like to be able to do.
When editing python code, I would like to be able to define a new type
of paragraph (and this applies only to functions and methods) as:

-- beginning:
the line starting with "def" or "    def"

-- end:
the blank line before next "def" or "    def"
or
the blank line before next line with content in column 0 (for example,
next class)
or
end of buffer if none of the above are possible.

It would be nice if that works for copying/deleting "paragraphs" -in
order words, for the ip commands-, but also for movements to first and
last line.
Is something like that even possible?
If yes, I only need the correct keywords to investigate it myself.


A second question would be if it is possible w/o messing with current
definition of paragraph.
Just wondering if what I am looking for can be done but things like
ip, or movement like }, keep working as they are.
Maybe with operator-pending mappings to redefine the new boundaries?


Thanks a lot in advance, whether it is possible or not.
Cheers,
Jose

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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: how to redefine paragraphs?

Tony Mechelynck
On Sat, Sep 9, 2017 at 12:18 AM, Jose Caballero
<[hidden email]> wrote:

> I have searched on google using the same words as the subject, but
> didn't get too much information. Or didn't understand what I found.
> Maybe people in this list can provide for hints on how to google it
> more precisely.
>
>
> So this is what I would like to be able to do.
> When editing python code, I would like to be able to define a new type
> of paragraph (and this applies only to functions and methods) as:
>
> -- beginning:
> the line starting with "def" or "    def"
>
> -- end:
> the blank line before next "def" or "    def"
> or
> the blank line before next line with content in column 0 (for example,
> next class)
> or
> end of buffer if none of the above are possible.
>
> It would be nice if that works for copying/deleting "paragraphs" -in
> order words, for the ip commands-, but also for movements to first and
> last line.
> Is something like that even possible?
> If yes, I only need the correct keywords to investigate it myself.
>
>
> A second question would be if it is possible w/o messing with current
> definition of paragraph.
> Just wondering if what I am looking for can be done but things like
> ip, or movement like }, keep working as they are.
> Maybe with operator-pending mappings to redefine the new boundaries?
>
>
> Thanks a lot in advance, whether it is possible or not.
> Cheers,
> Jose

The details are at ":help paragraph" but I don't understand it much
myself. IIUC (and that's a big if) the only _possible_ paragraph
boundaries are as follows:

• an empty line (with not even a space in it) is always a paragraph end
• a { in column 1 is a paragraph start if 'cpoptions' includes the {
flag (which by default only happens in 'compatible' mode with
$VIM_POSIX unset; but you can set it separately if you want)
• if the 'paragraphs' option is not empty, then a dot in column 1
immediately followed by one of the disjoint character pairs making up
'paragraphs' is a paragraph start. By default, this means one of .IP
.LP .PP .QP .P<space> .TP .HP .LI .Pp .Lp .It .pp .lp .ip .bp
• A section boundary is also a paragraph boundary. Section boundaries
are as follows:
  · A form feed (Ctrl-L) character in column 1 is always a section start
  · If 'sections' is not empty, then a dot in column 1 followed by a
character pair in 'sections' is a section start. By default this means
one of .SH .NH .H<space> .HU .nh .sh

Nothing else can be a paragraph boundary. In particular, "def" cannot
define a paragraph start regardless of any spaces before it on the
same line, an empty line is always a paragraph end, a line with one or
more whitespace characters is never a paragraph boundary, and in
addition, though it is not explicitly specified in the help AFAICT,
the first line in the file is always the start of a section and the
last line in the file is always the end of a section (and therefore,
in both cases, of a paragraph). I'm not sure what happens in the limit
case of a zero-length file. Maybe it is made up of one empty section
containing one empty paragraph containing one empty sentence; or maybe
it has no sections, no paragraphs and no sentences whatsoever.

If someone understands Vim paragraphs better than I do, please chime
in and say whether I interpreted that help item correctly or not.


Best regards,
Tony.

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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: how to redefine paragraphs?

Xavier Noria
I believe the idiomatic solution to this is a plugin that defines a text object for Python functions like https://github.com/bps/vim-textobj-python.

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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: how to redefine paragraphs?

Ben Fritz
In reply to this post by Tony Mechelynck
On Friday, September 8, 2017 at 6:33:56 PM UTC-5, Tony Mechelynck wrote:
> • if the 'paragraphs' option is not empty, then a dot in column 1
> immediately followed by one of the disjoint character pairs making up
> 'paragraphs' is a paragraph start. By default, this means one of .IP
> .LP .PP .QP .P<space> .TP .HP .LI .Pp .Lp .It .pp .lp .ip .bp

Is this option still actually useful to anyone today?

If not, perhaps it's time to extend this option to repurpose it to be actually useful in the modern world?

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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: how to redefine paragraphs?

Christian Brabandt

On Mo, 11 Sep 2017, Ben Fritz wrote:

> On Friday, September 8, 2017 at 6:33:56 PM UTC-5, Tony Mechelynck
> wrote:
> > • if the 'paragraphs' option is not empty, then a dot in column 1
> > immediately followed by one of the disjoint character pairs making
> > up 'paragraphs' is a paragraph start. By default, this means one of
> > .IP .LP .PP .QP .P<space> .TP .HP .LI .Pp .Lp .It .pp .lp .ip .bp
>
> Is this option still actually useful to anyone today?
>
> If not, perhaps it's time to extend this option to repurpose it to be
> actually useful in the modern world?

Some time ago I made a patch to allow for regular expressions to define
paragraph and section borders.
https://groups.google.com/forum/#!msg/vim_dev/6r6qX8W6I_Y/pQPexgLWI6UJ

I think the patch is still available here:
https://github.com/chrisbra/vim-mq-patches/blob/master/paragraphs_re

It probably does not apply cleanly anyhow and it might need some more
work. So if someone could test it and we can further define how it
should behave, we can probably finish it up. However, considering the
many todo items, it will probably take a while until this will be merged
but I guess, tests would help ;)


Best,
Christian
--
   /|__
  ///,-`
  o o ,
  | .' ",
  V-V\  ""-------.
      :           \.
      | /.____.\ ||\\
      ())       ()) "
      |||       |||
      <>>       <>>
  Transsylvanisches MULI

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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: how to redefine paragraphs?

Tim Chase
In reply to this post by Ben Fritz
On 2017-09-11 09:48, Ben Fritz wrote:
> On Friday, September 8, 2017 at 6:33:56 PM UTC-5, Tony Mechelynck
> wrote:
> > • if the 'paragraphs' option is not empty, then a dot in column 1
> > immediately followed by one of the disjoint character pairs
> > making up 'paragraphs' is a paragraph start. By default, this
> > means one
> > of .IP .LP .PP .QP .P<space> .TP .HP .LI .Pp .Lp .It .pp .lp .ip .bp  
>
> Is this option still actually useful to anyone today?

While I've done a the occasional groff/nroff/troff text-processing in
the last decade, it hasn't been much.

> If not, perhaps it's time to extend this option to repurpose it to
> be actually useful in the modern world?

And changing this up to allow smarter paragraph definitions
(Christian's reply just came in re regexp paragraph definitions) would
be great.  I largely use either HTML (using <p> tags) or Markdown
(using blank lines) but could see it being useful when coding to have
something like "\<def \<" for Python.

-tim


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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.