Re: breakindent, take 2

2007-05-30 Thread Václav Šmilauer
What do you think? I prefer (c) from implementation, efficiency and 
intuitivity perspective.


I agree. Strongly.


Based on popular demand, this patch implements, in addition, 
'breakindentshift' (brishift). It seems to work well, report problems. 
And please suggestions for some shorter names: breakindent is already 
long enough, breakindentshift is not nice at all.


Vaclav
Index: runtime/doc/eval.txt
===
--- runtime/doc/eval.txt	(revision 296)
+++ runtime/doc/eval.txt	(working copy)
@@ -5262,8 +5262,8 @@
 keymap			Compiled with 'keymap' support.
 langmap			Compiled with 'langmap' support.
 libcall			Compiled with |libcall()| support.
-linebreak		Compiled with 'linebreak', 'breakat' and 'showbreak'
-			support.
+linebreak		Compiled with 'linebreak', 'breakat', 'showbreak' and
+			'breakindent' support.
 lispindent		Compiled with support for lisp indenting.
 listcmds		Compiled with commands for the buffer list |:files|
 			and the argument list |arglist|.
Index: runtime/doc/options.txt
===
--- runtime/doc/options.txt	(revision 296)
+++ runtime/doc/options.txt	(working copy)
@@ -1145,6 +1145,39 @@
 	break if 'linebreak' is on.  Only works for ASCII and also for 8-bit
 	characters when 'encoding' is an 8-bit encoding.
 
+	
+		*'breakindent'* *'bri'*
+'breakindent' 'bri'	boolean (default off)
+			local to window
+			{not in Vi}
+			{not available when compiled without the |+linebreak|
+			feature}
+	Every wrapped line will continue visually indented (same amount of
+	space as the beginning of that line), thus preserving horizontal blocks
+	of text.
+
+		*'breakindentmin'* *'brimin'*
+'breakindentmin' 'brimin' number (default 20)
+			local to window
+			{not in Vi}
+			{not available when compiled without the |+linebreak|
+			feature}
+	Minimum text width that will be kept after applying 'breakindent',
+	even if the resulting text should normally be narrower. This prevents
+	text indented almost to the right window border oocupying lot of
+	vertical space when broken.
+
+		*'breakindentshift'* *'brishift'*
+'breakindentshift' 'brishift' number (default 20)
+			local to window
+			{not in Vi}
+			{not available when compiled without the |+linebreak|
+			feature}
+	After applying 'breakindent', wrapped line beginning will be shift by
+	given number of characters. It permits dynamic French paragraph
+	indentation (negative) or emphasizing the line continuation
+	(positive).
+
 		*'browsedir'* *'bsdir'*
 'browsedir' 'bsdir'	string	(default: last)
 			global
@@ -4227,12 +4260,13 @@
 			{not in Vi}
 			{not available when compiled without the  |+linebreak|
 			feature}
-	If on Vim will wrap long lines at a character in 'breakat' rather
+	If on, Vim will wrap long lines at a character in 'breakat' rather
 	than at the last character that fits on the screen.  Unlike
 	'wrapmargin' and 'textwidth', this does not insert EOLs in the file,
-	it only affects the way the file is displayed, not its contents.  The
-	value of 'showbreak' is used to put in front of wrapped lines.
-	This option is not used when the 'wrap' option is off or 'list' is on.
+	it only affects the way the file is displayed, not its contents.
+	If 'breakindent' is set, line is visually indented. Then, the value
+	of 'showbreak' is used to put in front of wrapped lines. This option
+	is not used when the 'wrap' option is off or 'list' is on.
 	Note that Tab characters after an EOL are mostly not displayed
 	with the right amount of white space.
 
Index: runtime/optwin.vim
===
--- runtime/optwin.vim	(revision 296)
+++ runtime/optwin.vim	(working copy)
@@ -329,6 +329,15 @@
 call append($, linebreak\twrap long lines at a character in 'breakat')
 call append($, \t(local to window))
 call SIDBinOptionL(lbr)
