Skip to content

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

Description

@Varato

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions