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

Special characters for markers? #164

Closed
dbmrq opened this issue Jun 29, 2018 · 8 comments
Closed

Special characters for markers? #164

dbmrq opened this issue Jun 29, 2018 · 8 comments
Labels

Comments

@dbmrq
Copy link
Contributor

dbmrq commented Jun 29, 2018

I just added this to my .vimrc:

let g:SignatureIncludeMarkers = '▶︎!@#$%ˆ&*('

Hoping m0 would give me that little arrow as a marker. But the markers just completely stopped working instead. Is there a reason why some characters aren't allowed as markers?

Thanks!

@kshenoy
Copy link
Owner

kshenoy commented Jun 29, 2018

I was able to manually place a sign with the arrow so it's definitely possible. I'll look into this over the weekend

@kshenoy kshenoy added the bug label Jun 29, 2018
@dbmrq
Copy link
Contributor Author

dbmrq commented Jun 29, 2018

Awesome, thanks!

@gkapfham
Copy link

Thanks for suggesting this feature @dbmrq and agreeing to look into it @kshenoy. I too would really appreciate the ability to use special characters as markers! Please let me know once the feature is implemented so that I can try it out and report back on whether or not it works correctly in Vim 8 and Neovim 0.3.1-dev.

@kshenoy
Copy link
Owner

kshenoy commented Jul 4, 2018

I looked into this and the code that messes things up is the following in autoload/signature/utils.vim::signature#utils#Input()

if match(l:in, '\d') >= 0
  let l:char = strpart(b:SignatureIncludeMarkers, l:in, 1)

The help for strpart says that it counts bytes and not characters. For simple characters this wasn't an issue since they are single-byte wide while the arrow is two bytes wide. Thus something like echo strpart('▶︎!@#$%ˆ&*(', 0, 1) wouldn't work correctly.

It also recommends using strcharpart to count the no. of characters and echo strcharpart('▶︎!@#$%ˆ&*(', 0, 1) correctly displays the arrow. However, I tried using echo strcharpart('▶︎!@#$%ˆ&*(', 1, 1) to get the exclamation mark and it didn't work. It seems I have to skip one character since the arrow is a double-wide character and use echo strcharpart('▶︎!@#$%ˆ&*(', 2, 1) to be able to do that.

I'm trying to figure out how to recognize that something is double-wide in order to increment the index by 1 or if there's a better way of going about it.

@dbmrq
Copy link
Contributor Author

dbmrq commented Jul 4, 2018

That's really weird that strcharpart('▶︎!@#$%ˆ&*(', 0, 1) won't get the exclamation mark.

However, this seems to work:

function! GetChar(string, position)
    let string = a:string
    let i = 0
    while i < strchars(a:string, 1)
        if i == a:position
            return strcharpart(string, 0, 1)
        else
            let string = substitute(string, '.', '', '')
        endif
        let i += 1
    endwhile
endfunction

echo(GetChar('▶︎!@#$%ˆ&*(', 0)) returns ▶︎.
echo(GetChar('▶︎!@#$%ˆ&*(', 1)) returns !.

Edit: Some more background: what makes this possible is that strchars() has the skipcc option, which counts ▶︎ as a single character. Unfortunately strcharpart() doesn't have that option.

@dbmrq
Copy link
Contributor Author

dbmrq commented Jul 4, 2018

Oh, and since the regex pattern seems to work properly, the function can be further simplified to this:

function! GetChar(string, pos)
    let pattern = '.\{-' . a:pos . '}\(.\).*'
    return substitute(a:string, pattern, '\1', '')
endfunction

So your code could be changed to this:

if match(l:in, '\d') >= 0
    let pattern = '.\{-' . l:in . '}\(.\).*'
    let l:char = substitute(b:SignatureIncludeMarkers, pattern, '\1', '')
    " ...

(I didn't test it, but it should work.)

dbmrq added a commit to dbmrq/vim-signature that referenced this issue Jul 6, 2018
dbmrq added a commit to dbmrq/vim-signature that referenced this issue Jul 6, 2018
dbmrq added a commit to dbmrq/vim-signature that referenced this issue Jul 6, 2018
@gkapfham
Copy link

gkapfham commented Jul 9, 2018

Hello @kshenoy and @dbmrq! I know that this issue is already closed, but I wanted to report that I have been using the improved version of this plugin for several days with NVIM v0.3.1-dev on Ubuntu 16.04 and I have not had any problems with the new functionality. I have been using a g:SignatureIncludeMarkers similar to the one suggested by @dbmrq while placing the markers in a wide variety of different locations in the files that I am editing. So far, I have not noticed any problems. Thanks for improving the plugin, I really enjoy using it on a regular basis!

@dbmrq
Copy link
Contributor Author

dbmrq commented Jul 9, 2018

@gkapfham No problem, thanks for letting us know. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants