bullets-vim / bullets.vim

🔫 Bullets.vim is a Vim/NeoVim plugin for automated bullet lists.
https://doriankarter.com
Other
474 stars 36 forks source link

API to check if current line is an applicable bullet #109

Closed mcauley-penney closed 2 years ago

mcauley-penney commented 3 years ago

Howdy all,

In the documentation, I could not find information about any exposed functions to determine if the current line is under the purview of the plugin. I am interested in defining conditional mappings, e.g. if this line is actionable with bullets.vim, tab demotes and backspace promotes but, if the line is not actionable, act normally. This would allow for behavior more akin to Word.

Does such a function exist? If so, I apologize that I have missed it

Edit: Related to #33, which had part of it's desired functionality created and merged

hupfdule commented 3 years ago

There are methods like

s:match_bullet_list_item(input_text)

that checks whether the given line matches a bullet list item (other such methods exist for the other types of bullet items, like numbered items, checkbox items, etc.). If it returns an empty dictionary, the line does not match the corresponding bullet item type.

It could be used like this:

let l:line = getline('.')
if s:match_bullet_list_item(l:line) == {}
   \ && s:match_checkbox_bullet_item(l:line) == {}
   \ && …
   " this line is not controlled by bullets.vim
 endif

However, since these methods are script-local you cannot use them outside of the plugin.

As bullets.vim doesn't use vims autoload feature, this could be made possible by changing bullets.vim to an autoload plugin as methods in autoload scripts are globally accessible. This would result in methods like bullets#match_bullet_list_item(input_text).