Patch 8.1.1960
Problem:    Fold code is spread out.
Solution:   Move fold functions to fold.c.
Files:      src/evalfunc.c, src/fold.c, src/proto/fold.pro


*** ../vim-8.1.1959/src/evalfunc.c      2019-08-31 22:16:30.774127008 +0200
--- src/evalfunc.c      2019-09-01 17:48:04.260573254 +0200
***************
*** 117,127 ****
  #endif
  static void f_fnameescape(typval_T *argvars, typval_T *rettv);
  static void f_fnamemodify(typval_T *argvars, typval_T *rettv);
- static void f_foldclosed(typval_T *argvars, typval_T *rettv);
- static void f_foldclosedend(typval_T *argvars, typval_T *rettv);
- static void f_foldlevel(typval_T *argvars, typval_T *rettv);
- static void f_foldtext(typval_T *argvars, typval_T *rettv);
- static void f_foldtextresult(typval_T *argvars, typval_T *rettv);
  static void f_foreground(typval_T *argvars, typval_T *rettv);
  static void f_funcref(typval_T *argvars, typval_T *rettv);
  static void f_function(typval_T *argvars, typval_T *rettv);
--- 117,122 ----
***************
*** 3642,3814 ****
  }
  
  /*
-  * "foldclosed()" function
-  */
-     static void
- foldclosed_both(
-     typval_T  *argvars UNUSED,
-     typval_T  *rettv,
-     int               end UNUSED)
- {
- #ifdef FEAT_FOLDING
-     linenr_T  lnum;
-     linenr_T  first, last;
- 
-     lnum = tv_get_lnum(argvars);
-     if (lnum >= 1 && lnum <= curbuf->b_ml.ml_line_count)
-     {
-       if (hasFoldingWin(curwin, lnum, &first, &last, FALSE, NULL))
-       {
-           if (end)
-               rettv->vval.v_number = (varnumber_T)last;
-           else
-               rettv->vval.v_number = (varnumber_T)first;
-           return;
-       }
-     }
- #endif
-     rettv->vval.v_number = -1;
- }
- 
- /*
-  * "foldclosed()" function
-  */
-     static void
- f_foldclosed(typval_T *argvars, typval_T *rettv)
- {
-     foldclosed_both(argvars, rettv, FALSE);
- }
- 
- /*
-  * "foldclosedend()" function
-  */
-     static void
- f_foldclosedend(typval_T *argvars, typval_T *rettv)
- {
-     foldclosed_both(argvars, rettv, TRUE);
- }
- 
- /*
-  * "foldlevel()" function
-  */
-     static void
- f_foldlevel(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
- {
- #ifdef FEAT_FOLDING
-     linenr_T  lnum;
- 
-     lnum = tv_get_lnum(argvars);
-     if (lnum >= 1 && lnum <= curbuf->b_ml.ml_line_count)
-       rettv->vval.v_number = foldLevel(lnum);
- #endif
- }
- 
- /*
-  * "foldtext()" function
-  */
-     static void
- f_foldtext(typval_T *argvars UNUSED, typval_T *rettv)
- {
- #ifdef FEAT_FOLDING
-     linenr_T  foldstart;
-     linenr_T  foldend;
-     char_u    *dashes;
-     linenr_T  lnum;
-     char_u    *s;
-     char_u    *r;
-     int               len;
-     char      *txt;
-     long      count;
- #endif
- 
-     rettv->v_type = VAR_STRING;
-     rettv->vval.v_string = NULL;
- #ifdef FEAT_FOLDING
-     foldstart = (linenr_T)get_vim_var_nr(VV_FOLDSTART);
-     foldend = (linenr_T)get_vim_var_nr(VV_FOLDEND);
-     dashes = get_vim_var_str(VV_FOLDDASHES);
-     if (foldstart > 0 && foldend <= curbuf->b_ml.ml_line_count
-           && dashes != NULL)
-     {
-       /* Find first non-empty line in the fold. */
-       for (lnum = foldstart; lnum < foldend; ++lnum)
-           if (!linewhite(lnum))
-               break;
- 
-       /* Find interesting text in this line. */
-       s = skipwhite(ml_get(lnum));
-       /* skip C comment-start */
-       if (s[0] == '/' && (s[1] == '*' || s[1] == '/'))
-       {
-           s = skipwhite(s + 2);
-           if (*skipwhite(s) == NUL
-                           && lnum + 1 < (linenr_T)get_vim_var_nr(VV_FOLDEND))
-           {
-               s = skipwhite(ml_get(lnum + 1));
-               if (*s == '*')
-                   s = skipwhite(s + 1);
-           }
-       }
-       count = (long)(foldend - foldstart + 1);
-       txt = NGETTEXT("+-%s%3ld line: ", "+-%s%3ld lines: ", count);
-       r = alloc(STRLEN(txt)
-                   + STRLEN(dashes)        // for %s
-                   + 20                    // for %3ld
-                   + STRLEN(s));           // concatenated
-       if (r != NULL)
-       {
-           sprintf((char *)r, txt, dashes, count);
-           len = (int)STRLEN(r);
-           STRCAT(r, s);
-           /* remove 'foldmarker' and 'commentstring' */
-           foldtext_cleanup(r + len);
-           rettv->vval.v_string = r;
-       }
-     }
- #endif
- }
- 
- /*
-  * "foldtextresult(lnum)" function
-  */
-     static void
- f_foldtextresult(typval_T *argvars UNUSED, typval_T *rettv)
- {
- #ifdef FEAT_FOLDING
-     linenr_T  lnum;
-     char_u    *text;
-     char_u    buf[FOLD_TEXT_LEN];
-     foldinfo_T  foldinfo;
-     int               fold_count;
-     static int        entered = FALSE;
- #endif
- 
-     rettv->v_type = VAR_STRING;
-     rettv->vval.v_string = NULL;
- #ifdef FEAT_FOLDING
-     if (entered)
-       return; /* reject recursive use */
-     entered = TRUE;
- 
-     lnum = tv_get_lnum(argvars);
-     /* treat illegal types and illegal string values for {lnum} the same */
-     if (lnum < 0)
-       lnum = 0;
-     fold_count = foldedCount(curwin, lnum, &foldinfo);
-     if (fold_count > 0)
-     {
-       text = get_foldtext(curwin, lnum, lnum + fold_count - 1,
-                                                              &foldinfo, buf);
-       if (text == buf)
-           text = vim_strsave(text);
-       rettv->vval.v_string = text;
-     }
- 
-     entered = FALSE;
- #endif
- }
- 
- /*
   * "foreground()" function
   */
      static void
--- 3637,3642 ----
*** ../vim-8.1.1959/src/fold.c  2019-08-24 20:54:15.979845564 +0200
--- src/fold.c  2019-09-01 17:50:49.663381373 +0200
***************
*** 244,253 ****
  }
  
  /* foldLevel() {{{2 */
  /*
   * Return fold level at line number "lnum" in the current window.
   */
!     int
  foldLevel(linenr_T lnum)
  {
      /* While updating the folds lines between invalid_top and invalid_bot have
--- 244,254 ----
  }
  
  /* foldLevel() {{{2 */
+ #ifdef FEAT_EVAL
  /*
   * Return fold level at line number "lnum" in the current window.
   */
!     static int
  foldLevel(linenr_T lnum)
  {
      /* While updating the folds lines between invalid_top and invalid_bot have
***************
*** 265,270 ****
--- 266,272 ----
  
      return foldLevelWin(curwin, lnum);
  }
+ #endif
  
  /* lineFolded()       {{{2 */
  /*
***************
*** 1989,1998 ****
  }
  
  /* foldtext_cleanup() {{{2 */
  /*
   * Remove 'foldmarker' and 'commentstring' from "str" (in-place).
   */
!     void
  foldtext_cleanup(char_u *str)
  {
      char_u    *cms_start;     /* first part or the whole comment */
--- 1991,2001 ----
  }
  
  /* foldtext_cleanup() {{{2 */
+ #ifdef FEAT_EVAL
  /*
   * Remove 'foldmarker' and 'commentstring' from "str" (in-place).
   */
!     static void
  foldtext_cleanup(char_u *str)
  {
      char_u    *cms_start;     /* first part or the whole comment */
***************
*** 2078,2083 ****
--- 2081,2087 ----
        }
      }
  }
+ #endif
  
  /* Folding by indent, expr, marker and syntax. {{{1 */
  /* Define "fline_T", passed to get fold level for a line. {{{2 */
***************
*** 3616,3619 ****
  #endif /* FEAT_SESSION */
  
  /* }}}1 */
! #endif /* defined(FEAT_FOLDING) || defined(PROTO) */
--- 3620,3794 ----
  #endif /* FEAT_SESSION */
  
  /* }}}1 */
! #endif // defined(FEAT_FOLDING) || defined(PROTO)
! 
! #if defined(FEAT_EVAL) || defined(PROTO)
! 
! /*
!  * "foldclosed()" and "foldclosedend()" functions
!  */
!     static void
! foldclosed_both(
!     typval_T  *argvars UNUSED,
!     typval_T  *rettv,
!     int               end UNUSED)
! {
! # ifdef FEAT_FOLDING
!     linenr_T  lnum;
!     linenr_T  first, last;
! 
!     lnum = tv_get_lnum(argvars);
!     if (lnum >= 1 && lnum <= curbuf->b_ml.ml_line_count)
!     {
!       if (hasFoldingWin(curwin, lnum, &first, &last, FALSE, NULL))
!       {
!           if (end)
!               rettv->vval.v_number = (varnumber_T)last;
!           else
!               rettv->vval.v_number = (varnumber_T)first;
!           return;
!       }
!     }
! #endif
!     rettv->vval.v_number = -1;
! }
! 
! /*
!  * "foldclosed()" function
!  */
!     void
! f_foldclosed(typval_T *argvars, typval_T *rettv)
! {
!     foldclosed_both(argvars, rettv, FALSE);
! }
! 
! /*
!  * "foldclosedend()" function
!  */
!     void
! f_foldclosedend(typval_T *argvars, typval_T *rettv)
! {
!     foldclosed_both(argvars, rettv, TRUE);
! }
! 
! /*
!  * "foldlevel()" function
!  */
!     void
! f_foldlevel(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
! {
! # ifdef FEAT_FOLDING
!     linenr_T  lnum;
! 
!     lnum = tv_get_lnum(argvars);
!     if (lnum >= 1 && lnum <= curbuf->b_ml.ml_line_count)
!       rettv->vval.v_number = foldLevel(lnum);
! # endif
! }
! 
! /*
!  * "foldtext()" function
!  */
!     void
! f_foldtext(typval_T *argvars UNUSED, typval_T *rettv)
! {
! # ifdef FEAT_FOLDING
!     linenr_T  foldstart;
!     linenr_T  foldend;
!     char_u    *dashes;
!     linenr_T  lnum;
!     char_u    *s;
!     char_u    *r;
!     int               len;
!     char      *txt;
!     long      count;
! # endif
! 
!     rettv->v_type = VAR_STRING;
!     rettv->vval.v_string = NULL;
! # ifdef FEAT_FOLDING
!     foldstart = (linenr_T)get_vim_var_nr(VV_FOLDSTART);
!     foldend = (linenr_T)get_vim_var_nr(VV_FOLDEND);
!     dashes = get_vim_var_str(VV_FOLDDASHES);
!     if (foldstart > 0 && foldend <= curbuf->b_ml.ml_line_count
!           && dashes != NULL)
!     {
!       // Find first non-empty line in the fold.
!       for (lnum = foldstart; lnum < foldend; ++lnum)
!           if (!linewhite(lnum))
!               break;
! 
!       // Find interesting text in this line.
!       s = skipwhite(ml_get(lnum));
!       // skip C comment-start
!       if (s[0] == '/' && (s[1] == '*' || s[1] == '/'))
!       {
!           s = skipwhite(s + 2);
!           if (*skipwhite(s) == NUL
!                           && lnum + 1 < (linenr_T)get_vim_var_nr(VV_FOLDEND))
!           {
!               s = skipwhite(ml_get(lnum + 1));
!               if (*s == '*')
!                   s = skipwhite(s + 1);
!           }
!       }
!       count = (long)(foldend - foldstart + 1);
!       txt = NGETTEXT("+-%s%3ld line: ", "+-%s%3ld lines: ", count);
!       r = alloc(STRLEN(txt)
!                   + STRLEN(dashes)        // for %s
!                   + 20                    // for %3ld
!                   + STRLEN(s));           // concatenated
!       if (r != NULL)
!       {
!           sprintf((char *)r, txt, dashes, count);
!           len = (int)STRLEN(r);
!           STRCAT(r, s);
!           // remove 'foldmarker' and 'commentstring'
!           foldtext_cleanup(r + len);
!           rettv->vval.v_string = r;
!       }
!     }
! # endif
! }
! 
! /*
!  * "foldtextresult(lnum)" function
!  */
!     void
! f_foldtextresult(typval_T *argvars UNUSED, typval_T *rettv)
! {
! # ifdef FEAT_FOLDING
!     linenr_T  lnum;
!     char_u    *text;
!     char_u    buf[FOLD_TEXT_LEN];
!     foldinfo_T  foldinfo;
!     int               fold_count;
!     static int        entered = FALSE;
! # endif
! 
!     rettv->v_type = VAR_STRING;
!     rettv->vval.v_string = NULL;
! # ifdef FEAT_FOLDING
!     if (entered)
!       return; // reject recursive use
!     entered = TRUE;
! 
!     lnum = tv_get_lnum(argvars);
!     // treat illegal types and illegal string values for {lnum} the same
!     if (lnum < 0)
!       lnum = 0;
!     fold_count = foldedCount(curwin, lnum, &foldinfo);
!     if (fold_count > 0)
!     {
!       text = get_foldtext(curwin, lnum, lnum + fold_count - 1,
!                                                              &foldinfo, buf);
!       if (text == buf)
!           text = vim_strsave(text);
!       rettv->vval.v_string = text;
!     }
! 
!     entered = FALSE;
! # endif
! }
! 
! #endif // FEAT_EVAL
*** ../vim-8.1.1959/src/proto/fold.pro  2018-05-17 13:52:36.000000000 +0200
--- src/proto/fold.pro  2019-09-01 17:50:55.499340197 +0200
***************
*** 3,9 ****
  int hasAnyFolding(win_T *win);
  int hasFolding(linenr_T lnum, linenr_T *firstp, linenr_T *lastp);
  int hasFoldingWin(win_T *win, linenr_T lnum, linenr_T *firstp, linenr_T 
*lastp, int cache, foldinfo_T *infop);
- int foldLevel(linenr_T lnum);
  int lineFolded(win_T *win, linenr_T lnum);
  long foldedCount(win_T *win, linenr_T lnum, foldinfo_T *infop);
  int foldmethodIsManual(win_T *wp);
--- 3,8 ----
***************
*** 36,42 ****
  void foldMarkAdjust(win_T *wp, linenr_T line1, linenr_T line2, long amount, 
long amount_after);
  int getDeepestNesting(void);
  char_u *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, foldinfo_T 
*foldinfo, char_u *buf);
- void foldtext_cleanup(char_u *str);
  void foldMoveRange(garray_T *gap, linenr_T line1, linenr_T line2, linenr_T 
dest);
  int put_folds(FILE *fd, win_T *wp);
  /* vim: set ft=c : */
