-
Notifications
You must be signed in to change notification settings - Fork 38
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
Autoformat indicator #18
Comments
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 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. |
The Would Also, since I have autoformat off by default and only toggle it manually, the dependence on cursor position shouldn't be an issue, right? |
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 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? |
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 |
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. |
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 Also, 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 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. |
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 |
I have a small feature proposal. I haven't forked this project, but I wouldn't mind doing so and creating a pull request if that sort of thing is welcomed.
My current workflow using vim-pencil with LaTeX involves frequently toggling autoformat on and off (for instance, to switch from writing a paragraph to writing an equation, where I want to manually specify all formatting), as I haven't quite figured out
g:pencil#autoformat_blacklist
. I thought it might be nice to provide a convenience function, similar toPencilMode()
, which returns a string (preferably user-overridable) indicating whether or not autoformat is enabled. To this end, I put the following in my .vimrc and it seems to work for my purposes:If this were built into
plugin/pencil.vim
(again, likePencilMode()
), people could then add something like this to their .vimrc:The text was updated successfully, but these errors were encountered: