This patch adds v:hlsearch variable that provides a way to determine whether 
search pattern is highligted if 'hlsearch' is on. This is useful in 
nohlsearch/set hlsearch togglers and also makes plugins like format.vim one 
step closer to generating a complete “screenshot” of what vim shows.

Variable is read-write thus togglers can be reduced to just

   :let v:hlsearch=!v:hlsearch

# HG changeset patch
# User ZyX <[email protected]>
# Date 1379841738 -14400
#      Sun Sep 22 13:22:18 2013 +0400
# Node ID ce3c96118fa2519caadb4e9ca92f8a9a1d59fc22
# Parent  53cd90707ec6b581f2e22d22acf262afdd42ba5e
Add v:hlsearch variable

diff -r 53cd90707ec6 -r ce3c96118fa2 runtime/doc/eval.txt
--- a/runtime/doc/eval.txt      Fri Sep 20 20:13:53 2013 +0200
+++ b/runtime/doc/eval.txt      Sun Sep 22 13:22:18 2013 +0400
@@ -1455,6 +1455,13 @@
 v:foldstart    Used for 'foldtext': first line of closed fold.
                Read-only in the |sandbox|. |fold-foldtext|
 
+                                       *v:hlsearch* *hlsearch-variable*
+v:hlsearch     Variable that determines whether search highligting is on. 
+               Makes sense only if 'hlsearch' is enabled which requires 
+               |+extra_search|. Setting this variable to zero acts like 
+               |:nohlsearch| call, setting it to one acts like >
+                       let &hlsearch = &hlsearch
+<
                                        *v:insertmode* *insertmode-variable*
 v:insertmode   Used for the |InsertEnter| and |InsertChange| autocommand
                events.  Values:
diff -r 53cd90707ec6 -r ce3c96118fa2 src/eval.c
--- a/src/eval.c        Fri Sep 20 20:13:53 2013 +0200
+++ b/src/eval.c        Sun Sep 22 13:22:18 2013 +0400
@@ -356,6 +356,7 @@
     {VV_NAME("mouse_col",       VAR_NUMBER), 0},
     {VV_NAME("operator",        VAR_STRING), VV_RO},
     {VV_NAME("searchforward",   VAR_NUMBER), 0},
+    {VV_NAME("hlsearch",        VAR_NUMBER), 0},
     {VV_NAME("oldfiles",        VAR_LIST), 0},
     {VV_NAME("windowid",        VAR_NUMBER), VV_RO},
 };
@@ -869,6 +870,7 @@
            hash_add(&compat_hashtab, p->vv_di.di_key);
     }
     set_vim_var_nr(VV_SEARCHFORWARD, 1L);
+    set_vim_var_nr(VV_HLSEARCH, 1L);
     set_reg_var(0);  /* default for v:register is not 0 but '"' */
 
 #ifdef EBCDIC
@@ -20577,6 +20579,13 @@
                v->di_tv.vval.v_number = get_tv_number(tv);
                if (STRCMP(varname, "searchforward") == 0)
                    set_search_direction(v->di_tv.vval.v_number ? '/' : '?');
+#ifdef FEAT_SEARCH_EXTRA
+               else if (STRCMP(varname, "hlsearch") == 0)
+               {
+                   no_hlsearch = !v->di_tv.vval.v_number;
+                   redraw_all_later(SOME_VALID);
+               }
+#endif
            }
            return;
        }
diff -r 53cd90707ec6 -r ce3c96118fa2 src/ex_docmd.c
--- a/src/ex_docmd.c    Fri Sep 20 20:13:53 2013 +0200
+++ b/src/ex_docmd.c    Sun Sep 22 13:22:18 2013 +0400
@@ -11390,6 +11390,9 @@
     exarg_T    *eap UNUSED;
 {
     no_hlsearch = TRUE;
+#ifdef FEAT_EVAL
+    set_vim_var_nr(VV_HLSEARCH, !no_hlsearch);
+#endif
     redraw_all_later(SOME_VALID);
 }
 
diff -r 53cd90707ec6 -r ce3c96118fa2 src/option.c
--- a/src/option.c      Fri Sep 20 20:13:53 2013 +0200
+++ b/src/option.c      Sun Sep 22 13:22:18 2013 +0400
@@ -7792,6 +7792,9 @@
     else if ((int *)varp == &p_hls)
     {
        no_hlsearch = FALSE;
+# ifdef FEAT_EVAL
+       set_vim_var_nr(VV_HLSEARCH, !no_hlsearch);
+# endif
     }
 #endif
 
diff -r 53cd90707ec6 -r ce3c96118fa2 src/screen.c
--- a/src/screen.c      Fri Sep 20 20:13:53 2013 +0200
+++ b/src/screen.c      Sun Sep 22 13:22:18 2013 +0400
@@ -7448,6 +7448,9 @@
                /* don't free regprog in the match list, it's a copy */
                vim_regfree(shl->rm.regprog);
                no_hlsearch = TRUE;
+#ifdef FEAT_EVAL
+               set_vim_var_nr(VV_HLSEARCH, !no_hlsearch);
+#endif
            }
            shl->rm.regprog = NULL;
            shl->lnum = 0;
diff -r 53cd90707ec6 -r ce3c96118fa2 src/search.c
--- a/src/search.c      Fri Sep 20 20:13:53 2013 +0200
+++ b/src/search.c      Sun Sep 22 13:22:18 2013 +0400
@@ -290,6 +290,9 @@
        if (p_hls)
            redraw_all_later(SOME_VALID);
        no_hlsearch = FALSE;
+# ifdef FEAT_EVAL
+       set_vim_var_nr(VV_HLSEARCH, !no_hlsearch);
+# endif
 #endif
     }
 }
@@ -334,6 +337,9 @@
        last_idx = saved_last_idx;
 # ifdef FEAT_SEARCH_EXTRA
        no_hlsearch = saved_no_hlsearch;
+#  ifdef FEAT_EVAL
+       set_vim_var_nr(VV_HLSEARCH, !no_hlsearch);
+#  endif
 # endif
     }
 }
@@ -1149,6 +1155,9 @@
     {
        redraw_all_later(SOME_VALID);
        no_hlsearch = FALSE;
+# ifdef FEAT_EVAL
+       set_vim_var_nr(VV_HLSEARCH, !no_hlsearch);
+# endif
     }
 #endif
 
@@ -5562,7 +5571,12 @@
                spats[idx].off.off = off;
 #ifdef FEAT_SEARCH_EXTRA
                if (setlast)
+               {
                    no_hlsearch = !hlsearch_on;
+# ifdef FEAT_EVAL
+                   set_vim_var_nr(VV_HLSEARCH, !no_hlsearch);
+# endif
+               }
 #endif
            }
        }
diff -r 53cd90707ec6 -r ce3c96118fa2 src/tag.c
--- a/src/tag.c Fri Sep 20 20:13:53 2013 +0200
+++ b/src/tag.c Sun Sep 22 13:22:18 2013 +0400
@@ -3330,7 +3330,12 @@
 #ifdef FEAT_SEARCH_EXTRA
        /* restore no_hlsearch when keeping the old search pattern */
        if (search_options)
+       {
            no_hlsearch = save_no_hlsearch;
+# ifdef FEAT_EVAL
+           set_vim_var_nr(VV_HLSEARCH, !no_hlsearch);
+# endif
+       }
 #endif
 
        /* Return OK if jumped to another file (at least we found the file!). */
diff -r 53cd90707ec6 -r ce3c96118fa2 src/testdir/test100.in
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/src/testdir/test100.in    Sun Sep 22 13:22:18 2013 +0400
@@ -0,0 +1,45 @@
+Test for v:hlsearch     vim: set ft=vim :
+
+STARTTEST
+:" Last abc: Q
+:so small.vim
+:new
+:call setline(1, repeat(['aaa'], 10))
+:set hlsearch nolazyredraw
+:let r=[]
+:command -nargs=0 -bar AddR :call add(r, [screenattr(1, 1), v:hlsearch])
+/aaa
+:AddR
+:nohlsearch
+:AddR
+:let v:hlsearch=1
+:AddR
+:let v:hlsearch=0
+:AddR
+:set hlsearch
+:AddR
+:let v:hlsearch=0
+:AddR
+n:AddR
+:let v:hlsearch=0
+:AddR
+/
+:AddR
+:let r1=r[0][0]
+:" I guess it is not guaranteed that screenattr outputs always the same 
character
+:call map(r, 'v:val[1].":".(v:val[0]==r1?"highlighted":"not highlighted")')
+:try
+:   let v:hlsearch=[]
+:catch
+:   call add(r, matchstr(v:exception,'^Vim(let):E\d\+:'))
+:endtry
+:bwipeout!
+:$put=r
+:call garbagecollect(1)
+:"
+:/^start:/,$wq! test.out
+:" vim: et ts=4 isk-=\:
+:call getchar()
+ENDTEST
+
+start:
diff -r 53cd90707ec6 -r ce3c96118fa2 src/testdir/test100.ok
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/src/testdir/test100.ok    Sun Sep 22 13:22:18 2013 +0400
@@ -0,0 +1,11 @@
+start:
+1:highlighted
+0:not highlighted
+1:highlighted
+0:not highlighted
+1:highlighted
+0:not highlighted
+1:highlighted
+0:not highlighted
+1:highlighted
+Vim(let):E706:
diff -r 53cd90707ec6 -r ce3c96118fa2 src/vim.h
--- a/src/vim.h Fri Sep 20 20:13:53 2013 +0200
+++ b/src/vim.h Sun Sep 22 13:22:18 2013 +0400
@@ -1864,9 +1864,10 @@
 #define VV_MOUSE_COL   51
 #define VV_OP          52
 #define VV_SEARCHFORWARD 53
-#define VV_OLDFILES    54
-#define VV_WINDOWID    55
-#define VV_LEN         56      /* number of v: vars */
+#define VV_HLSEARCH    54
+#define VV_OLDFILES    55
+#define VV_WINDOWID    56
+#define VV_LEN         57      /* number of v: vars */
 
 #ifdef FEAT_CLIPBOARD
 

-- 
-- 
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 -crN vim.53cd90707ec6/runtime/doc/eval.txt vim.ce3c96118fa2/runtime/doc/eval.txt
*** vim.53cd90707ec6/runtime/doc/eval.txt	2013-09-22 13:30:36.412543828 +0400
--- vim.ce3c96118fa2/runtime/doc/eval.txt	2013-09-22 13:30:36.459543362 +0400
***************
*** 1455,1460 ****
--- 1455,1467 ----
  v:foldstart	Used for 'foldtext': first line of closed fold.
  		Read-only in the |sandbox|. |fold-foldtext|
  
+ 					*v:hlsearch* *hlsearch-variable*
+ v:hlsearch	Variable that determines whether search highligting is on. 
+ 		Makes sense only if 'hlsearch' is enabled which requires 
+ 		|+extra_search|. Setting this variable to zero acts like 
+ 		|:nohlsearch| call, setting it to one acts like >
+ 			let &hlsearch = &hlsearch
+ <
  					*v:insertmode* *insertmode-variable*
  v:insertmode	Used for the |InsertEnter| and |InsertChange| autocommand
  		events.  Values:
diff -crN vim.53cd90707ec6/src/eval.c vim.ce3c96118fa2/src/eval.c
*** vim.53cd90707ec6/src/eval.c	2013-09-22 13:30:36.429543660 +0400
--- vim.ce3c96118fa2/src/eval.c	2013-09-22 13:30:36.474543214 +0400
***************
*** 356,361 ****
--- 356,362 ----
      {VV_NAME("mouse_col",	 VAR_NUMBER), 0},
      {VV_NAME("operator",	 VAR_STRING), VV_RO},
      {VV_NAME("searchforward",	 VAR_NUMBER), 0},
+     {VV_NAME("hlsearch",	 VAR_NUMBER), 0},
      {VV_NAME("oldfiles",	 VAR_LIST), 0},
      {VV_NAME("windowid",	 VAR_NUMBER), VV_RO},
  };
***************
*** 869,874 ****
--- 870,876 ----
  	    hash_add(&compat_hashtab, p->vv_di.di_key);
      }
      set_vim_var_nr(VV_SEARCHFORWARD, 1L);
+     set_vim_var_nr(VV_HLSEARCH, 1L);
      set_reg_var(0);  /* default for v:register is not 0 but '"' */
  
  #ifdef EBCDIC
***************
*** 20577,20582 ****
--- 20579,20591 ----
  		v->di_tv.vval.v_number = get_tv_number(tv);
  		if (STRCMP(varname, "searchforward") == 0)
  		    set_search_direction(v->di_tv.vval.v_number ? '/' : '?');
