-
-
Notifications
You must be signed in to change notification settings - Fork 14
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
Feature request: Support for custom filetypes using header characters (or just .vimrc / init.vim) #19
Comments
maybe as simple as adding: local Vimrc = {}
function Vimrc.get_headings(filepath, start, total)
local headings = {}
local index = start
local matches = {
'"" ',
'""" ',
'"""" ',
'""""" ',
'"""""" ',
}
while index <= total do
local line = vim.fn.getline(index)
-- match heading
for _, pattern in pairs(matches) do
if vim.startswith(line, pattern) then
table.insert(headings, {
heading = vim.trim(line),
line = index,
path = filepath,
})
break
end
end
::next::
index = index + 1
end
return headings
end
return Vimrc to extensions/headings/ ? |
Hacked something together over on |
I understand what you want. However, this is kinda a hack on comments instead of headings. |
I might be missing something about the semantics of what constitutes a header... I guess part of the problem is if there isn't a single agreed upon syntax for section headings in vim config files then tree-sitter integration wouldn't work, and it would be tricky to support those styles? But it seems like some sort of solution for section headings within a vim config file would be useful to lots of people. (for now my hack is sufficient for my own purposes) |
More generally it would be nice for the plugin to be more extensible / customizable with options like: (please excuse what may be non-functional lua, I'm not super familiar with the language) local mappings = {
{ft = 'markdown',
heading_match_pattern = '^#{1,6}',
tree_sitter_supported=true},
{ft = 'neorg',
heading_match_pattern='^*{1,6}',
tree_sitter_support=true},
{ft = 'vim',
heading_match_pattern='^"{2,6}',
tree_sitter_support=false},
} since so many languages use this multiple character pattern to define headings, this would also simply code which is duplicated between files in |
I think "comment heading" is a better description of this feature. And this should be another function provided by this plugin, which is based on comment string rather than simple But I have a question about this comment heading. Is there a common grammar or standard on how to define a heading inside a comment string? If there was, we would have use tree-sitter to query comments and just search with the standard format. This sounds good. |
I think applying this "multiples of the same comment for header levels" beyond markdown (and neorg) is wishful thinking on my part. I tried to scan some .vimrc or init.lua files, and couldn't find anyone else that does it this way. But generalizing the comment string to get headings for more filetypes still seems valuable. MATLAB uses |
Hello,
thanks for the plugin!
I use mutliple comment symbols to define headings in several filetypes (including my .vimrc)
This is almost identical to how headings are managed in markdown for instance. Is it possible with the current plugin to extend heading search to work in my .vimrc? Or would it be possible to add configurable parameters for additional filetypes by specifying the characters used for headings?
The text was updated successfully, but these errors were encountered: