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

Better to complete account names anywhere (e.g. at the begining of a line)? #67

Open
Varato opened this issue Feb 28, 2021 · 0 comments

Comments

@Varato
Copy link

Varato commented Feb 28, 2021

First of all, thanks a lot for this amazing plugin!
This is actually not an issue, but this might be informative for new users like me.

When I started using vim-beancount, I got the strange behavior as follows.
image.

I typed Exp:Med and expected it to complete as Expenses:Sub:Medium, but it cannot, and the suggestions are not filled at the correct cursor position (to override my typing).

After some dig-in, I found the complete function:

function! beancount#complete(findstart, base) abort
if a:findstart
let l:col = searchpos('\s', 'bn', line('.'))[1]
if l:col == 0
return -1
else
return l:col
endif
endif

So it returns -1 when one enters an account name at the beginning of a line, making the completion start from the current cursor location, according to :h complete-function

Negative return values:                                                                                                                       
   -2   To cancel silently and stay in completion mode.                                                                                       
   -3   To cancel silently and leave completion mode.                                                                                         
   Another negative value: completion starts at the cursor column 

This might be intended because in Beancount we never start a directive by an account name anyway. But this has confused (at least) me for a long time. I thought I messed up with other options of omni-completion, and spent a whole day dealing with this issue (I am VIM newbie).

I think it might be better to always return l:loc,

function! beancount#complete(findstart, base) abort                                                                                       
    if a:findstart                                                                                                                        
        let l:col = searchpos('\s', 'bn', line('.'))[1]                                                                                   
        return l:col                                                                                                                      
        " if l:col == 0                                                                                                                   
        "     return -1                                                                                                                   
        " else                                                                                                                            
        "     return l:col                                                                                                                
        " endif                                                                                                                           
    endif 

This enables a user to complete account names anywhere. Or maybe return -3 to leave completion mode indicating an account name is entered at a wrong position. I believe either way is less confusing than the original?

Of course, there might be some design purpose which I don't know. In that case, please simply close this issue.

@Varato Varato changed the title Better to complete account name anywhere (e.g. at the begining of a line)? Better to complete account names anywhere (e.g. at the begining of a line)? Feb 28, 2021
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

No branches or pull requests

1 participant