diff --git a/fnl/sm/config.fnl b/fnl/sm/config.fnl index e0799cd..16675e8 100644 --- a/fnl/sm/config.fnl +++ b/fnl/sm/config.fnl @@ -8,6 +8,7 @@ :date_format "%Y%m%d_%H%M%S" :auto_tag_git_repo false ; optional: add git repo name as tag when creating memo :copilot_integration false ; opt-in: attach copilot to memo buffers + :split_height 15 ; height for horizontal split window :template ["---" "tags: [%tags%]" "created: %date%" diff --git a/fnl/sm/memo.fnl b/fnl/sm/memo.fnl index 99198ce..5ecfb65 100644 --- a/fnl/sm/memo.fnl +++ b/fnl/sm/memo.fnl @@ -124,11 +124,14 @@ (fn M.open_in_split [filepath] "Open file in horizontal split at bottom" - (let [buf (vim.fn.bufadd filepath)] + (let [buf (vim.fn.bufadd filepath) + cfg (config.get)] (vim.fn.bufload buf) (tset vim.bo buf :filetype :markdown) (vim.cmd "botright split") (vim.api.nvim_win_set_buf 0 buf) + (when cfg.split_height + (vim.api.nvim_win_set_height 0 cfg.split_height)) (tset vim.wo :wrap true) (try_attach_copilot 1) buf)) diff --git a/fnl/sm/memo_test.fnl b/fnl/sm/memo_test.fnl index 7a12a95..9465142 100644 --- a/fnl/sm/memo_test.fnl +++ b/fnl/sm/memo_test.fnl @@ -110,4 +110,51 @@ (let [content (M2.generate_template "Test" (M2._get_initial_tags))] (assert (content:match "tags: %[test%-repo%]") "auto_tag: template includes repo tag"))) +;; Test split_height config sets window height +(do + ;; Clear package.loaded for fresh mocks + (tset package.loaded :sm.config nil) + (tset package.loaded :sm.git nil) + (tset package.loaded :sm.memo nil) + + ;; Track nvim_win_set_height calls + (var set_height_calls []) + (when (not _G.vim.api) + (set _G.vim.api {})) + (tset _G.vim.api :nvim_win_set_height + (fn [win height] + (table.insert set_height_calls {:win win :height height}))) + + ;; Mock config with split_height + (tset package.loaded :sm.config + {:get (fn [] + {:split_height 15 + :copilot_integration false + :date_format "%Y%m%d_%H%M%S" + :template ["---" "# %title%" ""]}) + :get_memos_dir (fn [] "/tmp/test-memos")}) + + ;; Mock other dependencies + (tset package.loaded :sm.git {:get_repo_tag (fn [] nil) :is_git_repo (fn [] false)}) + (tset package.loaded :sm.state {:set_last_edited (fn []) :add_recent (fn []) :load (fn [] {})}) + + ;; Mock vim functions needed by open_in_split + (tset _G.vim.fn :bufadd (fn [filepath] 1)) + (tset _G.vim.fn :bufload (fn [buf] nil)) + ;; vim.bo[buf] and vim.wo need metatable for buffer/window-specific access + (set _G.vim.bo (setmetatable {} {:__index (fn [] {})})) + (set _G.vim.wo (setmetatable {} {:__index (fn [] {})})) + (tset _G.vim :cmd (fn [cmd] nil)) + (tset _G.vim.api :nvim_win_set_buf (fn [win buf] nil)) + + ;; Re-require memo with mocks + (local M3 (require :sm.memo)) + + ;; Call open_in_split + (M3.open_in_split "/tmp/test-memos/test.md") + + ;; Verify nvim_win_set_height was called with correct value + (assert (= (length set_height_calls) 1) "split_height: nvim_win_set_height called once") + (assert (= (. set_height_calls 1 :height) 15) "split_height: height set to config value")) + (print "memo_test.lua: All tests passed") diff --git a/lua/sm/config.lua b/lua/sm/config.lua index b346d67..a649ac8 100644 --- a/lua/sm/config.lua +++ b/lua/sm/config.lua @@ -1,5 +1,5 @@ local M = {} -local defaults = {memos_dir = nil, state_file = nil, date_format = "%Y%m%d_%H%M%S", template = {"---", "tags: [%tags%]", "created: %date%", "---", "", "# %title%", ""}, window = {width = 80, height = 30, border = "rounded", style = "minimal"}, auto_tag_git_repo = false, copilot_integration = false} +local defaults = {memos_dir = nil, state_file = nil, date_format = "%Y%m%d_%H%M%S", split_height = 15, template = {"---", "tags: [%tags%]", "created: %date%", "---", "", "# %title%", ""}, window = {width = 80, height = 30, border = "rounded", style = "minimal"}, auto_tag_git_repo = false, copilot_integration = false} local config = nil local setup_called = false M.get_base_dir = function() diff --git a/lua/sm/memo.lua b/lua/sm/memo.lua index 82378a6..e65a1eb 100644 --- a/lua/sm/memo.lua +++ b/lua/sm/memo.lua @@ -123,10 +123,15 @@ local function goto_last_line() end M.open_in_split = function(filepath) local buf = vim.fn.bufadd(filepath) + local cfg = config.get() vim.fn.bufload(buf) vim.bo[buf]["filetype"] = "markdown" vim.cmd("botright split") vim.api.nvim_win_set_buf(0, buf) + if cfg.split_height then + vim.api.nvim_win_set_height(0, cfg.split_height) + else + end vim.wo["wrap"] = true try_attach_copilot(1) return buf @@ -188,10 +193,10 @@ M.list = function() ensure_memos_dir() local dir = config.get_memos_dir() local files = vim.fn.glob((dir .. "/*.md"), false, true) - local function _17_(a, b) + local function _18_(a, b) return (a > b) end - table.sort(files, _17_) + table.sort(files, _18_) return files end M.delete = function(filepath) diff --git a/lua/sm/memo_test.lua b/lua/sm/memo_test.lua index 9a7c911..6982483 100644 --- a/lua/sm/memo_test.lua +++ b/lua/sm/memo_test.lua @@ -120,4 +120,68 @@ do local content = M2.generate_template("Test", M2._get_initial_tags()) assert(content:match("tags: %[test%-repo%]"), "auto_tag: template includes repo tag") end +do + package.loaded["sm.config"] = nil + package.loaded["sm.git"] = nil + package.loaded["sm.memo"] = nil + local set_height_calls = {} + if not _G.vim.api then + _G.vim.api = {} + else + end + local function _20_(win, height) + return table.insert(set_height_calls, {win = win, height = height}) + end + _G.vim.api["nvim_win_set_height"] = _20_ + local function _21_() + return {split_height = 15, date_format = "%Y%m%d_%H%M%S", template = {"---", "# %title%", ""}, copilot_integration = false} + end + local function _22_() + return "/tmp/test-memos" + end + package.loaded["sm.config"] = {get = _21_, get_memos_dir = _22_} + local function _23_() + return nil + end + local function _24_() + return false + end + package.loaded["sm.git"] = {get_repo_tag = _23_, is_git_repo = _24_} + local function _25_() + end + local function _26_() + end + local function _27_() + return {} + end + package.loaded["sm.state"] = {set_last_edited = _25_, add_recent = _26_, load = _27_} + local function _28_(filepath) + return 1 + end + _G.vim.fn["bufadd"] = _28_ + local function _29_(buf) + return nil + end + _G.vim.fn["bufload"] = _29_ + local function _30_() + return {} + end + _G.vim.bo = setmetatable({}, {__index = _30_}) + local function _31_() + return {} + end + _G.vim.wo = setmetatable({}, {__index = _31_}) + local function _32_(cmd) + return nil + end + _G.vim["cmd"] = _32_ + local function _33_(win, buf) + return nil + end + _G.vim.api["nvim_win_set_buf"] = _33_ + local M3 = require("sm.memo") + M3.open_in_split("/tmp/test-memos/test.md") + assert((#set_height_calls == 1), "split_height: nvim_win_set_height called once") + assert((set_height_calls[1].height == 15), "split_height: height set to config value") +end return print("memo_test.lua: All tests passed")