Mercurial > vim
comparison runtime/macros/justify.vim @ 1668:0b796e045c42 v7.2b.000
updated for version 7.2b-000
author | vimboss |
---|---|
date | Sun, 13 Jul 2008 17:41:49 +0000 |
parents | 3fc0f57ecb91 |
children | 5c36fe9f19a5 |
comparison
equal
deleted
inserted
replaced
1667:131dbd3d2a4b | 1668:0b796e045c42 |
---|---|
254 | 254 |
255 " Trim trailing, leading and running whitespace | 255 " Trim trailing, leading and running whitespace |
256 let str = substitute(str, '\s\+$', '', '') | 256 let str = substitute(str, '\s\+$', '', '') |
257 let str = substitute(str, '^\s\+', '', '') | 257 let str = substitute(str, '^\s\+', '', '') |
258 let str = substitute(str, '\s\+', ' ', 'g') | 258 let str = substitute(str, '\s\+', ' ', 'g') |
259 let str_n = strlen(str) | 259 " Use substitute() hack to get strlen in characters instead of bytes |
260 let str_n = strlen(substitute(str, '.', 'x', 'g')) | |
260 | 261 |
261 " Possible addition of space after punctuation | 262 " Possible addition of space after punctuation |
262 if exists("join_str") | 263 if exists("join_str") |
263 let str = substitute(str, join_str, '\1 ', 'g') | 264 let str = substitute(str, join_str, '\1 ', 'g') |
264 endif | 265 endif |
265 let join_n = strlen(str) - str_n | 266 let join_n = strlen(substitute(str, '.', 'x', 'g')) - str_n |
266 | 267 |
267 " Can extraspaces be added? | 268 " Can extraspaces be added? |
268 " Note that str_n may be less than strlen(str) [joinspaces above] | 269 " Note that str_n may be less than strlen(str) [joinspaces above] |
269 if strlen(str) < tw - indent_n && str_n > 0 | 270 if strlen(substitute(str, '.', 'x', 'g')) < tw - indent_n && str_n > 0 |
270 " How many spaces should be added | 271 " How many spaces should be added |
271 let s_add = tw - str_n - indent_n - join_n | 272 let s_add = tw - str_n - indent_n - join_n |
272 let s_nr = strlen(substitute(str, '\S', '', 'g') ) - join_n | 273 let s_nr = strlen(substitute(str, '\S', '', 'g') ) - join_n |
273 let s_dup = s_add / s_nr | 274 let s_dup = s_add / s_nr |
274 let s_mod = s_add % s_nr | 275 let s_mod = s_add % s_nr |