feat: Add autocmd_pattern() and rename buffer functions with buf_ prefix#17
Conversation
- Add autocmd_pattern() helper for setting buffer-local keymaps via autocommands - Rename add_tag -> buf_add_tag, follow_link -> buf_follow_link - Add Buffer Keymaps documentation section to README.md - Add tests for autocmd_pattern()
There was a problem hiding this comment.
Pull request overview
This PR enhances the sm.nvim plugin's public API by adding a helper function for autocommand patterns and renaming buffer-scoped functions for better clarity. The changes enable users to set up buffer-local keymaps using native Neovim autocommands.
Changes:
- Added
autocmd_pattern()function that returns the file pattern for memo files ({memos_dir}/*.md) - Renamed
add_tag→buf_add_tagandfollow_link→buf_follow_linkto indicate buffer-scoped operations - Added comprehensive "Buffer Keymaps" documentation section with usage examples
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| fnl/sm/init.fnl | Added autocmd_pattern() function and renamed buffer functions with buf_ prefix |
| fnl/sm/cmd.fnl | Updated command implementations to use renamed functions |
| fnl/sm/init_test.fnl | Added new test file for autocmd_pattern() function |
| lua/sm/init.lua | Auto-generated Lua from Fennel source |
| lua/sm/cmd.lua | Auto-generated Lua from Fennel source |
| lua/sm/init_test.lua | Auto-generated Lua from Fennel test source |
| README.md | Added "Buffer Keymaps" section with examples and updated API documentation |
| | Event | Trigger | | ||
| |-------|---------| | ||
| | `BufNewFile` | New memo created via `create()` | | ||
| | `BufRead` | Existing memo opened via `open()`, `open_last()` | |
There was a problem hiding this comment.
The documentation references open() as a function that triggers the BufRead event, but there is no public open() function in the sm module API. The available functions are open_last() from the main API and api.open_memo(filepath) from the picker API.
Update the documentation to accurately reflect the available functions, such as:
BufRead| Existing memo opened viaapi.open_memo(),open_last()|
| | `BufRead` | Existing memo opened via `open()`, `open_last()` | | |
| | `BufRead` | Existing memo opened via `api.open_memo()`, `open_last()` | |
|
|
||
| (fn M.add_tag [?tag] | ||
| "Add tag to current memo" | ||
| (fn M.buf_add_tag [?tag] |
There was a problem hiding this comment.
This introduces a breaking API change by renaming add_tag to buf_add_tag without providing backward compatibility aliases or deprecation warnings. Users who have require("sm").add_tag in their configurations will experience immediate breakage.
Consider either:
- Keeping the old function names as deprecated aliases that call the new functions with a deprecation warning
- Documenting this breaking change in the CHANGELOG.md under the [Unreleased] section with a migration guide
Since the project is at version 0.2.0 (pre-1.0), breaking changes are more acceptable, but they should still be clearly documented to help users migrate.
|
|
||
| (fn M.follow_link [] | ||
| "Follow wiki link under cursor" | ||
| (fn M.buf_follow_link [] |
There was a problem hiding this comment.
This introduces a breaking API change by renaming follow_link to buf_follow_link without providing backward compatibility aliases or deprecation warnings. Users who have require("sm").follow_link in their configurations will experience immediate breakage.
Consider either:
- Keeping the old function names as deprecated aliases that call the new functions with a deprecation warning
- Documenting this breaking change in the CHANGELOG.md under the [Unreleased] section with a migration guide
Since the project is at version 0.2.0 (pre-1.0), breaking changes are more acceptable, but they should still be clearly documented to help users migrate.
- Change `open()` to `api.open_memo()` in Events table (open() doesn't exist)
Summary
autocmd_pattern()helper function that returns the pattern for autocommandsbuf_prefix for clarity:add_tag→buf_add_tagfollow_link→buf_follow_linkUsage
Users can now set buffer-local keymaps for memo files using native autocommands:
Test plan
make testpasses:SmAddTagand:SmFollowLinkcommands workautocmd_pattern()returns correct pattern🤖 Generated with Claude Code