Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace strcharpart() with substitute() for backward compatibility #834

Merged
merged 2 commits into from
Apr 26, 2018

Conversation

bravestarr
Copy link
Contributor

@bravestarr bravestarr commented Apr 26, 2018

Pull request #833 has supplied a fix to workaround the backward compatibility problem in #830. But the multi-byte path problem will appear again in the older version of vim before the function strcharpart was introduced. We can use substitute to achieve the same result as when strcharpart is used.

Copy link
Member

@PhilRunninger PhilRunninger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolve the conflicts, and I'll merge this. We don't need the if exists("*strcharpart") block introduced in #833 anymore, but your changes here don't account for its removal.

@@ -288,7 +288,7 @@ function! s:Bookmark.str()
let pathStr = self.path.str({'format': 'UI'})
if strdisplaywidth(pathStr) > pathStrMaxLen
while strdisplaywidth(pathStr) > pathStrMaxLen && strchars(pathStr) > 0
let pathStr = strcharpart(pathStr, 1)
let pathStr = substitute(pathStr, '.\{1}', '', '')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the regex '^.' would be safer to use here. That guarantees it finds the first character.

@@ -721,7 +721,7 @@ function! s:Path.str(...)
let limit = options['truncateTo']
if strdisplaywidth(toReturn) > limit-1
while strdisplaywidth(toReturn) > limit-1 && strchars(toReturn) > 0
let toReturn = strcharpart(toReturn, 1)
let toReturn = substitute(toReturn, '.\{1}', '', '')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same regex comment here.

@bravestarr bravestarr closed this Apr 26, 2018
@bravestarr bravestarr deleted the fix-multibyte-path branch April 26, 2018 13:14
@bravestarr bravestarr restored the fix-multibyte-path branch April 26, 2018 13:17
@bravestarr bravestarr reopened this Apr 26, 2018
@bravestarr
Copy link
Contributor Author

bravestarr commented Apr 26, 2018

I have commit this change to the branch used in #830, but the branch didn't sync to the master branch, so I did't mention the removal of if exists("*strcharpart"). Now I have resolved the conflicts and adopted the regex you advised.

@PhilRunninger PhilRunninger merged commit 925a96f into preservim:master Apr 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants