Definite's Extractor

My findings on Life, Linux, Open Source, and so on.

Monthly Archives: February 2007

Cream – Commentify

Cream Comment

No matter programming or editing latex files, “comment code” is an important feature. Cream supports comments as well, but it acts a bit weird. For example. If commenting following LaTeX paragraph.

A quick fox 
jump over 
the lazy dog.

If you mark from top to down, after commented, it looks like:

%%%%A quick fox 
%%%jump over 
%%the lazy dog.

If you mark from down to top, after commented, it looks like:

%A quick fox 
%%jump over 
%%%the lazy dog.

After some tracing, I found that some thing strange happened in EnhancedCommentify.vim:

Normally, whenever user selects Tools ->Block comment, Cream_decommentify("v") should be called exact once. However, for very strange reason, it will be called as many times as the number of lines be marked. If you have this problem, you may try my patch, which is shown as follows:

--- EnhancedCommentify.vim.orig	Thu Feb 15 16:43:15 2007
+++ EnhancedCommentify.vim	Mon Oct 23 18:02:12 2006
@@ -39,19 +39,27 @@
 let g:EnhCommentifyAlignRight = 'Yes'
 " we don't use this, but it ensures  maps aren't created
 let g:EnhCommentifyUserBindings = 'Yes'
+" Added by Ding-Yi Chen
+let g:EnhCommentifyCountdown =0
+let g:EnhCommentifyMyline1 =-1
+let g:EnhCommentifyMyline2 =-1
 
 " 1}}}
 " Functions
 " Cream_commentify() {{{1
 function! Cream_commentify(mode)
 " comment selection or current line if none
-
 	if a:mode == "v"
 		normal gv
 		" cursor in first column of last line implies not selected
 		let mycol = col('.')
 		let myline1 = line("'")
+		if g:EnhCommentifyCountdown == 0
+			let g:EnhCommentifyCountdown = myline2-myline1+1
+			let g:EnhCommentifyMyline1 =myline1
+			let g:EnhCommentifyMyline2 =myline2
+		endif
 		if mycol == "1"
 			let myline2 = myline2 - 1
 		endif
@@ -59,6 +67,9 @@
 		" use current line for start/stop
 		let myline1 = line('.')
 		let myline2 = line('.')
+		let g:EnhCommentifyCountdown=1
+		let g:EnhCommentifyMyline1 =myline1
+		let g:EnhCommentifyMyline2 =myline2
 	endif
 
 	" fix hang if empty (or only returns) selection
@@ -66,8 +77,15 @@
 		return
 	endif
 
-	call EnhancedCommentifyInitBuffer()
-	call EnhancedCommentify("Yes", "comment", myline1, myline2)
+	let g:EnhCommentifyCountdown = g:EnhCommentifyCountdown -1
+	if g:EnhCommentifyCountdown == 0
+		call EnhancedCommentifyInitBuffer()
+		if mycol== "1"
+			let g:EnhCommentifyMyline2 = g:EnhCommentifyMyline2 -1
+		endif
+		call EnhancedCommentify("Yes", "comment", g:EnhCommentifyMyline1, g:EnhCommentifyMyline2)
+	endif
+
 
 	if a:mode == "v"
 		normal gv
@@ -85,6 +103,11 @@
 		let mycol = col('.')
 		let myline1 = line("'")
+		if g:EnhCommentifyCountdown == 0
+			let g:EnhCommentifyCountdown = myline2-myline1+1
+			let g:EnhCommentifyMyline1 =myline1
+			let g:EnhCommentifyMyline2 =myline2
+		endif
 		if mycol == "1"
 			let myline2 = myline2 - 1
 		endif
@@ -92,6 +115,9 @@
 		" use current line for start/stop
 		let myline1 = line('.')
 		let myline2 = line('.')
+		let g:EnhCommentifyCountdown=1
+		let g:EnhCommentifyMyline1 =myline1
+		let g:EnhCommentifyMyline2 =myline2
 	endif
 
 	" fix hang if empty (or only returns) selection
@@ -99,8 +125,14 @@
 		return
 	endif
 
-	call EnhancedCommentifyInitBuffer()
-	call EnhancedCommentify("Yes", "decomment", myline1, myline2)
+	let g:EnhCommentifyCountdown = g:EnhCommentifyCountdown -1
+	if g:EnhCommentifyCountdown == 0
+		call EnhancedCommentifyInitBuffer()
+		if mycol== "1"
+			let g:EnhCommentifyMyline2 = g:EnhCommentifyMyline2 -1
+		endif
+		call EnhancedCommentify("Yes", "decomment", g:EnhCommentifyMyline1, g:EnhCommentifyMyline2)
+	endif
 
 	if a:mode == "v"
 		normal gv