+call append($, breakindent\tpreserve indentation in wrapped text)
+call append($, \t(local to window))
+call SIDBinOptionL(bri)
+call append($, breakindentmin\tminimum text width after indent in 'breakindent')
+call append($, \t(local to window))
+call SIDOptionL(brimin)
+call append($, breakindentshift\tshift beginning of 'breakindent'ed line by this number of characters (negative left))
+call append($, \t(local to window))
+call SIDOptionL(brishift)
 call append($, breakat\twhich characters might cause a line break)
 call SIDOptionG(brk, brk)
 call append($, showbreak\tstring to put before wrapped screen lines)
Index: src/ex_cmds.c
===
--- src/ex_cmds.c	(revision 296)
+++ src/ex_cmds.c	(working copy)
@@ -260,7 +260,7 @@
 	;
 save = *last;
 *last = NUL;
-len = linetabsize(line);		/* get line length */
+len = linetabsize(line, curwin-w_cursor.lnum); /* get line length */
 if (has_tab != NULL)		/* check for embedded TAB */
 	*has_tab = (vim_strrchr(first, TAB) != 

Re: breakindent, take 2

2007-05-29 Thread Václav Šmilauer
It would be nice if I could specificy additional indent for continuation 
lines.
You make indent for continuation line *EQUAL* to indent of the 1st 
screen line.


I use showbreak for this. Wouldn't breakindent=2 just duplicate the 
funcitonality of ':set breakindent' and ':set showbreak=\ \ ' (except 
the higlighting color)? It would not be difficult to add, though.
(And for negative breakindent, well, I would think this is rather 
typesetting issue; but it is true once breakindent is a number, that 
would be trivial enhancement).


Vaclav



Re: breakindent, take 2

2007-05-29 Thread Matthew Winn
On Mon, 28 May 2007 16:04:17 +0200, A.J.Mechelynck
[EMAIL PROTECTED] wrote:

 With this change plus 'linebreak' on, it could be made to simulate French 
 paragrah style for text, where the first line of a paragraph starts maybe 1em 
 or so right of the left margin (but with no blank line, unlike American 
 paragraph style which uses flush-left alignment with a blank line between 
 paragraphs).

That would be useful.

Would there be any benefit from making it a string option that
accepted numbers only, so there could be three styles?

breakindent=nabsolute positioning or broken lines
breakindent=+n   broken lines have additional indentation
breakindent=-n   broken lines have reduced indentation

-- 
Matthew Winn


Re: breakindent, take 2

2007-05-29 Thread Václav Šmilauer

Would there be any benefit from making it a string option that
accepted numbers only, so there could be three styles?

breakindent=nabsolute positioning or broken lines
breakindent=+n   broken lines have additional indentation
breakindent=-n   broken lines have reduced indentation


I am a bit at loss now:

(a) if I switch to breakindent being a number, how will it be turned 
off? As suggested, the actual breakindent is 0, positive/negative values 
would be possible for shifting the indent right/left. But there is no 
value to say: no breakindent, except for the suggestion


(b) breakindent being string and parsing 0' as no breakindent, +0 
(=-0) as keep the indentation, etc for +-1, ... . But it is 
non-intuitive to have +0==-0!=0 and I am not sure how to do that (e.g. 
what variable will keep that in? if string, it will be very slow, it 
would have to be parsed at every line being displayed (!) etc.).


(c) Another option would be to have a numerical value 'breakindentextra' 
 or 'breakindentshift' (or some different name) taking numerical 
(negative, 0, positive) that would do the extra indent, while keeping 
breakindent bool to turn that on/off. But that gives 3 variables (bri, 
brimin, briextra).


(d) To save the variable, 'breakindentmin' could be used do disable 
breakindent (if 0, since that makes no sense) or enable it (if 0), 
while breakindentextra would be as sub (c). In this case, 
'breakindentmin' would be probably renamed to breakindent. But it is not 
very intuitive.


What do you think? I prefer (c) from implementation, efficiency and 
intuitivity perspective.


Vaclav


Re: breakindent, take 2

2007-05-29 Thread Nico Weber

Hi,

What do you think? I prefer (c) from implementation, efficiency and  
intuitivity perspective.


I agree. Strongly.

Great patch, by the way :-)

