Skip to content

Commit

Permalink
update: stylua format
Browse files Browse the repository at this point in the history
  • Loading branch information
LudoPinelli committed Jan 27, 2024
1 parent a36a704 commit 754dd68
Show file tree
Hide file tree
Showing 12 changed files with 559 additions and 425 deletions.
290 changes: 164 additions & 126 deletions lua/mind/commands.lua

Large diffs are not rendered by default.

23 changes: 11 additions & 12 deletions lua/mind/data.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

local M = {}

local notify = require'mind.notify'.notify
local path = require'plenary.path'
local notify = require("mind.notify").notify
local path = require("plenary.path")

-- Create a new random file in a given directory.
--
Expand All @@ -16,20 +16,20 @@ M.new_data_file = function(dir, name, extension, content, should_expand)
end

-- filter the name
name = name:gsub('[^%w-]', ' ') -- remove anything that is not a word or a dash
name = name:gsub('%s+', '-') -- replace consecutive spaces with a single one
name = name:gsub('-+', '-') -- replace consecutive dashes with a single one
name = name:gsub('^-', '') -- remove leading dash
name = name:gsub('-$', '') -- remove trailing dash
name = name:gsub("[^%w-]", " ") -- remove anything that is not a word or a dash
name = name:gsub("%s+", "-") -- replace consecutive spaces with a single one
name = name:gsub("-+", "-") -- replace consecutive dashes with a single one
name = name:gsub("^-", "") -- remove leading dash
name = name:gsub("-$", "") -- remove trailing dash

local filename = vim.fn.strftime('%Y%m%d%H%M%S-') .. name .. extension
local filename = vim.fn.strftime("%Y%m%d%H%M%S-") .. name .. extension
local p = path:new(dir, filename)
local file_path = (should_expand and p:expand()) or tostring(p)

local file = io.open(file_path, 'w')
local file = io.open(file_path, "w")

if (file == nil) then
notify('cannot open data file: ' .. file_path)
if file == nil then
notify("cannot open data file: " .. file_path)
return nil
end

Expand All @@ -44,5 +44,4 @@ M.delete_data_file = function(file_path)
os.remove(file_path)
end


return M
149 changes: 77 additions & 72 deletions lua/mind/defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,34 @@
-- URL opener depends on the platform.
local sysname = vim.loop.os_uname().sysname
local url_open
if sysname == 'Linux' then
url_open = 'xdg-open'
elseif sysname == 'Darwin' then
url_open = 'open'
elseif sysname == 'Windows' then
if sysname == "Linux" then
url_open = "xdg-open"
elseif sysname == "Darwin" then
url_open = "open"
elseif sysname == "Windows" then
url_open = 'start ""'
end

return {
-- persistence, both for the tree state and data files
persistence = {
-- path where the global mind tree is stored
state_path = '~/.local/share/mind.nvim/mind.json',
state_path = "~/.local/share/mind.nvim/mind.json",

-- directory where to create global data files
data_dir = '~/.local/share/mind.nvim/data',
data_dir = "~/.local/share/mind.nvim/data",
},

-- edit options
edit = {
-- file extension to use when creating a data file
data_extension = '.md',
data_extension = ".md",

-- default header to put in newly created data files
data_header = '# %s',
data_header = "# %s",

-- format string for copied links
copy_link_format = '[](%s)'
copy_link_format = "[](%s)",
},

-- tree options
Expand All @@ -51,119 +51,124 @@ return {
-- default width of the tree view window
width = 30,

-- split to open window in
position = "left",

-- should mind window be closed when a file is opened
close_on_file_open = false,

-- marker used for empty indentation
empty_indent_marker = '',
empty_indent_marker = "",

-- marker used for node indentation
node_indent_marker = '',
node_indent_marker = "",

-- marker used to identify the root of the tree (left to its name)
root_marker = '',
root_marker = "",

-- marker used to identify a local root (right to its name)
local_marker = 'local',
local_marker = "local",

-- marker used to show that a node has an associated data file
data_marker = '',
data_marker = "",

-- marker used to show that a node has an URL
url_marker = '',
url_marker = "",

-- marker used to show that a node is currently selected
select_marker = '',
select_marker = "",

-- highlight options
highlight = {
-- highlight used on closed marks
closed_marker = 'LineNr',
closed_marker = "LineNr",

-- highlight used on open marks
open_marker = 'LineNr',
open_marker = "LineNr",

-- highlight used on the name of the root node
node_root = 'Function',
node_root = "Function",

-- highlight used on regular nodes with no children
node_leaf = 'String',
node_leaf = "String",

-- highlight used on regular nodes with children
node_parent = 'Title',
node_parent = "Title",

-- highlight used on the local marker
local_marker = 'Comment',
local_marker = "Comment",

-- highlight used on the data marker
data_marker = 'Comment',
data_marker = "Comment",

-- highlight used on the url marker
url_marker = 'Comment',
url_marker = "Comment",

-- highlight used on empty nodes (i.e. no children and no data)
modifier_empty = 'Comment',
modifier_empty = "Comment",

-- highlight used on the selection marker
select_marker = 'Error',
select_marker = "Error",
},

-- preset of icons
icon_preset = {
{ '', 'Sub-project' },
{ '', 'Journal, newspaper, weekly and daily news' },
{ '', 'For when you have an idea' },
{ '', 'Note taking?' },
{ '', 'Task management' },
{ '', 'Uncheck, empty square or backlog' },
{ '', 'Full square or on-going' },
{ '', 'Check or done' },
{ '', 'Trash bin, deleted, cancelled, etc.' },
{ '', 'GitHub' },
{ '', 'Monitoring' },
{ '', 'Internet, Earth, everyone!' },
{ '', 'Frozen, on-hold' },
}
{ "", "Sub-project" },
{ "", "Journal, newspaper, weekly and daily news" },
{ "", "For when you have an idea" },
{ "", "Note taking?" },
{ "", "Task management" },
{ "", "Uncheck, empty square or backlog" },
{ "", "Full square or on-going" },
{ "", "Check or done" },
{ "", "Trash bin, deleted, cancelled, etc." },
{ "", "GitHub" },
{ "", "Monitoring" },
{ "", "Internet, Earth, everyone!" },
{ "", "Frozen, on-hold" },
{ "", "Data, knowledge" },
{ "", "Neovim" },
},
},

