Skip to content

Add clickable regions to statusline with %[FuncName] item#19841

Open
mattn wants to merge 6 commits intovim:masterfrom
mattn:statusline-click
Open

Add clickable regions to statusline with %[FuncName] item#19841
mattn wants to merge 6 commits intovim:masterfrom
mattn:statusline-click

Conversation

@mattn
Copy link
Copy Markdown
Member

@mattn mattn commented Mar 27, 2026

Add support for clickable regions in the statusline using %[FuncName] syntax. When a user clicks on a region, the specified Vim function is called with a dictionary argument. The function can return non-zero to trigger a statusline redraw.

%[FuncName] starts a clickable region, %[] ends it. If %[] is omitted, the region extends to the end of the statusline. %N[FuncName] passes an identifier N to the callback as minwid.

The callback receives a Dictionary with:

  • minwid: identifier from %N[Func] (0 if not specified)
  • nclicks: number of clicks (1, 2, or 3)
  • button: "l" (left), "m" (middle), "r" (right)
  • mods: modifier keys, combination of "s" (shift), "c" (ctrl), "a" (alt)
  • winid: window-ID of the clicked statusline

Use has('statusline_click') to check availability.

func! ClickFile(info)
    if a:info.button ==# 'l' && a:info.nclicks == 2
        browse edit
    endif
    return 0
endfunc
set statusline=%[ClickFile]%f%[]\ %l:%c
2026-03-26.231437.mp4

mattn added 2 commits March 25, 2026 23:48
Add support for clickable regions in the statusline using the %@funcName@
syntax. When a user clicks on a region, the specified Vim function is called
with a dictionary containing click details (button, nclicks, modifiers, minwid,
winid). The function can return non-zero to trigger a statusline redraw.

- Add %@funcName@ and %@@ (end region) parsing in build_stl_str_hl()
- Add stl_click_handler() in mouse.c to dispatch clicks to callbacks
- Store resolved click regions per window (w_stl_click)
- Add 'statusline_click' feature flag for has() detection
- Add 'statuslineclick' option to statuslineopt for enable/disable
- Add documentation and tests
Use %[FuncName] to start a clickable region and %[] to end it,
instead of %@funcName@ and %@@. This avoids conflict with the
existing %@ line break notation and works with :set without
needing to escape special characters.
@mattn mattn force-pushed the statusline-click branch from 233a453 to ee84edf Compare March 27, 2026 03:30
mattn added 2 commits March 27, 2026 12:31
Rename parameters mouse_col and mod_mask to mcol and mods to avoid
shadowing the global variables with the same names.
@mattn mattn force-pushed the statusline-click branch from ee84edf to 27370a6 Compare March 27, 2026 03:32
@mattn
Copy link
Copy Markdown
Member Author

mattn commented Mar 27, 2026

I plan to add clickable region support for tabpanel as well in a follow-up.

- Fix -Wshadow in win_free(): remove inner 'int i' that shadows outer
- Fix -Wunused-parameter in stl_click_handler(): cast params to void
  when FEAT_EVAL is not defined (tiny build)
@chrisbra
Copy link
Copy Markdown
Member

Thanks, unfortunately ASAN detected a memory leak.

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