On Thursday, November 28, 2013 5:50:23 PM UTC+5:30, Bram Moolenaar wrote: ... > > The attached patch adds a 'listchars' option 'lsp' which marks leading > > > space at 'shiftwidth' with the defined characer so that you can follow > > > the indent level in a bit too much nested code when you also have > > > 'expandtab' option set and use spaces for indentation (e.g. Python > > > code in many repos enforce a 'spaces only indenting' policy). > > > > I can't help but reading "lsp" as Lisp... > > > > Can you attach a screenshot, so that we can see what the effect is > > without rebuilding Vim? > > > > The change to Make_mvc.mak seems unrelated. > > > > I guess that most users would prefer highlighting the character, rather > > than replacing it with a printable character. > > I'm not sure this can already done with a :match. Might be tricky. > > It does seem very useful to highlight the indent every 'sw', especially > > for Python. It would clearly show code blocks. >
After giving this more thought, I feel that overloading 'list' and 'listchars' to show indentation levels is not right. Also, the other patch mentioned above [1] provides functionality to show space characters when list is set, which is the expected behaviour. Since the need here is to indicate indentation levels, it is better handled by a different option. I've redone the patch in that direction. The attached patch adds two options -- 'showindent' and 'indentmarker'. 'indentmarker' is a character (or a code point) and 'showindent' is a boolean. When 'showindent' is true, the displayed character after each 'shiftwidth' (or 'tabstop' if 'sw' is 0) is changed to 'indentmarker'. This is done for indentation using tabs and space characters. As requested earlier, a sample screenshot is also attached to illustrate the effect. [1] https://groups.google.com/d/msg/vim_dev/dIQHjW1g92s/FPUU_-9N3wYJ -- hari.g -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
diff -r fe4feaa73453 runtime/doc/options.txt
--- a/runtime/doc/options.txt Mon Nov 18 14:42:51 2013 +0530
+++ b/runtime/doc/options.txt Sun Dec 01 13:17:43 2013 +0530
@@ -4250,6 +4250,14 @@
The format is identical to 'cinkeys', see |indentkeys-format|.
See |C-indenting| and |indent-expression|.
+ *'indentmarker'* *'indm'*
+'indentmarker' 'indm' number (default 124 or "|" character)
+ local to buffer
+ {not in Vi}
+
+ A character used to mark indent levels on screen when 'showindent' is
+ also set.
+
*'infercase'* *'inf'* *'noinfercase'* *'noinf'*
'infercase' 'inf' boolean (default off)
local to buffer
@@ -6334,6 +6342,16 @@
'completeopt', because the completion from the search pattern may not
match the typed text.
+
+ *'showindent'* *'sind'* *'noshowindent'* *'nosind'*
+'showindent' 'sind' boolean (default off)
+ local
+ {not in Vi}
+
+ Show indent guides at 'shiftwidth' using the character specified by
+ 'indentmarker'. When 'list' is also set the 'list' character wins if
+ positions overlap.
+
*'showmatch'* *'sm'* *'noshowmatch'* *'nosm'*
'showmatch' 'sm' boolean (default off)
global
diff -r fe4feaa73453 runtime/optwin.vim
--- a/runtime/optwin.vim Mon Nov 18 14:42:51 2013 +0530
+++ b/runtime/optwin.vim Sun Dec 01 13:17:43 2013 +0530
@@ -1345,5 +1345,7 @@
let &sc = s:old_sc
let &cpo = s:cpo_save
unlet s:old_title s:old_icon s:old_ru s:old_sc s:cpo_save s:idx s:lnum
+" Character used to display indent level guides
+set indentmarker = \|
" vim: ts=8 sw=2 sts=2
diff -r fe4feaa73453 src/option.c
--- a/src/option.c Mon Nov 18 14:42:51 2013 +0530
+++ b/src/option.c Sun Dec 01 13:17:43 2013 +0530
@@ -184,6 +184,7 @@
* The WV_ values are defined in option.h.
*/
#define PV_LIST OPT_WIN(WV_LIST)
+#define PV_SIND OPT_WIN(WV_SIND)
#ifdef FEAT_ARABIC
# define PV_ARAB OPT_WIN(WV_ARAB)
#endif
@@ -1525,6 +1526,10 @@
{(char_u *)0L, (char_u *)0L}
#endif
SCRIPTID_INIT},
+
+ {"indentmarker", "indm", P_NUM|P_VIM|P_RWIN,
+ (char_u *)&p_indm, PV_NONE,
+ {(char_u *)0x7C, (char_u *)0x7C} SCRIPTID_INIT},
{"infercase", "inf", P_BOOL|P_VI_DEF,
(char_u *)&p_inf, PV_INF,
{(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
@@ -2355,6 +2360,9 @@
{"showfulltag", "sft", P_BOOL|P_VI_DEF,
(char_u *)&p_sft, PV_NONE,
{(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
+ {"showindent", "sind", P_BOOL|P_VIM|P_RWIN,
+ (char_u *)VAR_WIN, PV_SIND,
+ {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
{"showmatch", "sm", P_BOOL|P_VI_DEF,
(char_u *)&p_sm, PV_NONE,
{(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
@@ -4538,6 +4546,30 @@
goto skip;
}
}
+ /*
+ * Accept a single character or a number for 'indentmarker'
+ */
+ else if ((int *)varp == &p_indm)
+ {
+ if (VIM_ISDIGIT(*arg))
+ {
+ value = strtol((char *)arg, NULL, 0);
+ }
+ else
+ {
+#ifdef FEAT_MBYTE
+ value = mb_ptr2char_adv(&arg);
+#else
+ value = *arg;
+#endif
+ }
+ if (value < 0x21 || value > 0x2F8FF)
+ {
+ errmsg = e_invarg;
+ goto skip;
+ }
+ }
+
/* allow negative numbers (for 'undolevels') */
else if (*arg == '-' || VIM_ISDIGIT(*arg))
{
@@ -9936,6 +9968,7 @@
case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
#endif
case PV_LIST: return (char_u *)&(curwin->w_p_list);
+ case PV_SIND: return (char_u *)&(curwin->w_p_sind);
#ifdef FEAT_SPELL
case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
#endif
@@ -10154,6 +10187,7 @@
to->wo_arab = from->wo_arab;
#endif
to->wo_list = from->wo_list;
+ to->wo_sind = from->wo_sind;
to->wo_nu = from->wo_nu;
to->wo_rnu = from->wo_rnu;
#ifdef FEAT_LINEBREAK
diff -r fe4feaa73453 src/option.h
--- a/src/option.h Mon Nov 18 14:42:51 2013 +0530
+++ b/src/option.h Sun Dec 01 13:17:43 2013 +0530
@@ -566,6 +566,7 @@
EXTERN int p_imdisable; /* 'imdisable' */
#endif
EXTERN int p_is; /* 'incsearch' */
+EXTERN int p_indm; /* 'indentmarker' */
EXTERN int p_im; /* 'insertmode' */
EXTERN char_u *p_isf; /* 'isfname' */
EXTERN char_u *p_isi; /* 'isident' */
@@ -1044,6 +1045,7 @@
enum
{
WV_LIST = 0
+ , WV_SIND
#ifdef FEAT_ARABIC
, WV_ARAB
#endif
diff -r fe4feaa73453 src/screen.c
--- a/src/screen.c Mon Nov 18 14:42:51 2013 +0530
+++ b/src/screen.c Sun Dec 01 13:17:43 2013 +0530
@@ -2847,6 +2847,7 @@
long vcol_prev = -1; /* "vcol" of previous character */
char_u *line; /* current line */
char_u *ptr; /* current position in "line" */
+ int nw_seen = 0; /* Seen a non-white character */
int row; /* row in the window, excl w_winrow */
int screen_row; /* row on the screen, incl w_winrow */
@@ -3251,6 +3252,7 @@
line = ml_get_buf(wp->w_buffer, lnum, FALSE);
ptr = line;
+ nw_seen = 0; /* Reset for each line */
#ifdef FEAT_SPELL
if (has_spell)
@@ -4027,6 +4029,23 @@
#endif
++p_extra;
}
+
+ if (wp->w_p_sind && !nw_seen && vcol && vcol % (curbuf->b_p_sw ?
+ curbuf->b_p_sw : curbuf->b_p_ts) == 0 && c != TAB)
+ {
+ c = p_indm;
+#ifdef FEAT_MBYTE
+ mb_c = c; /* doesn't handle non-utf-8 multi-byte! */
+ if (enc_utf8 && (*mb_char2len)(c) > 1)
+ {
+ mb_utf8 = TRUE;
+ u8cc[0] = 0;
+ c = 0xc0;
+ }
+ else
+ mb_utf8 = FALSE;
+#endif
+ }
--n_extra;
}
else
@@ -4035,6 +4054,7 @@
* Get a character from the line itself.
*/
c = *ptr;
+ nw_seen = nw_seen || !vim_iswhite(c);
#ifdef FEAT_MBYTE
if (has_mbyte)
{
@@ -4253,6 +4273,30 @@
mb_utf8 = FALSE;
#endif
}
+ /* Show indent levels */
+ if (wp->w_p_sind && !nw_seen )
+ {
+ if (vcol && vcol % (curbuf->b_p_sw ? curbuf->b_p_sw :
+ curbuf->b_p_ts) == 0 && c != TAB)
+ c = p_indm;
+ if (area_attr == 0 && search_attr == 0)
+ {
+ n_attr = 1;
+ extra_attr = hl_attr(HLF_8);
+ saved_attr2 = char_attr; /* save current attr */
+ }
+#ifdef FEAT_MBYTE
+ mb_c = c;
+ if (enc_utf8 && (*mb_char2len)(c) > 1)
+ {
+ mb_utf8 = TRUE;
+ u8cc[0] = 0;
+ c = 0xc0;
+ }
+ else
+ mb_utf8 = FALSE;
+#endif
+ }
if (extra_check)
{
@@ -4418,7 +4462,24 @@
/* See "Tab alignment" below. */
FIX_FOR_BOGUSCOLS;
#endif
- c = ' ';
+ if (wp->w_p_sind && !nw_seen && vcol && vcol % (curbuf->b_p_sw ?
+ curbuf->b_p_sw : curbuf->b_p_ts) == 0 && c == TAB)
+ {
+ c = p_indm;
+#ifdef FEAT_MBYTE
+ mb_c = c;
+ if (enc_utf8 && (*mb_char2len)(c) > 1)
+ {
+ mb_utf8 = TRUE;
+ u8cc[0] = 0;
+ c = 0xc0;
+ }
+ else
+ mb_utf8 = FALSE;
+#endif
+ }
+ else
+ c = ' ';
}
}
#endif
@@ -4493,7 +4554,24 @@
else
{
c_extra = ' ';
- c = ' ';
+ if (wp->w_p_sind && !nw_seen && vcol && vcol % (curbuf->b_p_sw ?
+ curbuf->b_p_sw : curbuf->b_p_ts) == 0 && c == TAB)
+ {
+ c = p_indm;
+#ifdef FEAT_MBYTE
+ mb_c = c;
+ if (enc_utf8 && (*mb_char2len)(c) > 1)
+ {
+ mb_utf8 = TRUE;
+ u8cc[0] = 0;
+ c = 0xc0;
+ }
+ else
+ mb_utf8 = FALSE;
+#endif
+ }
+ else
+ c = ' ';
}
}
else if (c == NUL
diff -r fe4feaa73453 src/structs.h
--- a/src/structs.h Mon Nov 18 14:42:51 2013 +0530
+++ b/src/structs.h Sun Dec 01 13:17:43 2013 +0530
@@ -176,6 +176,8 @@
#endif
int wo_list;
#define w_p_list w_onebuf_opt.wo_list /* 'list' */
+ int wo_sind;
+#define w_p_sind w_onebuf_opt.wo_sind /* 'showindent' */
int wo_nu;
#define w_p_nu w_onebuf_opt.wo_nu /* 'number' */
int wo_rnu;
<<attachment: vim-indent-marker.png>>