- Nico




Re: breakindent, take 2

2007-05-29 Thread Yakov Lerner

On 5/29/07, Nico Weber [EMAIL PROTECTED] wrote:

 What do you think? I prefer (c) from implementation, efficiency and
 intuitivity perspective.

I agree. Strongly.


Yes, I agree with (c) , too. I suggested once new type of options to vim that
behaved both like boolean, and numeric. But Bram rejected this. It's a pity
because this would make for lesser number of options. Actually, the
options that would be three-way boolean, and string, and numeric would be
even better.

Yakov


Re: breakindent, take 2

2007-05-29 Thread Yakov Lerner

On 5/29/07, Yakov Lerner [EMAIL PROTECTED] wrote:

On 5/29/07, Nico Weber [EMAIL PROTECTED] wrote:
  What do you think? I prefer (c) from implementation, efficiency and
  intuitivity perspective.

 I agree. Strongly.

Yes, I agree with (c) , too. I suggested once new type of options to vim that
behaved both like boolean, and numeric. But Bram rejected this. It's a pity
because this would make for lesser number of options. Actually, the
options that would be three-way boolean, and string, and numeric would be
even better.


An afterthought.
A string-typed  'breakindent' option could work, too. Empty value=off,
0=on, +n, -n.
Another advantage of string option is that you can add
additional flags to it later, without multiplying number of new options
( a-la 'compatible', 'viminfo', 'giooptions' bag-of-flags ). Bram
is always reluctant to add new options, so this can be a consideration.

Yakov


Re: breakindent, take 2

2007-05-28 Thread Yakov Lerner

On 5/14/07, Václav Šmilauer [EMAIL PROTECTED] wrote:

Hello,

