Skip to content

Add code folding event. #547

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: default
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions core/events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ local M = {}
-- This event is never emitted when Textadept is running in the terminal.
-- @field FOCUS

--- Emitted after code folding is done by the lexer.
-- This is useful for performing manual folding and manipulation of the folding table
-- `buffer.fold_level` after lexer is done folding the code, where the built-in facilities for
-- code folding doesn't suffice.
-- @field FOLDED

--- Emitted when clicking the mouse on text that has an indicator present.
-- Arguments:
--
Expand Down
1 change: 1 addition & 0 deletions core/lexer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ local function highlight(buffer, start_pos, end_pos)
local level = buffer.fold_level[line] & buffer.FOLDLEVELNUMBERMASK
local folds = buffer.lexer:fold(buffer:text_range(start_pos, end_pos), line, level)
for line, level in pairs(folds) do buffer.fold_level[line] = level end
events.emit(events.FOLDED)
end

local mutex
Expand Down
10 changes: 9 additions & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4871,7 +4871,7 @@ shortly after this event.
The buffer **must not** be modified during this event.

<a id="events.BUFFER_BEFORE_SWITCH"></a>
#### `events.BUFFER_BEFORE_SWITCH`
#### `events.BUFFER_BEFORE_SWITCH`

Emitted right before switching to another buffer.
The buffer being switched from is [`buffer`](#buffer).
Expand Down Expand Up @@ -5119,6 +5119,14 @@ Arguments:

- *name*: The language lexer's name.

<a id="events.FOLDED"></a>
#### `events.FOLDED`

Emitted after code folding is done by the lexer.
This is useful for performing manual folding and manipulation of the folding table
`buffer.fold_level` after lexer is done folding the code, where the built-in facilities for
[code folding](#code-folding) doesn't suffice.

<a id="events.MARGIN_CLICK"></a>
#### `events.MARGIN_CLICK`

Expand Down