Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow users to specify additional sentence terminators #17

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ghost
Copy link

@ghost ghost commented Aug 24, 2020

I use this to prevent LeTeX environments from interfering with sentence rewrapping (gqis). In my after/ftplugin/tex.vim:

let g:re_term_user =                                                                 
  \ '|\\begin\{[a-zA-Z]*\}' .
  \ '|\\end\{[a-zA-Z]*\}'

call textobj#sentence#init()

Copy link
Member

@alerque alerque left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking the time to contribute. Can you please add a commit to this PR that documents this feature in the README so that it is discoverable?

@ghost
Copy link
Author

ghost commented Aug 27, 2020

Okay, I will do that. I am also thinking about the interface and might try to make it more flexible. Will probably update the pull request on the weekend. Thanks for considering to merge it!

@sekoenig
Copy link

I have been working on it and noticed a problem: there is interference with the l:re_negative_lookback. What I mean is, when I add a custom terminator and use gqis on a line preceeded by one of the custom terminators, it will read backwards to far and reformat too much.

I noticed that problem is gone when I remove l:re_negative_lookback from b:textobj_sentence_re_i, but that is of course not a satisfactory solution.

Any suggestions how this can be fixed properly, i.e., by adjusting l:re_negative_lookback based on g:re_extra_sentence_term?

@sekoenig
Copy link

I've been trying but can't quite get it to work due to lack of experience with lookahead and lookbehind regexp tricks. What I want to do is modify l:re_negative_lookback so that it does not read across anything that is specified in g:re_extra_sentence_term. Can you perhaps help me by explaining what exactly the current l:re_negative_lookback does and what is its interplay with l:leading and l:trailing?

Comment on lines +94 to +95
\ '([!?]' .
\ g:re_extra_sentence_term .
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A cursory look at your question ... wouldn't the extra expressions you are trying to inject need to go inside the character class expression rather than after it? Something like:

Suggested change
\ '([!?]' .
\ g:re_extra_sentence_term .
\ '([!?'. g:re_extra_sentence_term .']' .

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh hmm you aren't adding characters you're adding whole expressions. We probably need to setup all our matches as an array of expressions and join them at the last minute using (one|two|three) option grouping instead of a character class.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh hmm you aren't adding characters you're adding whole expressions. We probably need to setup all our matches as an array of expressions and join them at the last minute using (one|two|three) option grouping instead of a character class.

Yes, I want to allow whole expressions. Let me give an example and demonstrate the problem:

\documentclass{minimal}
\begin{document}

\newcommand{\beq}{\begin{equation}}
\newcommand{\eeq}{\end{equation}}

This is a long sentence, exceeding eighty characters and containing an equation environment below, starting here:
\beq
  x = 1 \,,
\eeq
and it is followed by another long sentence that exceeds eighty characters and should be wrapped by \texttt{gqis}.

\end{document}

Consider this with

let g:re_extra_sentence_term =
  \ '|\\beq' .
  \ '|\\eeq'
  
call textobj#sentence#init()

With my proposed implementation, when I place the cursor on the line before the equation and hit gqis, it does (almost) the right thing:

This is a long sentence, exceeding eighty characters and containing an equation
environment below, starting here: \beq
...

(I noticed only now it's not perfect, the \beq should actually stay on its own line ideally, but that may be a paragraph issue rather than a sentence issue).

Setting that aside, the main trouble is that hitting gqis when the cursor is in the line after the \eeq, it does not rewrap that but rather the cursor jumps to above the equation and gives again

This is a long sentence, exceeding eighty characters and containing an equation
environment below, starting here: \beq
...

As far as I can tell, the reason is that the negative lookback jumps over the \eeq and \beq somehow.

@VimWei
Copy link

VimWei commented Jun 8, 2024

Has there been any new progress on this PR (Pull Request)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants