Skip to content

A neovim plugin which generates proper include guard for C++

License

Notifications You must be signed in to change notification settings

pogyomo/cppguard.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🛡️ cppguard.nvim

Automatically generates proper include guard for C++

📋 Requirements

  • Neovim >= 0.10.0
  • luasnip (optional)

📥 Installation

With lazy.nvim

return {
    "pogyomo/cppguard.nvim",
    dependencies = {
        "L3MON4D3/LuaSnip" -- If you're using luasnip.
    },
    lazy = true,
}

📓 Introduction

C++ requires developer to write include guard to prevent that file is included more than twice, and sometimes you need to write longer include guard, and it's painful.

So, this plugin provides apis that automatically generates such include guard.

🚀 Usage

This plugin provides guard_string which generates a string that is unique for using in include guard.

For examples, consider the following directory structure.

project
|---CMakeLists.txt
|---src
    |---dir
        |---sub
            |---file.h <-here

When you open file.h, then call this function, you will get PROJECT_DIR_SUB_FILE_H_, that is following google C++ Style Guide.

If you're using luasnip, you can add a snippet that automatically creates include guard with following code:

local luasnip = require("luasnip")
luasnip.add_snippets("cpp", {
    -- Register snippet which can summon by typing `guard`
    require("cppguard").snippet_luasnip("guard")
})

This snippet works as follow when you're in such above, for example:

guard|

↓ expand

#ifndef PROJECT_DIR_SUB_FILE_H_
#define PROJECT_DIR_SUB_FILE_H_

|

#endif

🖥️ APIS

  • guard_string(opts)
    • opts?: table Options to manage the movement of this function. Having following fields:
      • naming_method?: string How to generates the include guard. Accept following strings:
  • snippent_luasnip(trig, opts)
    • trig: string What summon this snippent.
    • opts?: table Options to manage how to generate include guard. Same as opts in guard_string.

About

A neovim plugin which generates proper include guard for C++

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages