Skip to content

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

@pidgeon777

Description

@pidgeon777

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.

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