+ #ifdef FEAT_SEARCH_EXTRA
+ 		else if (STRCMP(varname, "hlsearch") == 0)
+ 		{
+ 		    no_hlsearch = !v->di_tv.vval.v_number;
+ 		    redraw_all_later(SOME_VALID);
+ 		}
+ #endif
  	    }
  	    return;
  	}
diff -crN vim.53cd90707ec6/src/ex_docmd.c vim.ce3c96118fa2/src/ex_docmd.c
*** vim.53cd90707ec6/src/ex_docmd.c	2013-09-22 13:30:36.397543977 +0400
--- vim.ce3c96118fa2/src/ex_docmd.c	2013-09-22 13:30:36.443543521 +0400
***************
*** 11390,11395 ****
--- 11390,11398 ----
      exarg_T	*eap UNUSED;
  {
      no_hlsearch = TRUE;
+ #ifdef FEAT_EVAL
+     set_vim_var_nr(VV_HLSEARCH, !no_hlsearch);
+ #endif
      redraw_all_later(SOME_VALID);
  }
  
diff -crN vim.53cd90707ec6/src/option.c vim.ce3c96118fa2/src/option.c
*** vim.53cd90707ec6/src/option.c	2013-09-22 13:30:36.402543927 +0400
--- vim.ce3c96118fa2/src/option.c	2013-09-22 13:30:36.449543462 +0400
***************
*** 7792,7797 ****
--- 7792,7800 ----
      else if ((int *)varp == &p_hls)
      {
  	no_hlsearch = FALSE;
+ # ifdef FEAT_EVAL
+ 	set_vim_var_nr(VV_HLSEARCH, !no_hlsearch);
+ # endif
      }
  #endif
  
diff -crN vim.53cd90707ec6/src/screen.c vim.ce3c96118fa2/src/screen.c
*** vim.53cd90707ec6/src/screen.c	2013-09-22 13:30:36.391544036 +0400
--- vim.ce3c96118fa2/src/screen.c	2013-09-22 13:30:36.438543570 +0400
***************
*** 7448,7453 ****
--- 7448,7456 ----
  		/* don't free regprog in the match list, it's a copy */
  		vim_regfree(shl->rm.regprog);
  		no_hlsearch = TRUE;
+ #ifdef FEAT_EVAL
+ 		set_vim_var_nr(VV_HLSEARCH, !no_hlsearch);
+ #endif
  	    }
  	    shl->rm.regprog = NULL;
  	    shl->lnum = 0;
diff -crN vim.53cd90707ec6/src/search.c vim.ce3c96118fa2/src/search.c
*** vim.53cd90707ec6/src/search.c	2013-09-22 13:30:36.404543907 +0400
--- vim.ce3c96118fa2/src/search.c	2013-09-22 13:30:36.451543442 +0400
***************
*** 290,295 ****
--- 290,298 ----
  	if (p_hls)
  	    redraw_all_later(SOME_VALID);
  	no_hlsearch = FALSE;
+ # ifdef FEAT_EVAL
+ 	set_vim_var_nr(VV_HLSEARCH, !no_hlsearch);
+ # endif
  #endif
      }
  }
***************
*** 334,339 ****
--- 337,345 ----
  	last_idx = saved_last_idx;
  # ifdef FEAT_SEARCH_EXTRA
  	no_hlsearch = saved_no_hlsearch;
+ #  ifdef FEAT_EVAL
+ 	set_vim_var_nr(VV_HLSEARCH, !no_hlsearch);
+ #  endif
  # endif
      }
  }
***************
*** 1149,1154 ****
--- 1155,1163 ----
      {
  	redraw_all_later(SOME_VALID);
  	no_hlsearch = FALSE;
+ # ifdef FEAT_EVAL
+ 	set_vim_var_nr(VV_HLSEARCH, !no_hlsearch);
+ # endif
      }
  #endif
  
***************
*** 5562,5568 ****
--- 5571,5582 ----
  		spats[idx].off.off = off;
  #ifdef FEAT_SEARCH_EXTRA
  		if (setlast)
+ 		{
  		    no_hlsearch = !hlsearch_on;
+ # ifdef FEAT_EVAL
+ 		    set_vim_var_nr(VV_HLSEARCH, !no_hlsearch);
+ # endif
+ 		}
  #endif
  	    }
  	}
