adding functionalities on the buffer

This commit is contained in:
Carlos
2025-07-28 19:28:46 -04:00
parent 2baa8ee836
commit 658a56ca55
16 changed files with 1809 additions and 178 deletions

View File

@@ -0,0 +1,151 @@
-- ideaDrop/utils/constants.lua
local M = {}
-- File extensions
M.FILE_EXTENSIONS = {
MARKDOWN = ".md",
LUA = ".lua",
}
-- Default file templates
M.DEFAULT_TEMPLATES = {
IDEA = {
"# %s",
"",
"- ",
},
MEETING = {
"# Meeting: %s",
"",
"## Date: %s",
"## Attendees:",
"- ",
"",
"## Agenda:",
"- ",
"",
"## Notes:",
"- ",
"",
"## Action Items:",
"- [ ] ",
},
PROJECT = {
"# Project: %s",
"",
"## Overview:",
"",
"## Goals:",
"- ",
"",
"## Tasks:",
"- [ ] ",
"",
"## Notes:",
"- ",
},
}
-- Window dimensions (as percentages of screen)
M.WINDOW_DIMENSIONS = {
RIGHT_SIDE_WIDTH = 0.3, -- 30% of screen width
TREE_WIDTH = 0.25, -- 25% of screen width
FLOATING_HEIGHT = 0.8, -- 80% of screen height
}
-- Buffer options
M.BUFFER_OPTIONS = {
IDEA_BUFFER = {
filetype = "markdown",
buftype = "acwrite",
bufhidden = "hide",
},
TREE_BUFFER = {
filetype = "ideaDrop-tree",
buftype = "nofile",
modifiable = false,
bufhidden = "hide",
},
}
-- Window options
M.WINDOW_OPTIONS = {
RIGHT_SIDE = {
wrap = true,
number = true,
relativenumber = false,
cursorline = true,
},
TREE = {
wrap = false,
number = false,
relativenumber = false,
cursorline = true,
},
}
-- Search settings
M.SEARCH_SETTINGS = {
MAX_RESULTS = 20,
CONTEXT_LENGTH = 80,
FUZZY_SCORE_BONUS = 10,
}
-- Tag settings
M.TAG_SETTINGS = {
PATTERN = "#([%w%-_]+)",
MAX_DEPTH = 10,
}
-- Common words to exclude from tags
M.COMMON_WORDS = {
"the", "and", "or", "but", "in", "on", "at", "to", "for", "of", "with",
"by", "is", "are", "was", "were", "be", "been", "have", "has", "had",
"do", "does", "did", "will", "would", "could", "should", "may", "might",
"can", "this", "that", "these", "those", "i", "you", "he", "she", "it",
"we", "they", "me", "him", "her", "us", "them", "my", "your", "his",
"her", "its", "our", "their", "mine", "yours", "hers", "ours", "theirs"
}
-- Icons for different file types and actions
M.ICONS = {
FILE = "📄",
DIRECTORY = "📁",
IDEA = "💡",
SEARCH = "🔍",
TAG = "🏷️",
TREE = "🌳",
SUCCESS = "",
ERROR = "",
WARNING = "⚠️",
INFO = "",
SAVE = "💾",
REFRESH = "🔄",
}
-- Key mappings (default)
M.DEFAULT_KEYMAPS = {
TOGGLE_TREE = "<C-t>",
REFRESH_FILE = "<C-r>",
CLOSE_WINDOW = "q",
SELECT_ITEM = "<CR>",
}
-- Notification messages
M.MESSAGES = {
PLUGIN_LOADED = "ideaDrop loaded!",
NO_FILES_FOUND = "📂 No idea files found",
NO_TAGS_FOUND = "🏷️ No tags found in your ideas",
NO_SEARCH_RESULTS = "🔍 No results found for '%s'",
FILE_SAVED = "💾 Idea saved to %s",
FILE_REFRESHED = "🔄 File refreshed",
TAG_ADDED = "✅ Added tag '%s' to %s",
TAG_REMOVED = "✅ Removed tag '%s' from %s",
TAG_EXISTS = "🏷️ Tag '%s' already exists in file",
TAG_NOT_FOUND = "🏷️ Tag '%s' not found in file",
NO_ACTIVE_FILE = "❌ No active idea file. Open an idea first.",
PROVIDE_TAG = "❌ Please provide a tag name",
PROVIDE_QUERY = "❌ Please provide a search query",
}
return M

View File

@@ -0,0 +1,20 @@
-- ideaDrop/utils/keymaps.lua
local M = {}
---Setup function for keymaps
---@return nil
function M.setup()
-- Global keymaps for ideaDrop
-- These can be customized by users in their config
-- Example: Quick access to ideaDrop commands
-- vim.keymap.set("n", "<leader>id", ":IdeaRight<CR>", { desc = "Open today's idea" })
-- vim.keymap.set("n", "<leader>it", ":IdeaTree<CR>", { desc = "Open idea tree" })
-- vim.keymap.set("n", "<leader>is", ":IdeaSearch ", { desc = "Search ideas" })
-- vim.keymap.set("n", "<leader>it", ":IdeaTags<CR>", { desc = "Browse tags" })
-- Note: Keymaps are commented out by default to avoid conflicts
-- Users can uncomment and customize these in their config
end
return M

View File

@@ -0,0 +1,181 @@
-- ideaDrop/utils/utils.lua
local M = {}
---@class Utils
---@field ensure_dir fun(path: string): nil
---@field get_relative_path fun(full_path: string, base_path: string): string
---@field sanitize_filename fun(filename: string): string
---@field format_date fun(date_format: string|nil): string
---@field truncate_string fun(str: string, max_length: number): string
---@field table_contains fun(tbl: table, value: any): boolean
---@field deep_copy fun(orig: table): table
---Ensures a directory exists, creating it if necessary
---@param path string Directory path to ensure
---@return nil
function M.ensure_dir(path)
if vim.fn.isdirectory(path) == 0 then
vim.fn.mkdir(path, "p")
end
end
---Gets the relative path from a full path
---@param full_path string Full file path
---@param base_path string Base directory path
---@return string Relative path
function M.get_relative_path(full_path, base_path)
if full_path:sub(1, #base_path) == base_path then
return full_path:sub(#base_path + 2) -- Remove base_path + "/"
end
return full_path
end
---Sanitizes a filename for safe file creation
---@param filename string Original filename
---@return string Sanitized filename
function M.sanitize_filename(filename)
-- Remove or replace invalid characters
local sanitized = filename:gsub("[<>:\"/\\|?*]", "_")
-- Remove leading/trailing spaces and dots
sanitized = sanitized:gsub("^[%s%.]+", ""):gsub("[%s%.]+$", "")
-- Ensure it's not empty
if sanitized == "" then
sanitized = "untitled"
end
return sanitized
end
---Formats current date with optional format
---@param date_format string|nil Date format string (default: "%Y-%m-%d")
---@return string Formatted date string
function M.format_date(date_format)
date_format = date_format or "%Y-%m-%d"
return os.date(date_format)
end
---Truncates a string to specified length with ellipsis
---@param str string String to truncate
---@param max_length number Maximum length
---@return string Truncated string
function M.truncate_string(str, max_length)
if #str <= max_length then
return str
end
return str:sub(1, max_length - 3) .. "..."
end
---Checks if a table contains a specific value
---@param tbl table Table to search
---@param value any Value to find
---@return boolean True if value is found
function M.table_contains(tbl, value)
for _, v in ipairs(tbl) do
if v == value then
return true
end
end
return false
end
---Creates a deep copy of a table
---@param orig table Original table
---@return table Deep copy of the table
function M.deep_copy(orig)
local copy
if type(orig) == "table" then
copy = {}
for orig_key, orig_value in next, orig, nil do
copy[M.deep_copy(orig_key)] = M.deep_copy(orig_value)
end
setmetatable(copy, M.deep_copy(getmetatable(orig)))
else
copy = orig
end
return copy
end
---Splits a string by delimiter
---@param str string String to split
---@param delimiter string Delimiter character
---@return table Array of substrings
function M.split_string(str, delimiter)
delimiter = delimiter or "\n"
local result = {}
for match in (str .. delimiter):gmatch("(.-)" .. delimiter) do
table.insert(result, match)
end
return result
end
---Joins table elements with a delimiter
---@param tbl table Table to join
---@param delimiter string Delimiter string
---@return string Joined string
function M.join_strings(tbl, delimiter)
delimiter = delimiter or "\n"
return table.concat(tbl, delimiter)
end
---Gets file extension from filename
---@param filename string Filename
---@return string File extension (without dot)
function M.get_file_extension(filename)
return filename:match("%.([^%.]+)$") or ""
end
---Removes file extension from filename
---@param filename string Filename
---@return string Filename without extension
function M.remove_file_extension(filename)
return filename:match("(.+)%.[^%.]+$") or filename
end
---Checks if a string starts with a prefix
---@param str string String to check
---@param prefix string Prefix to look for
---@return boolean True if string starts with prefix
function M.starts_with(str, prefix)
return str:sub(1, #prefix) == prefix
end
---Checks if a string ends with a suffix
---@param str string String to check
---@param suffix string Suffix to look for
---@return boolean True if string ends with suffix
function M.ends_with(str, suffix)
return str:sub(-#suffix) == suffix
end
---Escapes special characters in a string for shell commands
---@param str string String to escape
---@return string Escaped string
function M.escape_shell(str)
return vim.fn.shellescape(str)
end
---Gets the current buffer's file path
---@return string|nil Current buffer file path or nil
function M.get_current_file_path()
local buf_name = vim.api.nvim_buf_get_name(0)
if buf_name and buf_name ~= "" then
return buf_name
end
return nil
end
---Gets the current working directory
---@return string Current working directory
function M.get_cwd()
return vim.fn.getcwd()
end
---Shows a notification with optional log level
---@param message string Message to show
---@param level string|nil Log level (INFO, WARN, ERROR)
---@return nil
function M.notify(message, level)
level = level or vim.log.levels.INFO
vim.notify(message, level)
end
return M