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

how can I autopair < and > only for C header files? #96

Open
4rtemis-4rrow opened this issue Aug 2, 2024 · 3 comments
Open

how can I autopair < and > only for C header files? #96

4rtemis-4rrow opened this issue Aug 2, 2024 · 3 comments

Comments

@4rtemis-4rrow
Copy link

I searched high and low, went over all the docs, and though I don't know lua (I know, I have to learn it, my config is 1225 lines of lua, it's getting hard to maintain), I tried my best

internal_pairs={-- *ultimate-autopair-pairs-default-pairs*
    {'[',']',fly=true,dosuround=true,newline=true,space=true},
    {'(',')',fly=true,dosuround=true,newline=true,space=true},
    {'{','}',fly=true,dosuround=true,newline=true,space=true},
    {'"','"',suround=true,multiline=false},
    {"'","'",suround=true,cond=function(fn) return not fn.in_lisp() or fn.in_string() end,alpha=true,nft={'tex'},multiline=false},
    {'`','`',cond=function(fn) return not fn.in_lisp() or fn.in_string() end,nft={'tex'},multiline=false},
    {'``',"''",ft={'tex'}},
    {'```','```',newline=true,ft={'markdown'}},
    {'<!--','-->',ft={'markdown','html'},space=true},
    {'"""','"""',newline=true,ft={'python'}},
    {"'''","'''",newline=true,ft={'python'}},
    {'<','>',-- Condition for #include
    cond=function()
        local line = vim.api.nvim_get_current_line()
        return line:match("#include%s*$") ~= nil
    end,
    ft={'c','cpp'}
    },
},

I failed, if anyone can help me, that'd be greatly appreciated, I submit this here, for I don't know where else to ask

thank you for taking the time to read this, and have a great day, whoever you may be, wherever you may be

@altermo
Copy link
Owner

altermo commented Aug 2, 2024

Wouldn't checking if the buffer name ends with .h work? (e.g. vim.api.nvim_buf_get_name(0):match('%.h$')

@4rtemis-4rrow
Copy link
Author

no, a buffer ending with .h would be when you are editing the header file itself, I'm talking about when you are including a header file in a C project, eg
#include <stdlib.h>
and I can't do it to all C files in general, because using < and > for anything other than include statements would be annoying, so it has to be only when the line begins with #include

@altermo
Copy link
Owner

altermo commented Aug 2, 2024

Then wouldn't current_line:match('^%s*#%s*include[^%w]') solve the problem? (notice that the pattern doesn't use $ at the end)

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