Tuesday, February 2, 2010

Re: How to show plain text document's structure and syntax highlight

On Tue, Feb 02, 2010 at 09:34:24AM EST, vimer_at_cn wrote:

> I change the plugin name to "TxtBrowser" to reflect its original name
> and add some new features:

Sounds like a good idea - text.vim was just too generic to be safe or
even useful.

But see below.

> 1)Open the URL under cursor in Vim: Put the cursor to the link and use
> ":TxtBrowserUrl" or <Leasder>g to open the link,

Will give it a shot.

> 2)Dictionary lookup for words under cursor. Put the cursor to the word
> and use ":TxtBrowserWord" or <Leasder>f to open lookup result, Use
> ":help txt-browser-dict" for how to customize your prefered web
> dictionary.

Would it make sense to also include an option to fire up a web browser
and start a search engine with the word under the cursor, with perhaps a
few additional words as keywords?

> 3)Search the web for words under the cursor by search engine. Put the
> cursor to the word and use ":TxtBrowserSearch" or <Leasder>s to open
> the search result, Use ":help txt-browser-search" for how to customize
> your prefered dictionary.

I've left my above comment untouched. I wrote my reply to 2) before
reading 3) and it looks like I was reading your thoughts :-)

> All the features are expected to work where Vim works. Please report
> if you find bugs and use ":help txtbrowser" for overview and details
> after install.

I'll check it out asap.

OTOH, I'm not too optimistic about being able to pull this off in the
context of a vim plugin:

I noticed for instance this small problem.

Download this link:

http://www.stlyrics.com/songs/j/jamesbrown4607/itsamansmansmansworld207850.html

| $ elinks -dump -dump-width 100 [http-link] > /tmp/jb.txt

.. or something similar should do it... and then fire up vim:

| $ vim /tmp/jb.txt

As you will notice, the succession of apostrophes on the first line
causes the following to be highlighted:

| It's a Man's Man's Man's World
------- -----

I have underlined the characters that are highlighted on my display.

Unless you're searching for text that happens to be delimited by
apostrophes, there is no good reason why 's a Man' and 's Man' should be
highlighted.

Contrast with:

The difference between 's a Man' and 's Man' is that there is an extra
------- -----
'a' between 's' and 'Man'.
- - ---

Here it makes sense to highlight 's a Man' and 's Man' since the quotes
indicate that the character strings should be taken literally and for
the reader's benefit, it may be worth highlighting them to stress this
fact.

Naturally the issue here is that in the second sentence each occurrence
of an apostrophe forms a logical pair with the one that immediately
follows, which is not the case with the first sentence where the first
's is a contraction of 'it is' and the second is a genitive.

Likewise, still in the first sentence, I can't think of any reason why
the plugin should highlight the letters between the next two ensuing
apostrophes, since they are not part of any common structure and just
correspond to unrelated genitives.

See the problem?

So it looks like TxtBrowser needs to be smart enough to detect this type
of scenerio, and probably quite a few others that I have not even
considered, having little familiarity with parsing English text.

Another example that comes to mind is this bash command:

$ sort<filein >fileout

.. where TxtBrowser highlights 'filein' for no legitimate reason.

So it looks like you would need to define some form of grammar that lets
you correctly parse and highlight English text, and a few subsets or
related dialects that might for instance include programming languages,
mathematical formulas, and quite a few others I'm sure.

Sounds rather daunting as it is, but unfortunately it does not end there
either: why should the TxtBrowser plugin only be capable of correctly
highlighting English .txt files..? What happens with .txt files that
contain Russian, Spanish, German, Vietnamese..? Is there any reason to
exclude them? Shouldn't TxtBrowser be able to provide correct
highlighting for every script that might populate a .txt file?

I'm trying not to sound too negative, but it seems like a huge mountain
indeed you have started climbing.

CJ

--
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php

No comments: