Idea for wrapping lines and conceal feature

127 views
Skip to first unread message

Marcin Szamotulski

unread,
Aug 21, 2011, 12:33:29 AM8/21/11
to vim...@googlegroups.com
Hi,

With the conceal feature enabled it happens that a long line that fills
several screen lines (without conceal) is break at exactly the same places
when conceal is not enabled. For example look at the following line with the
following settings: set ft=tex, set cole=2
\(\bigcap_{i\in I}\;A\otimes I_i\ni\sum_{l=1}^n a_l\otimes b_l & \;\Leftrightarrow\;\forall_{i\in I}\ \sum_{l=1}^n a_l\otimes b_l\in A\otimes I_i\notag\)

It would be nice if vim could fill whole the lines, i.e. break them in
more accurate places when conceal is enabled.

Best,
Marcin

Peter Odding

unread,
Aug 21, 2011, 6:57:03 AM8/21/11
to vim...@googlegroups.com
Hi Marcin,

> With the conceal feature enabled it happens that a long line that fills
> several screen lines (without conceal) is break at exactly the same places
> when conceal is not enabled. For example look at the following line with the
> following settings: set ft=tex, set cole=2

> \(\bigcap_{i\in I}\;A\otimes I_i\ni\sum_{l=1}^n a_l\otimes b_l& \;\Leftrightarrow\;\forall_{i\in I}\ \sum_{l=1}^n a_l\otimes b_l\in A\otimes I_i\notag\)


>
> It would be nice if vim could fill whole the lines, i.e. break them in
> more accurate places when conceal is enabled.

I've also noticed this problem and mentioned it on vim-dev, wondering
whether it could be fixed or if it would complicate Vim too much,
however I got no replies so I guess that means it would indeed be hard
too fix, probably for the reasons I expected (see the attached message).

- Peter

mkd.vim
README.md

Marcin Szamotulski

unread,
Aug 21, 2011, 7:02:20 AM8/21/11
to vim...@googlegroups.com
> --
> You received this message from the "vim_dev" 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

> Date: Thu, 22 Jul 2010 05:53:44 +0200
> From: Peter Odding <pe...@peterodding.com>
> To: vim_dev <vim...@googlegroups.com>
> Subject: Markdown syntax script using the new conceal feature
> Reply-To: vim...@googlegroups.com
>
> Hi list,
>
> Last night I switched to Vim 7.3 and one of the first things I wanted to
> try was the new conceal feature. A perfect test subject for me was
> Markdown text formatting because its goal is to be very readable but its
> syntax rules kind of get in the way of readability :-) (IMHO).
>
> After some late night hacking I now have a ~/.vim/syntax/mkd.vim script
> which can conceal most of the extra syntax in Markdown texts and I
> really like it so far. Thanks to everyone who made this possible!
>
> I don't know how far the conceal feature is supposed to be pushed (e.g.
> my syntax script hides full URLs which can more or less span a whole
> screen line...) but during testing I found that it's not really
> compatible with the 'wrap' option, at least not unless you like very
> jagged paragraphs :-(
>
> I've attached the syntax script and a test case (a README from one of my
> Vim plug-ins with a lot of inline hyper links that make the text hard to
> follow without the conceal feature) for anyone who's interested. These
> two files could make a good test case for the line wrapping bug, if
> indeed it is considered a bug and can be fixed with reasonable effort (I
> suppose if concealing can make full screen lines disappear that might
> complicate Vim's drawing code significantly...)
>
> - Peter Odding

> syntax spell toplevel
> setlocal conceallevel=2
>
> runtime! syntax/html.vim
>
> " # Headings
> syntax match mkdHeading /^#.*/ contains=mkdCode,mkdInlineLink,mkdRefLink
> syntax match mkdHeadingMarker /^#\+\s*/ conceal contained containedin=mkdHeading
>
> " Italic text.
> syntax region mkdItalic matchgroup=mkdMarker start=/\\\@<!\*/ end=/\\\@<!\*/ concealends
>
> " Bold text.
> syntax region mkdBold matchgroup=mkdMarker start=/\\\@<!\*\*/ end=/\\\@<!\*\*/ concealends
>
> " Inline `code` fragments.
> syntax region mkdCode matchgroup=mkdMarker start=/\\\@<!`/ end=/\\\@<!`/ concealends
>
> " Pre-formatted code blocks.
> syntax match mkdCodeBlock /\(\_^ .*\)\+/ contains=@NoSpell
>
> " <literal-link-syntax>
> syntax match mkdLiteralLink !<\(\w\+://[^>]\+\|[^ \t\n>@]\+@[^ \t\n>]\+\)>! contains=@NoSpell
> syntax match mkdLiteralLinkMarker /[<>]/ conceal contained containedin=mkdLiteralLink
>
> " [inline](link://syntax)
> syntax match mkdInlineLink /\[\_[^\]]\+]([^)]\+)/
> syntax match mkdInlineLinkLabel /\[\@<=\_[^\]]\+]\@=/ contained containedin=mkdInlineLink contains=@NoSpell
> syntax match mkdInlineLinkTarget /(\@<=[^)]\+)\@=/ contained containedin=mkdInlineLinkEnd contains=@NoSpell
> syntax match mkdInlineLinkStart /\[/ conceal contained containedin=mkdInlineLink
> syntax match mkdInlineLinkEnd /]([^)]\+)/ conceal contained containedin=mkdInlineLink
>
> " [reference][link-syntax]
> syntax match mkdRefLink /\[\_[^\]]\+]\s*\[[^\]]\+]/
> syntax match mkdRefLinkLabel /\[\@<=\_[^\]]\+\%(]\s*\[\)\@=/ contained containedin=mkdRefLink contains=@NoSpell
> syntax match mkdRefLinkName /\%(]\s*\[\)\@<=[^\]]\+]\@=/ contained containedin=mkdRefLinkEnd contains=@NoSpell
> syntax match mkdRefLinkStart /\[/ conceal contained containedin=mkdRefLink
> syntax match mkdRefLinkEnd /]\s*\[[^\]]\+]/ conceal contained containedin=mkdRefLink
>
> " [reference]: definitions
> syntax match mkdRefDef /^\[[^\]]\+]:\s\+.*/
> syntax match mkdRefDefName /\(^\[\)\@<=[^\]]\+]\@=/ contained containedin=mkdRefDef contains=@NoSpell
> syntax match mkdRefDefTarget /\(]:\s*\)\@<=.*/ contained containedin=mkdRefDef contains=@NoSpell
> syntax match mkdRefDefStart /^\[/ conceal contained containedin=mkdRefDef
> syntax match mkdRefDefDelim /]:\@=/ conceal contained containedin=mkdRefDef
>
> " The ability to do this is awesome :-)
> syntax match mkdLessThan /&lt;/ conceal cchar=<
> syntax match mkdGreaterThan /&gt;/ conceal cchar=>
> syntax match mkdAmpersand /&amp;/ conceal cchar=&
> syntax match mkdBullet /\(^\s*\)\@<=[-*+]/ conceal cchar=???
> highlight link mkdBullet Comment
>
> " Default highlighting styles.
> highlight link mkdBold htmlBold
> highlight link mkdCode String
> highlight link mkdCodeBlock String
> highlight link mkdHeading Title
> highlight link mkdHeadingMarker Comment
> highlight link mkdInlineLinkLabel Underlined
> highlight link mkdInlineLinkTarget String
> highlight link mkdItalic htmlItalic
> highlight link mkdLiteralLink Underlined
> highlight link mkdMarker Comment
> highlight link mkdRefDefName String
> highlight link mkdRefDefTarget Underlined
> highlight link mkdRefLinkLabel Underlined
> highlight link mkdRefLinkName String
>
> " I know this is a hack but I *really* don't like the default highlighting of
> " concealed text, which isn't gui=standout but it sure does stand out!
> highlight Conceal guifg=fg guibg=bg
>
> let b:current_syntax = "mkd"

