Townk / vim-autoclose

This plugin for Vim enable an auto-close chars feature for you. For instance if you type an '(', ``autoclose`` will automatically insert a ')' and put the cursor between than.
http://townk.github.com/vim-autoclose/
503 stars 66 forks source link

Apostrophes get miscounted as single quotes #15

Open artm opened 13 years ago

artm commented 13 years ago

Single quotes are treated specially: when a single quote follows alpha-numeric character it doesn't trigger insertion of a closing character - it's most probably an apostrophe. But when a free single quote is typed on a line already containing such an apostrophe it is not auto-closed because it's considered a closing counterpart of the apostrophe.

Example, when typing:

Apostrophe isn't a quote. And '

I expect the second single quote to be auto-closed.

But I'm not sure this is fixable (closing single quotes are difficult to distinguish from apostrophes).

blueyed commented 12 years ago

What is the difference between apostrophes and single quotes? Apostrophes follow some alphanumeric character directly?

That could get tested for when looking for "opening"/starting single quotes maybe.

artm commented 12 years ago

I'm not sure apostrophe can always be detected. (<-- there is one in the previous sentence).

'Single quotes' border on whitespace: opening one follows a whitespace and closing one precedes whitespace.

But some apostrophes are also like that: 'tis not uncommon to do that or this: neighbours' and then continue the sentence. The latter two are indistiguishable form single quotes by the simple means we have available, but the first one (in the middle of the word) we could detect.

blueyed commented 12 years ago

You cannot really handle the 3rd example (easily). But single quotes often are not surrounded by whitespace, e.g. in foo='bar'.'baz'. But they are surrounded by non-alphanumeric characters / punctuation.

artm commented 12 years ago

hmm, actually the conventions differ for plain text (e.g. comments) and code. In fact I would prefer to be able to not auto-close in comments and inside strings, and keep single quote handling in the rest of the code as it is now (there are no "apostrophes" in most programming languages except for may be transpose operator in matlab/octave).