Skip to content

Commit 0b0b4a4

Browse files
committed
updated for version 7.3.750
Problem: The justify macro does not always work correctly. Solution: Fix off-by-one error (James McCoy)
1 parent fa4157d commit 0b0b4a4

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

runtime/macros/justify.vim

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
" Function to left and rigt align text.
1+
" Function to left and right align text.
22
"
33
" Written by: Preben "Peppe" Guldberg <[email protected]>
44
" Created: 980806 14:13 (or around that time anyway)
@@ -256,18 +256,17 @@ function! Justify(...) range
256256
let str = substitute(str, '\s\+$', '', '')
257257
let str = substitute(str, '^\s\+', '', '')
258258
let str = substitute(str, '\s\+', ' ', 'g')
259-
" Use substitute() hack to get strlen in characters instead of bytes
260-
let str_n = strlen(substitute(str, '.', 'x', 'g'))
259+
let str_n = strdisplaywidth(str)
261260

262261
" Possible addition of space after punctuation
263262
if exists("join_str")
264263
let str = substitute(str, join_str, '\1 ', 'g')
265264
endif
266-
let join_n = strlen(substitute(str, '.', 'x', 'g')) - str_n
265+
let join_n = strdisplaywidth(str) - str_n
267266

268267
" Can extraspaces be added?
269268
" 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
271270
" How many spaces should be added
272271
let s_add = tw - str_n - indent_n - join_n
273272
let s_nr = strlen(substitute(str, '\S', '', 'g') ) - join_n

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,8 @@ static char *(features[]) =
725725

726726
static int included_patches[] =
727727
{ /* Add new patch number below this line */
728+
/**/
729+
750,
728730
/**/
729731
749,
730732
/**/

0 commit comments

Comments
 (0)