Giter Club home page Giter Club logo

Comments (7)

reedes avatar reedes commented on May 25, 2024

I should document the blacklist a bit better, but it's pretty straightforward. It's just a list of syntax highlighting groups, that when detected at the cursor position, will disable autoformat:

Try the following in your .vimrc:

let g:pencil#autoformat_blacklist = [
        \ 'markdownCode',
        \ 'markdownUrl',
        \ 'markdownIdDeclaration',
        \ 'markdownLinkDelimiter',
        \ 'markdownHighlight[A-Za-z0-9]+',
        \ 'mkdCode',
        \ 'mkdIndentCode',
        \ 'markdownFencedCodeBlock',
        \ 'markdownInlineCode',
        \ 'mmdTable[A-Za-z0-9]*',
        \ 'txtCode',
        \ 'texMath',
        \ ]

...where texMath should part of the highlight group name when the cursor is inside a formula.

If that works, I'll add it to the default group list.

Another way to identify the highlight group via an F10 key mapping (or another mapping of your choice):

map <F10> :echo "hi<"
\ . synIDattr(synID(line("."),col("."),1),"name") . '> trans<'
\ . synIDattr(synID(line("."),col("."),0),"name") . "> lo<"
\ . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<CR>

ETA: the status line indicator will be tricky, because the autoformat is dependent on cursor position. So better to rely on highlight groups.

from vim-pencil.

ixjlyons avatar ixjlyons commented on May 25, 2024

The texMath addition does work for the math environments (like \begin{equation}...\end{equation} and \[...\]). However, I pretty much want total control over formatting any time I'm working between \begin{...} and \end{...}, and there aren't really highlight groups for these cases. In fact, I think the only time I actually want autoformatting on is in texSectionZone, texSubsectionZone, and texSubSubSectionZone.

Would g:pencil#autoformat_whitelist be something worth looking into? That is, if I have autoformat off by default, I could set it to activate only in specific environments.

Also, since I have autoformat off by default and only toggle it manually, the dependence on cursor position shouldn't be an issue, right?

from vim-pencil.

reedes avatar reedes commented on May 25, 2024

The blacklist is still enforced even when toggling autoformat on, so if you enter insert mode when cursor position on a blacklisted highlight group, there will be no set fo+=a. Thus, the indicator would be misleading. I'm not certain if it's possible to reliably update the status line in that case to reflect that autoformat isn't active due to the blacklisting.

I'll have to think about the whitelist idea. It could be applied after the blacklist as an override to prevent autoformat from being disabled. (That assumes there's a distinct highlight group to whitelist.)

I'll try working with a tex filetype to get a better handle on how it might work. Could you point me to representative samples?

from vim-pencil.

ixjlyons avatar ixjlyons commented on May 25, 2024

Here is one example which demonstrates some of the basic environments [link].

Essentially the lorem ipsum paragraphs are where I'd want autoformatting, and everything else I can format myself. There are occasions, such as in the caption environment of a figure, where it would be convenient to have autoformat enabled, but is rare enough that just hitting gq a few times is easy and efficient enough.

from vim-pencil.

reedes avatar reedes commented on May 25, 2024

That sample document is very helpful.

I found a better mapping to show the highlight stack: link

Could you try the following addition to your blacklist and see how it behaves?

let g:pencil#autoformat_blacklist = [
        \ 'markdownCode',
        \ 'markdownUrl',
        \ 'markdownIdDeclaration',
        \ 'markdownLinkDelimiter',
        \ 'markdownHighlight[A-Za-z0-9]+',
        \ 'mkdCode',
        \ 'mkdIndentCode',
        \ 'markdownFencedCodeBlock',
        \ 'markdownInlineCode',
        \ 'mmdTable[A-Za-z0-9]*',
        \ 'txtCode',
        \ 'texAbstract',
        \ 'texBeginEndName',
        \ 'texDelimiter',
        \ 'texDocType',
        \ 'texInputFile',
        \ 'texMath',
        \ 'texRefZone',
        \ 'texSection$',
        \ 'texStatement',
        \ 'texTitle',
        \ ]

There's still a problem with entering insert mode from the leading characters in the begin{figure} block, but I could fix that with a code change that scans the line more comprehensively for blacklisted highlight groups.

from vim-pencil.

ixjlyons avatar ixjlyons commented on May 25, 2024

I've been thinking that what you describe at the end is the problem. That is, when I start typing on the line after entering \begin{figure}<CR>, whatever I start typing pops up the line above. I guess I'm thinking autoformatting is causing problems as I'm writing rather than when I make changes to a line and don't want autoformatting to mess up the formatting I've already deliberately specified.

Also, texAbstract is a place where I would want autoformatting enabled.

Honestly, you shouldn't feel obligated to support writing LaTeX documents fluently. I think it would require pretty substantial effort to do so, as there are many packages which provide their own environments, plus an author can define his or her own environments at will. The whitelist idea may also not work, as I've found that inside a table environment, for example, the highlight group is texSectionZone (so it's basically the only highlight group where I want autoformatting, but not always). It might be more appropriate to integrate the idea of vim-pencil into a full-on LaTeX plugin, like Vim-LaTeX or LaTeX-Box, as they probably provide much more powerful ways of obtaining information about the environment than highlight groups. As far as I know, neither of them provides the functionality.

For quite a while, I've done pretty much everything in vim except write LaTeX documents, mainly because I was never satisfied with line wrapping options I tried. I discovered this plugin, and it's basically what I've always wanted -- when I insert text into an already-wrapped line, it maintains the textwidth of the line. After adding the little bit of script from my original post, I'm actually quite happy leaving autoformat off by default and toggling it on only when I'm working on a paragraph.

from vim-pencil.

reedes avatar reedes commented on May 25, 2024

With the latest commit, if pencil can't find a highlight group when entering Insert mode, it'll scan first towards the beginning of the line from the cursor position (as it has done). And now if it still no highlight group, it'll scan towards the end of the line.

The default blacklist is also updated.

I'm holding off on the whitelist idea for now, but will consider it for the future.

For the autoformat indicator, feel free to fork and see if you can get it working to your satisfaction.

Agreed that the LaTeX environment can get complex. But if pencil can support the common case for the shipped syntax file, it should cater to many (most?) users.

As far as disabling autoformat when entering \begin{figure}<CR>, that's a good question. I've had a similar problem defining a new triple-backquote block in markdown, requiring me to hit escape and then Insert again. I'm not sure yet how to detect and disable.

from vim-pencil.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.