home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / patches / 7.1 / 7.1.215 < prev    next >
Encoding:
Internet Message Format  |  2008-01-09  |  6.3 KB

  1. To: vim-dev@vim.org
  2. Subject: Patch 7.1.215
  3. Fcc: outbox
  4. From: Bram Moolenaar <Bram@moolenaar.net>
  5. Mime-Version: 1.0
  6. Content-Type: text/plain; charset=ISO-8859-1
  7. Content-Transfer-Encoding: 8bit
  8. ------------
  9.  
  10. Patch 7.1.215
  11. Problem:    It is difficult to figure out what syntax items are nested at a
  12.         certain position.
  13. Solution:   Add the synstack() function.
  14. Files:        runtime/doc/eval.txt, src/eval.c, src/proto/syntax.pro,
  15.         src/syntax.c
  16.  
  17.  
  18. *** ../vim-7.1.214/runtime/doc/eval.txt    Sun Jan  6 20:05:36 2008
  19. --- runtime/doc/eval.txt    Thu Jan 10 22:20:31 2008
  20. ***************
  21. *** 1,4 ****
  22. ! *eval.txt*      For Vim version 7.1.  Last change: 2008 Jan 06
  23.   
  24.   
  25.             VIM REFERENCE MANUAL    by Bram Moolenaar
  26. --- 1,4 ----
  27. ! *eval.txt*      For Vim version 7.1.  Last change: 2008 Jan 10
  28.   
  29.   
  30.             VIM REFERENCE MANUAL    by Bram Moolenaar
  31. ***************
  32. *** 1786,1791 ****
  33. --- 1786,1792 ----
  34.   synIDattr( {synID}, {what} [, {mode}])
  35.                   String    attribute {what} of syntax ID {synID}
  36.   synIDtrans( {synID})        Number    translated syntax ID of {synID}
  37. + synstack({lnum}, {col})        List    stack of syntax IDs at {lnum} and {col}
  38.   system( {expr} [, {input}])    String    output of shell command/filter {expr}
  39.   tabpagebuflist( [{arg}])    List    list of buffer numbers in tab page
  40.   tabpagenr( [{arg}])        Number    number of current or last tab page
  41. ***************
  42. *** 4962,4967 ****
  43. --- 4966,4989 ----
  44.           highlight the character.  Highlight links given with
  45.           ":highlight link" are followed.
  46.   
  47. + synstack({lnum}, {col})                    *synstack()*
  48. +         Return a |List|, which is the stack of syntax items at the
  49. +         position {lnum} and {col} in the current window.  Each item in
  50. +         the List is an ID like what |synID()| returns.
  51. +         The stack is the situation in between the character at "col"
  52. +         and the next character.  Note that a region of only one
  53. +         character will not show up, it only exists inside that
  54. +         character, not in between characters.
  55. +         The first item in the List is the outer region, following are
  56. +         items contained in that one.  The last one is what |synID()|
  57. +         returns, unless not the whole item is highlighted or it is a
  58. +         transparent item.
  59. +         This function is useful for debugging a syntax file.
  60. +         Example that shows the syntax stack under the cursor: >
  61. +             for id in synstack(line("."), col("."))
  62. +                echo synIDattr(id, "name")
  63. +             endfor
  64.   system({expr} [, {input}])                *system()* *E677*
  65.           Get the output of the shell command {expr}.
  66.           When {input} is given, this string is written to a file and
  67. *** ../vim-7.1.214/src/eval.c    Sun Jan  6 20:05:36 2008
  68. --- src/eval.c    Wed Jan  9 13:42:56 2008
  69. ***************
  70. *** 651,656 ****
  71. --- 651,657 ----
  72.   static void f_synID __ARGS((typval_T *argvars, typval_T *rettv));
  73.   static void f_synIDattr __ARGS((typval_T *argvars, typval_T *rettv));
  74.   static void f_synIDtrans __ARGS((typval_T *argvars, typval_T *rettv));
  75. + static void f_synstack __ARGS((typval_T *argvars, typval_T *rettv));
  76.   static void f_system __ARGS((typval_T *argvars, typval_T *rettv));
  77.   static void f_tabpagebuflist __ARGS((typval_T *argvars, typval_T *rettv));
  78.   static void f_tabpagenr __ARGS((typval_T *argvars, typval_T *rettv));
  79. ***************
  80. *** 7252,7257 ****
  81. --- 7253,7259 ----
  82.       {"synID",        3, 3, f_synID},
  83.       {"synIDattr",    2, 3, f_synIDattr},
  84.       {"synIDtrans",    1, 1, f_synIDtrans},
  85. +     {"synstack",    2, 2, f_synstack},
  86.       {"system",        1, 2, f_system},
  87.       {"tabpagebuflist",    0, 1, f_tabpagebuflist},
  88.       {"tabpagenr",    0, 1, f_tabpagenr},
  89. ***************
  90. *** 15843,15848 ****
  91. --- 15845,15890 ----
  92.       id = 0;
  93.   
  94.       rettv->vval.v_number = id;
  95. + }
  96. + /*
  97. +  * "synstack(lnum, col)" function
  98. +  */
  99. + /*ARGSUSED*/
  100. +     static void
  101. + f_synstack(argvars, rettv)
  102. +     typval_T    *argvars;
  103. +     typval_T    *rettv;
  104. + {
  105. + #ifdef FEAT_SYN_HL
  106. +     long    lnum;
  107. +     long    col;
  108. +     int        i;
  109. +     int        id;
  110. + #endif
  111. +     rettv->v_type = VAR_LIST;
  112. +     rettv->vval.v_list = NULL;
  113. + #ifdef FEAT_SYN_HL
  114. +     lnum = get_tv_lnum(argvars);        /* -1 on type error */
  115. +     col = get_tv_number(&argvars[1]) - 1;    /* -1 on type error */
  116. +     if (lnum >= 1 && lnum <= curbuf->b_ml.ml_line_count
  117. +         && col >= 0 && col < (long)STRLEN(ml_get(lnum))
  118. +         && rettv_list_alloc(rettv) != FAIL)
  119. +     {
  120. +     (void)syn_get_id(curwin, lnum, (colnr_T)col, FALSE, NULL);
  121. +     for (i = 0; ; ++i)
  122. +     {
  123. +         id = syn_get_stack_item(i);
  124. +         if (id < 0)
  125. +         break;
  126. +         if (list_append_number(rettv->vval.v_list, id) == FAIL)
  127. +         break;
  128. +     }
  129. +     }
  130. + #endif
  131.   }
  132.   
  133.   /*
  134. *** ../vim-7.1.214/src/proto/syntax.pro    Tue Jul 24 14:32:44 2007
  135. --- src/proto/syntax.pro    Wed Jan  9 13:38:20 2008
  136. ***************
  137. *** 13,18 ****
  138. --- 13,19 ----
  139.   void set_context_in_syntax_cmd __ARGS((expand_T *xp, char_u *arg));
  140.   char_u *get_syntax_name __ARGS((expand_T *xp, int idx));
  141.   int syn_get_id __ARGS((win_T *wp, long lnum, colnr_T col, int trans, int *spellp));
  142. + int syn_get_stack_item __ARGS((int i));
  143.   int syn_get_foldlevel __ARGS((win_T *wp, long lnum));
  144.   void init_highlight __ARGS((int both, int reset));
  145.   int load_colors __ARGS((char_u *name));
  146. *** ../vim-7.1.214/src/syntax.c    Sun Oct  7 15:21:31 2007
  147. --- src/syntax.c    Wed Jan  9 15:17:47 2008
  148. ***************
  149. *** 6104,6109 ****
  150. --- 6102,6123 ----
  151.   
  152.       return (trans ? current_trans_id : current_id);
  153.   }
  154. + #if defined(FEAT_EVAL) || defined(PROTO)
  155. + /*
  156. +  * Return the syntax ID at position "i" in the current stack.
  157. +  * The caller must have called syn_get_id() before to fill the stack.
  158. +  * Returns -1 when "i" is out of range.
  159. +  */
  160. +     int
  161. + syn_get_stack_item(i)
  162. +     int i;
  163. + {
  164. +     if (i >= current_state.ga_len )
  165. +     return -1;
  166. +     return CUR_STATE(i).si_id;
  167. + }
  168. + #endif
  169.   
  170.   #if defined(FEAT_FOLDING) || defined(PROTO)
  171.   /*
  172. *** ../vim-7.1.214/src/version.c    Wed Jan  9 22:39:55 2008
  173. --- src/version.c    Thu Jan 10 22:17:38 2008
  174. ***************
  175. *** 668,669 ****
  176. --- 668,671 ----
  177.   {   /* Add new patch number below this line */
  178. + /**/
  179. +     215,
  180.   /**/
  181.  
  182. -- 
  183. TALL KNIGHT: We are now no longer the Knights Who Say Ni!
  184. ONE KNIGHT:  Ni!
  185. OTHERS:      Sh!
  186. ONE KNIGHT:  (whispers) Sorry.
  187.                  "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
  188.  
  189.  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
  190. ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
  191. \\\        download, build and distribute -- http://www.A-A-P.org        ///
  192.  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
  193.