I submit patch that implements the 'breakindent' feature. It is on vim todo
list, since the moment I tried a few years ago (see e.g.
http://marc.info/?l=vim-devm=109921292009721w=1). Picture says what it's
about (showbreak is aligned with first non-whitespace):

http://beta.arcig.cz/~eudoxos/vim7/breakindent1.png
http://beta.arcig.cz/~eudoxos/vim7/breakindent2.png

I tried to address all Bram's comments he had to the original patch, like
coding style, functionality in diff mode, selections etc. I had to change a
few prototypes to pass line number.

There is one bug and some (easily fixable) limitations:

* BUG: there is some weird interaction with quickfix window, where very
rarely there is the ml_get(): invalid line number error. I think it is
caused by passing wrong line number thgouth the *chartabsize*  family
routines (line in the main buffer interpreted as line in the quickfix window
or something like that), but I am not sure.

* No test case. This will be added once there is enough interest from
developers (there _is_ documentation).

* The bri_min variable is not exposed to userspace yet, is set to 20 in the
code. If the rest is considered ready for inclusion, I will add a
user-serrable variable for that.

The patch is against current svn (vim7, rev. 288). Any comments are welcome.


Nice feature. I hope Bram includes it.

Yakov


Re: breakindent, take 2

2007-05-28 Thread Yakov Lerner

On 5/14/07, Václav Šmilauer [EMAIL PROTECTED] wrote:

Hello,

I submit patch that implements the 'breakindent' feature. It is on vim todo
list, since the moment I tried a few years ago (see e.g.
http://marc.info/?l=vim-devm=109921292009721w=1). Picture says what it's
about (showbreak is aligned with first non-whitespace):

http://beta.arcig.cz/~eudoxos/vim7/breakindent1.png
http://beta.arcig.cz/~eudoxos/vim7/breakindent2.png

I tried to address all Bram's comments he had to the original patch, like
coding style, functionality in diff mode, selections etc. I had to change a
few prototypes to pass line number.

There is one bug and some (easily fixable) limitations:

* BUG: there is some weird interaction with quickfix window, where very
rarely there is the ml_get(): invalid line number error. I think it is
caused by passing wrong line number thgouth the *chartabsize*  family
routines (line in the main buffer interpreted as line in the quickfix window
or something like that), but I am not sure.

* No test case. This will be added once there is enough interest from
developers (there _is_ documentation).

* The bri_min variable is not exposed to userspace yet, is set to 20 in the
code. If the rest is considered ready for inclusion, I will add a
user-serrable variable for that.

The patch is against current svn (vim7, rev. 288). Any comments are welcome.


I played with the patch. Works smoothly, I did not find any deficiencies.

I have one wish though.

It would be nice if I could specificy additional indent for continuation lines.
You make indent for continuation line *EQUAL* to indent of the 1st screen line.
Let's say  you have 3 consequitive long lines with same indent, and
each lines wrapped into 4 screen lines. With current 'breakindent'
patch, you see 8 lines
with *same* indent. It's not that easy to see beginning of each long lines.
If breakindent would be numeric value N which meant assign indent K+N
to continuation indent, where K is indent of the line itself. Current
breakindent corresponds to N==0. But I'd probably prefer N=1 or N==2.

Just my 2 cents
Thanks
Yakov
** nobreakindent
 line1line1line1line1
line1line1line1line
 line2line2line2line2
line2line2line2line
** breakindent=0
 line1line1line1line1
 line1line1line1line
 line2line2line2line2
 line2line2line2line
** breakindent=2
 line1line1line1line1
   line1line1line1line
 line2line2line2line2
   line2line2line2line
**


Re: breakindent, take 2

2007-05-28 Thread A.J.Mechelynck

Yakov Lerner wrote:

On 5/14/07, Václav Šmilauer [EMAIL PROTECTED] wrote:

Hello,

I submit patch that implements the 'breakindent' feature. It is on vim 
todo

list, since the moment I tried a few years ago (see e.g.
http://marc.info/?l=vim-devm=109921292009721w=1). Picture says what 
it's

about (showbreak is aligned with first non-whitespace):

http://beta.arcig.cz/~eudoxos/vim7/breakindent1.png
http://beta.arcig.cz/~eudoxos/vim7/breakindent2.png

I tried to address all Bram's comments he had to the original patch, like
coding style, functionality in diff mode, selections etc. I had to 
change a

few prototypes to pass line number.

There is one bug and some (easily fixable) limitations:

* BUG: there is some weird interaction with quickfix window, where very
rarely there is the ml_get(): invalid line number error. I think it is
caused by passing wrong line number thgouth the *chartabsize*  family
routines (line in the main buffer interpreted as line in the quickfix 
window

or something like that), but I am not sure.

* No test case. This will be added once there is enough interest from
developers (there _is_ documentation).

* The bri_min variable is not exposed to userspace yet, is set to 20 
in the

code. If the rest is considered ready for inclusion, I will add a
user-serrable variable for that.

The patch is against current svn (vim7, rev. 288). Any comments are 
welcome.


I played with the patch. Works smoothly, I did not find any deficiencies.

I have one wish though.

It would be nice if I could specificy additional indent for continuation 
lines.
You make indent for continuation line *EQUAL* to indent of the 1st 
screen line.

Let's say  you have 3 consequitive long lines with same indent, and
each lines wrapped into 4 screen lines. With current 'breakindent'
patch, you see 8 lines
with *same* indent. It's not that easy to see beginning of each long lines.
If breakindent would be numeric value N which meant assign indent K+N
to continuation indent, where K is indent of the line itself. Current
breakindent corresponds to N==0. But I'd probably prefer N=1 or N==2.

Just my 2 cents
Thanks
Yakov
** nobreakindent
 line1line1line1line1
line1line1line1line
 line2line2line2line2
line2line2line2line
** breakindent=0
 line1line1line1line1
 line1line1line1line
 line2line2line2line2
 line2line2line2line
** breakindent=2
 line1line1line1line1
   line1line1line1line
 line2line2line2line2
   line2line2line2line
**




With this change plus 'linebreak' on, it could be made to simulate French 
paragrah style for text, where the first line of a paragraph starts maybe 1em 
or so right of the left margin (but with no blank line, unlike American 
paragraph style which uses flush-left alignment with a blank line between 
paragraphs).


Thus breakindent=0 flush left (as above)
breakindent=-3 French style with first line indented 3 spaces, as follows:

The quick brown fox jumps over the lazy dog. The quick
 brown fox jumps over the lazy dog. The quick brown fox jumps
 over the lazy dog.
Line two starts here; neither line goes back to the left
 margin of the Vim window. The lazy dog is jumped over by the
 quick brown fox. The lazy dog is jumped over by the quick
 brown fox. The lazy dog is jumped over by the quick brown fox.

breakindent=2 all lines except the first indented 2 spaces (as you show above)

A single option cannot be both boolean and integer; if a negative number is 
greater than the 1st line indent, don't go back farther left than the left 
margin of the window; thus breakindent=-999 would agree with your first 
example.



Best regards,
Tony.
--
Sex is a natural bodily process, like a stroke.


Re: breakindent, take 2

2007-05-27 Thread Václav Šmilauer
* BUG: there is some weird interaction with quickfix window, where very 
rarely there is the ml_get(): invalid line number error. I think it is 
caused by passing wrong line number thgouth the *chartabsize*  family 
routines (line in the main buffer interpreted as line in the quickfix 
window or something like that), but I am not sure.


Thanks to Tim Pope (to whom I wish to give credit for his try and
comments) I was able to debug this one (the code was supposing that the
window in question was always current, which is not the case with
quickfix window (and possibly other cases)). I know of no other bugs at
this moment.

I also added the brimin option (used to be hardcoded at 20). The
hardcoded 8 for numberlines was fixed as well, now uses number_width.

The patch is against svn 296, please go ahead and test.

Regards, Vaclav.


Index: ex_cmds.c
===
--- ex_cmds.c	(revision 296)
+++ ex_cmds.c	(working copy)
@@ -260,7 +260,7 @@
 	;
 save = *last;
 *last = NUL;
-len = linetabsize(line);		/* get line length */
+len = linetabsize(line, curwin-w_cursor.lnum); /* get line length */
 if (has_tab != NULL)		/* check for embedded TAB */
 	*has_tab = (vim_strrchr(first, TAB) != NULL);
 *last = save;
Index: option.c
===
--- option.c	(revision 296)
+++ option.c	(working copy)
@@ -186,6 +186,10 @@
 #ifdef FEAT_ARABIC
 # define PV_ARAB	OPT_WIN(WV_ARAB)
 #endif
+#ifdef FEAT_LINEBREAK
+# define PV_BRI		OPT_WIN(WV_BRI)
+# define PV_BRIMIN	OPT_WIN(WV_BRIMIN)
+#endif
 #ifdef FEAT_DIFF
 # define PV_DIFF	OPT_WIN(WV_DIFF)
 #endif
@@ -627,6 +631,21 @@
 			{(char_u *)0L, (char_u *)0L}
 #endif
 			},
+{breakindent,   bri,  P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
+#ifdef FEAT_LINEBREAK
+			(char_u *)VAR_WIN, PV_BRI,
+#else
+			(char_u *)NULL, PV_NONE,
+#endif
+			{(char_u *)FALSE, (char_u *)0L}},
+{breakindentmin, brimin, P_NUM|P_VI_DEF|P_VIM|P_RWIN,
+#ifdef FEAT_LINEBREAK
+			(char_u *)VAR_WIN, PV_BRIMIN,
+#else
+			(char_u *)NULL, PV_NONE,
+#endif
+			{(char_u *)20L, (char_u *)20L}},
+			
 {browsedir,   bsdir,P_STRING|P_VI_DEF,
 #ifdef FEAT_BROWSE
 			(char_u *)p_bsdir, PV_NONE,
@@ -7867,6 +7886,16 @@
 	}
 	curwin-w_nrwidth_line_count = 0;
 }
+
+/* 'breakindentmin' must be positive */
+else if (pp == curwin-w_p_brimin)
+{
+	if (curwin-w_p_brimin  1)
+	{
+	errmsg = e_positive;
+	curwin-w_p_brimin = 1;
+	}
+}
 #endif
 
 /*
@@ -9012,6 +9041,8 @@
 	case PV_WRAP:	return (char_u *)(curwin-w_p_wrap);
 #ifdef FEAT_LINEBREAK
 	case PV_LBR:	return (char_u *)(curwin-w_p_lbr);
+	case PV_BRI:	return (char_u *)(curwin-w_p_bri);
+	case PV_BRIMIN:	return (char_u *)(curwin-w_p_brimin);
 #endif
 #ifdef FEAT_SCROLLBIND
 	case PV_SCBIND: return (char_u *)(curwin-w_p_scb);
@@ -9190,6 +9221,8 @@
 to-wo_wrap = from-wo_wrap;
 #ifdef FEAT_LINEBREAK
 to-wo_lbr = from-wo_lbr;
+to-wo_bri = from-wo_bri;
+to-wo_brimin = from-wo_brimin;
 #endif
 #ifdef FEAT_SCROLLBIND
 to-wo_scb = from-wo_scb;
Index: option.h
===
--- option.h	(revision 296)
+++ option.h	(working copy)
@@ -1007,6 +1007,10 @@
 #ifdef FEAT_ARABIC
 , WV_ARAB
 #endif
+#ifdef FEAT_LINEBREAK
+, WV_BRI
+, WV_BRIMIN
+#endif
 #ifdef FEAT_DIFF
 , WV_DIFF
 #endif
Index: proto/charset.pro
===
--- proto/charset.pro	(revision 296)
+++ proto/charset.pro	(working copy)
@@ -14,8 +14,8 @@
 int vim_strsize __ARGS((char_u *s));
 int vim_strnsize __ARGS((char_u *s, int len));
 int chartabsize __ARGS((char_u *p, colnr_T col));
-int linetabsize __ARGS((char_u *s));
-int win_linetabsize __ARGS((win_T *wp, char_u *p, colnr_T len));
+int linetabsize __ARGS((char_u *s, linenr_T lnum));
+int win_linetabsize __ARGS((win_T *wp, char_u *p, colnr_T len, linenr_T lnum));
 int vim_isIDc __ARGS((int c));
 int vim_iswordc __ARGS((int c));
 int vim_iswordp __ARGS((char_u *p));
@@ -23,9 +23,9 @@
 int vim_isfilec __ARGS((int c));
 int vim_isprintc __ARGS((int c));
 int vim_isprintc_strict __ARGS((int c));
-int lbr_chartabsize __ARGS((unsigned char *s, colnr_T col));
-int lbr_chartabsize_adv __ARGS((char_u **s, colnr_T col));
-int win_lbr_chartabsize __ARGS((win_T *wp, char_u *s, colnr_T col, int *headp));
+int lbr_chartabsize __ARGS((unsigned char *s, colnr_T col, linenr_T lnum));
+int lbr_chartabsize_adv __ARGS((char_u **s, colnr_T col, linenr_T lnum));
+int win_lbr_chartabsize __ARGS((win_T *wp, char_u *s, colnr_T col, int *headp, linenr_T lnum));
 int in_win_border __ARGS((win_T *wp, colnr_T vcol));
 void getvcol __ARGS((win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *end));
 colnr_T getvcol_nolist __ARGS((pos_T *posp));
Index: proto/misc1.pro
===
--- proto/misc1.pro	

Re: breakindent, take 2

2007-05-14 Thread Martin Stubenschrott
On Mon, May 14, 2007 at 07:30:23PM +0200, Václav Šmilauer wrote:
 The patch is against current svn (vim7, rev. 288). Any comments are welcome.

I know this might not be desired comment, since I didn't even look at
the patch but only at the screenshots.

I just wanted to say that this feature would really be awesome, as I am
doing a lot of LaTeX coding myself, and the default wrapping really
doesn't look well. 

Martin

PS: it would be nice if we could have the vim latex-suite autoindent by
default in vim without the need to install the latex-suite (which is
just overkill in my opinion).
http://vim-latex.sourceforge.net