-- default keymaps; see 'mind.commands' for a list of commands that can be mapped to keys here
keymaps = {
-- keybindings when navigating the tree normally
normal = {
['<cr>'] = 'open_data',
['<s-cr>'] = 'open_data_index',
['<tab>'] = 'toggle_node',
['<s-tab>'] = 'toggle_parent',
['/'] = 'select_path',
['$'] = 'change_icon_menu',
c = 'add_inside_end_index',
I = 'add_inside_start',
i = 'add_inside_end',
l = 'copy_node_link',
L = 'copy_node_link_index',
d = 'delete',
D = 'delete_file',
O = 'add_above',
o = 'add_below',
q = 'quit',
r = 'rename',
R = 'change_icon',
u = 'make_url',
x = 'select',
["<cr>"] = "open_data",
["<s-cr>"] = "open_data_index",
["<tab>"] = "toggle_node",
["<s-tab>"] = "toggle_parent",
["/"] = "select_path",
["$"] = "change_icon_menu",
c = "add_inside_end_index",
I = "add_inside_start",
i = "add_inside_end",
l = "copy_node_link",
L = "copy_node_link_index",
d = "delete",
D = "delete_file",
O = "add_above",
o = "add_below",
q = "quit",
r = "rename",
R = "change_icon",
u = "make_url",
x = "select",
},

-- keybindings when a node is selected
selection = {
['<cr>'] = 'open_data',
['<tab>'] = 'toggle_node',
['<s-tab>'] = 'toggle_parent',
['/'] = 'select_path',
I = 'move_inside_start',
i = 'move_inside_end',
O = 'move_above',
o = 'move_below',
q = 'quit',
x = 'select',
["<cr>"] = "open_data",
["<tab>"] = "toggle_node",
["<s-tab>"] = "toggle_parent",
["/"] = "select_path",
I = "move_inside_start",
i = "move_inside_end",
O = "move_above",
o = "move_below",
q = "quit",
x = "select",
},
}
},
}
60 changes: 50 additions & 10 deletions lua/mind/highlight.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,74 @@ local M = {}

M.create_highlight_groups = function(opts)
-- highlight used on closed marks
vim.api.nvim_set_hl(0, 'MindClosedMarker', { default = true, link = opts.ui.highlight.closed_marker })
vim.api.nvim_set_hl(
0,
"MindClosedMarker",
{ default = true, link = opts.ui.highlight.closed_marker }
)

-- highlight used on open marks
vim.api.nvim_set_hl(0, 'MindOpenMarker', { default = true, link = opts.ui.highlight.open_marker })
vim.api.nvim_set_hl(
0,
"MindOpenMarker",
{ default = true, link = opts.ui.highlight.open_marker }
)

-- highlight used on the name of the root node
vim.api.nvim_set_hl(0, 'MindNodeRoot', { default = true, link = opts.ui.highlight.node_root })
vim.api.nvim_set_hl(
0,
"MindNodeRoot",
{ default = true, link = opts.ui.highlight.node_root }
)

-- highlight used on regular nodes with no children
vim.api.nvim_set_hl(0, 'MindNodeLeaf', { default = true, link = opts.ui.highlight.node_leaf })
vim.api.nvim_set_hl(
0,
"MindNodeLeaf",
{ default = true, link = opts.ui.highlight.node_leaf }
)

-- highlight used on regular nodes with children
vim.api.nvim_set_hl(0, 'MindNodeParent', { default = true, link = opts.ui.highlight.node_parent })
vim.api.nvim_set_hl(
0,
"MindNodeParent",
{ default = true, link = opts.ui.highlight.node_parent }
)

-- highlight used on the local marker
vim.api.nvim_set_hl(0, 'MindLocalMarker', { default = true, link = opts.ui.highlight.local_marker })
vim.api.nvim_set_hl(
0,
"MindLocalMarker",
{ default = true, link = opts.ui.highlight.local_marker }
)

-- highlight used on the data marker
vim.api.nvim_set_hl(0, 'MindDataMarker', { default = true, link = opts.ui.highlight.data_marker })
vim.api.nvim_set_hl(
0,
"MindDataMarker",
{ default = true, link = opts.ui.highlight.data_marker }
)

-- highlight used on the URL marker
vim.api.nvim_set_hl(0, 'MindURLMarker', { default = true, link = opts.ui.highlight.url_marker })
vim.api.nvim_set_hl(
0,
"MindURLMarker",
{ default = true, link = opts.ui.highlight.url_marker }
)

-- highlight used on empty nodes (i.e. no children and no data)
vim.api.nvim_set_hl(0, 'MindModifierEmpty', { default = true, link = opts.ui.highlight.modifier_empty })
vim.api.nvim_set_hl(
0,
"MindModifierEmpty",
{ default = true, link = opts.ui.highlight.modifier_empty }
)

-- highlight used on the selection marker
vim.api.nvim_set_hl(0, 'MindSelectMarker', { default = true, link = opts.ui.highlight.select_marker })
vim.api.nvim_set_hl(
0,
"MindSelectMarker",
{ default = true, link = opts.ui.highlight.select_marker }
)
end

return M
Loading

0 comments on commit 754dd68

Please sign in to comment.