> # Automatic reloading of Vim scripts
>
> The [reload.vim][reload] plug-in automatically reloads various types of [Vim][vim] scripts as they're being edited in Vim to give you instant feedback on the changes you make. For example while writing a Vim syntax script you can open a split window of the relevant file type and every time you [:update][update] your syntax script, [reload.vim][reload] will refresh the syntax highlighting in the split window. Automatic reloading of Vim scripts is currently supported for the following types of scripts:
>
> * [Standard plug-ins](http://vimdoc.sourceforge.net/htmldoc/usr_05.html#standard-plugin) located at `~/.vim/plugin/*.vim` on UNIX, `~\_vimfiles\plugin\*.vim` on Windows;
>
> * [Auto-load scripts](http://vimdoc.sourceforge.net/htmldoc/eval.html#autoload) located at `~/.vim/autoload/*.vim` on UNIX, `~\_vimfiles\autoload\*.vim` on Windows;
>
> * [File-type plug-ins](http://vimdoc.sourceforge.net/htmldoc/filetype.html#filetype-plugins) located at `~/.vim/ftplugin/*.vim` on UNIX, `~\_vimfiles\ftplugin\*.vim` on Windows;
>
> * [Syntax highlighting scripts](http://vimdoc.sourceforge.net/htmldoc/syntax.html#syntax-highlighting) located at `~/.vim/syntax/*.vim` on UNIX, `~\_vimfiles\syntax\*.vim` on Windows;
>
> * [File-type indentation plug-ins](http://vimdoc.sourceforge.net/htmldoc/usr_30.html#30.3) located at `~/.vim/indent/*.vim` on UNIX, `~\_vimfiles\indent\*.vim` on Windows;
>
> * [Color scheme scripts](http://vimdoc.sourceforge.net/htmldoc/syntax.html#:colorscheme) located at `~/.vim/colors/*.vim` on UNIX, `~\_vimfiles\colors\*.vim` on Windows.
>
> Note that [vimrc scripts][vimrc] are not reloaded because that seems to cause more trouble than it's worth...
>
> ## Install & first use
>
> Unzip the most recent [ZIP archive](http://peterodding.com/code/vim/downloads/reload) file inside your Vim profile directory (usually this is `~/.vim` on UNIX and `%USERPROFILE%\vimfiles` on Windows), restart Vim and execute the command `:helptags ~/.vim/doc` (use `:helptags ~\vimfiles\doc` instead on Windows). Now try it out: Edit any Vim script that's already loaded (you can check using the [:scriptnames command][scriptnames]) and confirm that the script is reloaded when you save it (the reload.vim plug-in will print a message to confirm when a script is reloaded).
>
> Out of the box the [reload.vim][reload] plug-in is configured to automatically reload all Vim scripts that it knows how to. If you like it this way then you don't need to configure anything! However if you don't like the automatic reloading then you'll need the following:
>
> ### The `g:reload_on_write` option
>
> If you don't like automatic reloading because it slows Vim down or causes problems you can add the following line to your [vimrc script][vimrc]:
>
> let g:reload_on_write = 0
>
> This disables automatic reloading which means you'll have to reload scripts using the command discussed below.
>
> ### The `:ReloadScript` command
>
> You can execute the `:ReloadScript` command to reload the Vim script you're editing. If you provide a script name as argument to the command then that script will be reloaded instead, e.g.:
>
> :ReloadScript ~/.vim/plugin/reload.vim
>
> If after executing this command you see Vim errors such as "Function already exists" ([E122](http://vimdoc.sourceforge.net/htmldoc/eval.html#E122)) or "Command already exists" ([E174](http://vimdoc.sourceforge.net/htmldoc/map.html#E174)) then you'll need to change your Vim script(s) slightly to enable reloading, see below.
>
> ## Things that prevent reloading
>
> If you want your Vim plug-ins and/or other scripts to be automatically reloaded they'll have to be written a certain way, though you can consider the following points good practice for Vim script writing anyway:
>
> ### Use a bang in command and function definitions!
>
> Function and command definitions using Vim's [:command](http://vimdoc.sourceforge.net/htmldoc/map.html#:command) and [:function](http://vimdoc.sourceforge.net/htmldoc/eval.html#:function) built-ins should include a [bang (!)](http://vimdoc.sourceforge.net/htmldoc/map.html#:command-bang) symbol, otherwise Vim will complain that the command or function already exists:
>
> " Bad:
> :command MyCmd call MyFun()
> :function MyFun()
> :endfunction
>
> " Good:
> :command! MyCmd call MyFun()
> :function! MyFun()
> :endfunction
>
> ### Use automatic command groups
>
> Automatic commands using Vim's [:autocmd][autocmd] built-in should be defined inside of an [automatic command group](http://vimdoc.sourceforge.net/htmldoc/autocmd.html#:augroup) that's cleared so the automatic commands don't stack indefinitely when your [:autocmd][autocmd] commands are executed several times:
>
> " Bad example: If the following line were re-evaluated, the message would
> " appear multiple times the next time the automatic command fires:
> :autocmd TabEnter * echomsg "Entered tab page"
>
> " Good example: The following three lines can be reloaded without the
> " message appearing multiple times:
> :augroup MyPlugin
> : autocmd! TabEnter * echomsg "Entered tab page"
> :augroup END
>
> ## Alternatives
>
> The [ReloadScript](http://www.vim.org/scripts/script.php?script_id=1904) plug-in on [www.vim.org][vim] also supports reloading of Vim scripts, but there are a few notable differences:
>
> * This plug-in focuses on automatic reloading (I'm lazy) while the other one requires manual reloading;
>
> * This plug-in will *never* [:source](http://vimdoc.sourceforge.net/htmldoc/repeat.html#:source) a file that hasn't already been loaded by Vim -- it checks using Vim's [:scriptnames][scriptnames] command;
>
> * This plug-in can more or less reload itself ;-)
>
> ## Contact
>
> If you have questions, bug reports, suggestions, etc. the author can be contacted at <pe...@peterodding.com>. The latest version is available at <http://peterodding.com/code/vim/reload/> and <http://github.com/xolox/vim-reload>. If you like the plug-in please vote for it on [www.vim.org](http://www.vim.org/scripts/script.php?script_id=3148).
>
> ## License
>
> This software is licensed under the [MIT license](http://en.wikipedia.org/wiki/MIT_License).
> ?? 2010 Peter Odding &lt;<pe...@peterodding.com>&gt;.
>
>
> [autocmd]: http://vimdoc.sourceforge.net/htmldoc/autocmd.html#:autocmd
> [reload]: http://github.com/xolox/vim-reload/blob/master/reload.vim
> [scriptnames]: http://vimdoc.sourceforge.net/htmldoc/repeat.html#:scriptnames
> [update]: http://vimdoc.sourceforge.net/htmldoc/editing.html#:update
> [vim]: http://www.vim.org/
> [vimrc]: http://vimdoc.sourceforge.net/htmldoc/starting.html#vimrc

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


Thanks!
Marcin

Christian Brabandt

unread,
Aug 21, 2011, 7:33:54 AM8/21/11
to vim...@googlegroups.com
Hi Marcin!

I also noticed that behaviour and according to Bram it's "not easy to
make that work better"¹. It looks indeed a little bit strange, but it is
not that bad after all, so I don't care too much about it.

¹) http://groups.google.com/group/vim_dev/msg/349e26164282817b

regards,
Christian

Bram Moolenaar

unread,
Aug 21, 2011, 11:53:27 AM8/21/11
to Marcin Szamotulski, vim...@googlegroups.com

Marcin Szamotulski wrote:

This is intentional. Without this cursor movements would be messed up,
as the screen line depends on how text is concealed, which requires
syntax parsing, which is slow.

There still is the bug that cursor positioning with the mouse doesn't
work properly. To fix that requires something similar as what is
required for this feature. Perhaps someone can make that work, it's not
going to be easy.

--
No children may attend school with their breath smelling of "wild onions."
[real standing law in West Virginia, United States of America]

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Reply all
Reply to author
Forward
0 new messages