On Fri, Dec 12, 2014 at 12:57:39AM +0100, Roland Eggner wrote:
> Patch "Make closed folds line up" by Charles Campbell is already on Brams 
> todo list.
> http://www.drchip.org/astronaut/vim/patch/folding.ptch
> 
> It works nicely apart from case "relativenumber nonumber" with numberwidth 
> smaller than for absolute linenumbers would be appropriate.  And in this 
> particular case, I am encountering rare crashes -- both with and without the 
> named patch applied, “foldmethod=expr” and „syntax on” always in effect.  So 
> far 
> I cannot reproduce the crashes, they are too rare.
> 
> E.g. with terminal LINES=90 relativenumbers are never longer than 2 digits, 
> thus 
> I set numberwidth=3.  If the buffer holds a file with >10000 lines of text, 
> numberwidth<6 seems to be not considered in all related code parts, the 
> relativenumbers are consuming part of the padding introduced by the patch, 
> which 
> does not look as nice as with “norelativenumber number” set.


Patch improved:
•  Cover the case “:set relativenumber nonumber numberwidth=3”.
•  Adjust padding to minimum required for line numbers aligned in a column.
•  “make test” runs cleanly.
•  Has been working flawlessly during 2 days intensive usage.


Example “:help netrw” exhibits the effect nicely:
(1)  Plain vim-7.4.529.
(2)  With “Charles Campbell 2014  Make closed folds line up.patch”
(3)  With “Charles Campbell 2014  Make closed folds line up.patch”, improved 
     version provided below.

:set nonumber norelativenumber
(1)
==============================================================================|~
+-- 88 lines: 1. Contents      *netrw-contents* ------------------------------|~
+-- 73 lines: 2. Starting With Netrw     *netrw-start* -----------------------|~
+--273 lines: 3. Netrw Reference     *netrw-ref* -----------------------------|~
+--209 lines: 4. Network-Oriented File Transfer   *netrw-xfer* ---------------|~
+-- 17 lines: 5. Activation      *netrw-activate* ----------------------------|~
+-- 16 lines: 6. Transparent Remote File Editing  *netrw-transparent* --------|~
+-- 58 lines: 7. Ex Commands      *netrw-ex* ---------------------------------|~
+--182 lines: 8. Variables and Options  *netrw-var* *netrw-settings* ---------|~
+--1923 lines: 9. Browsing  *netrw-browsing* *netrw-browse* *netrw-help* -----|~
+--294 lines: 10. Problems and Fixes     *netrw-problems* --------------------|~
+-- 56 lines: 11. Debugging Netrw Itself    *netrw-debug* --------------------|~
+--273 lines: 12. History      *netrw-history* -------------------------------|~
+--  9 lines: 13. Todo      *netrw-todo* -------------------------------------|~
+-- 24 lines: 14. Credits      *netrw-credits* -------------------------------|~
+--  2 lines: Modelines: -----------------------------------------------------|~

(2)
==============================================================================|~
+--     88 lines: 1. Contents      *netrw-contents* --------------------------|~
+--     73 lines: 2. Starting With Netrw     *netrw-start* -------------------|~
+--    273 lines: 3. Netrw Reference     *netrw-ref* -------------------------|~
+--    209 lines: 4. Network-Oriented File Transfer   *netrw-xfer* -----------|~
+--     17 lines: 5. Activation      *netrw-activate* ------------------------|~
+--     16 lines: 6. Transparent Remote File Editing  *netrw-transparent* ----|~
+--     58 lines: 7. Ex Commands      *netrw-ex* -----------------------------|~
+--    182 lines: 8. Variables and Options  *netrw-var* *netrw-settings* -----|~
+--   1923 lines: 9. Browsing  *netrw-browsing* *netrw-browse* *netrw-help* --|~
+--    294 lines: 10. Problems and Fixes     *netrw-problems* ----------------|~
+--     56 lines: 11. Debugging Netrw Itself    *netrw-debug* ----------------|~
+--    273 lines: 12. History      *netrw-history* ---------------------------|~
+--      9 lines: 13. Todo      *netrw-todo* ---------------------------------|~
+--     24 lines: 14. Credits      *netrw-credits* ---------------------------|~
+--      2 lines: Modelines: -------------------------------------------------|~