diff -crN vim.53cd90707ec6/src/tag.c vim.ce3c96118fa2/src/tag.c
*** vim.53cd90707ec6/src/tag.c	2013-09-22 13:30:36.431543640 +0400
--- vim.ce3c96118fa2/src/tag.c	2013-09-22 13:30:36.475543204 +0400
***************
*** 3330,3336 ****
--- 3330,3341 ----
  #ifdef FEAT_SEARCH_EXTRA
  	/* restore no_hlsearch when keeping the old search pattern */
  	if (search_options)
+ 	{
  	    no_hlsearch = save_no_hlsearch;
+ # ifdef FEAT_EVAL
+ 	    set_vim_var_nr(VV_HLSEARCH, !no_hlsearch);
+ # endif
+ 	}
  #endif
  
  	/* Return OK if jumped to another file (at least we found the file!). */
diff -crN vim.53cd90707ec6/src/testdir/test100.in vim.ce3c96118fa2/src/testdir/test100.in
*** vim.53cd90707ec6/src/testdir/test100.in	1970-01-01 03:00:00.000000000 +0300
--- vim.ce3c96118fa2/src/testdir/test100.in	2013-09-22 13:30:36.431543640 +0400
***************
*** 0 ****
--- 1,45 ----
+ Test for v:hlsearch     vim: set ft=vim :
+ 
+ STARTTEST
+ :" Last abc: Q
+ :so small.vim
+ :new
+ :call setline(1, repeat(['aaa'], 10))
+ :set hlsearch nolazyredraw
+ :let r=[]
+ :command -nargs=0 -bar AddR :call add(r, [screenattr(1, 1), v:hlsearch])
+ /aaa
+ :AddR
+ :nohlsearch
+ :AddR
+ :let v:hlsearch=1
+ :AddR
+ :let v:hlsearch=0
+ :AddR
+ :set hlsearch
+ :AddR
+ :let v:hlsearch=0
+ :AddR
+ n:AddR
+ :let v:hlsearch=0
+ :AddR
+ /
+ :AddR
+ :let r1=r[0][0]
+ :" I guess it is not guaranteed that screenattr outputs always the same character
+ :call map(r, 'v:val[1].":".(v:val[0]==r1?"highlighted":"not highlighted")')
+ :try
+ :   let v:hlsearch=[]
+ :catch
+ :   call add(r, matchstr(v:exception,'^Vim(let):E\d\+:'))
+ :endtry
+ :bwipeout!
+ :$put=r
+ :call garbagecollect(1)
+ :"
+ :/^start:/,$wq! test.out
+ :" vim: et ts=4 isk-=\:
+ :call getchar()
+ ENDTEST
+ 
+ start:
diff -crN vim.53cd90707ec6/src/testdir/test100.ok vim.ce3c96118fa2/src/testdir/test100.ok
*** vim.53cd90707ec6/src/testdir/test100.ok	1970-01-01 03:00:00.000000000 +0300
--- vim.ce3c96118fa2/src/testdir/test100.ok	2013-09-22 13:30:36.431543640 +0400
***************
*** 0 ****
--- 1,11 ----
+ start:
+ 1:highlighted
+ 0:not highlighted
+ 1:highlighted
+ 0:not highlighted
+ 1:highlighted
+ 0:not highlighted
+ 1:highlighted
+ 0:not highlighted
+ 1:highlighted
+ Vim(let):E706:
diff -crN vim.53cd90707ec6/src/vim.h vim.ce3c96118fa2/src/vim.h
*** vim.53cd90707ec6/src/vim.h	2013-09-22 13:30:36.387544076 +0400
--- vim.ce3c96118fa2/src/vim.h	2013-09-22 13:30:36.434543610 +0400
***************
*** 1864,1872 ****
  #define VV_MOUSE_COL	51
  #define VV_OP		52
  #define VV_SEARCHFORWARD 53
! #define VV_OLDFILES	54
! #define VV_WINDOWID	55
! #define VV_LEN		56	/* number of v: vars */
  
  #ifdef FEAT_CLIPBOARD
  
--- 1864,1873 ----
  #define VV_MOUSE_COL	51
  #define VV_OP		52
  #define VV_SEARCHFORWARD 53
! #define VV_HLSEARCH	54
! #define VV_OLDFILES	55
! #define VV_WINDOWID	56
! #define VV_LEN		57	/* number of v: vars */
  
  #ifdef FEAT_CLIPBOARD
  

Raspunde prin e-mail lui