Skip to content
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
5 changes: 5 additions & 0 deletions doc/pages/expansions.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,11 @@ The following expansions are supported (with required context _in italics_):
_in window scope_ +
line of the main cursor, the third component of `%val{selection_desc}`

*%val{cursor_line_percent}*::
_in window scope_ +
line of the main cursor expressed as percentage of the number of lines
in the current buffer

*%val{error}*::
_in `try` command's <on_error_commands> parameter_ +
the text of the error that cancelled execution of the <commands> parameter
Expand Down
5 changes: 5 additions & 0 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ static const EnvVarDesc builtin_env_vars[] = { {
"cursor_line", false,
[](StringView name, const Context& context) -> Vector<String>
{ return {to_string(context.selections().main().cursor().line + 1)}; }
}, {
"cursor_line_percent", false,
[](StringView name, const Context& context) -> Vector<String>
{ auto cursor_line = context.selections().main().cursor().line + 1;
return {to_string(100 * cursor_line / context.buffer().line_count())}; }
}, {
"cursor_column", false,
[](StringView name, const Context& context) -> Vector<String>
Expand Down
2 changes: 2 additions & 0 deletions test/display/cursor-line-percent/cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:set-option global modelinefmt '%val{cursor_line_percent}'
6g
10 changes: 10 additions & 0 deletions test/display/cursor-line-percent/in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
1
2
3
4
5
6
7
8
9
10
1 change: 1 addition & 0 deletions test/display/cursor-line-percent/script
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ui_out -until '{ "jsonrpc": "2.0", "method": "draw_status", "params": [[], [{ "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "60" }], { "fg": "cyan", "bg": "default", "underline": "default", "attributes": [] }] }'