--- 35,45 ----
  void foldMarkAdjust(win_T *wp, linenr_T line1, linenr_T line2, long amount, 
long amount_after);
  int getDeepestNesting(void);
  char_u *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, foldinfo_T 
*foldinfo, char_u *buf);
  void foldMoveRange(garray_T *gap, linenr_T line1, linenr_T line2, linenr_T 
dest);
  int put_folds(FILE *fd, win_T *wp);
+ void f_foldclosed(typval_T *argvars, typval_T *rettv);
+ void f_foldclosedend(typval_T *argvars, typval_T *rettv);
+ void f_foldlevel(typval_T *argvars, typval_T *rettv);
+ void f_foldtext(typval_T *argvars, typval_T *rettv);
+ void f_foldtextresult(typval_T *argvars, typval_T *rettv);
  /* vim: set ft=c : */
*** ../vim-8.1.1959/src/version.c       2019-09-01 17:38:05.336455178 +0200
--- src/version.c       2019-09-01 17:45:30.485734082 +0200
***************
*** 763,764 ****
--- 763,766 ----
  {   /* Add new patch number below this line */
+ /**/
+     1960,
  /**/

-- 
If you feel lonely, try schizophrenia.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
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].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/201909011552.x81FquZv023037%40masaka.moolenaar.net.

Raspunde prin e-mail lui