comparison runtime/macros/justify.vim @ 3990:5c36fe9f19a5 v7.3.750

updated for version 7.3.750 Problem: The justify macro does not always work correctly. Solution: Fix off-by-one error (James McCoy)
author Bram Moolenaar <bram@vim.org>
date Wed, 05 Dec 2012 17:03:22 +0100
parents 0b796e045c42
children 7ac9d9e98892
comparison
equal deleted inserted replaced
3989:953a4672434a 3990:5c36fe9f19a5
1 " Function to left and rigt align text. 1 " Function to left and right align text.
2 " 2 "
3 " Written by: Preben "Peppe" Guldberg <c928400@student.dtu.dk> 3 " Written by: Preben "Peppe" Guldberg <c928400@student.dtu.dk>
4 " Created: 980806 14:13 (or around that time anyway) 4 " Created: 980806 14:13 (or around that time anyway)
5 " Revised: 001103 00:36 (See "Revisions" below) 5 " Revised: 001103 00:36 (See "Revisions" below)
6 6
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 " Use substitute() hack to get strlen in characters instead of bytes 259 let str_n = strdisplaywidth(str)
260 let str_n = strlen(substitute(str, '.', 'x', 'g'))
261 260
262 " Possible addition of space after punctuation 261 " Possible addition of space after punctuation
263 if exists("join_str") 262 if exists("join_str")
264 let str = substitute(str, join_str, '\1 ', 'g') 263 let str = substitute(str, join_str, '\1 ', 'g')
265 endif 264 endif
266 let join_n = strlen(substitute(str, '.', 'x', 'g')) - str_n 265 let join_n = strdisplaywidth(str) - str_n
267 266
268 " Can extraspaces be added? 267 " Can extraspaces be added?
269 " Note that str_n may be less than strlen(str) [joinspaces above] 268 " Note that str_n may be less than strlen(str) [joinspaces above]
270 if strlen(substitute(str, '.', 'x', 'g')) < tw - indent_n && str_n > 0 269 if strdisplaywidth(str) <= tw - indent_n && str_n > 0
271 " How many spaces should be added 270 " How many spaces should be added
272 let s_add = tw - str_n - indent_n - join_n 271 let s_add = tw - str_n - indent_n - join_n
273 let s_nr = strlen(substitute(str, '\S', '', 'g') ) - join_n 272 let s_nr = strlen(substitute(str, '\S', '', 'g') ) - join_n
274 let s_dup = s_add / s_nr 273 let s_dup = s_add / s_nr
275 let s_mod = s_add % s_nr 274 let s_mod = s_add % s_nr