Skip to content
Merged
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
1 change: 1 addition & 0 deletions fnl/sm/config.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new split_height configuration option is not documented in README.md. The configuration table in the Options section (around line 119-127) should include an entry for split_height explaining its purpose, default value (15), and that it can be set to nil to use Neovim's default behavior.

Suggested change
:split_height 15 ; height for horizontal split window
:split_height 15 ; height for horizontal split window (set to nil to use Neovim's default behavior)

Copilot uses AI. Check for mistakes.
:template ["---"
"tags: [%tags%]"
"created: %date%"
Expand Down
5 changes: 4 additions & 1 deletion fnl/sm/memo.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
47 changes: 47 additions & 0 deletions fnl/sm/memo_test.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Comment on lines +113 to +158
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test only covers the case where split_height is set to 15. According to the PR description, setting split_height to nil should skip the height setting and use Neovim's default behavior. A test case should be added to verify that nvim_win_set_height is NOT called when split_height is nil.

Copilot uses AI. Check for mistakes.

(print "memo_test.lua: All tests passed")
2 changes: 1 addition & 1 deletion lua/sm/config.lua
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
9 changes: 7 additions & 2 deletions lua/sm/memo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
64 changes: 64 additions & 0 deletions lua/sm/memo_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")