(3)
==============================================================================|~
+--   88 lines: 1. Contents      *netrw-contents* ----------------------------|~
+--   73 lines: 2. Starting With Netrw     *netrw-start* ---------------------|~
+--  273 lines: 3. Netrw Reference     *netrw-ref* ---------------------------|~
+--  209 lines: 4. Network-Oriented File Transfer   *netrw-xfer* -------------|~
+--   17 lines: 5. Activation      *netrw-activate* --------------------------|~
+--   16 lines: 6. Transparent Remote File Editing  *netrw-transparent* ------|~
+--   58 lines: 7. Ex Commands      *netrw-ex* -------------------------------|~
+--  182 lines: 8. Variables and Options  *netrw-var* *netrw-settings* -------|~
+-- 1923 lines: 9. Browsing  *netrw-browsing* *netrw-browse* *netrw-help* ----|~
+--  294 lines: 10. Problems and Fixes     *netrw-problems* ------------------|~
+--   56 lines: 11. Debugging Netrw Itself    *netrw-debug* ------------------|~
+--  273 lines: 12. History      *netrw-history* -----------------------------|~
+--    9 lines: 13. Todo      *netrw-todo* -----------------------------------|~
+--   24 lines: 14. Credits      *netrw-credits* -----------------------------|~
+--    2 lines: Modelines: ---------------------------------------------------|~

:set nonumber relativenumber numberwidth=3
(1)
 5 
==============================================================================|~
 6 +-- 88 lines: 1. Contents      *netrw-contents* 
------------------------------|~
 7 +-- 73 lines: 2. Starting With Netrw     *netrw-start* 
-----------------------|~
 8 +--273 lines: 3. Netrw Reference     *netrw-ref* 
-----------------------------|~
 9 +--209 lines: 4. Network-Oriented File Transfer   *netrw-xfer* 
---------------|~
10 +-- 17 lines: 5. Activation      *netrw-activate* 
----------------------------|~
11 +-- 16 lines: 6. Transparent Remote File Editing  *netrw-transparent* 
--------|~
12 +-- 58 lines: 7. Ex Commands      *netrw-ex* 
---------------------------------|~
13 +--182 lines: 8. Variables and Options  *netrw-var* *netrw-settings* 
---------|~
14 +--1923 lines: 9. Browsing  *netrw-browsing* *netrw-browse* *netrw-help* 
-----|~
15 +--294 lines: 10. Problems and Fixes     *netrw-problems* 
--------------------|~
16 +-- 56 lines: 11. Debugging Netrw Itself    *netrw-debug* 
--------------------|~
17 +--273 lines: 12. History      *netrw-history* 
-------------------------------|~
18 +--  9 lines: 13. Todo      *netrw-todo* 
-------------------------------------|~
19 +-- 24 lines: 14. Credits      *netrw-credits* 
-------------------------------|~
20 +--  2 lines: Modelines: 
-----------------------------------------------------|~

(2)
 2 
==============================================================================|~
 3 +-- 88 lines: 1. Contents      *netrw-contents* 
------------------------------|~
 4 +-- 73 lines: 2. Starting With Netrw     *netrw-start* 
-----------------------|~
 5 +-- 273 lines: 3. Netrw Reference     *netrw-ref* 
----------------------------|~
 6 +-- 209 lines: 4. Network-Oriented File Transfer   *netrw-xfer* 
--------------|~
 7 +-- 17 lines: 5. Activation      *netrw-activate* 
----------------------------|~
 8 +-- 16 lines: 6. Transparent Remote File Editing  *netrw-transparent* 
--------|~
 9 +-- 58 lines: 7. Ex Commands      *netrw-ex* 
---------------------------------|~
10 +-- 182 lines: 8. Variables and Options  *netrw-var* *netrw-settings* 
--------|~
11 +-- 1923 lines: 9. Browsing  *netrw-browsing* *netrw-browse* *netrw-help* 
----|~
12 +-- 294 lines: 10. Problems and Fixes     *netrw-problems* 
-------------------|~
13 +-- 56 lines: 11. Debugging Netrw Itself    *netrw-debug* 
--------------------|~
14 +-- 273 lines: 12. History      *netrw-history* 
------------------------------|~
15 +--  9 lines: 13. Todo      *netrw-todo* 
-------------------------------------|~
16 +-- 24 lines: 14. Credits      *netrw-credits* 
-------------------------------|~
17 +--  2 lines: Modelines: 
-----------------------------------------------------|~

(3)
 2 
==============================================================================|~
 3 +--   88 lines: 1. Contents      *netrw-contents* 
----------------------------|~
 4 +--   73 lines: 2. Starting With Netrw     *netrw-start* 
---------------------|~
 5 +--  273 lines: 3. Netrw Reference     *netrw-ref* 
---------------------------|~
 6 +--  209 lines: 4. Network-Oriented File Transfer   *netrw-xfer* 
-------------|~
 7 +--   17 lines: 5. Activation      *netrw-activate* 
--------------------------|~
 8 +--   16 lines: 6. Transparent Remote File Editing  *netrw-transparent* 
------|~
 9 +--   58 lines: 7. Ex Commands      *netrw-ex* 
