diff --git a/4coder_API.html b/4coder_API.html index 779ede5d..ac3d40e1 100644 --- a/4coder_API.html +++ b/4coder_API.html @@ -2,7 +2,7 @@

4cpp Lexing Library

Table of Contents

§1 Introduction

This is the documentation for alpha 4.0.11 The documentation is still under construction so some of the links are linking to sections that have not been written yet. What is here should be correct and I suspect useful even without some of the other sections.

If you have questions or discover errors please contact editor@4coder.net or to get help from community members you can post on the 4coder forums hosted on handmade.network at 4coder.handmade.network

§2 4coder Systems

Coming Soon
-

§3 Types and Functions

§3.1 Function List

§3.2 Type List

§3.3 Function Descriptions

§3.3.1: exec_command

bool32 app->exec_command(
Application_Links *app,
Command_ID command_id
)
Parameters
command_id
The command_id parameter specifies which internal command to execute.
Return
This call returns non-zero if command_id named a valid internal command.
Description
A call to exec_command executes an internal command. +

§3 Types and Functions

§3.1 Function List

§3.2 Type List

§3.3 Function Descriptions

§3.3.1: exec_command

bool32 app->exec_command(
Application_Links *app,
Command_ID command_id
)
Parameters
command_id
The command_id parameter specifies which internal command to execute.
Return
This call returns non-zero if command_id named a valid internal command.
Description
A call to exec_command executes an internal command. If command_id is invalid a warning is posted to *messages*.

See Also

§3.3.2: exec_system_command

bool32 app->exec_system_command(
Application_Links *app,
View_Summary *view,
Buffer_Identifier buffer,
char *path,
int32_t path_len,
char *command,
int32_t command_len,
Command_Line_Input_Flag flags
)
Parameters
view
If the view parameter is non-null it specifies a view to display the command's output buffer.
buffer
The buffer the command will output to is specified by the buffer parameter. See Buffer_Identifier for information on how this type specifies a buffer.
path
The path parameter specifies the path in which the command shall be executed. The string need not be null terminated.
path_len
The parameter path_len specifies the length of the path string.
command
The command parameter specifies the command that shall be executed. The string need not be null terminated.
command_len
The parameter command_len specifies the length of the command string.
flags
Flags for the behavior of the call are specified in the flags parameter.
Return
This call returns non-zero on success.
Description
A call to exec_system_command executes a command as if called from the command line, and sends the output to a buffer. The buffer identifier can either name a new buffer that does not exist, name a buffer that does @@ -29,72 +29,72 @@ this call is equivalent to inserting the string at start. If len == 0 this call is equivalent to deleteing the range from start to end.

This call fails if the buffer does not exist, or if the replace -range is not within the bounds of the buffer.

See Also

§3.3.14: buffer_compute_cursor

bool32 app->buffer_compute_cursor(
Application_Links *app,
Buffer_Summary *buffer,
Buffer_Seek seek,
Partial_Cursor *cursor_out
)
Parameters
buffer
The buffer parameter specifies the buffer on which to run the cursor computation.
seek
The seek parameter specifies the target position for the seek.
cursor_out
On success this struct is filled with the result of the seek.
Return
This call returns non-zero on success.
Description
Computes a Partial_Cursor for the given seek position with no side effects. +range is not within the bounds of the buffer.

See Also

§3.3.14: buffer_compute_cursor

bool32 app->buffer_compute_cursor(
Application_Links *app,
Buffer_Summary *buffer,
Buffer_Seek seek,
Partial_Cursor *cursor_out
)
Parameters
buffer
The buffer parameter specifies the buffer on which to run the cursor computation.
seek
The seek parameter specifies the target position for the seek.
cursor_out
On success this struct is filled with the result of the seek.
Return
This call returns non-zero on success. This call can fail if the buffer summary provided +does not summarize an actual buffer in 4coder, or if the provided seek format is invalid. The valid +seek types are seek_pos and seek_line_char.
Description
Computes a Partial_Cursor for the given seek position with no side effects. The seek position must be one of the types supported by Partial_Cursor. Those -types are absolute position and line,column position.

See Also

§3.3.15: buffer_batch_edit

bool32 app->buffer_batch_edit(
Application_Links *app,
Buffer_Summary *buffer,
char *str,
int32_t str_len,
Buffer_Edit *edits,
int32_t edit_count,
Buffer_Batch_Edit_Type type
)
Parameters
str
This parameter provides all of the source string for the edits in the batch.
str_len
This parameter specifies the length of the str string.
edits
This parameter provides about the source string and destination range of each edit as an array.
edit_count
This parameter specifies the number of Buffer_Edit structs in edits.
type
This prameter specifies what type of batch edit to execute.
Return
This call returns non-zero if the batch edit succeeds.
Description
TODO

See Also

§3.3.16: buffer_set_setting

bool32 app->buffer_set_setting(
Application_Links *app,
Buffer_Summary *buffer,
Buffer_Setting_ID setting,
int32_t value
)
Parameters
buffer
The buffer parameter specifies the buffer on which to set a setting.
setting
The setting parameter identifies the setting that shall be changed.
value
The value parameter specifies the value to which the setting shall be changed.
See Also

§3.3.17: buffer_auto_indent

bool32 app->buffer_auto_indent(
Application_Links *app,
Buffer_Summary *buffer,
int32_t start,
int32_t end,
int32_t tab_width,
Auto_Indent_Flag flags
)
Parameters
buffer
The buffer specifies the buffer in which to apply auto indentation.
start
This parameter specifies the absolute position of the start of the indentation range.
end
This parameter specifies the absolute position of the end of the indentation range.
tab_width
The tab_width parameter specifies how many spaces should be used for one indentation in space mode.
flags
This parameter specifies behaviors for the indentation.
Return
This call returns non-zero when the call succeeds.
Description
Applies the built in auto-indentation rule to the code in the range from -start to end by inserting spaces or tabs at the beginning of the lines. -If the buffer does not have lexing enabled or the lexing job has not -completed this function will fail.

See Also

§3.3.18: create_buffer

Buffer_Summary app->create_buffer(
Application_Links *app,
char *filename,
int32_t filename_len,
Buffer_Create_Flag flags
)
Parameters
filename
The filename parameter specifies the name of the file to be opened or created; it need not be null terminated.
filename_len
The filename_len parameter spcifies the length of the filename string.
flags
The flags parameter specifies behaviors for buffer creation.
Return
This call returns the summary of the created buffer.
Description
Tries to create a new buffer and associate it to the given filename. If such a buffer already +types are absolute position and line,column position.

See Also

§3.3.15: buffer_batch_edit

bool32 app->buffer_batch_edit(
Application_Links *app,
Buffer_Summary *buffer,
char *str,
int32_t str_len,
Buffer_Edit *edits,
int32_t edit_count,
Buffer_Batch_Edit_Type type
)
Parameters
str
This parameter provides all of the source string for the edits in the batch.
str_len
This parameter specifies the length of the str string.
edits
This parameter provides about the source string and destination range of each edit as an array.
edit_count
This parameter specifies the number of Buffer_Edit structs in edits.
type
This prameter specifies what type of batch edit to execute.
Return
This call returns non-zero if the batch edit succeeds. This call can fail if the provided +buffer summary does not refer to an actual buffer in 4coder.
Description
TODO

See Also

§3.3.16: buffer_set_setting

bool32 app->buffer_set_setting(
Application_Links *app,
Buffer_Summary *buffer,
Buffer_Setting_ID setting,
int32_t value
)
Parameters
buffer
The buffer parameter specifies the buffer on which to set a setting.
setting
The setting parameter identifies the setting that shall be changed.
value
The value parameter specifies the value to which the setting shall be changed.
See Also

§3.3.17: buffer_token_count

int32_t app->buffer_token_count(
Application_Links *app,
Buffer_Summary *buffer
)
No documentation generated for this function.

§3.3.18: buffer_read_tokens

bool32 app->buffer_read_tokens(
Application_Links *app,
Buffer_Summary *buffer,
int32_t first_token,
int32_t last_token,
Cpp_Token *tokens_out
)
No documentation generated for this function.

§3.3.19: create_buffer

Buffer_Summary app->create_buffer(
Application_Links *app,
char *filename,
int32_t filename_len,
Buffer_Create_Flag flags
)
Parameters
filename
The filename parameter specifies the name of the file to be opened or created; it need not be null terminated.
filename_len
The filename_len parameter spcifies the length of the filename string.
flags
The flags parameter specifies behaviors for buffer creation.
Return
This call returns the summary of the created buffer.
Description
Tries to create a new buffer and associate it to the given filename. If such a buffer already exists the existing buffer is returned in the Buffer_Summary and no new buffer is created. If the buffer does not exist a new buffer is created and named after the given filename. If the filename corresponds to a file on the disk that file is loaded and put into buffer, if -the filename does not correspond to a file on disk the buffer is created empty.

See Also

§3.3.19: save_buffer

bool32 app->save_buffer(
Application_Links *app,
Buffer_Summary *buffer,
char *filename,
int32_t filename_len,
uint32_t flags
)
Parameters
buffer
The buffer parameter specifies the buffer to save to a file.
filename
The filename parameter specifies the name of the file to associated to the buffer; it need not be null terminated.
filename_len
The filename_len parameter specifies the length of the filename string.
flags
This parameter is not currently used and should be set to 0 for now.
Return
This call returns non-zero on success.

§3.3.20: kill_buffer

bool32 app->kill_buffer(
Application_Links *app,
Buffer_Identifier buffer,
View_ID view_id,
Buffer_Kill_Flag flags
)
Parameters
buffer
The buffer parameter specifies the buffer to try to kill.
view_id
The view_id parameter specifies the view that will contain the "are you sure" dialogue if the buffer is dirty.
flags
The flags parameter specifies behaviors for the buffer kill.
Return
This call returns non-zero if the buffer is killed.
Description
Tries to kill the idenfied buffer. If the buffer is dirty and the "are you sure" +the filename does not correspond to a file on disk the buffer is created empty.

See Also

§3.3.20: save_buffer

bool32 app->save_buffer(
Application_Links *app,
Buffer_Summary *buffer,
char *filename,
int32_t filename_len,
uint32_t flags
)
Parameters
buffer
The buffer parameter specifies the buffer to save to a file.
filename
The filename parameter specifies the name of the file to associated to the buffer; it need not be null terminated.
filename_len
The filename_len parameter specifies the length of the filename string.
flags
This parameter is not currently used and should be set to 0 for now.
Return
This call returns non-zero on success.

§3.3.21: kill_buffer

bool32 app->kill_buffer(
Application_Links *app,
Buffer_Identifier buffer,
View_ID view_id,
Buffer_Kill_Flag flags
)
Parameters
buffer
The buffer parameter specifies the buffer to try to kill.
view_id
The view_id parameter specifies the view that will contain the "are you sure" dialogue if the buffer is dirty.
flags
The flags parameter specifies behaviors for the buffer kill.
Return
This call returns non-zero if the buffer is killed.
Description
Tries to kill the idenfied buffer. If the buffer is dirty and the "are you sure" dialogue needs to be displayed the provided view is used to show the dialogue. -If the view is not open the kill fails.

See Also

§3.3.21: get_view_first

View_Summary app->get_view_first(
Application_Links *app,
Access_Flag access
)
Parameters
access
The access parameter determines what levels of protection this call can access.
Return
This call returns the summary of the first view in a view loop.
Description
This call begins a loop across all the open views.

+If the view is not open the kill fails.

See Also

§3.3.22: get_view_first

View_Summary app->get_view_first(
Application_Links *app,
Access_Flag access
)
Parameters
access
The access parameter determines what levels of protection this call can access.
Return
This call returns the summary of the first view in a view loop.
Description
This call begins a loop across all the open views.

If the View_Summary returned is a null summary, the loop is finished. -Views should not be closed or opened durring a view loop.

See Also

§3.3.22: get_view_next

void app->get_view_next(
Application_Links *app,
View_Summary *view,
Access_Flag access
)
Parameters
view
The View_Summary pointed to by view is iterated to the next view or to a null summary if this is the last view.
access
The access parameter determines what levels of protection this call can access. The view outputted will be the next view that is accessible.
Description
This call steps a View_Summary to the next view in the global view order.

+Views should not be closed or opened durring a view loop.

See Also

§3.3.23: get_view_next

void app->get_view_next(
Application_Links *app,
View_Summary *view,
Access_Flag access
)
Parameters
view
The View_Summary pointed to by view is iterated to the next view or to a null summary if this is the last view.
access
The access parameter determines what levels of protection this call can access. The view outputted will be the next view that is accessible.
Description
This call steps a View_Summary to the next view in the global view order.

If the view outputted does not exist, the loop is finished. -Views should not be closed or opened durring a view loop.

See Also

§3.3.23: get_view

View_Summary app->get_view(
Application_Links *app,
View_ID view_id,
Access_Flag access
)
Parameters
view_id
The view_id specifies the view to try to get.
access
The access parameter determines what levels of protection this call can access.
Return
This call returns a summary that describes the indicated view if it is open and accessible.
See Also

§3.3.24: get_active_view

View_Summary app->get_active_view(
Application_Links *app,
Access_Flag access
)
Parameters
access
The access parameter determines what levels of protection this call can access.
Return
This call returns a summary that describes the active view.
See Also

§3.3.25: open_view

View_Summary app->open_view(
Application_Links *app,
View_Summary *view_location,
View_Split_Position position
)
Parameters
view_location
The view_location parameter specifies the view to split to open the new view.
position
The position parameter specifies how to split the view and where to place the new view.
Return
If this call succeeds it returns a View_Summary describing the newly created view, if it fails it +Views should not be closed or opened durring a view loop.

See Also

§3.3.24: get_view

View_Summary app->get_view(
Application_Links *app,
View_ID view_id,
Access_Flag access
)
Parameters
view_id
The view_id specifies the view to try to get.
access
The access parameter determines what levels of protection this call can access.
Return
This call returns a summary that describes the indicated view if it is open and accessible.
See Also

§3.3.25: get_active_view

View_Summary app->get_active_view(
Application_Links *app,
Access_Flag access
)
Parameters
access
The access parameter determines what levels of protection this call can access.
Return
This call returns a summary that describes the active view.
See Also

§3.3.26: open_view

View_Summary app->open_view(
Application_Links *app,
View_Summary *view_location,
View_Split_Position position
)
Parameters
view_location
The view_location parameter specifies the view to split to open the new view.
position
The position parameter specifies how to split the view and where to place the new view.
Return
If this call succeeds it returns a View_Summary describing the newly created view, if it fails it returns a null summary.
Description
4coder is built with a limit of 16 views. If 16 views are already open when this is called the -call will fail.

See Also

§3.3.26: close_view

bool32 app->close_view(
Application_Links *app,
View_Summary *view
)
Parameters
view
The view parameter specifies which view to close.
Return
This call returns non-zero on success.
Description
If the given view is open and is not the last view, it will be closed. +call will fail.

See Also

§3.3.27: close_view

bool32 app->close_view(
Application_Links *app,
View_Summary *view
)
Parameters
view
The view parameter specifies which view to close.
Return
This call returns non-zero on success.
Description
If the given view is open and is not the last view, it will be closed. If the given view is the active view, the next active view in the global order of view will be made active. -If the given view is the last open view in the system, the call will fail.


§3.3.27: set_active_view

bool32 app->set_active_view(
Application_Links *app,
View_Summary *view
)
Parameters
view
The view parameter specifies which view to make active.
Return
This call returns non-zero on success.
Description
If the given view is open, it is set as the +If the given view is the last open view in the system, the call will fail.


§3.3.28: set_active_view

bool32 app->set_active_view(
Application_Links *app,
View_Summary *view
)
Parameters
view
The view parameter specifies which view to make active.
Return
This call returns non-zero on success.
Description
If the given view is open, it is set as the active view, and takes subsequent commands and is returned -from get_active_view.

See Also

§3.3.28: view_set_setting

bool32 app->view_set_setting(
Application_Links *app,
View_Summary *view,
View_Setting_ID setting,
int32_t value
)
Parameters
view
The view parameter specifies the view on which to set a setting.
setting
The setting parameter identifies the setting that shall be changed.
value
The value parameter specifies the value to which the setting shall be changed.
Return
This call returns non-zero on success.
See Also

§3.3.29: view_set_split_proportion

bool32 app->view_set_split_proportion(
Application_Links *app,
View_Summary *view,
float t
)
Parameters
view
The view parameter specifies which view shall have it's size adjusted.
t
The t parameter specifies the proportion of the containing box that the view should occupy. t should be in [0,1].
Return
This call returns non-zero on success.

§3.3.30: view_compute_cursor

bool32 app->view_compute_cursor(
Application_Links *app,
View_Summary *view,
Buffer_Seek seek,
Full_Cursor *cursor_out
)
Parameters
view
The view parameter specifies the view on which to run the cursor computation.
seek
The seek parameter specifies the target position for the seek.
cursor_out
On success this struct is filled with the result of the seek.
Return
This call returns non-zero on success.
Description
Computes a Full_Cursor for the given seek position with no side effects.

See Also

§3.3.31: view_set_cursor

bool32 app->view_set_cursor(
Application_Links *app,
View_Summary *view,
Buffer_Seek seek,
bool32 set_preferred_x
)
Parameters
view
The view parameter specifies the view in which to set the cursor.
seek
The seek parameter specifies the target position for the seek.
set_preferred_x
If this parameter is true the preferred x is updated to match the new cursor x.
Return
This call returns non-zero on success.
Description
This call sets the the view's cursor position. set_preferred_x should usually be true +from get_active_view.

See Also

§3.3.29: view_set_setting

bool32 app->view_set_setting(
Application_Links *app,
View_Summary *view,
View_Setting_ID setting,
int32_t value
)
Parameters
view
The view parameter specifies the view on which to set a setting.
setting
The setting parameter identifies the setting that shall be changed.
value
The value parameter specifies the value to which the setting shall be changed.
Return
This call returns non-zero on success.
See Also

§3.3.30: view_set_split_proportion

bool32 app->view_set_split_proportion(
Application_Links *app,
View_Summary *view,
float t
)
Parameters
view
The view parameter specifies which view shall have it's size adjusted.
t
The t parameter specifies the proportion of the containing box that the view should occupy. t should be in [0,1].
Return
This call returns non-zero on success.

§3.3.31: view_compute_cursor

bool32 app->view_compute_cursor(
Application_Links *app,
View_Summary *view,
Buffer_Seek seek,
Full_Cursor *cursor_out
)
Parameters
view
The view parameter specifies the view on which to run the cursor computation.
seek
The seek parameter specifies the target position for the seek.
cursor_out
On success this struct is filled with the result of the seek.
Return
This call returns non-zero on success.
Description
Computes a Full_Cursor for the given seek position with no side effects.

See Also

§3.3.32: view_set_cursor

bool32 app->view_set_cursor(
Application_Links *app,
View_Summary *view,
Buffer_Seek seek,
bool32 set_preferred_x
)
Parameters
view
The view parameter specifies the view in which to set the cursor.
seek
The seek parameter specifies the target position for the seek.
set_preferred_x
If this parameter is true the preferred x is updated to match the new cursor x.
Return
This call returns non-zero on success.
Description
This call sets the the view's cursor position. set_preferred_x should usually be true unless the change in cursor position is is a vertical motion that tries to keep the -cursor in the same column or x position.

See Also

§3.3.32: view_set_scroll

bool32 app->view_set_scroll(
Application_Links *app,
View_Summary *view,
GUI_Scroll_Vars scroll
)
Description
TODO

See Also

§3.3.33: view_set_mark

bool32 app->view_set_mark(
Application_Links *app,
View_Summary *view,
Buffer_Seek seek
)
Parameters
view
The view parameter specifies the view in which to set the mark.
seek
The seek parameter specifies the target position for the seek.
Return
This call returns non-zero on success.
Description
This call sets the the view's mark position.

See Also

§3.3.34: view_set_highlight

bool32 app->view_set_highlight(
Application_Links *app,
View_Summary *view,
int32_t start,
int32_t end,
bool32 turn_on
)
Parameters
view
The view parameter specifies the view in which to set the highlight.
start
This parameter specifies the absolute position of the first character of the highlight range.
end
This parameter specifies the absolute position of the character one past the end of the highlight range.
turn_on
This parameter indicates whether the highlight is being turned on or off.
Return
This call returns non-zero on success.
Description
The highlight is mutually exclusive to the cursor. When the turn_on parameter +cursor in the same column or x position.

See Also

§3.3.33: view_set_scroll

bool32 app->view_set_scroll(
Application_Links *app,
View_Summary *view,
GUI_Scroll_Vars scroll
)
Description
TODO

See Also

§3.3.34: view_set_mark

bool32 app->view_set_mark(
Application_Links *app,
View_Summary *view,
Buffer_Seek seek
)
Parameters
view
The view parameter specifies the view in which to set the mark.
seek
The seek parameter specifies the target position for the seek.
Return
This call returns non-zero on success.
Description
This call sets the the view's mark position.

See Also

§3.3.35: view_set_highlight

bool32 app->view_set_highlight(
Application_Links *app,
View_Summary *view,
int32_t start,
int32_t end,
bool32 turn_on
)
Parameters
view
The view parameter specifies the view in which to set the highlight.
start
This parameter specifies the absolute position of the first character of the highlight range.
end
This parameter specifies the absolute position of the character one past the end of the highlight range.
turn_on
This parameter indicates whether the highlight is being turned on or off.
Return
This call returns non-zero on success.
Description
The highlight is mutually exclusive to the cursor. When the turn_on parameter is set to true the highlight will be shown and the cursor will be hidden. After that either setting the cursor with view_set_cursor or calling view_set_highlight -and the turn_on set to false, will switch back to showing the cursor.


§3.3.35: view_set_buffer

bool32 app->view_set_buffer(
Application_Links *app,
View_Summary *view,
Buffer_ID buffer_id,
Set_Buffer_Flag flags
)
Parameters
view
The view parameter specifies the view in which to display the buffer.
buffer_id
The buffer_id parameter specifies which buffer to show in the view.
flags
The flags parameter specifies behaviors for setting the buffer.
Return
This call returns non-zero on success.
Description
On success view_set_buffer sets the specified view's current buffer and -cancels and dialogue shown in the view and displays the file.

See Also

§3.3.36: view_post_fade

bool32 app->view_post_fade(
Application_Links *app,
View_Summary *view,
float seconds,
int32_t start,
int32_t end,
int_color color
)
Parameters
view
The view parameter specifies the view onto which the fade effect shall be posted.
seconds
This parameter specifies the number of seconds the fade effect should last.
start
This parameter specifies the absolute position of the first character of the fade range.
end
This parameter specifies the absolute position of the character one past the end of the fdae range.
color
The color parameter specifies the initial color of the text before it fades to it's natural color.
Return
This call returns non-zero on success.
See Also

§3.3.37: get_user_input

User_Input app->get_user_input(
Application_Links *app,
Input_Type_Flag get_type,
Input_Type_Flag abort_type
)
Parameters
get_type
The get_type parameter specifies the set of input types that should be returned.
abort_type
The get_type parameter specifies the set of input types that should trigger an abort signal.
Return
This call returns a User_Input that describes a user input event.
Description
This call preempts the command. The command is resumed if either a get or abort condition +and the turn_on set to false, will switch back to showing the cursor.


§3.3.36: view_set_buffer

bool32 app->view_set_buffer(
Application_Links *app,
View_Summary *view,
Buffer_ID buffer_id,
Set_Buffer_Flag flags
)
Parameters
view
The view parameter specifies the view in which to display the buffer.
buffer_id
The buffer_id parameter specifies which buffer to show in the view.
flags
The flags parameter specifies behaviors for setting the buffer.
Return
This call returns non-zero on success.
Description
On success view_set_buffer sets the specified view's current buffer and +cancels and dialogue shown in the view and displays the file.

See Also

§3.3.37: view_post_fade

bool32 app->view_post_fade(
Application_Links *app,
View_Summary *view,
float seconds,
int32_t start,
int32_t end,
int_color color
)
Parameters
view
The view parameter specifies the view onto which the fade effect shall be posted.
seconds
This parameter specifies the number of seconds the fade effect should last.
start
This parameter specifies the absolute position of the first character of the fade range.
end
This parameter specifies the absolute position of the character one past the end of the fdae range.
color
The color parameter specifies the initial color of the text before it fades to it's natural color.
Return
This call returns non-zero on success.
See Also

§3.3.38: get_user_input

User_Input app->get_user_input(
Application_Links *app,
Input_Type_Flag get_type,
Input_Type_Flag abort_type
)
Parameters
get_type
The get_type parameter specifies the set of input types that should be returned.
abort_type
The get_type parameter specifies the set of input types that should trigger an abort signal.
Return
This call returns a User_Input that describes a user input event.
Description
This call preempts the command. The command is resumed if either a get or abort condition is met, or if another command is executed. If either the abort condition is met or another command is executed an abort signal is returned. If an abort signal is ever returned the command should finish execution without any more calls that preempt the command. -If a get condition is met the user input is returned.

See Also

§3.3.38: get_command_input

User_Input app->get_command_input(
Application_Links *app
)
Return
This call returns the input that triggered the currently executing command.
See Also

§3.3.39: get_mouse_state

Mouse_State app->get_mouse_state(
Application_Links *app
)
Return
This call returns the current mouse state as of the beginning of the frame.
See Also

§3.3.40: start_query_bar

bool32 app->start_query_bar(
Application_Links *app,
Query_Bar *bar,
uint32_t flags
)
Parameters
bar
This parameter provides a Query_Bar that should remain in valid memory +If a get condition is met the user input is returned.

See Also

§3.3.39: get_command_input

User_Input app->get_command_input(
Application_Links *app
)
Return
This call returns the input that triggered the currently executing command.
See Also

§3.3.40: get_mouse_state

Mouse_State app->get_mouse_state(
Application_Links *app
)
Return
This call returns the current mouse state as of the beginning of the frame.
See Also

§3.3.41: start_query_bar

bool32 app->start_query_bar(
Application_Links *app,
Query_Bar *bar,
uint32_t flags
)
Parameters
bar
This parameter provides a Query_Bar that should remain in valid memory until end_query_bar or the end of the command. It is commonly a good idea to make this a pointer to a Query_Bar stored on the stack.
flags
This parameter is not currently used and should be 0 for now.
Return
This call returns non-zero on success.
Description
This call tells the active view to begin displaying a "Query_Bar" which is a small GUI element that can overlap a buffer or other 4coder GUI. The contents of the bar can be changed after the call to start_query_bar and the query bar shown by 4coder will reflect the change. Since the bar stops showing when the command exits the -only use for this call is in an interactive command that makes calls to get_user_input.


§3.3.41: end_query_bar

void app->end_query_bar(
Application_Links *app,
Query_Bar *bar,
uint32_t flags
)
Parameters
bar
This parameter should be a bar pointer of a currently active query bar.
flags
This parameter is not currently used and should be 0 for now.
Description
Stops showing the particular query bar specified by the bar parameter.



§3.3.43: change_theme

void app->change_theme(
Application_Links *app,
char *name,
int32_t len
)
Parameters
name
The name parameter specifies the name of the theme to begin using; it need not be null terminated.
len
The len parameter specifies the length of the name string.
Description
This call changes 4coder's color pallet to one of the built in themes.


§3.3.44: change_font

void app->change_font(
Application_Links *app,
char *name,
int32_t len,
bool32 apply_to_all_files
)
Parameters
name
The name parameter specifies the name of the font to begin using; it need not be null terminated.
len
The len parameter specifies the length of the name string.
apply_to_all_files
If this is set all open files change to this font. Usually this should be true -durring the start hook because several files already exist at that time.
Description
This call changes 4coder's default font to one of the built in fonts.


§3.3.45: buffer_set_font

void app->buffer_set_font(
Application_Links *app,
Buffer_Summary *buffer,
char *name,
int32_t len
)
Parameters
buffer
This parameter the buffer that shall have it's font changed
name
The name parameter specifies the name of the font to begin using; it need not be null terminated.
len
The len parameter specifies the length of the name string.
Description
This call sets the display font of a particular buffer.


§3.3.46: set_theme_colors

void app->set_theme_colors(
Application_Links *app,
Theme_Color *colors,
int32_t count
)
Parameters
colors
The colors pointer provides an array of color structs pairing differet style tags to color codes.
count
The count parameter specifies the number of Theme_Color structs in the colors array.
Description
For each struct in the array, the slot in the main color pallet specified by the +only use for this call is in an interactive command that makes calls to get_user_input.


§3.3.42: end_query_bar

void app->end_query_bar(
Application_Links *app,
Query_Bar *bar,
uint32_t flags
)
Parameters
bar
This parameter should be a bar pointer of a currently active query bar.
flags
This parameter is not currently used and should be 0 for now.
Description
Stops showing the particular query bar specified by the bar parameter.



§3.3.44: change_theme

void app->change_theme(
Application_Links *app,
char *name,
int32_t len
)
Parameters
name
The name parameter specifies the name of the theme to begin using; it need not be null terminated.
len
The len parameter specifies the length of the name string.
Description
This call changes 4coder's color pallet to one of the built in themes.


§3.3.45: change_font

void app->change_font(
Application_Links *app,
char *name,
int32_t len,
bool32 apply_to_all_files
)
Parameters
name
The name parameter specifies the name of the font to begin using; it need not be null terminated.
len
The len parameter specifies the length of the name string.
apply_to_all_files
If this is set all open files change to this font. Usually this should be true +durring the start hook because several files already exist at that time.
Description
This call changes 4coder's default font to one of the built in fonts.


§3.3.46: buffer_set_font

void app->buffer_set_font(
Application_Links *app,
Buffer_Summary *buffer,
char *name,
int32_t len
)
Parameters
buffer
This parameter the buffer that shall have it's font changed
name
The name parameter specifies the name of the font to begin using; it need not be null terminated.
len
The len parameter specifies the length of the name string.
Description
This call sets the display font of a particular buffer.


§3.3.47: set_theme_colors

void app->set_theme_colors(
Application_Links *app,
Theme_Color *colors,
int32_t count
)
Parameters
colors
The colors pointer provides an array of color structs pairing differet style tags to color codes.
count
The count parameter specifies the number of Theme_Color structs in the colors array.
Description
For each struct in the array, the slot in the main color pallet specified by the struct's tag is set to the color code in the struct. If the tag value is invalid -no change is made to the color pallet.


§3.3.47: get_theme_colors

void app->get_theme_colors(
Application_Links *app,
Theme_Color *colors,
int32_t count
)
Parameters
colors
an array of color structs listing style tags to get color values for
count
the number of color structs in the colors array
Description
For each struct in the array, the color field of the struct is filled with the +no change is made to the color pallet.


§3.3.48: get_theme_colors

void app->get_theme_colors(
Application_Links *app,
Theme_Color *colors,
int32_t count
)
Parameters
colors
an array of color structs listing style tags to get color values for
count
the number of color structs in the colors array
Description
For each struct in the array, the color field of the struct is filled with the color from the slot in the main color pallet specified by the tag. If the tag -value is invalid the color is filled with black.


§3.3.48: directory_get_hot

int32_t app->directory_get_hot(
Application_Links *app,
char *out,
int32_t capacity
)
Parameters
out
This parameter provides a character buffer that receives the 4coder 'hot directory'.
capacity
This parameter specifies the maximum size to be output to the out buffer.
Return
This call returns the size of the string written into the buffer.
Description
4coder has a concept of a 'hot directory' which is the directory most recently +value is invalid the color is filled with black.


§3.3.49: directory_get_hot

int32_t app->directory_get_hot(
Application_Links *app,
char *out,
int32_t capacity
)
Parameters
out
This parameter provides a character buffer that receives the 4coder 'hot directory'.
capacity
This parameter specifies the maximum size to be output to the out buffer.
Return
This call returns the size of the string written into the buffer.
Description
4coder has a concept of a 'hot directory' which is the directory most recently accessed in the GUI. Whenever the GUI is opened it shows the hot directory.

In the future this will be deprecated and eliminated in favor of more flexible -directories controlled on the custom side.


§3.3.49: get_file_list

File_List app->get_file_list(
Application_Links *app,
char *dir,
int32_t len
)
Parameters
dir
This parameter specifies the directory whose files will be enumerated in the returned list; it need not be null terminated.
len
This parameter the length of the dir string.
Return
This call returns a File_List struct containing pointers to the names of the files in +directories controlled on the custom side.


§3.3.50: get_file_list

File_List app->get_file_list(
Application_Links *app,
char *dir,
int32_t len
)
Parameters
dir
This parameter specifies the directory whose files will be enumerated in the returned list; it need not be null terminated.
len
This parameter the length of the dir string.
Return
This call returns a File_List struct containing pointers to the names of the files in the specified directory. The File_List returned should be passed to free_file_list -when it is no longer in use.

§3.3.50: free_file_list

void app->free_file_list(
Application_Links *app,
File_List list
)
Parameters
list
This parameter provides the file list to be freed.
Description
After this call the file list passed in should not be read or written to.


§3.3.51: memory_allocate

void* app->memory_allocate(
Application_Links *app,
int32_t size
)
Parameters
size
The size in bytes of the block that should be returned.
Description
This calls to a low level OS allocator which means it is best used +when it is no longer in use.

§3.3.51: free_file_list

void app->free_file_list(
Application_Links *app,
File_List list
)
Parameters
list
This parameter provides the file list to be freed.
Description
After this call the file list passed in should not be read or written to.


§3.3.52: memory_allocate

void* app->memory_allocate(
Application_Links *app,
int32_t size
)
Parameters
size
The size in bytes of the block that should be returned.
Description
This calls to a low level OS allocator which means it is best used for infrequent, large allocations. The size of the block must be remembered -if it will be freed or if it's mem protection status will be changed.

See Also

§3.3.52: memory_set_protection

bool32 app->memory_set_protection(
Application_Links *app,
void *ptr,
int32_t size,
Memory_Protect_Flags flags
)
Parameters
ptr
The base of the block on which to set memory protection flags.
size
The size that was originally used to allocate this block.
flags
The new memory protection flags.
Description
This call sets the memory protection flags of a block of memory that was previously -allocate by memory_allocate.

See Also

§3.3.53: memory_free

void app->memory_free(
Application_Links *app,
void *ptr,
int32_t size
)
Parameters
mem
The base of a block to free.
size
The size that was originally used to allocate this block.
Description
This call frees a block of memory that was previously allocated by -memory_allocate.

See Also

§3.3.54: file_exists

bool32 app->file_exists(
Application_Links *app,
char *filename,
int32_t len
)
Parameters
filename
This parameter specifies the full path to a file; it need not be null terminated.
len
This parameter specifies the length of the filename string.
Return
This call returns non-zero if and only if the file exists.

§3.3.55: directory_cd

bool32 app->directory_cd(
Application_Links *app,
char *dir,
int32_t *len,
int32_t capacity,
char *rel_path,
int32_t rel_len
)
Parameters
dir
This parameter provides a character buffer that stores a directory; it need not be null terminated.
len
This parameter specifies the length of the dir string.
capacity
This parameter specifies the maximum size of the dir string.
rel_path
This parameter specifies the path to change to, may include '.' or '..'; it need not be null terminated.
rel_len
This parameter specifies the length of the rel_path string.
Return
This call returns non-zero if the call succeeds.
Description
This call succeeds if the new directory exists and the it fits inside the +if it will be freed or if it's mem protection status will be changed.

See Also

§3.3.53: memory_set_protection

bool32 app->memory_set_protection(
Application_Links *app,
void *ptr,
int32_t size,
Memory_Protect_Flags flags
)
Parameters
ptr
The base of the block on which to set memory protection flags.
size
The size that was originally used to allocate this block.
flags
The new memory protection flags.
Description
This call sets the memory protection flags of a block of memory that was previously +allocate by memory_allocate.

See Also

§3.3.54: memory_free

void app->memory_free(
Application_Links *app,
void *ptr,
int32_t size
)
Parameters
mem
The base of a block to free.
size
The size that was originally used to allocate this block.
Description
This call frees a block of memory that was previously allocated by +memory_allocate.

See Also

§3.3.55: file_exists

bool32 app->file_exists(
Application_Links *app,
char *filename,
int32_t len
)
Parameters
filename
This parameter specifies the full path to a file; it need not be null terminated.
len
This parameter specifies the length of the filename string.
Return
This call returns non-zero if and only if the file exists.

§3.3.56: directory_cd

bool32 app->directory_cd(
Application_Links *app,
char *dir,
int32_t *len,
int32_t capacity,
char *rel_path,
int32_t rel_len
)
Parameters
dir
This parameter provides a character buffer that stores a directory; it need not be null terminated.
len
This parameter specifies the length of the dir string.
capacity
This parameter specifies the maximum size of the dir string.
rel_path
This parameter specifies the path to change to, may include '.' or '..'; it need not be null terminated.
rel_len
This parameter specifies the length of the rel_path string.
Return
This call returns non-zero if the call succeeds.
Description
This call succeeds if the new directory exists and the it fits inside the dir buffer. If the call succeeds the dir buffer is filled with the new directory and len is overwritten with the length of the new string in the buffer.

For instance if dir contains "C:/Users/MySelf" and rel is "Documents" the buffer will contain "C:/Users/MySelf/Documents" and len will contain the length of that string. This call can also be used with rel set to ".." to traverse to parent -folders.


§3.3.56: get_4ed_path

bool32 app->get_4ed_path(
Application_Links *app,
char *out,
int32_t capacity
)
Parameters
out
This parameter provides a character buffer that receives the path to the 4ed executable file.
capacity
This parameter specifies the maximum capacity of the out buffer.
Return
This call returns non-zero on success.

§3.3.57: show_mouse_cursor

void app->show_mouse_cursor(
Application_Links *app,
Mouse_Cursor_Show_Type show
)
Parameters
show
This parameter specifies the new state of the mouse cursor.
See Also

§3.3.58: toggle_fullscreen

void app->toggle_fullscreen(
Application_Links *app
)
Description
This call tells 4coder to switch into or out of full screen mode. +folders.


§3.3.57: get_4ed_path

bool32 app->get_4ed_path(
Application_Links *app,
char *out,
int32_t capacity
)
Parameters
out
This parameter provides a character buffer that receives the path to the 4ed executable file.
capacity
This parameter specifies the maximum capacity of the out buffer.
Return
This call returns non-zero on success.

§3.3.58: show_mouse_cursor

