Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
167 changes: 153 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Global-note.nvim

It's a simple Neovim plugin that provides a global note in a float window.
It could also provide other global, project local, file local notes (if it's required).

Expand All @@ -16,6 +17,7 @@ vim.keymap.set("n", "<leader>n", global_note.toggle_note, {
```

### Options

<details><summary>click</summary>
All options here are default:

Expand All @@ -33,10 +35,6 @@ All options here are default:
-- string or fun(): string
title = "Global note",

-- Ex command name.
-- string
command_name = "GlobalNote",

-- A nvim_open_win config to show float window.
-- table or fun(): table
window_config = function()
Expand Down Expand Up @@ -79,6 +77,7 @@ All options here are default:
<!-- panvimdoc-ignore-end -->

### Additional presets

You can use additional presets to have other global notes, project
local notes, file local notes or anything you can come up with.

Expand All @@ -97,14 +96,12 @@ require("global-note").setup({
projects = {
filename = "projects-to-do.md",
title = "List of projects",
command_name = "ProjectsNote",
-- All not specified options are used from the root.
},

food = {
filename = "want-to-eat.md",
title = "List of food",
command_name = "FoodNote",
-- All not specified options are used from the root.
},
},
Expand All @@ -115,19 +112,164 @@ require("global-note").toggle_note()
require("global-note").toggle_note("projects")
require("global-note").toggle_note("food")

-- Commands to toggle notes (they are generated by command_name field):
-- :GlobalNote -- by default
-- :ProjectsNote
-- :FoodNote
-- Commands to toggle notes (they are generated field name):
-- :GlobalNote -- default global note
-- :GlobalNote projects
-- :GlobalNote food

-- Command to pick a note:
-- :GlobalNotePick
```

### Dynamically managing notes with scopes

A note can have a **global** or project **local** scope, and can be created dynamically without having to predefine them.

A local note is a note that is specific to a project. And they are stored as `<global-note-directory>/<project_name>/<note_name>.md`.

#### Create note

To create a note, use the following function:

```lua
require('global-note').create_note(opts)
```

`opts?`: table, with the following fields:

- `local_scope?: boolean` if true, create a local note, otherwise, create a global note

<details><summary>Examples</summary>

```lua
-- create a global note
require('global-note').create_note()
--or
require('global-note').create_note({local_scope=false})

-- create a local note
require('global-note').create_note({local_scope=true})
```

</details>

#### Toggle note

To open a note, use the following function:

```lua
require('global-note').toggle_note(preset_name, local_scope)
```

`preset_name?: string` if not provided, open the default global note

`local_scope?: boolean` if true, look for a local note with name `<preset_name>`, otherwise, look for a global note with name `<preset_name>`

<details><summary>Examples</summary>

```lua
-- toggle the default global note
require('global-note').toggle_note()

-- toggle the global note `projects`
require('global-note').toggle_note('projects')
--or
require('global-note').toggle_note('projects', {local_scope=false})

-- toggle the local note `projects`
require('global-note').toggle_note('projects', {local_scope=true})
```

</details>

#### Pick note

To pick a note, use the following function:

```lua
require('global-note').pick_note(opts)
```

`opts?`: table, with the following fields:

- `local_scope: boolean` if true, pick a local note, otherwise, pick a global note

<details><summary>Examples</summary>

```lua
-- pick a global note
require('global-note').pick_note()
--or
require('global-note').pick_note({local_scope=false})

-- pick a local note
require('global-note').pick_note({local_scope=true})
```

</details>

#### Commands

`:GlobalNoteCreate <scope>`: create a note, `<scope>` is optional, if it is `local`, create a local note, otherwise global note

<details><summary>Examples</summary>

```lua
-- create a global note
-- :GlobalNoteCreate
-- or
-- :GlobalNoteCreate global

-- create a local note
-- :GlobalNoteCreate local
```

</details>

`:GlobalNote <preset_name> <scope>`: open global note, if `<preset_name>` is not provided, open the default global note, otherwise, open the note with name `<preset_name>` and the given scope

<details><summary>Examples</summary>

```lua
-- open the default global note
-- :GlobalNote
-- or
-- :GlobalNote global

-- open the global note `projects`
-- :GlobalNote projects
-- or
-- :GlobalNote projects global

-- open the local note `projects`
-- :GlobalNote projects local
```

</details>

`:GlobalNotePick <scope>`: pick a note to open, `<scope>` is optional, if it is `local`, select a local note, otherwise global note

<details><summary>Examples</summary>

```lua
-- pick a global note
-- :GlobalNotePick
-- or
-- :GlobalNotePick global

-- pick a local note
-- :GlobalNotePick local
```

</details>

<!-- panvimdoc-ignore-start -->

---

<!-- panvimdoc-ignore-end -->

### Configuration usecases:
### Configuration usecases

:warning: **Usecases require some functions from below!**

Expand All @@ -138,7 +280,6 @@ local global_note = require("global-note")
global_note.setup({
additional_presets = {
project_local = {
command_name = "ProjectNote",

filename = function()
return get_project_name() .. ".md"
Expand All @@ -165,8 +306,6 @@ local global_note = require("global-note")
global_note.setup({
additional_presets = {
git_branch_local = {
command_name = "GitBranchNote",

directory = function()
return vim.fn.stdpath("data") .. "/global-note/" .. get_project_name()
end,
Expand Down
Loading