-------------------------------|~
10 +--  182 lines: 8. Variables and Options  *netrw-var* *netrw-settings* 
-------|~
11 +-- 1923 lines: 9. Browsing  *netrw-browsing* *netrw-browse* *netrw-help* 
----|~
12 +--  294 lines: 10. Problems and Fixes     *netrw-problems* 
------------------|~
13 +--   56 lines: 11. Debugging Netrw Itself    *netrw-debug* 
------------------|~
14 +--  273 lines: 12. History      *netrw-history* 
-----------------------------|~
15 +--    9 lines: 13. Todo      *netrw-todo* 
-----------------------------------|~
16 +--   24 lines: 14. Credits      *netrw-credits* 
-----------------------------|~
17 +--    2 lines: Modelines: 
---------------------------------------------------|~


────────────────────────────────────────────────────────────────────────────

Make closed folds line up.

┌──────────────────────────────────────────────────────────────────────────┐
│                       Make closed folds line up.                         │
└──────────────────────────────────────────────────────────────────────────┛

todo.txt entry:
Patch to make closed folds line up. (Charles Campbell, 2014 Sep 12)

Latest update for:
vim-7.4.529

Original author:
Charles Campbell 2014  http://www.drchip.org/astronaut/vim/patch/folding.ptch

Improved by:
Roland Eggner 2014

Bug reports and development discussion:
http://www.vim.org/maillist.php

License and Copyright:
http://vimdoc.sourceforge.net/htmldoc/uganda.html
────────────────────────────────────────────────────────────────────────────

Roland Eggner 2014-12-15
•  Cover the case “:set relativenumber nonumber numberwidth=3”.
•  Adjust padding to minimum required for line numbers aligned in a column.
────────────────────────────────────────────────────────────────────────────

diff --git a/src/eval.c b/src/eval.c
--- a/src/eval.c
+++ b/src/eval.c
@@ -11030,12 +11030,16 @@ f_foldtext(argvars, rettv)
 #ifdef FEAT_FOLDING
     linenr_T   lnum;
     char_u     *s;
     char_u     *r;
     int                len;
     char       *txt;
+    char        fmt[30];
+    int         nuw;
+    int         padding;
+    unsigned    rlen;
 #endif
 
     rettv->v_type = VAR_STRING;
     rettv->vval.v_string = NULL;
 #ifdef FEAT_FOLDING
     if ((linenr_T)vimvars[VV_FOLDSTART].vv_nr > 0
@@ -11063,22 +11067,33 @@ f_foldtext(argvars, rettv)
            {
                s = skipwhite(ml_get(lnum + 1));
                if (*s == '*')
                    s = skipwhite(s + 1);
            }
        }
-       txt = _("+-%s%3ld lines: ");
-       r = alloc((unsigned)(STRLEN(txt)
-                   + STRLEN(vimvars[VV_FOLDDASHES].vv_str)    /* for %s */
-                   + 20                                    /* for %3ld */
-                   + STRLEN(s)));                          /* concatenated */
+       /* next two lines construct a format to be used for the folded region.
+        * Example: assume nuw=5, then fmt becomes "+-%-5s%5ld lines: %*s"
+        */
+       lnum = curwin->w_buffer->b_ml.ml_line_count;
+       nuw = 1;                        /* obtain log10(lastline) */
+       do
+       {
+           lnum /= 10;
+           ++nuw;
+       } while (lnum > 0);
+       padding= STRLEN(vimvars[VV_FOLDDASHES].vv_str);
+       txt = _("lines");               /* internationalize       */
+       sprintf(fmt,"+-%%-%ds%%%dld %s:%%*s",padding,nuw,txt);
+       rlen= (STRLEN(fmt) - 10) + 2*nuw + ((padding > nuw)? padding : nuw) + 
STRLEN(s);
+       r   = alloc(rlen);
        if (r != NULL)
        {
-           sprintf((char *)r, txt, vimvars[VV_FOLDDASHES].vv_str,
+           sprintf((char *)r, fmt, vimvars[VV_FOLDDASHES].vv_str,
                    (long)((linenr_T)vimvars[VV_FOLDEND].vv_nr
-                               - (linenr_T)vimvars[VV_FOLDSTART].vv_nr + 1));
+                               - (linenr_T)vimvars[VV_FOLDSTART].vv_nr + 1),
+                   padding," ");
            len = (int)STRLEN(r);
            STRCAT(r, s);
            /* remove 'foldmarker' and 'commentstring' */
            foldtext_cleanup(r + len);
            rettv->vval.v_string = r;
        }



-- 
Roland Eggner

-- 
-- 
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/d/optout.

Attachment: pgpW_1bXJhzb9.pgp
Description: PGP signature

Raspunde prin e-mail lui