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

[Bug + Solution] The plugin returns 'failed to load/parse file' when a buffer associated to a bookmark is not already open #175

Open
pidgeon777 opened this issue May 23, 2022 · 1 comment

Comments

@pidgeon777
Copy link

When loading bookmarks with BookmarkLoad, the plugin sometimes return an error stating:

Failed to load/parse file

This happens because of the sign place command, which could be called with a file argument associated to a buffer which hasn't been opened yet:

" add sign with certain index
function! bm_sign#add_at(file, sign_idx, line_nr, is_annotation)
call bm_sign#lazy_init()
let name = a:is_annotation ==# 1 ? "BookmarkAnnotation" : "Bookmark"
execute "sign place ". a:sign_idx ." line=" . a:line_nr ." name=". name ." file=". a:file
if (a:sign_idx >=# g:bm_sign_index)
let g:bm_sign_index = a:sign_idx + 1
endif
endfunction

If a:file is associated to a buffer which is not already open, the sign place command will obviously fail, thus the plugin will report the Failed to load/parse file error.

This could be easily fixed by adding the following at the beginning of the bm_sign#add_at function:

  if bufnr(a:file) ==# -1
    return
  endif

So if a bookmarked file is not already opened in Vim, the sign place command won't be called, thus avoiding the exception.

@rod-stuchi
Copy link

@pidgeon777 thank you, that indeed solved the problem!

kflu added a commit to kflu/vim-bookmarks that referenced this issue May 6, 2024
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

2 participants