Skip to content

Commit

Permalink
Merge pull request #15 from Diogo-ss/dev
Browse files Browse the repository at this point in the history
feat: add git support, rewrite part of the code, add new checking and CI and new error handling.
  • Loading branch information
Diogo-ss authored Apr 11, 2024
2 parents eecdd33 + 2ff0f16 commit d728a99
Show file tree
Hide file tree
Showing 9 changed files with 343 additions and 307 deletions.
122 changes: 72 additions & 50 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,80 +3,102 @@
This plugin is whole re-write of [42header](https://github.com/42Paris/42header) in Lua.

## ✨ Features

- Command: `Stdheader`
- Customizable options
- Modulate
- Auto update on save (optional)
- Support many [file types](https://github.com/Diogo-ss/42-header.nvim/blob/main/lua/42header/config/init.lua) by default
- Supports `commentstring`
- Supports Git

## 🚀 Showcase

![header](https://raw.githubusercontent.com/Diogo-ss/42-header.nvim/7528c7ff25c51bf32301dfc1ece995128d2ae7d5/.github/header_img.png)

## 🎈 Setup

### 📦 Packer.nvim
```lua
use { "Diogo-ss/42-header.nvim" }
```
<details>
<summary>📦 Packer.nvim</summary>

### 💤 Lazy.nvim
```lua
{ "Diogo-ss/42-header.nvim" }
use {
"Diogo-ss/42-header.nvim",
cmd = { "Stdheader" },
config = function()
require "42header"setup {
default_map = true, -- Default mapping <F1> in normal mode.
auto_update = true, -- Update header when saving.
user = "username", -- Your user.
mail = "[email protected]", -- Your mail.
-- add other options.
}
end,
}
```

</details>

<details>
<summary>💤 Lazy.nvim</summary>

```lua
{
"Diogo-ss/42-header.nvim",
lazy = false,
config = function()
local header = require("42header")
header.setup({
default_map = true, -- default Mapping <F1> in normal mode
auto_update = true, -- update header when saving
user = "Diogo-ss", -- your user
mail = "[email protected]", -- your mail
})
end
return {
"Diogo-ss/42-header.nvim",
cmd = { "Stdheader" },
keys = {"<F1>"},
opts = {
default_map = true, -- Default mapping <F1> in normal mode.
auto_update = true, -- Update header when saving.
user = "username", -- Your user.
mail = "[email protected]", -- Your mail.
-- add other options.
},
config = function(_, opts)
require("42header").setup(opts)
end,
}
```

### 🔌 Vim-plug
```lua
call plug#begin()
Plug 'Diogo-ss/42-header.nvim'
call plug#end()
```
</details>

## ⚙ Options

```lua
local header = require("42header")
header.setup({
length = 80, -- headers of different sizes are incompatible with each other
margin = 5,
default_map = true, -- default Mapping <F1> in normal mode
auto_update = true, -- update header when saving
user = "Diogo-ss", -- your user
mail = "[email protected]", -- your mail
-- asciiart = { "......", "......",} -- headers with different ascii arts are incompatible with each other
})
{
---Max header size (not recommended change).
--length = 80,
---Header margin (not recommended change).
--margin = 5,
---Activate default mapping (e.g. F1).
default_map = true,
---Enable auto-update of headers.
auto_update = true,
---Default user.name.
user = "username",
---Default user.email.
mail = "[email protected]",
---ASCII art.
--asciiart = { "---", "---", ... },
---Git config.
git = {
---Enable Git support.
enabled = false,
---PATH to the Git binary.
bin = "git",
---Use global user.name, otherwise use local user.name.
user_global = true,
---Use global user.email, otherwise use local user.email.
email_global = true,
},
}
```

## 🌐 User and Mail

`user` and `mail` can be defined using global variables.

```lua
vim.g.user = "Diogo-ss"
vim.g.mail = "[email protected]"
vim.g.user = "username"
vim.g.mail = "[email protected]"
```
> **_NOTE:_** global variables have higher priority than setup values
## 🍦 Credits
Lua version by [Diogo-ss](https://github.com/Diogo-ss)

Original VimScript version:
<br>
[zazard](https://github.com/zazard) - creator
[alexandregv](https://github.com/alexandregv) - contributor
[mjacq42](https://github.com/mjacq42) - contributor
[sungmcho](https://github.com/lordtomi0325) - contributor


> **_NOTE:_** The order of priority: `global variables` > `git config (if support enabled)` > `user config`.
34 changes: 34 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: check

on:
push:
branches-ignore:
- main
paths:
- "lua/**/*.lua"
pull_request:
paths:
- "lua/**/*.lua"
workflow_call:

jobs:
check:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Create Luacheck config
run: echo 'globals = { "vim" }' > .luacheckrc

- name: Luacheck
uses: lunarmodules/luacheck@v1
with:
args: .

- name: Stylua check
uses: JohnnyMorganz/stylua-action@v4
with:
token: ${{ secrets.GH_TOKEN }}
version: latest
args: --color always --check lua/
44 changes: 44 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: ci
on:
push:
paths-ignore:
- ".github/**"
- ".stylua.toml"
- ".gitignore"
branches:
- main
jobs:
check:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4

- name: create luacheck config
run: echo 'globals = { "vim" }' > .luacheckrc

- name: luacheck
uses: lunarmodules/luacheck@v1
with:
args: .

- name: stylua check
uses: johnnymorganz/stylua-action@v4
with:
token: ${{ secrets.GH_TOKEN }}
version: latest
args: --color always --check lua/

release:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
needs: check
steps:
- name: checkout
uses: actions/checkout@v4

- name: create release
uses: google-github-actions/release-please-action@v4
with:
token: ${{ secrets.GH_TOKEN }}
release-type: simple
49 changes: 0 additions & 49 deletions .github/workflows/format.yml

This file was deleted.

9 changes: 5 additions & 4 deletions lua/42header.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
local M = {}
local config = require "42header.config"
local utils = require "42header.utils"
local utils = require "42header.utils.header"

local M = {}

function M.setup(options)
function M.setup(opts)
local custom = vim.api.nvim_create_augroup("custom_header_group", {})

config.set(vim.tbl_extend("force", config.opts, options or {}))
config.set(opts)
vim.api.nvim_create_user_command("Stdheader", utils.stdheader, {})

if config.opts.auto_update == true then
Expand Down
64 changes: 9 additions & 55 deletions lua/42header/config/init.lua
Original file line number Diff line number Diff line change
@@ -1,64 +1,12 @@
--- Module for managing configuration options for the 42header plugin.
-- This module defines default configuration options and allows users to set custom options.
local M = {}

--- Default configuration options for the 42header plugin.
-- Users can customize these options by setting their own values.
-- @field length (number) The maximum line length for the header.
-- @field margin (number) The margin size.
-- @field default_map (boolean) Whether to enable the default key mapping.
-- @field auto_update (boolean) Whether to enable automatic header updates on file save.
-- @field types (table) A table mapping file extensions to their corresponding comment symbols.
-- - Each entry consists of a table of file extensions and a table of comment symbols.
-- - The comment symbols include the start, fill, and end symbols.
-- @field asciiart (table) A table containing ASCII art lines for the header decoration.
M.opts = {
length = 80,
margin = 5,
default_map = true,
auto_update = true,
user = "username",
mail = "[email protected]",
types = {
[{
"c",
"cc",
"cpp",
"cxx",
"tpp",
"glsl",
"h",
"hh",
"hxx",
"hpp",
"cs",
"d",
"php",
"css",
"sql",
"swift",
"kt",
"kts",
}] = {
"/*",
"*",
"*/",
},
[{ "go" }] = { "//", "*", "//" },
[{ "lua", "hs" }] = { "--", "*", "--" },
[{ "md", "htm", "html", "xml" }] = { "<!--", "*", "-->" },
[{ "js", "ts", "rs", "java" }] = { "//", "*", "//" },
[{ "tex" }] = { "%", "*", "%" },
[{ "ml", "mli", "mll", "mly" }] = { "(*", "*", "*)" },
[{ "vim", "vimrc" }] = { '"', "*", '"' },
[{ "el", "asm", "s" }] = { ";", "*", ";" },
[{ "emacs", "f90", "f95", "f03", "f" }] = { ";", "*", ";" },
[{ "bat" }] = { "REM", "*", "REM" },
[{ "vb" }] = { "'", "*", "'" },
[{ "cob" }] = { "*", "*", "*" },
[{ "scala", "dart" }] = { "//", "*", "//" },
[{ "plsql", "vhdl" }] = { "--", "*", "--" },
},
asciiart = {
" ::: ::::::::",
" :+: :+: :+:",
Expand All @@ -68,12 +16,18 @@ M.opts = {
" #+# #+# ",
" ### ########.fr ",
},
git = {
enabled = false,
bin = "git",
user_global = true,
email_global = true,
},
}

--- Set custom configuration options.
-- @param opts (table) A table of custom configuration options to override the defaults.
---Applies the user options to the default table.
---@param opts table: settings
M.set = function(opts)
M.opts = opts
M.opts = vim.tbl_deep_extend("force", M.opts, opts or {})
end

return M
Loading

0 comments on commit d728a99

Please sign in to comment.