Hi Bram,

As reported in Debian[0], macros/justify.vim doesn't always fully
correctly justify the text.  This is due to a off-by-one in the justify
logic.  The attached patch fixes this as well as updating the script to
use strdisplaywidth() instead of the strlen(substitute(s, '.', 'x',
'g')) hack.

[0]: http://bugs.debian.org/620106
-- 
James
GPG Key: 4096R/331BA3DB 2011-12-05 James McCoy <james...@debian.org>
diff --git a/runtime/macros/justify.vim b/runtime/macros/justify.vim
--- a/runtime/macros/justify.vim
+++ b/runtime/macros/justify.vim
@@ -1,4 +1,4 @@
-" Function to left and rigt align text.
+" Function to left and right align text.
 "
 " Written by:	Preben "Peppe" Guldberg <c928...@student.dtu.dk>
 " Created:	980806 14:13 (or around that time anyway)
@@ -256,18 +256,17 @@
 	let str = substitute(str, '\s\+$', '', '')
 	let str = substitute(str, '^\s\+', '', '')
 	let str = substitute(str, '\s\+', ' ', 'g')
-	" Use substitute() hack to get strlen in characters instead of bytes
-	let str_n = strlen(substitute(str, '.', 'x', 'g'))
+	let str_n = strdisplaywidth(str)
 
 	" Possible addition of space after punctuation
 	if exists("join_str")
 	    let str = substitute(str, join_str, '\1 ', 'g')
 	endif
-	let join_n = strlen(substitute(str, '.', 'x', 'g')) - str_n
+	let join_n = strdisplaywidth(str) - str_n
 
 	" Can extraspaces be added?
 	" Note that str_n may be less than strlen(str) [joinspaces above]
-	if strlen(substitute(str, '.', 'x', 'g')) < tw - indent_n && str_n > 0
+	if strdisplaywidth(str) <= tw - indent_n && str_n > 0
 	    " How many spaces should be added
 	    let s_add = tw - str_n - indent_n - join_n
 	    let s_nr  = strlen(substitute(str, '\S', '', 'g') ) - join_n

Attachment: signature.asc
Description: Digital signature

Reply via email to