void app->show_mouse_cursor(
Application_Links *app,
Mouse_Cursor_Show_Type show
)
Parameters
show
This parameter specifies the new state of the mouse cursor.
See Also

§3.3.59: toggle_fullscreen

void app->toggle_fullscreen(
Application_Links *app
)
Description
This call tells 4coder to switch into or out of full screen mode. The changes of full screen mode do not take effect until the end of the current frame. On Windows this call will not work unless 4coder was started in "stream mode". -Stream mode can be enabled with -S or -F flags on the command line to 4ed.


§3.3.59: is_fullscreen

bool32 app->is_fullscreen(
Application_Links *app
)
Description
This call returns true if the 4coder is in full screen mode. This call +Stream mode can be enabled with -S or -F flags on the command line to 4ed.


§3.3.60: is_fullscreen

bool32 app->is_fullscreen(
Application_Links *app
)
Description
This call returns true if the 4coder is in full screen mode. This call takes toggles that have already occured this frame into account. So it may return true even though the frame has not ended and actually put 4coder into full screen. If it returns true though, 4coder will definitely be full screen by the beginning of the next -frame if the state is not changed.


§3.3.60: send_exit_signal

void app->send_exit_signal(
Application_Links *app
)
Description
This call sends a signal to 4coder to attempt to exit. If there are unsaved +frame if the state is not changed.


§3.3.61: send_exit_signal

void app->send_exit_signal(
Application_Links *app
)
Description
This call sends a signal to 4coder to attempt to exit. If there are unsaved files this triggers a dialogue ensuring you're okay with closing.


§3.4 Type Descriptions

§3.4.1: bool32

typedef int32_t bool32;
Description
bool32 is an alias name to signal that an integer parameter or field is for true/false vales.


§3.4.2: int_color

typedef uint32_t int_color;
Description
int_color is an alias name to signal that an integer parameter or field is for a color value, colors are specified as 24 bit integers in 3 channels: 0xRRGGBB.


§3.4.3: Key_Code

typedef unsigned char Key_Code;
Description
Key_Code is the alias for key codes including raw codes and codes translated @@ -170,9 +170,12 @@ for concisely creating Buffer_Seek structs. They can be found in 4coder_buffer_ character. The unrounded behavior is the expected behavior when moving vertically and keeping the preferred x.

x
The x coordinate for xy type seeks.

y
The y coordinate for xy type seeks.

line
The line number of a line-character type seek.

character
The character number of a line-character type seek.

See Also

§3.4.37: Buffer_Edit

struct Buffer_Edit {
int32_t str_start;
int32_t len;
int32_t start;
int32_t end;
};
Description
Buffer_Edit describes a range of a buffer and string to replace that range. A Buffer_Edit has to be paired with a string that contains the actual text that -will be replaced into the buffer.

Fields
str_start
The str_start field specifies the first character in the accompanying string that corresponds with this edit.

len
The len field specifies the length of the string being written into the buffer.

start
The start field specifies the start of the range in the buffer to replace in absolute position.

end
The end field specifies one past the end of the range in the buffer to replace in absolute position.


§3.4.38: Buffer_Summary

struct Buffer_Summary {
bool32 exists;
bool32 ready;
int32_t buffer_id;
Access_Flag lock_flags;
int32_t size;
int32_t line_count;
char * file_name;
int32_t file_name_len;
char * buffer_name;
int32_t buffer_name_len;
bool32 is_lexed;
int32_t map_id;
bool32 unwrapped_lines;
};
Description
Buffer_Summary acts as a handle to a buffer and describes the state of the buffer.

Fields
exists
This field indicates whether the Buffer_Summary describes a buffer that is open in 4coder. +will be replaced into the buffer.

Fields
str_start
The str_start field specifies the first character in the accompanying string that corresponds with this edit.

len
The len field specifies the length of the string being written into the buffer.

start
The start field specifies the start of the range in the buffer to replace in absolute position.

end
The end field specifies one past the end of the range in the buffer to replace in absolute position.


§3.4.38: Buffer_Summary

struct Buffer_Summary {
bool32 exists;
bool32 ready;
int32_t buffer_id;
Access_Flag lock_flags;
int32_t size;
int32_t line_count;
char * file_name;
int32_t file_name_len;
char * buffer_name;
int32_t buffer_name_len;
bool32 is_lexed;
bool32 tokens_are_ready;
int32_t map_id;
bool32 unwrapped_lines;
};
Description
Buffer_Summary acts as a handle to a buffer and describes the state of the buffer.

Fields
exists
This field indicates whether the Buffer_Summary describes a buffer that is open in 4coder. When this field is false the summary is referred to as a "null summary".

ready
If this is not a null summary, this field indicates whether the buffer has finished loading.

buffer_id
If this is not a null summary this field is the id of the associated buffer. - If this is a null summary then buffer_id is 0.

lock_flags
If this is not a null summary, this field contains flags describing the protection status of the buffer.

size
If this is not a null summary, this field specifies the size of the text in the buffer.

line_count
If this is not a null summary, this field specifies the number of lines in the buffer.

file_name
If this is not a null summary, this field specifies the file name associated to this buffer.

file_name_len
This field specifies the length of the file_name string.

buffer_name
If this is not a null summary, this field specifies the name of the buffer.

buffer_name_len
This field specifies the length of the buffer_name string.

is_lexed
If this is not a null summary, this field indicates whether the buffer is set to lex tokens.

map_id
If this is not a null summary, this field specifies the id of the command map for this buffer.

unwrapped_lines
If this is not a null summary, this field indicates whether the buffer 'prefers' wrapped lines.

See Also

§3.4.39: View_Summary

struct View_Summary {
bool32 exists;
int32_t view_id;
int32_t buffer_id;
Access_Flag lock_flags;
Full_Cursor cursor;
Full_Cursor mark;
float preferred_x;
float line_height;
bool32 unwrapped_lines;
bool32 show_whitespace;
i32_Rect file_region;
GUI_Scroll_Vars scroll_vars;
};
Description
View_Summary acts as a handle to a view and describes the state of the view.

Fields
exists
This field indicates whether the View_Summary describes a view that is open in 4coder. + If this is a null summary then buffer_id is 0.

lock_flags
If this is not a null summary, this field contains flags describing the protection status of the buffer.

size
If this is not a null summary, this field specifies the size of the text in the buffer.

line_count
If this is not a null summary, this field specifies the number of lines in the buffer.

file_name
If this is not a null summary, this field specifies the file name associated to this buffer.

file_name_len
This field specifies the length of the file_name string.

buffer_name
If this is not a null summary, this field specifies the name of the buffer.

buffer_name_len
This field specifies the length of the buffer_name string.

is_lexed
If this is not a null summary, this field indicates whether the buffer is set to lex tokens.

tokens_are_ready
If this is not a null summary, this field indicates whether the buffer has up to date tokens available. + If this field is false, it may simply mean the tokens are still being generated in a background task and will + be available later. If that is the case, is_lexed will be true to indicate that the buffer is trying to get + it's tokens up to date.

map_id
If this is not a null summary, this field specifies the id of the command map for this buffer.

unwrapped_lines
If this is not a null summary, this field indicates whether the buffer 'prefers' wrapped lines.

See Also

§3.4.39: View_Summary

struct View_Summary {
bool32 exists;
int32_t view_id;
int32_t buffer_id;
Access_Flag lock_flags;
Full_Cursor cursor;
Full_Cursor mark;
float preferred_x;
float line_height;
bool32 unwrapped_lines;
bool32 show_whitespace;
i32_Rect file_region;
GUI_Scroll_Vars scroll_vars;
};
Description
View_Summary acts as a handle to a view and describes the state of the view.

Fields
exists
This field indicates whether the View_Summary describes a view that is open in 4coder. When this field is false the summary is referred to as a "null summary".

view_id
If this is not a null summary, this field is the id of the associated view. If this is a null summary then view_id is 0.

buffer_id
If this is not a null summary, then this is the id of the buffer this view currently sees.

lock_flags
If this is not a null summary, this field contains flags describing the protection status of the view.

cursor
If this is not a null summary, this describes the position of the cursor.

mark
If this is not a null summary, this describes the position of the mark.

preferred_x
If this is not a null summary, this is the x position that is maintained in vertical navigation.

line_height
If this is not a null summary, this specifies the height of a line rendered in the view.

unwrapped_lines
If this is not a null summary, this indicates that the view is set to render with unwrapped lines.

show_whitespace
If this is not a null summary, this indicates that the view is set to highlight white space.

file_region
If this is not a null summary, this describes the screen position in which this view's buffer is displayed.

scroll_vars
If this is not a null summary, this describes the scrolling position inside the view.

See Also

§3.4.40: User_Input

struct User_Input {
User_Input_Type_ID type;
bool32 abort;
union {
Key_Event_Data key;
Mouse_State mouse;
};
Generic_Command command;
};
Description
User_Input describes a user input event which can be either a key press or mouse event.

Fields
type
This field specifies whether the event was a key press or mouse event.

abort
This field indicates that an abort event has occurred and the command needs to shut down.

key
This field describes a key press event.

mouse
This field describes a mouse input event.

command
If this event would trigger a command, this field specifies what the command would be.

See Also

§3.4.41: Query_Bar

struct Query_Bar {
String prompt;
String string;
};
Description
Query_Bar is a struct used to store information in the user's control that will be displayed as a drop down bar durring an interactive command.

Fields
prompt
This specifies the prompt portion of the drop down bar.

string
This specifies the main string portion of the drop down bar.


§3.4.42: Event_Message

struct Event_Message {
int32_t type;
};
Description
This feature is not implemented.

Fields
type
This feature is not implemented.


§3.4.43: Theme_Color

struct Theme_Color {
Style_Tag tag;
int_color color;
};
Description
Theme_Color stores a style tag/color pair, for the purpose of setting and getting colors in the theme .

Fields
tag
color
See Also

