Skip to content

feat: Add autocmd_pattern() and rename buffer functions with buf_ prefix#17

Merged
Cassin01 merged 3 commits into
mainfrom
delete_file
Jan 18, 2026
Merged

feat: Add autocmd_pattern() and rename buffer functions with buf_ prefix#17
Cassin01 merged 3 commits into
mainfrom
delete_file

Conversation

@Cassin01
Copy link
Copy Markdown
Owner

Summary

  • Add autocmd_pattern() helper function that returns the pattern for autocommands
  • Rename buffer-scoped functions with buf_ prefix for clarity:
    • add_tagbuf_add_tag
    • follow_linkbuf_follow_link
  • Add "Buffer Keymaps" documentation section to README.md

Usage

Users can now set buffer-local keymaps for memo files using native autocommands:

vim.api.nvim_create_autocmd({ "BufNewFile", "BufRead" }, {
  pattern = require("sm").autocmd_pattern(),
  callback = function(args)
    vim.keymap.set("n", "<leader>mt", require("sm").buf_add_tag, { buffer = args.buf })
    vim.keymap.set("n", "<leader>mf", require("sm").buf_follow_link, { buffer = args.buf })
  end,
})

Test plan

  • make test passes
  • :SmAddTag and :SmFollowLink commands work
  • autocmd_pattern() returns correct pattern

🤖 Generated with Claude Code

- 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()
Copilot AI review requested due to automatic review settings January 18, 2026 15:40
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_tagbuf_add_tag and follow_linkbuf_follow_link to 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

Comment thread README.md Outdated
| Event | Trigger |
|-------|---------|
| `BufNewFile` | New memo created via `create()` |
| `BufRead` | Existing memo opened via `open()`, `open_last()` |
Copy link

Copilot AI Jan 18, 2026

Choose a reason for hiding this comment

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

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 via api.open_memo(), open_last() |
Suggested change
| `BufRead` | Existing memo opened via `open()`, `open_last()` |
| `BufRead` | Existing memo opened via `api.open_memo()`, `open_last()` |

Copilot uses AI. Check for mistakes.
Comment thread fnl/sm/init.fnl

(fn M.add_tag [?tag]
"Add tag to current memo"
(fn M.buf_add_tag [?tag]
Copy link

Copilot AI Jan 18, 2026

Choose a reason for hiding this comment

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

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:

  1. Keeping the old function names as deprecated aliases that call the new functions with a deprecation warning
  2. 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.

Copilot uses AI. Check for mistakes.
Comment thread fnl/sm/init.fnl

(fn M.follow_link []
"Follow wiki link under cursor"
(fn M.buf_follow_link []
Copy link

Copilot AI Jan 18, 2026

Choose a reason for hiding this comment

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

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:

  1. Keeping the old function names as deprecated aliases that call the new functions with a deprecation warning
  2. 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.

Copilot uses AI. Check for mistakes.
- Change `open()` to `api.open_memo()` in Events table (open() doesn't exist)
Copilot AI review requested due to automatic review settings January 18, 2026 16:11
@Cassin01 Cassin01 merged commit a91b681 into main Jan 18, 2026
5 checks passed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants