I add a small inner function just like php's trim or python's strip.
If merged, in vim script, we would be able to use
let str = trim(" some_string_with_spaces_quoted \t\t ")
to trim the spaces. And str would be "some_string_with_spaces_quoted"
If we want to trim other characters, just add the second parameter.
let str = trim("xxxyyyJUST NEED THISzzzwww", "wxyz")
We would got s = "JUST NEED THIS"
I'm a 7-yeared vim user. This is my first commit. Thank you for you guys built such a great editor.
https://github.com/vim/vim/pull/1280
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
Needs tests. https://github.com/vim/vim/blob/master/src/testdir/README.txt
I am often annoyed that trim()
does not exist. It can be achieved with substitute()
, if one is careful, but it's still annoying. So I would welcome this change.
Needs tests.
and doc.
This trim doesn't support multi-byte.
Test added. But simple.
Can someone give me a few instructions on how to add docs?
And I will work on multibyte support
Can someone give me a few instructions on how to add docs?
https://github.com/vim/vim/pull/1277/files
Okey. Please refer to changes of This PR.
And I will work on multibyte support
Please show me your Vim script codes working on multibyte support and you should add multibyte test.
This should have at least 30 different test cases. There are many possible input variations.
Oops, my patch is wrong. will fix soon.
fixed my patch. feel free to use.
How can I merge mattn's patch ? I'm still thinking on how to test multibyte. Maybe test Chinese characters, since I'm from China.
Sorry again. please wait merging. my patch still wrong.
Should be fixed.
@bukn pushed 12 commits.
—
You are receiving this because you are subscribed to this thread.
Hope the multibytes test cases are enough.
Doc added~
please add more three tests.
trim("", "")
trim("", "a")
trim("a", "")
@k-takata commented on this pull request.
> @@ -2824,8 +2826,8 @@ char2nr({expr}[, {utf8}]) *char2nr()* char2nr("ABC") returns 65 < When {utf8} is omitted or zero, the current 'encoding' is used. Example for "utf-8": > - char2nr("�") returns 225 - char2nr("�"[0]) returns 195 + char2nr("?") returns 225 + char2nr("?"[0]) returns 195
This change is not needed.
It's better to set enc=utf-8
when you edit eval.txt
.
@mattn commented on this pull request.
> @@ -2824,8 +2826,8 @@ char2nr({expr}[, {utf8}]) *char2nr()* char2nr("ABC") returns 65 < When {utf8} is omitted or zero, the current 'encoding' is used. Example for "utf-8": > - char2nr("�") returns 225 - char2nr("�"[0]) returns 195 + char2nr("?") returns 225 + char2nr("?"[0]) returns 195
should be latin-1. :e ++enc=latin-1 runtime/doc/eval.txt
@bukn commented on this pull request.
> @@ -2824,8 +2826,8 @@ char2nr({expr}[, {utf8}]) *char2nr()* char2nr("ABC") returns 65 < When {utf8} is omitted or zero, the current 'encoding' is used. Example for "utf-8": > - char2nr("�") returns 225 - char2nr("�"[0]) returns 195 + char2nr("?") returns 225 + char2nr("?"[0]) returns 195
fixed
—
You are receiving this because you are subscribed to this thread.
How to pass the first check? It seemed that not this pr's problem.
How to pass the first check?
Do you mean coveralls?
You don't need to worry about it if your test covers the newly written part. (Sometimes coveralls reports unexpected result.)
However seeing the result, f_trim()
doesn't seem to be executed. Something missing with your test?
I'm just curious why this function didn't exists all this vim lifetime so far.
I'm just curious why this function didn't exists all this vim lifetime so far.
Because it isn't that hard to get the same effect without it:
let trimmed = substitute('xxxyyyJUST NEED THISzzzwww', '\m^[wxyz]*\(.\{-}\)[wxyz]*$', '\1', '')
or
let trimmed = matchstr('xxxyyyJUST NEED THISzzzwww', '\m^[wxyz]*\zs.\{-}\ze[wxyz]*$')
As you know, it's difficult to use substitute in map().
:echo map(list, "sustitute(v:val, '\\m^[wxyz]*\\zs.\{-}\\ze[wxyz]*$')")
but trim is
:echo map(list, "trim(v:val, 'wxyz')")
well, lambda expressions make it readable again. Also, while I agree that the pattern becomes hard to read, you could always store the pattern in a separate variable and use that one explicitly in the map() call.
That doesn't mean, I am against a trim() function
As you know, it's difficult to use substitute in map().
Sure, then you can do something like this:
function! Trim(what, junk) let rx = '[' . substitute(a:junk, '\m\([]^\\-]\)', '\\\1', 'g') . ']*' return matchstr(a:what, '\m^' . rx . '\zs.\{-}\ze' . rx . '$') endfunction let trimmed_list = map(list, "Trim(v:val, 'wxyz')")
Which isn't to say I'm against adding a trim()
function, either. Just pointing out that missing it until now wasn't a crippling issue. There are other functions that are much harder to replace.
However seeing the result, f_trim() doesn't seem to be executed. Something missing with your test?
I added test followed this instruction https://github.com/vim/vim/blob/master/src/testdir/README.txt
It says:
2) Add test_.vim to NEW_TESTS in Make_all.mak in alphabetical order.
But I saw that in Make_all.mak, NEW_TESTS section, the cases are all named with .res postfix. Is this the problem? And is it a little mistake of the document ?
—
You are receiving this because you are subscribed to this thread.
Ah, is there anything I need to improve? How to know vim's new feature merge plan?
—
You are receiving this because you are subscribed to this thread.
Your patch has been already added in the todo.txt.
https://github.com/vim/vim/blob/3421566376b5723213af502bd3c2b9debe025ef1/runtime/doc/todo.txt#L192
So just wait patiently. Maybe a few weeks or a few months, (or sometimes even a few years).
Adding new feature has lower priority than fixing bugs.
How to know vim's new feature merge plan?
Only Bram knows. 😉