diff --git a/4coder_auto_indent.cpp b/4coder_auto_indent.cpp new file mode 100644 index 00000000..7f3cd5ae --- /dev/null +++ b/4coder_auto_indent.cpp @@ -0,0 +1,556 @@ + +#ifndef FCODER_AUTO_INDENT_INC +#define FCODER_AUTO_INDENT_INC + +struct Hard_Start_Result{ + int32_t char_pos; + int32_t indent_pos; + int32_t all_whitespace; + int32_t all_space; +}; + +static Hard_Start_Result +buffer_find_hard_start(Application_Links *app, Buffer_Summary *buffer, int32_t line_start, int32_t tab_width){ + Hard_Start_Result result = {0}; + char data_chunk[1024]; + Stream_Chunk stream = {0}; + char c; + + tab_width -= 1; + + result.all_space = 1; + result.indent_pos = 0; + result.char_pos = line_start; + + stream.add_null = 1; + if (init_stream_chunk(&stream, app, buffer, line_start, data_chunk, sizeof(data_chunk))){ + int32_t still_looping = 1; + do{ + for (; result.char_pos < stream.end; ++result.char_pos){ + c = stream.data[result.char_pos]; + + if (c == '\n' || c == 0){ + result.all_whitespace = 1; + goto double_break; + } + + if (c >= '!' && c <= '~'){ + goto double_break; + } + + if (c == '\t'){ + result.indent_pos += tab_width; + } + + if (c != ' '){ + result.all_space = 0; + } + + result.indent_pos += 1; + } + still_looping = forward_stream_chunk(&stream); + }while(still_looping); + } + + double_break:; + return(result); +} + +struct Indent_Options{ + bool32 empty_blank_lines; + bool32 use_tabs; + int32_t tab_width; +}; + +#include "4cpp_lexer.h" + +static int32_t +buffer_get_line_start(Application_Links *app, Buffer_Summary *buffer, int32_t line){ + Partial_Cursor partial_cursor; + app->buffer_compute_cursor(app, buffer, seek_line_char(line, 1), &partial_cursor); + return(partial_cursor.pos); +} + +static int32_t +buffer_get_line_index(Application_Links *app, Buffer_Summary *buffer, int32_t pos){ + Partial_Cursor partial_cursor; + app->buffer_compute_cursor(app, buffer, seek_pos(pos), &partial_cursor); + return(partial_cursor.line); +} + +static Cpp_Token* +get_first_token_at_line(Application_Links *app, Buffer_Summary *buffer, Cpp_Token_Array tokens, int32_t line){ + int32_t line_start = buffer_get_line_start(app, buffer, line); + Cpp_Get_Token_Result get_token = cpp_get_token(&tokens, line_start); + + if (get_token.in_whitespace){ + get_token.token_index += 1; + } + + Cpp_Token *result = tokens.tokens + get_token.token_index; + + return(result); +} + +static Cpp_Token* +seek_matching_token_backwards(Cpp_Token_Array tokens, Cpp_Token *token, + Cpp_Token_Type open_type, Cpp_Token_Type close_type){ + int32_t nesting_level = 0; + if (token <= tokens.tokens){ + token = tokens.tokens; + } + else{ + for (; token > tokens.tokens; --token){ + if (!(token->flags & CPP_TFLAG_PP_BODY)){ + if (token->type == close_type){ + ++nesting_level; + } + else if (token->type == open_type){ + if (nesting_level == 0){ + break; + } + else{ + --nesting_level; + } + } + } + } + } + return(token); +} + +struct Indent_Parse_State{ + int32_t current_indent; + int32_t previous_line_indent; + int32_t paren_nesting; + int32_t paren_anchor_indent[16]; + int32_t comment_shift; +}; + +static int32_t +compute_this_indent(Application_Links *app, Buffer_Summary *buffer, Indent_Parse_State indent, + Cpp_Token T, Cpp_Token prev_token, int32_t line_i, int32_t tab_width){ + + int32_t previous_indent = indent.previous_line_indent; + int32_t this_indent = 0; + + int32_t this_line_start = buffer_get_line_start(app, buffer, line_i); + int32_t next_line_start = 0; + + if (line_i+1 < buffer->line_count){ + next_line_start = buffer_get_line_start(app, buffer, line_i+1); + } + else{ + next_line_start = buffer->size; + } + + bool32 did_special_behavior = false; + + if (prev_token.start <= this_line_start && + prev_token.start + prev_token.size > this_line_start){ + if (prev_token.type == CPP_TOKEN_COMMENT){ + Hard_Start_Result hard_start = buffer_find_hard_start(app, buffer, this_line_start, tab_width); + + if (hard_start.all_whitespace){ + this_indent = previous_indent; + did_special_behavior = true; + } + else{ + int32_t line_pos = hard_start.char_pos - this_line_start; + this_indent = line_pos + indent.comment_shift; + if (this_indent < 0){ + this_indent = 0; + } + did_special_behavior = true; + } + } + else if (prev_token.type == CPP_TOKEN_STRING_CONSTANT){ + this_indent = previous_indent; + did_special_behavior = true; + } + } + + + if (!did_special_behavior){ + this_indent = indent.current_indent; + if (T.start < next_line_start){ + if (T.flags & CPP_TFLAG_PP_DIRECTIVE){ + this_indent = 0; + } + else{ + switch (T.type){ + case CPP_TOKEN_BRACKET_CLOSE: this_indent -= tab_width; break; + case CPP_TOKEN_BRACE_CLOSE: this_indent -= tab_width; break; + case CPP_TOKEN_BRACE_OPEN: break; + + default: + if (indent.current_indent > 0){ + if (!(prev_token.flags & CPP_TFLAG_PP_BODY || + prev_token.flags & CPP_TFLAG_PP_DIRECTIVE)){ + switch (prev_token.type){ + case CPP_TOKEN_BRACKET_OPEN: + case CPP_TOKEN_BRACE_OPEN: case CPP_TOKEN_BRACE_CLOSE: + case CPP_TOKEN_SEMICOLON: case CPP_TOKEN_COLON: + case CPP_TOKEN_COMMA: case CPP_TOKEN_COMMENT: break; + default: this_indent += tab_width; + } + } + } + } + } + } + if (this_indent < 0) this_indent = 0; + } + + if (indent.paren_nesting > 0){ + if (prev_token.type != CPP_TOKEN_PARENTHESE_OPEN){ + int32_t level = indent.paren_nesting-1; + if (level >= ArrayCount(indent.paren_anchor_indent)){ + level = ArrayCount(indent.paren_anchor_indent)-1; + } + this_indent = indent.paren_anchor_indent[level]; + } + } + return(this_indent); +} + +static int32_t* +get_line_indentation_marks(Application_Links *app, Partition *part, Buffer_Summary *buffer, Cpp_Token_Array tokens, + int32_t line_start, int32_t line_end, int32_t tab_width){ + + int32_t indent_mark_count = line_end - line_start; + int32_t *indent_marks = push_array(part, int32_t, indent_mark_count); + + Indent_Parse_State indent = {0}; + Cpp_Token *token = get_first_token_at_line(app, buffer, tokens, line_start); + + if (token != tokens.tokens){ + --token; + for (; token > tokens.tokens; --token){ + if (!(token->flags & CPP_TFLAG_PP_BODY)){ + switch(token->type){ + case CPP_TOKEN_BRACE_OPEN: + case CPP_TOKEN_BRACE_CLOSE: + goto out_of_loop; + } + } + } + out_of_loop:; + } + + // TODO(allen): This can maybe be it's own function now, so that we + // can do the decls in the order we want and avoid the extra binary search. + int32_t found_safe_start_position = 0; + do{ + int32_t line = buffer_get_line_index(app, buffer, token->start); + int32_t start = buffer_get_line_start(app, buffer, line); + Hard_Start_Result hard_start = buffer_find_hard_start(app, buffer, start, tab_width); + + indent.current_indent = hard_start.indent_pos; + + Cpp_Token *start_token = get_first_token_at_line(app, buffer, tokens, line); + Cpp_Token *brace_token = token; + + if (start_token->type == CPP_TOKEN_PARENTHESE_OPEN){ + if (start_token == tokens.tokens){ + found_safe_start_position = 1; + } + else{ + token = start_token-1; + } + } + else{ + int32_t close = 0; + + for (token = brace_token; token > start_token; --token){ + switch(token->type){ + case CPP_TOKEN_PARENTHESE_CLOSE: + case CPP_TOKEN_BRACKET_CLOSE: + case CPP_TOKEN_BRACE_CLOSE: + close = token->type; + goto out_of_loop2; + } + } + out_of_loop2:; + + switch (close){ + case 0: token = start_token; found_safe_start_position = 1; break; + + case CPP_TOKEN_PARENTHESE_CLOSE: + token = seek_matching_token_backwards(tokens, token-1, + CPP_TOKEN_PARENTHESE_OPEN, + CPP_TOKEN_PARENTHESE_CLOSE); + break; + + case CPP_TOKEN_BRACKET_CLOSE: + token = seek_matching_token_backwards(tokens, token-1, + CPP_TOKEN_BRACKET_OPEN, + CPP_TOKEN_BRACKET_CLOSE); + break; + + case CPP_TOKEN_BRACE_CLOSE: + token = seek_matching_token_backwards(tokens, token-1, + CPP_TOKEN_BRACE_OPEN, + CPP_TOKEN_BRACE_CLOSE); + break; + } + } + } while(found_safe_start_position == 0); + + // NOTE(allen): Shift the array so that line_i can just operate in + // it's natural value range. + indent_marks -= line_start; + + int32_t line_i = buffer_get_line_index(app, buffer, token->start); + + if (line_i > line_start){ + line_i = line_start; + } + + int32_t next_line_start = buffer->size; + if (line_i+1 < buffer->line_count){ + next_line_start = buffer_get_line_start(app, buffer, line_i+1); + } + + switch (token->type){ + case CPP_TOKEN_BRACKET_OPEN: indent.current_indent += tab_width; break; + case CPP_TOKEN_BRACE_OPEN: indent.current_indent += tab_width; break; + case CPP_TOKEN_PARENTHESE_OPEN: indent.current_indent += tab_width; break; + } + + indent.previous_line_indent = indent.current_indent; + Cpp_Token T; + Cpp_Token prev_token = *token; + ++token; + + for (; line_i < line_end; ++token){ + if (token < tokens.tokens + tokens.count){ + T = *token; + } + else{ + T.type = CPP_TOKEN_EOF; + T.start = buffer->size; + T.flags = 0; + } + + for (; T.start >= next_line_start && line_i < line_end;){ + if (line_i+1 < buffer->line_count){ + next_line_start = buffer_get_line_start(app, buffer, line_i+1); + } + else{ + next_line_start = buffer->size; + } + + int32_t this_indent = + compute_this_indent(app, buffer, indent, T, prev_token, line_i, tab_width); + + // NOTE(allen): Rebase the paren anchor if the first token + // after an open paren is on the next line. + if (indent.paren_nesting > 0){ + if (prev_token.type == CPP_TOKEN_PARENTHESE_OPEN){ + int32_t level = indent.paren_nesting-1; + if (level >= ArrayCount(indent.paren_anchor_indent)){ + level = ArrayCount(indent.paren_anchor_indent)-1; + } + indent.paren_anchor_indent[level] = this_indent; + } + } + + if (line_i >= line_start){ + indent_marks[line_i] = this_indent; + } + ++line_i; + + indent.previous_line_indent = this_indent; + } + + switch (T.type){ + case CPP_TOKEN_BRACKET_OPEN: indent.current_indent += 4; break; + case CPP_TOKEN_BRACKET_CLOSE: indent.current_indent -= 4; break; + case CPP_TOKEN_BRACE_OPEN: indent.current_indent += 4; break; + case CPP_TOKEN_BRACE_CLOSE: indent.current_indent -= 4; break; + + case CPP_TOKEN_COMMENT: + { + int32_t line = buffer_get_line_index(app, buffer, T.start); + int32_t start = buffer_get_line_start(app, buffer, line); + + indent.comment_shift = (indent.current_indent - (T.start - start)); + }break; + + case CPP_TOKEN_PARENTHESE_OPEN: + if (!(T.flags & CPP_TFLAG_PP_BODY)){ + if (indent.paren_nesting < ArrayCount(indent.paren_anchor_indent)){ + int32_t line = buffer_get_line_index(app, buffer, T.start); + int32_t start = buffer_get_line_start(app, buffer, line); + int32_t char_pos = T.start - start; + + Hard_Start_Result hard_start = + buffer_find_hard_start(app, buffer, start, tab_width); + + int32_t line_pos = hard_start.char_pos - start; + + indent.paren_anchor_indent[indent.paren_nesting] = + char_pos - line_pos + indent.previous_line_indent + 1; + } + ++indent.paren_nesting; + } + break; + + case CPP_TOKEN_PARENTHESE_CLOSE: + if (!(T.flags & CPP_TFLAG_PP_BODY)){ + --indent.paren_nesting; + } + break; + } + prev_token = T; + } + + // NOTE(allen): Unshift the indent_marks array so that the return value + // is the exact starting point of the array that was actually allocated. + indent_marks += line_start; + + return(indent_marks); +} + +struct Make_Batch_Result{ + char *str_base; + int32_t str_size; + + Buffer_Edit *edits; + int32_t edit_max; + int32_t edit_count; +}; + +static Make_Batch_Result +make_batch_from_indent_marks(Application_Links *app, Partition *part, Buffer_Summary *buffer, + int32_t line_start, int32_t line_end, int32_t *indent_marks, Indent_Options opts){ + + Make_Batch_Result result = {0}; + + int32_t edit_max = line_end - line_start; + int32_t edit_count = 0; + + Buffer_Edit *edits = push_array(part, Buffer_Edit, edit_max); + + char *str_base = (char*)part->base + part->pos; + int32_t str_size = 0; + + // NOTE(allen): Shift the array so that line_i can just operate in + // it's natural value range. + indent_marks -= line_start; + + for (int32_t line_i = line_start; line_i < line_end; ++line_i){ + int32_t line_start = buffer_get_line_start(app, buffer, line_i); + Hard_Start_Result hard_start = + buffer_find_hard_start(app, buffer, line_start, opts.tab_width); + + int32_t correct_indentation = indent_marks[line_i]; + if (hard_start.all_whitespace && opts.empty_blank_lines) correct_indentation = 0; + if (correct_indentation == -1) correct_indentation = hard_start.indent_pos; + + // TODO(allen): Only replace spaces if we are using space based indentation. + // TODO(allen): See if the first clause can just be removed because it's dumb. + if ((hard_start.all_whitespace && hard_start.char_pos > line_start) || + !hard_start.all_space || correct_indentation != hard_start.indent_pos){ + + Buffer_Edit new_edit; + new_edit.str_start = str_size; + str_size += correct_indentation; + char *str = push_array(part, char, correct_indentation); + int32_t j = 0; + if (opts.use_tabs){ + int32_t i = 0; + for (; i + opts.tab_width <= correct_indentation; i += opts.tab_width) str[j++] = '\t'; + for (; i < correct_indentation; ++i) str[j++] = ' '; + } + else{ + for (; j < correct_indentation; ++j) str[j] = ' '; + } + new_edit.len = j; + new_edit.start = line_start; + new_edit.end = hard_start.char_pos; + edits[edit_count++] = new_edit; + } + + Assert(edit_count <= edit_max); + } + + result.str_base = str_base; + result.str_size = str_size; + + result.edits = edits; + result.edit_max = edit_max; + result.edit_count = edit_count; + + return(result); +} + +static bool32 +buffer_auto_indent(Application_Links *app, Partition *part, Buffer_Summary *buffer, + int32_t start, int32_t end, int32_t tab_width, Auto_Indent_Flag flags)/* +DOC_PARAM(buffer, The buffer specifies the buffer in which to apply auto indentation.) +DOC_PARAM(start, This parameter specifies the absolute position of the start of the indentation range.) +DOC_PARAM(end, This parameter specifies the absolute position of the end of the indentation range.) +DOC_PARAM(tab_width, The tab_width parameter specifies how many spaces should be used for one indentation in space mode.) +DOC_PARAM(flags, This parameter specifies behaviors for the indentation.) +DOC_RETURN(This call returns non-zero when the call succeeds.) + +DOC(Applies the built in auto-indentation rule to the code in the range +from start to end by inserting spaces or tabs at the beginning of the +lines. If the buffer does not have lexing enabled or the lexing job has +not completed this function will fail.) + +DOC_SEE(Auto_Indent_Flag) +DOC_SEE(4coder_Buffer_Positioning_System) +*/{ + + Indent_Options opts = {0}; + + bool32 result = 0; + if (buffer->exists && buffer->tokens_are_ready){ + result = 1; + + opts.empty_blank_lines = (flags & AutoIndent_ClearLine); + opts.use_tabs = (flags & AutoIndent_UseTab); + opts.tab_width = tab_width; + + Temp_Memory temp = begin_temp_memory(part); + + // TODO(allen): Only read in the tokens in the range we need. + Cpp_Token_Array tokens; + tokens.count = app->buffer_token_count(app, buffer); + tokens.max_count = tokens.count; + tokens.tokens = push_array(part, Cpp_Token, tokens.count); + app->buffer_read_tokens(app, buffer, 0, tokens.count, tokens.tokens); + + int32_t line_start = buffer_get_line_index(app, buffer, start); + int32_t line_end = buffer_get_line_index(app, buffer, end); + + int32_t *indent_marks = + get_line_indentation_marks(app, part, buffer, tokens, + line_start, line_end, opts.tab_width); + + Make_Batch_Result batch = + make_batch_from_indent_marks(app, part, buffer, line_start, line_end, indent_marks, opts); + + if (batch.edit_count > 0){ + app->buffer_batch_edit(app, buffer, batch.str_base, batch.str_size, + batch.edits, batch.edit_count, BatchEdit_PreserveTokens); + } + + end_temp_memory(temp); + } + + return(result); +} + +static bool32 +buffer_auto_indent(Application_Links *app, Buffer_Summary *buffer, + int32_t start, int32_t end, int32_t tab_width, Auto_Indent_Flag flags){ + bool32 result = buffer_auto_indent(app, &global_part, buffer, start, end, tab_width, flags); + return(result); +} + +#endif + diff --git a/4coder_custom_api.h b/4coder_custom_api.h index 64dd0a0e..5dfc3251 100644 --- a/4coder_custom_api.h +++ b/4coder_custom_api.h @@ -14,7 +14,8 @@ #define BUFFER_COMPUTE_CURSOR_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, Buffer_Seek seek, Partial_Cursor *cursor_out) #define BUFFER_BATCH_EDIT_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, char *str, int32_t str_len, Buffer_Edit *edits, int32_t edit_count, Buffer_Batch_Edit_Type type) #define BUFFER_SET_SETTING_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, Buffer_Setting_ID setting, int32_t value) -#define BUFFER_AUTO_INDENT_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, int32_t start, int32_t end, int32_t tab_width, Auto_Indent_Flag flags) +#define BUFFER_TOKEN_COUNT_SIG(n) int32_t n(Application_Links *app, Buffer_Summary *buffer) +#define BUFFER_READ_TOKENS_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, int32_t first_token, int32_t last_token, Cpp_Token *tokens_out) #define CREATE_BUFFER_SIG(n) Buffer_Summary n(Application_Links *app, char *filename, int32_t filename_len, Buffer_Create_Flag flags) #define SAVE_BUFFER_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, char *filename, int32_t filename_len, uint32_t flags) #define KILL_BUFFER_SIG(n) bool32 n(Application_Links *app, Buffer_Identifier buffer, View_ID view_id, Buffer_Kill_Flag flags) @@ -74,7 +75,8 @@ typedef BUFFER_REPLACE_RANGE_SIG(Buffer_Replace_Range_Function); typedef BUFFER_COMPUTE_CURSOR_SIG(Buffer_Compute_Cursor_Function); typedef BUFFER_BATCH_EDIT_SIG(Buffer_Batch_Edit_Function); typedef BUFFER_SET_SETTING_SIG(Buffer_Set_Setting_Function); -typedef BUFFER_AUTO_INDENT_SIG(Buffer_Auto_Indent_Function); +typedef BUFFER_TOKEN_COUNT_SIG(Buffer_Token_Count_Function); +typedef BUFFER_READ_TOKENS_SIG(Buffer_Read_Tokens_Function); typedef CREATE_BUFFER_SIG(Create_Buffer_Function); typedef SAVE_BUFFER_SIG(Save_Buffer_Function); typedef KILL_BUFFER_SIG(Kill_Buffer_Function); @@ -135,7 +137,8 @@ Buffer_Replace_Range_Function *buffer_replace_range; Buffer_Compute_Cursor_Function *buffer_compute_cursor; Buffer_Batch_Edit_Function *buffer_batch_edit; Buffer_Set_Setting_Function *buffer_set_setting; -Buffer_Auto_Indent_Function *buffer_auto_indent; +Buffer_Token_Count_Function *buffer_token_count; +Buffer_Read_Tokens_Function *buffer_read_tokens; Create_Buffer_Function *create_buffer; Save_Buffer_Function *save_buffer; Kill_Buffer_Function *kill_buffer; @@ -203,7 +206,8 @@ app_links->buffer_replace_range = Buffer_Replace_Range;\ app_links->buffer_compute_cursor = Buffer_Compute_Cursor;\ app_links->buffer_batch_edit = Buffer_Batch_Edit;\ app_links->buffer_set_setting = Buffer_Set_Setting;\ -app_links->buffer_auto_indent = Buffer_Auto_Indent;\ +app_links->buffer_token_count = Buffer_Token_Count;\ +app_links->buffer_read_tokens = Buffer_Read_Tokens;\ app_links->create_buffer = Create_Buffer;\ app_links->save_buffer = Save_Buffer;\ app_links->kill_buffer = Kill_Buffer;\ diff --git a/4coder_default_include.cpp b/4coder_default_include.cpp index a3671bed..f1d507d2 100644 --- a/4coder_default_include.cpp +++ b/4coder_default_include.cpp @@ -142,6 +142,7 @@ struct Stream_Chunk{ char *base_data; int32_t start, end; int32_t min_start, max_end; + bool32 add_null; int32_t data_size; char *data; @@ -175,11 +176,11 @@ refresh_view(Application_Links *app, View_Summary *view){ *view = app->get_view(app, view->view_id, AccessAll); } -int32_t +bool32 init_stream_chunk(Stream_Chunk *chunk, Application_Links *app, Buffer_Summary *buffer, int32_t pos, char *data, int32_t size){ - int32_t result = false; + bool32 result = false; refresh_buffer(app, buffer); if (pos >= 0 && pos < buffer->size && size > 0){ @@ -190,8 +191,7 @@ init_stream_chunk(Stream_Chunk *chunk, chunk->start = round_down(pos, size); chunk->end = round_up(pos, size); - if (chunk->max_end > buffer->size - || chunk->max_end == 0){ + if (chunk->max_end > buffer->size || chunk->max_end == 0){ chunk->max_end = buffer->size; } @@ -235,6 +235,15 @@ forward_stream_chunk(Stream_Chunk *chunk){ result = true; } } + + else if (chunk->add_null && chunk->end + 1 < buffer->size){ + chunk->start = buffer->size; + chunk->end = buffer->size + 1; + chunk->base_data[0] = 0; + chunk->data = chunk->base_data - chunk->start; + result = true; + } + return(result); } @@ -262,6 +271,14 @@ backward_stream_chunk(Stream_Chunk *chunk){ result = true; } } + + else if (chunk->add_null && chunk->start > -1){ + chunk->start = -1; + chunk->end = 0; + chunk->base_data[0] = 0; + chunk->data = chunk->base_data - chunk->start; + } + return(result); } @@ -887,17 +904,17 @@ move_past_lead_whitespace(Application_Links *app, View_Summary *view, Buffer_Sum } } -//#include "4coder_auto_indent.cpp" +#include "4coder_auto_indent.cpp" CUSTOM_COMMAND_SIG(auto_tab_line_at_cursor){ uint32_t access = AccessOpen; View_Summary view = app->get_active_view(app, access); Buffer_Summary buffer = app->get_buffer(app, view.buffer_id, access); - app->buffer_auto_indent(app, &buffer, - view.cursor.pos, view.cursor.pos, - DEF_TAB_WIDTH, - DEFAULT_INDENT_FLAGS); + buffer_auto_indent(app, &buffer, + view.cursor.pos, view.cursor.pos, + DEF_TAB_WIDTH, + DEFAULT_INDENT_FLAGS); move_past_lead_whitespace(app, &view, &buffer); } @@ -906,10 +923,10 @@ CUSTOM_COMMAND_SIG(auto_tab_whole_file){ View_Summary view = app->get_active_view(app, access); Buffer_Summary buffer = app->get_buffer(app, view.buffer_id, access); - app->buffer_auto_indent(app, &buffer, - 0, buffer.size, - DEF_TAB_WIDTH, - DEFAULT_INDENT_FLAGS); + buffer_auto_indent(app, &buffer, + 0, buffer.size, + DEF_TAB_WIDTH, + DEFAULT_INDENT_FLAGS); } CUSTOM_COMMAND_SIG(auto_tab_range){ @@ -918,10 +935,10 @@ CUSTOM_COMMAND_SIG(auto_tab_range){ Buffer_Summary buffer = app->get_buffer(app, view.buffer_id, access); Range range = get_range(&view); - app->buffer_auto_indent(app, &buffer, - range.min, range.max, - DEF_TAB_WIDTH, - DEFAULT_INDENT_FLAGS); + buffer_auto_indent(app, &buffer, + range.min, range.max, + DEF_TAB_WIDTH, + DEFAULT_INDENT_FLAGS); move_past_lead_whitespace(app, &view, &buffer); } @@ -1417,10 +1434,10 @@ long_braces(Application_Links *app, char *text, int32_t size){ app->buffer_replace_range(app, &buffer, pos, pos, text, size); app->view_set_cursor(app, &view, seek_pos(pos + 2), true); - app->buffer_auto_indent(app, &buffer, - pos, pos + size, - DEF_TAB_WIDTH, - DEFAULT_INDENT_FLAGS); + buffer_auto_indent(app, &buffer, + pos, pos + size, + DEF_TAB_WIDTH, + DEFAULT_INDENT_FLAGS); move_past_lead_whitespace(app, &view, &buffer); } @@ -1491,10 +1508,10 @@ CUSTOM_COMMAND_SIG(if0_off){ } range = get_range(&view); - app->buffer_auto_indent(app, &buffer, - range.min, range.max, - DEF_TAB_WIDTH, - DEFAULT_INDENT_FLAGS); + buffer_auto_indent(app, &buffer, + range.min, range.max, + DEF_TAB_WIDTH, + DEFAULT_INDENT_FLAGS); move_past_lead_whitespace(app, &view, &buffer); } } diff --git a/4coder_types.h b/4coder_types.h index 94b6b285..140f2c73 100644 --- a/4coder_types.h +++ b/4coder_types.h @@ -607,6 +607,11 @@ struct Buffer_Summary{ /* DOC(If this is not a null summary, this field indicates whether the buffer is set to lex tokens.) */ bool32 is_lexed; + /* DOC(If this is not a null summary, this field indicates whether the buffer has up to date tokens available. + If this field is false, it may simply mean the tokens are still being generated in a background task and will + be available later. If that is the case, is_lexed will be true to indicate that the buffer is trying to get + it's tokens up to date.) */ + bool32 tokens_are_ready; /* DOC(If this is not a null summary, this field specifies the id of the command map for this buffer.) */ int32_t map_id; /* DOC(If this is not a null summary, this field indicates whether the buffer 'prefers' wrapped lines.) */ diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp index 3c0dab5b..9926bb6d 100644 --- a/4ed_api_implementation.cpp +++ b/4ed_api_implementation.cpp @@ -32,6 +32,16 @@ fill_buffer_summary(Buffer_Summary *buffer, Editing_File *file, Working_Set *wor buffer->buffer_name = file->name.live_name.str; buffer->is_lexed = file->settings.tokens_exist; + + if (file->state.token_array.tokens && + file->state.tokens_complete && + !file->state.still_lexing){ + buffer->tokens_are_ready = 1; + } + else{ + buffer->tokens_are_ready = 0; + } + buffer->map_id = file->settings.base_map_id; buffer->unwrapped_lines = file->settings.unwrapped_lines; @@ -752,7 +762,9 @@ Buffer_Compute_Cursor(Application_Links *app, Buffer_Summary *buffer, Buffer_See DOC_PARAM(buffer, The buffer parameter specifies the buffer on which to run the cursor computation.) DOC_PARAM(seek, The seek parameter specifies the target position for the seek.) DOC_PARAM(cursor_out, On success this struct is filled with the result of the seek.) -DOC_RETURN(This call returns non-zero on success.) +DOC_RETURN(This call returns non-zero on success. This call can fail if the buffer summary provided +does not summarize an actual buffer in 4coder, or if the provided seek format is invalid. The valid +seek types are seek_pos and seek_line_char.) DOC(Computes a Partial_Cursor for the given seek position with no side effects. The seek position must be one of the types supported by Partial_Cursor. Those types are absolute position and line,column position.) @@ -780,7 +792,8 @@ DOC_PARAM(str_len, This parameter specifies the length of the str string.) DOC_PARAM(edits, This parameter provides about the source string and destination range of each edit as an array.) DOC_PARAM(edit_count, This parameter specifies the number of Buffer_Edit structs in edits.) DOC_PARAM(type, This prameter specifies what type of batch edit to execute.) -DOC_RETURN(This call returns non-zero if the batch edit succeeds.) +DOC_RETURN(This call returns non-zero if the batch edit succeeds. This call can fail if the provided +buffer summary does not refer to an actual buffer in 4coder.) DOC(TODO) DOC_SEE(Buffer_Edit) DOC_SEE(Buffer_Batch_Edit_Type) @@ -812,9 +825,8 @@ DOC_SEE(Buffer_Batch_Edit_Type) end_temp_memory(temp); } - else{ - result = true; - } + + result = true; } return(result); @@ -916,43 +928,32 @@ DOC_SEE(Buffer_Setting_ID) return(result); } -API_EXPORT bool32 -Buffer_Auto_Indent(Application_Links *app, Buffer_Summary *buffer, int32_t start, int32_t end, int32_t tab_width, Auto_Indent_Flag flags)/* -DOC_PARAM(buffer, The buffer specifies the buffer in which to apply auto indentation.) -DOC_PARAM(start, This parameter specifies the absolute position of the start of the indentation range.) -DOC_PARAM(end, This parameter specifies the absolute position of the end of the indentation range.) -DOC_PARAM(tab_width, The tab_width parameter specifies how many spaces should be used for one indentation in space mode.) -DOC_PARAM(flags, This parameter specifies behaviors for the indentation.) -DOC_RETURN(This call returns non-zero when the call succeeds.) -DOC -( -Applies the built in auto-indentation rule to the code in the range from -start to end by inserting spaces or tabs at the beginning of the lines. -If the buffer does not have lexing enabled or the lexing job has not -completed this function will fail. -) -DOC_SEE(Auto_Indent_Flag) -DOC_SEE(4coder_Buffer_Positioning_System) -*/{ +API_EXPORT int32_t +Buffer_Token_Count(Application_Links *app, Buffer_Summary *buffer){ Command_Data *cmd = (Command_Data*)app->cmd_context; - System_Functions *system = cmd->system; - Models *models = cmd->models; - - Indent_Options opts = {0}; - bool32 result = false; - Editing_File *file = imp_get_file(cmd, buffer); - if (file && file->state.token_array.tokens && - file->state.tokens_complete && !file->state.still_lexing){ - result = true; + + int32_t count = 0; + + if (file && file->state.token_array.tokens && file->state.tokens_complete){ + count = file->state.token_array.count; + } + + return(count); +} + +API_EXPORT bool32 +Buffer_Read_Tokens(Application_Links *app, Buffer_Summary *buffer, int32_t first_token, int32_t last_token, Cpp_Token *tokens_out){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + Editing_File *file = imp_get_file(cmd, buffer); + + bool32 result = 0; + + if (file && file->state.token_array.tokens && file->state.tokens_complete){ + result = 1; - opts.empty_blank_lines = (flags & AutoIndent_ClearLine); - opts.use_tabs = (flags & AutoIndent_UseTab); - opts.tab_width = tab_width; - - file_auto_tab_tokens(system, models, file, start, start, end, opts); - - fill_buffer_summary(buffer, file, cmd); + memcpy(tokens_out, file->state.token_array.tokens + first_token, + sizeof(Cpp_Token)*(last_token - first_token)); } return(result); diff --git a/4ed_defines.h b/4ed_defines.h index 60680774..2ae6067d 100644 --- a/4ed_defines.h +++ b/4ed_defines.h @@ -41,9 +41,6 @@ typedef double f64; #define globalconst static const -inline i32 -raw_ptr_dif(void *a, void *b) { return (i32)((u8*)a - (u8*)b); } - #define COMP_ID_(a,b,c,d) (d << 24) | (c << 16) | (b << 8) | a #define COMPOSE_ID(a,b,c,d) (COMP_ID_((a),(b),(c),(d))) diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index 5ed4447f..1c674764 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -2517,465 +2517,6 @@ file_compute_edit(Mem_Options *mem, Editing_File *file, return(spec); } -struct Indent_Options{ - b32 empty_blank_lines; - b32 use_tabs; - i32 tab_width; -}; - -struct Make_Batch_Result{ - char *str_base; - i32 str_size; - - Buffer_Edit *edits; - i32 edit_max; - i32 edit_count; -}; - -internal Cpp_Token* -get_first_token_at_line(Buffer *buffer, Cpp_Token_Array tokens, i32 line){ - i32 start_pos = buffer->line_starts[line]; - Cpp_Get_Token_Result get_token = cpp_get_token(&tokens, start_pos); - - if (get_token.in_whitespace){ - get_token.token_index += 1; - } - - Cpp_Token *result = tokens.tokens + get_token.token_index; - - return(result); -} - -internal Cpp_Token* -seek_matching_token_backwards(Cpp_Token_Array tokens, Cpp_Token *token, - Cpp_Token_Type open_type, Cpp_Token_Type close_type){ - int32_t nesting_level = 0; - if (token <= tokens.tokens){ - token = tokens.tokens; - } - else{ - for (; token > tokens.tokens; --token){ - if (!(token->flags & CPP_TFLAG_PP_BODY)){ - if (token->type == close_type){ - ++nesting_level; - } - else if (token->type == open_type){ - if (nesting_level == 0){ - break; - } - else{ - --nesting_level; - } - } - } - } - } - return(token); -} - -struct Indent_Parse_State{ - i32 current_indent; - i32 previous_line_indent; - i32 paren_nesting; - i32 paren_anchor_indent[16]; - i32 comment_shift; -}; - -internal i32 -compute_this_indent(Buffer *buffer, Indent_Parse_State indent, - Cpp_Token T, Cpp_Token prev_token, i32 line_i, i32 tab_width){ - - i32 previous_indent = indent.previous_line_indent; - i32 this_indent = 0; - - i32 this_line_start = buffer->line_starts[line_i]; - i32 next_line_start = 0; - - if (line_i+1 < buffer->line_count){ - next_line_start = buffer->line_starts[line_i+1]; - } - else{ - next_line_start = buffer_size(buffer); - } - - b32 did_special_behavior = false; - - if (prev_token.start <= this_line_start && - prev_token.start + prev_token.size > this_line_start){ - if (prev_token.type == CPP_TOKEN_COMMENT){ - Hard_Start_Result hard_start = buffer_find_hard_start(buffer, this_line_start, tab_width); - - if (hard_start.all_whitespace){ - this_indent = previous_indent; - did_special_behavior = true; - } - else{ - i32 line_pos = hard_start.char_pos - this_line_start; - this_indent = line_pos + indent.comment_shift; - if (this_indent < 0){ - this_indent = 0; - } - did_special_behavior = true; - } - } - else if (prev_token.type == CPP_TOKEN_STRING_CONSTANT){ - this_indent = previous_indent; - did_special_behavior = true; - } - } - - - if (!did_special_behavior){ - this_indent = indent.current_indent; - if (T.start < next_line_start){ - if (T.flags & CPP_TFLAG_PP_DIRECTIVE){ - this_indent = 0; - } - else{ - switch (T.type){ - case CPP_TOKEN_BRACKET_CLOSE: this_indent -= tab_width; break; - case CPP_TOKEN_BRACE_CLOSE: this_indent -= tab_width; break; - case CPP_TOKEN_BRACE_OPEN: break; - - default: - if (indent.current_indent > 0){ - if (!(prev_token.flags & CPP_TFLAG_PP_BODY || - prev_token.flags & CPP_TFLAG_PP_DIRECTIVE)){ - switch (prev_token.type){ - case CPP_TOKEN_BRACKET_OPEN: - case CPP_TOKEN_BRACE_OPEN: case CPP_TOKEN_BRACE_CLOSE: - case CPP_TOKEN_SEMICOLON: case CPP_TOKEN_COLON: - case CPP_TOKEN_COMMA: case CPP_TOKEN_COMMENT: break; - default: this_indent += tab_width; - } - } - } - } - } - } - if (this_indent < 0) this_indent = 0; - } - - if (indent.paren_nesting > 0){ - if (prev_token.type != CPP_TOKEN_PARENTHESE_OPEN){ - i32 level = indent.paren_nesting-1; - if (level >= ArrayCount(indent.paren_anchor_indent)){ - level = ArrayCount(indent.paren_anchor_indent)-1; - } - this_indent = indent.paren_anchor_indent[level]; - } - } - return(this_indent); -} - -internal i32* -get_line_indentation_marks(Partition *part, Buffer *buffer, Cpp_Token_Array tokens, - i32 line_start, i32 line_end, i32 tab_width){ - - i32 indent_mark_count = line_end - line_start; - i32 *indent_marks = push_array(part, i32, indent_mark_count); - - Indent_Parse_State indent = {0}; - Cpp_Token *token = get_first_token_at_line(buffer, tokens, line_start); - - if (token != tokens.tokens){ - --token; - for (; token > tokens.tokens; --token){ - if (!(token->flags & CPP_TFLAG_PP_BODY)){ - switch(token->type){ - case CPP_TOKEN_BRACE_OPEN: - case CPP_TOKEN_BRACE_CLOSE: - goto out_of_loop; - } - } - } - out_of_loop:; - } - - // TODO(allen): This can maybe be it's own function now, so that we - // can do the decls in the order we want and avoid the extra binary search. - i32 found_safe_start_position = 0; - do{ - i32 line = buffer_get_line_index(buffer, token->start); - i32 start = buffer->line_starts[line]; - Hard_Start_Result hard_start = buffer_find_hard_start(buffer, start, tab_width); - - indent.current_indent = hard_start.indent_pos; - - Cpp_Token *start_token = get_first_token_at_line(buffer, tokens, line); - Cpp_Token *brace_token = token; - - if (start_token->type == CPP_TOKEN_PARENTHESE_OPEN){ - if (start_token == tokens.tokens){ - found_safe_start_position = 1; - } - else{ - token = start_token-1; - } - } - else{ - int32_t close = 0; - - for (token = brace_token; token > start_token; --token){ - switch(token->type){ - case CPP_TOKEN_PARENTHESE_CLOSE: - case CPP_TOKEN_BRACKET_CLOSE: - case CPP_TOKEN_BRACE_CLOSE: - close = token->type; - goto out_of_loop2; - } - } - out_of_loop2:; - - switch (close){ - case 0: token = start_token; found_safe_start_position = 1; break; - - case CPP_TOKEN_PARENTHESE_CLOSE: - token = seek_matching_token_backwards(tokens, token-1, - CPP_TOKEN_PARENTHESE_OPEN, - CPP_TOKEN_PARENTHESE_CLOSE); - break; - - case CPP_TOKEN_BRACKET_CLOSE: - token = seek_matching_token_backwards(tokens, token-1, - CPP_TOKEN_BRACKET_OPEN, - CPP_TOKEN_BRACKET_CLOSE); - break; - - case CPP_TOKEN_BRACE_CLOSE: - token = seek_matching_token_backwards(tokens, token-1, - CPP_TOKEN_BRACE_OPEN, - CPP_TOKEN_BRACE_CLOSE); - break; - } - } - } while(found_safe_start_position == 0); - - // NOTE(allen): Shift the array so that line_i can just operate in - // it's natural value range. - indent_marks -= line_start; - - i32 line_i = buffer_get_line_index(buffer, token->start); - - if (line_i > line_start){ - line_i = line_start; - } - - i32 next_line_start = buffer_size(buffer); - if (line_i+1 < buffer->line_count){ - next_line_start = buffer->line_starts[line_i+1]; - } - - switch (token->type){ - case CPP_TOKEN_BRACKET_OPEN: indent.current_indent += tab_width; break; - case CPP_TOKEN_BRACE_OPEN: indent.current_indent += tab_width; break; - case CPP_TOKEN_PARENTHESE_OPEN: indent.current_indent += tab_width; break; - } - - indent.previous_line_indent = indent.current_indent; - Cpp_Token T; - Cpp_Token prev_token = *token; - ++token; - - for (; line_i < line_end; ++token){ - if (token < tokens.tokens + tokens.count){ - T = *token; - } - else{ - T.type = CPP_TOKEN_EOF; - T.start = buffer_size(buffer); - T.flags = 0; - } - - for (; T.start >= next_line_start && line_i < line_end;){ - if (line_i+1 < buffer->line_count){ - next_line_start = buffer->line_starts[line_i+1]; - } - else{ - next_line_start = buffer_size(buffer); - } - - i32 this_indent = - compute_this_indent(buffer, indent, T, prev_token, line_i, tab_width); - - // NOTE(allen): Rebase the paren anchor if the first token - // after an open paren is on the next line. - if (indent.paren_nesting > 0){ - if (prev_token.type == CPP_TOKEN_PARENTHESE_OPEN){ - i32 level = indent.paren_nesting-1; - if (level >= ArrayCount(indent.paren_anchor_indent)){ - level = ArrayCount(indent.paren_anchor_indent)-1; - } - indent.paren_anchor_indent[level] = this_indent; - } - } - - if (line_i >= line_start){ - indent_marks[line_i] = this_indent; - } - ++line_i; - - indent.previous_line_indent = this_indent; - } - - switch (T.type){ - case CPP_TOKEN_BRACKET_OPEN: indent.current_indent += 4; break; - case CPP_TOKEN_BRACKET_CLOSE: indent.current_indent -= 4; break; - case CPP_TOKEN_BRACE_OPEN: indent.current_indent += 4; break; - case CPP_TOKEN_BRACE_CLOSE: indent.current_indent -= 4; break; - - case CPP_TOKEN_COMMENT: - { - i32 line = buffer_get_line_index(buffer, T.start); - i32 start = buffer->line_starts[line]; - - indent.comment_shift = (indent.current_indent - (T.start - start)); - }break; - - case CPP_TOKEN_PARENTHESE_OPEN: - if (!(T.flags & CPP_TFLAG_PP_BODY)){ - if (indent.paren_nesting < ArrayCount(indent.paren_anchor_indent)){ - i32 line = buffer_get_line_index(buffer, T.start); - i32 start = buffer->line_starts[line]; - i32 char_pos = T.start - start; - - Hard_Start_Result hard_start = - buffer_find_hard_start(buffer, start, tab_width); - - i32 line_pos = hard_start.char_pos - start; - - indent.paren_anchor_indent[indent.paren_nesting] = - char_pos - line_pos + indent.previous_line_indent + 1; - } - ++indent.paren_nesting; - } - break; - - case CPP_TOKEN_PARENTHESE_CLOSE: - if (!(T.flags & CPP_TFLAG_PP_BODY)){ - --indent.paren_nesting; - } - break; - } - prev_token = T; - } - - // NOTE(allen): Unshift the indent_marks array so that the return value - // is the exact starting point of the array that was actually allocated. - indent_marks += line_start; - - return(indent_marks); -} - -internal Make_Batch_Result -make_batch_from_indent_marks(Partition *part, Buffer *buffer, i32 line_start, i32 line_end, - i32 *indent_marks, Indent_Options opts){ - - Make_Batch_Result result = {0}; - - i32 edit_max = line_end - line_start; - i32 edit_count = 0; - - Buffer_Edit *edits = push_array(part, Buffer_Edit, edit_max); - - char *str_base = (char*)part->base + part->pos; - i32 str_size = 0; - - // NOTE(allen): Shift the array so that line_i can just operate in - // it's natural value range. - indent_marks -= line_start; - - for (i32 line_i = line_start; line_i < line_end; ++line_i){ - i32 start = buffer->line_starts[line_i]; - Hard_Start_Result hard_start = - buffer_find_hard_start(buffer, start, opts.tab_width); - - i32 correct_indentation = indent_marks[line_i]; - if (hard_start.all_whitespace && opts.empty_blank_lines) correct_indentation = 0; - if (correct_indentation == -1) correct_indentation = hard_start.indent_pos; - - if ((hard_start.all_whitespace && hard_start.char_pos > start) || - !hard_start.all_space || correct_indentation != hard_start.indent_pos){ - Buffer_Edit new_edit; - new_edit.str_start = str_size; - str_size += correct_indentation; - char *str = push_array(part, char, correct_indentation); - i32 j = 0; - if (opts.use_tabs){ - i32 i = 0; - for (; i + opts.tab_width <= correct_indentation; i += opts.tab_width) str[j++] = '\t'; - for (; i < correct_indentation; ++i) str[j++] = ' '; - } - else{ - for (; j < correct_indentation; ++j) str[j] = ' '; - } - new_edit.len = j; - new_edit.start = start; - new_edit.end = hard_start.char_pos; - edits[edit_count++] = new_edit; - } - - Assert(edit_count <= edit_max); - } - - result.str_base = str_base; - result.str_size = str_size; - - result.edits = edits; - result.edit_max = edit_max; - result.edit_count = edit_count; - - return(result); -} - -internal void -file_auto_tab_tokens(System_Functions *system, Models *models, - Editing_File *file, i32 pos, i32 start, i32 end, Indent_Options opts){ -#if BUFFER_EXPERIMENT_SCALPEL <= 0 - Mem_Options *mem = &models->mem; - Partition *part = &mem->part; - Buffer *buffer = &file->state.buffer; - - Assert(file && !file->is_dummy); - Cpp_Token_Array tokens = file->state.token_array; - Assert(tokens.tokens); - - i32 line_start = buffer_get_line_index(buffer, start); - i32 line_end = buffer_get_line_index(buffer, end) + 1; - - Temp_Memory temp = begin_temp_memory(part); - - i32 *indent_marks = - get_line_indentation_marks(part, buffer, tokens, line_start, line_end, opts.tab_width); - - Make_Batch_Result batch = - make_batch_from_indent_marks(part, buffer, line_start, line_end, indent_marks, opts); - - if (batch.edit_count > 0){ - Assert(buffer_batch_debug_sort_check(batch.edits, batch.edit_count)); - - // NOTE(allen): computing edit spec, doing batch edit - Buffer_Edit *inverse_array = push_array(part, Buffer_Edit, batch.edit_count); - Assert(inverse_array); - - char *inv_str = (char*)part->base + part->pos; - Edit_Spec spec = - file_compute_edit(mem, file, - batch.edits, batch.str_base, batch.str_size, - inverse_array, inv_str, part->max - part->pos, - batch.edit_count, BatchEdit_PreserveTokens); - - file_do_batch_edit(system, models, file, spec, hist_normal, BatchEdit_PreserveTokens); - } - end_temp_memory(temp); -#endif -} - -struct Get_Link_Result{ - b32 in_link; - i32 index; -}; - internal u32* style_get_color(Style *style, Cpp_Token token){ u32 *result; @@ -5555,54 +5096,73 @@ draw_file_bar(Render_Target *target, View *view, Editing_File *file, i32_Rect re bar.text_shift_y = 2; bar.text_shift_x = 0; - draw_rectangle(target, bar.rect, back_color); - if (!file){ - intbar_draw_string(target, &bar, make_lit_string("*NULL*"), base_color); + draw_rectangle(target, bar.rect, back_color); + + Assert(file); + + intbar_draw_string(target, &bar, file->name.live_name, base_color); + intbar_draw_string(target, &bar, make_lit_string(" -"), base_color); + + if (file->is_loading){ + intbar_draw_string(target, &bar, make_lit_string(" loading"), base_color); } else{ - intbar_draw_string(target, &bar, file->name.live_name, base_color); - intbar_draw_string(target, &bar, make_lit_string(" -"), base_color); + char bar_space[526]; + String bar_text = make_fixed_width_string(bar_space); + append_ss (&bar_text, make_lit_string(" L#")); + append_int_to_str(&bar_text, view->edit_pos->cursor.line); + append_ss (&bar_text, make_lit_string(" C#")); + append_int_to_str(&bar_text, view->edit_pos->cursor.character); - if (file->is_loading){ - intbar_draw_string(target, &bar, make_lit_string(" loading"), base_color); + append_ss(&bar_text, make_lit_string(" -")); + + if (file->settings.dos_write_mode){ + append_ss(&bar_text, make_lit_string(" dos")); } else{ - char line_number_space[30]; - String line_number = make_fixed_width_string(line_number_space); - append_ss(&line_number, make_lit_string(" L#")); - append_int_to_str(&line_number, view->edit_pos->cursor.line); - append_ss(&line_number, make_lit_string(" C#")); - append_int_to_str(&line_number, view->edit_pos->cursor.character); + append_ss(&bar_text, make_lit_string(" nix")); + } + + append_ss(&bar_text, make_lit_string(" -")); + + Command_Map *map = view->map; + if (map == &models->map_top){ + append_ss(&bar_text, make_lit_string(" global")); + } + else if (map == &models->map_file){ + append_ss(&bar_text, make_lit_string(" file")); + } + else if (map == &models->map_ui){ + append_ss(&bar_text, make_lit_string(" gui")); + } + else{ + i32 map_index = (i32)(view->map - models->user_maps); + i32 map_id = models->map_id_table[map_index]; - intbar_draw_string(target, &bar, line_number, base_color); - - intbar_draw_string(target, &bar, make_lit_string(" -"), base_color); - - if (file->settings.dos_write_mode){ - intbar_draw_string(target, &bar, make_lit_string(" dos"), base_color); - } - else{ - intbar_draw_string(target, &bar, make_lit_string(" nix"), base_color); - } - - if (file->state.still_lexing){ - intbar_draw_string(target, &bar, make_lit_string(" parsing"), pop1_color); - } - - if (!file->settings.unimportant){ - switch (file_get_sync(file)){ - case SYNC_BEHIND_OS: - { - persist String out_of_sync = make_lit_string(" !"); - intbar_draw_string(target, &bar, out_of_sync, pop2_color); - }break; - - case SYNC_UNSAVED: - { - persist String out_of_sync = make_lit_string(" *"); - intbar_draw_string(target, &bar, out_of_sync, pop2_color); - }break; - } + append_ss (&bar_text, make_lit_string(" user:")); + append_int_to_str(&bar_text, map_id); + } + + intbar_draw_string(target, &bar, bar_text, base_color); + + + if (file->state.still_lexing){ + intbar_draw_string(target, &bar, make_lit_string(" parsing"), pop1_color); + } + + if (!file->settings.unimportant){ + switch (file_get_sync(file)){ + case SYNC_BEHIND_OS: + { + persist String out_of_sync = make_lit_string(" !"); + intbar_draw_string(target, &bar, out_of_sync, pop2_color); + }break; + + case SYNC_UNSAVED: + { + persist String out_of_sync = make_lit_string(" *"); + intbar_draw_string(target, &bar, out_of_sync, pop2_color); + }break; } } } diff --git a/TODO.txt b/TODO.txt index 8eaeca3f..673ec61c 100644 --- a/TODO.txt +++ b/TODO.txt @@ -82,8 +82,11 @@ ; BEFORE I SHIP ; -; [] tokens in the custom API -; [] auto indent on the custom side +; [X] tokens in the custom API +; [X] auto indent on the custom side +; [] clean up and comment the auto indent code to allow for customizations +; [] more built in options for auto indenting +; [] token seeking on custom side ; [] expose dirty flags ; [] option to not open *messages* every startup ; [] commands for resizing panels @@ -96,7 +99,12 @@ ; [] hook on exit ; [] read only files ; [] occasionally missing the (!) mark on files on windows -; [] don't execute frames on events dealing only with ctrl/alt/shift +; [] case insensitive interactive switch buffer +; [] option to hide hidden files +; [] tab to complete folder names in the new file dialogue +; [] view fails to follow cursor when the view is shrunk +; [] view fails to follow cursor after deleting long line +; [] scroll down on compilation buffer durring compilation ; ; TODOS @@ -134,6 +142,7 @@ ; [X] full screen option ; [X] add to APIs ; [X] try to make win32 version better +; [X] don't execute frames on events dealing only with ctrl/alt/shift ; ; [] support full length unicode file names ; [] switch based word complete diff --git a/win32_4ed.cpp b/win32_4ed.cpp index 7061a645..f89ebf40 100644 --- a/win32_4ed.cpp +++ b/win32_4ed.cpp @@ -18,12 +18,12 @@ # define FSTRING_C # include "4coder_string.h" -#include "4coder_version.h" +# include "4coder_version.h" # include "4coder_keycodes.h" # include "4coder_style.h" # include "4coder_rect.h" - # include "4coder_mem.h" +# include "4cpp_lexer.h" // TODO(allen): This is duplicated from 4coder_custom.h // I need to work out a way to avoid this. @@ -111,11 +111,7 @@ struct Control_Keys{ b8 l_alt; b8 r_alt; }; -inline Control_Keys -control_keys_zero(){ - Control_Keys result = {0}; - return(result); -} +static Control_Keys null_control_keys; struct Win32_Input_Chunk_Transient{ Key_Input_Data key_data; @@ -1837,7 +1833,8 @@ Win32Callback(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){ win32vars.input_chunk.pers.mouse_l = 0; win32vars.input_chunk.pers.mouse_r = 0; - win32vars.input_chunk.pers.controls = control_keys_zero(); + win32vars.input_chunk.pers.control_keys[MDFR_SHIFT_INDEX] = 0; + win32vars.input_chunk.pers.controls = null_control_keys; }break; case WM_SIZE: