diff --git a/4coder_API.html b/4coder_API.html index e4344020..8c080761 100644 --- a/4coder_API.html +++ b/4coder_API.html @@ -22,7 +22,7 @@ ul { list-style: none; padding: 0; margin: 0; }

§1 Introduction

-This is the documentation for alpha 4.0.10 super! 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.

+This is the documentation for alpha 4.0.9 super! 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

@@ -44,6 +44,7 @@ Coming Soon
  • buffer_boundary_seek
  • buffer_read_range
  • buffer_replace_range
  • +
  • buffer_batch_edit
  • buffer_set_setting
  • buffer_auto_indent
  • create_buffer
  • @@ -93,6 +94,7 @@ Coming Soon
  • Command_ID
  • User_Input_Type_ID
  • Event_Message_Type_ID
  • +
  • Buffer_Batch_Edit_Type
  • Buffer_Setting_ID
  • View_Setting_ID
  • Mouse_Cursor_Show_Type
  • @@ -117,6 +119,7 @@ Coming Soon
  • GUI_Scroll_Vars
  • Full_Cursor
  • Buffer_Seek
  • +
  • Buffer_Edit
  • Buffer_Summary
  • View_Summary
  • User_Input
  • @@ -378,8 +381,34 @@ 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
    4coder_Buffer_Positioning_System

    +
    +

    §3.3.13: 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.
    See Also
    Buffer_Edit
    Buffer_Batch_Edit_Type

    -

    §3.3.13: buffer_set_setting

    +

    §3.3.14: buffer_set_setting

    bool32 app->buffer_set_setting(
    Application_Links *app,
    Buffer_Summary *buffer,
    Buffer_Setting_ID setting,
    int32_t value
    )
    @@ -397,7 +426,7 @@ range is not within the bounds of the buffer.
    See Also
    Buffer_Setting_ID

    -

    §3.3.14: buffer_auto_indent

    +

    §3.3.15: 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
    )
    @@ -426,7 +455,7 @@ 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
    Auto_Indent_Flag
    4coder_Buffer_Positioning_System

    -

    §3.3.15: create_buffer

    +

    §3.3.16: create_buffer

    Buffer_Summary app->create_buffer(
    Application_Links *app,
    char *filename,
    int32_t filename_len,
    Buffer_Create_Flag flags
    )
    @@ -448,7 +477,7 @@ If the buffer does not exist a new buffer is created and named after the given f 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
    Buffer_Create_Flag

    -

    §3.3.16: save_buffer

    +

    §3.3.17: save_buffer

    bool32 app->save_buffer(
    Application_Links *app,
    Buffer_Summary *buffer,
    char *filename,
    int32_t filename_len,
    uint32_t flags
    )
    @@ -470,7 +499,7 @@ the filename does not correspond to a file on disk the buffer is created empty.<
    Return
    This call returns non-zero on success.

    -

    §3.3.17: kill_buffer

    +

    §3.3.18: kill_buffer

    bool32 app->kill_buffer(
    Application_Links *app,
    Buffer_Identifier buffer,
    View_ID view_id,
    Buffer_Kill_Flag flags
    )
    @@ -490,7 +519,7 @@ the filename does not correspond to a file on disk the buffer is created empty.< 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
    Buffer_Kill_Flag
    Buffer_Identifier

    -

    §3.3.18: get_view_first

    +

    §3.3.19: get_view_first

    View_Summary app->get_view_first(
    Application_Links *app,
    Access_Flag access
    )
    @@ -503,7 +532,7 @@ If the view is not open the kill fails.
    See Also
    Access_Flag
    get_view_next

    -

    §3.3.19: get_view_next

    +

    §3.3.20: get_view_next

    void app->get_view_next(
    Application_Links *app,
    View_Summary *view,
    Access_Flag access
    )
    @@ -520,7 +549,7 @@ Views should not be closed or opened durring a view loop.
    See Also
    Access_Flag
    get_view_first

    -

    §3.3.20: get_view

    +

    §3.3.21: get_view

    View_Summary app->get_view(
    Application_Links *app,
    View_ID view_id,
    Access_Flag access
    )
    @@ -534,7 +563,7 @@ Views should not be closed or opened durring a view loop.
    Return
    This call returns a summary that describes the indicated view if it is open and accessible.
    See Also
    Access_Flag

    -

    §3.3.21: get_active_view

    +

    §3.3.22: get_active_view

    View_Summary app->get_active_view(
    Application_Links *app,
    Access_Flag access
    )
    @@ -544,7 +573,7 @@ Views should not be closed or opened durring a view loop.
    Return
    This call returns a summary that describes the active view.
    See Also
    set_active_view
    Access_Flag

    -

    §3.3.22: open_view

    +

    §3.3.23: open_view

    View_Summary app->open_view(
    Application_Links *app,
    View_Summary *view_location,
    View_Split_Position position
    )
    @@ -560,7 +589,7 @@ Views should not be closed or opened durring a view loop.
    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
    View_Split_Position

    -

    §3.3.23: close_view

    +

    §3.3.24: close_view

    bool32 app->close_view(
    Application_Links *app,
    View_Summary *view
    )
    @@ -573,7 +602,7 @@ 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.24: set_active_view

    +

    §3.3.25: set_active_view

    bool32 app->set_active_view(
    Application_Links *app,
    View_Summary *view
    )
    @@ -585,7 +614,7 @@ If the given view is the last open view in the system, the call will fail.
    active view, and takes subsequent commands and is returned from get_active_view.
    See Also
    get_active_view

    -

    §3.3.25: view_set_setting

    +

    §3.3.26: view_set_setting

    bool32 app->view_set_setting(
    Application_Links *app,
    View_Summary *view,
    View_Setting_ID setting,
    int32_t value
    )
    @@ -603,7 +632,7 @@ from get_active_view.
    Return
    This call returns non-zero on success.
    See Also
    View_Setting_ID

    -

    §3.3.26: view_set_split_proportion

    +

    §3.3.27: view_set_split_proportion

    bool32 app->view_set_split_proportion(
    Application_Links *app,
    View_Summary *view,
    float t
    )
    @@ -617,7 +646,7 @@ from get_active_view.
    Return
    This call returns non-zero on success.

    -

    §3.3.27: view_compute_cursor

    +

    §3.3.28: view_compute_cursor

    bool32 app->view_compute_cursor(
    Application_Links *app,
    View_Summary *view,
    Buffer_Seek seek,
    Full_Cursor *cursor_out
    )
    @@ -635,7 +664,7 @@ from get_active_view.
    Return
    This call returns non-zero on success.
    Description
    Computes a Full_Cursor for the given seek position with no side effects.
    See Also
    Buffer_Seek
    Full_Cursor

    -

    §3.3.28: view_set_cursor

    +

    §3.3.29: view_set_cursor

    bool32 app->view_set_cursor(
    Application_Links *app,
    View_Summary *view,
    Buffer_Seek seek,
    bool32 set_preferred_x
    )
    @@ -655,7 +684,7 @@ from get_active_view.
    See Also
    Buffer_Seek

    -

    §3.3.29: view_set_mark

    +

    §3.3.30: view_set_mark

    bool32 app->view_set_mark(
    Application_Links *app,
    View_Summary *view,
    Buffer_Seek seek
    )
    @@ -669,7 +698,7 @@ cursor in the same column or x position.
    Return
    This call returns non-zero on success.
    Description
    This call sets the the view's mark position.
    See Also
    Buffer_Seek

    -

    §3.3.30: view_set_highlight

    +

    §3.3.31: view_set_highlight

    bool32 app->view_set_highlight(
    Application_Links *app,
    View_Summary *view,
    int32_t start,
    int32_t end,
    bool32 turn_on
    )
    @@ -694,7 +723,7 @@ is set to true the highlight will be shown and the cursor will be hidden. After that either setting the 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.31: view_set_buffer

    +

    §3.3.32: view_set_buffer

    bool32 app->view_set_buffer(
    Application_Links *app,
    View_Summary *view,
    Buffer_ID buffer_id,
    Set_Buffer_Flag flags
    )
    @@ -713,7 +742,7 @@ the turn_on set to false, will switch back to showing the cursor.

    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
    Set_Buffer_Flag

    -

    §3.3.32: view_post_fade

    +

    §3.3.33: 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
    )
    @@ -739,7 +768,7 @@ cancels and dialogue shown in the view and displays the file.
    Return
    This call returns non-zero on success.
    See Also
    int_color

    -

    §3.3.33: get_user_input

    +

    §3.3.34: get_user_input

    User_Input app->get_user_input(
    Application_Links *app,
    Input_Type_Flag get_type,
    Input_Type_Flag abort_type
    )
    @@ -757,19 +786,19 @@ command is executed an abort signal is returned. If an abort signal is ever ret 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
    Input_Type_Flag
    User_Input

    -

    §3.3.34: get_command_input

    +

    §3.3.35: 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
    User_Input

    -

    §3.3.35: get_mouse_state

    +

    §3.3.36: 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
    Mouse_State

    -

    §3.3.36: start_query_bar

    +

    §3.3.37: start_query_bar

    bool32 app->start_query_bar(
    Application_Links *app,
    Query_Bar *bar,
    uint32_t flags
    )
    @@ -789,7 +818,7 @@ can be changed after the call to start_query_bar and the query bar shown by 4cod 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.37: end_query_bar

    +

    §3.3.38: end_query_bar

    void app->end_query_bar(
    Application_Links *app,
    Query_Bar *bar,
    uint32_t flags
    )
    @@ -803,7 +832,7 @@ only use for this call is in an interactive command that makes calls to get_user
    Description
    Stops showing the particular query bar specified by the bar parameter.

    Description
    This call posts a string to the *messages* buffer.

    -

    §3.3.39: change_theme

    +

    §3.3.40: change_theme

    void app->change_theme(
    Application_Links *app,
    char *name,
    int32_t len
    )
    @@ -831,7 +860,7 @@ only use for this call is in an interactive command that makes calls to get_user
    Description
    This call changes 4coder's theme to one of the built in themes.

    -

    §3.3.40: change_font

    +

    §3.3.41: change_font

    void app->change_font(
    Application_Links *app,
    char *name,
    int32_t len
    )
    @@ -845,7 +874,7 @@ only use for this call is in an interactive command that makes calls to get_user
    Description
    This call changes 4coder's font to one of the built in fonts.

    -

    §3.3.41: set_theme_colors

    +

    §3.3.42: set_theme_colors

    void app->set_theme_colors(
    Application_Links *app,
    Theme_Color *colors,
    int32_t count
    )
    @@ -861,7 +890,7 @@ only use for this call is in an interactive command that makes calls to get_user 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.42: get_theme_colors

    +

    §3.3.43: get_theme_colors

    void app->get_theme_colors(
    Application_Links *app,
    Theme_Color *colors,
    int32_t count
    )
    @@ -877,7 +906,7 @@ no change is made to the color pallet.

    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.43: directory_get_hot

    +

    §3.3.44: directory_get_hot

    int32_t app->directory_get_hot(
    Application_Links *app,
    char *out,
    int32_t capacity
    )
    @@ -895,7 +924,7 @@ 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.44: get_file_list

    +

    §3.3.45: get_file_list

    File_List app->get_file_list(
    Application_Links *app,
    char *dir,
    int32_t len
    )
    @@ -911,7 +940,7 @@ directories controlled on the custom side.

    the specified directory. The File_List returned should be passed to free_file_list when it is no longer in use.
    -

    §3.3.45: free_file_list

    +

    §3.3.46: free_file_list

    void app->free_file_list(
    Application_Links *app,
    File_List list
    )
    @@ -921,7 +950,7 @@ when it is no longer in use.

    Description
    After this call the file list passed in should not be read or written to.

    -

    §3.3.46: file_exists

    +

    §3.3.47: file_exists

    bool32 app->file_exists(
    Application_Links *app,
    char *filename,
    int len
    )
    @@ -935,7 +964,7 @@ when it is no longer in use.

    Return
    This call returns non-zero if and only if the file exists.

    -

    §3.3.47: directory_cd

    +

    §3.3.48: directory_cd

    bool32 app->directory_cd(
    Application_Links *app,
    char *dir,
    int *len,
    int capacity,
    char *rel_path,
    int rel_len
    )
    @@ -968,7 +997,7 @@ 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.48: get_4ed_path

    +

    §3.3.49: get_4ed_path

    bool32 app->get_4ed_path(
    Application_Links *app,
    char *out,
    int32_t capacity
    )
    @@ -982,7 +1011,7 @@ folders.

    Return
    This call returns non-zero on success.

    -

    §3.3.49: show_mouse_cursor

    +

    §3.3.50: show_mouse_cursor

    void app->show_mouse_cursor(
    Application_Links *app,
    Mouse_Cursor_Show_Type show
    )
    @@ -1173,8 +1202,20 @@ the range [1,16].

    TODO.

    +
    +

    §3.4.10: Buffer_Batch_Edit_Type

    +
    enum Buffer_Batch_Edit_Type;
    +
    Description
    A Buffer_Batch_Edit_Type is a type of batch operation.
    Values
    +
    BatchEdit_Normal
    +
    +
    +
    +
    BatchEdit_PreserveTokens
    +
    +
    +

    -

    §3.4.10: Buffer_Setting_ID

    +

    §3.4.11: Buffer_Setting_ID

    enum Buffer_Setting_ID;
    Description
    A Buffer_Setting_ID names a setting in a buffer.
    Values
    BufferSetting_Null
    @@ -1203,7 +1244,7 @@ the range [1,16].


    -

    §3.4.11: View_Setting_ID

    +

    §3.4.12: View_Setting_ID

    enum View_Setting_ID;
    Description
    A View_Setting_ID names a setting in a view.
    Values
    ViewSetting_Null
    @@ -1227,7 +1268,7 @@ the range [1,16].


    -

    §3.4.12: Mouse_Cursor_Show_Type

    +

    §3.4.13: Mouse_Cursor_Show_Type

    enum Mouse_Cursor_Show_Type;
    Description
    A Mouse_Cursor_Show_Type value specifes a mode for 4coder to handle the mouse cursor.
    Values
    MouseCursorShow_Never
    @@ -1239,7 +1280,7 @@ the range [1,16].


    -

    §3.4.13: Buffer_Seek_Type

    +

    §3.4.14: Buffer_Seek_Type

    enum Buffer_Seek_Type;
    Description
    The Buffer_Seek_Type is is used in a Buffer_Seek to identify which coordinates are suppose to be used for the seek.
    Values
    @@ -1260,7 +1301,7 @@ coordinates are suppose to be used for the seek.
    See Also
    Buffer_Seek
    4coder_Buffer_Positioning_System

    -

    §3.4.14: View_Split_Position

    +

    §3.4.15: View_Split_Position

    enum View_Split_Position;
    Description
    A View_Split_Position specifies where a new view should be placed as a result of a view split operation.
    Values
    @@ -1281,7 +1322,7 @@ a view split operation.
    -

    §3.4.15: Key_Modifier_Flag

    +

    §3.4.16: Key_Modifier_Flag

    enum Key_Modifier_Flag;
    Description
    A Key_Modifier_Flag field is used to specify a specific state of modifiers. Flags can be combined with bit or to specify a state with multiple modifiers.
    Flags
    @@ -1302,7 +1343,7 @@ Flags can be combined with bit or to specify a state with multiple modifiers.

    -

    §3.4.16: Buffer_Create_Flag

    +

    §3.4.17: Buffer_Create_Flag

    enum Buffer_Create_Flag;
    Description
    A Buffer_Create_Flag field specifies how a buffer should be created.
    Flags
    BufferCreate_Background = 0x1
    @@ -1315,7 +1356,7 @@ Flags can be combined with bit or to specify a state with multiple modifiers.

    -

    §3.4.17: Buffer_Kill_Flag

    +

    §3.4.18: Buffer_Kill_Flag

    enum Buffer_Kill_Flag;
    Description
    A Buffer_Kill_Flag field specifies how a buffer should be killed.
    Flags
    BufferKill_Background = 0x1
    @@ -1328,7 +1369,7 @@ Flags can be combined with bit or to specify a state with multiple modifiers.

    -

    §3.4.18: Access_Flag

    +

    §3.4.19: Access_Flag

    enum Access_Flag;
    Description
    An Access_Flag field specifies what sort of permission you grant to an access call. An access call is usually one the returns a summary struct. If a @@ -1358,7 +1399,7 @@ that protection flag, the object is still returned from the access call.

    -

    §3.4.19: Seek_Boundary_Flag

    +

    §3.4.20: Seek_Boundary_Flag

    enum Seek_Boundary_Flag;
    Description
    A Seek_Boundary_Flag field specifies a set of "boundary" types used in seeks for the beginning or end of different types of words.
    Flags
    @@ -1379,7 +1420,7 @@ beginning or end of different types of words.
    -

    §3.4.20: Command_Line_Input_Flag

    +

    §3.4.21: Command_Line_Input_Flag

    enum Command_Line_Input_Flag;
    Description
    A Command_Line_Input_Flag field specifies the behavior of a call to a command line interface.
    Flags
    CLI_OverlapWithConflict = 0x1
    @@ -1400,7 +1441,7 @@ beginning or end of different types of words.
    -

    §3.4.21: Auto_Indent_Flag

    +

    §3.4.22: Auto_Indent_Flag

    enum Auto_Indent_Flag;
    Description
    An Auto_Indent_Flag field specifies the behavior of an auto indentation operation.
    Flags
    AutoIndent_ClearLine = 0x1
    @@ -1416,7 +1457,7 @@ beginning or end of different types of words.
    -

    §3.4.22: Set_Buffer_Flag

    +

    §3.4.23: Set_Buffer_Flag

    enum Set_Buffer_Flag;
    Description
    A Set_Buffer_Flag field specifies the behavior of an operation that sets the buffer of a view.
    Flags
    SetBuffer_KeepOriginalGUI = 0x1
    @@ -1426,7 +1467,7 @@ beginning or end of different types of words.
    -

    §3.4.23: Input_Type_Flag

    +

    §3.4.24: Input_Type_Flag

    enum Input_Type_Flag;
    Description
    A Input_Type_Flag field specifies a set of input event types.
    Flags
    EventOnAnyKey = 0x1
    @@ -1466,7 +1507,7 @@ beginning or end of different types of words.
    -

    §3.4.24: Generic_Command

    +

    §3.4.25: Generic_Command

    union Generic_Command {
    Command_ID cmdid;
    @@ -1487,7 +1528,7 @@ internal command or a custom command.
    -

    §3.4.25: Key_Event_Data

    +

    §3.4.26: Key_Event_Data

    struct Key_Event_Data {
    Key_Code keycode;
    @@ -1521,7 +1562,7 @@ at the time of the event.
    -

    §3.4.26: Mouse_State

    +

    §3.4.27: Mouse_State

    struct Mouse_State {
    char l;
    @@ -1581,7 +1622,7 @@ mouse if in the window.
    -

    §3.4.27: Range

    +

    §3.4.28: Range

    union Range {
    struct {
    @@ -1621,7 +1662,7 @@ Throughout the API ranges are thought of in the form [min,max
    -

    §3.4.28: File_Info

    +

    §3.4.29: File_Info

    struct File_Info {
    char * filename;
    @@ -1644,7 +1685,7 @@ int folder;
    See Also

    -

    §3.4.29: File_List

    +

    §3.4.30: File_List

    struct File_List {
    void * block;
    @@ -1672,7 +1713,7 @@ int block_size;

    -

    §3.4.30: Buffer_Identifier

    +

    §3.4.31: Buffer_Identifier

    struct Buffer_Identifier {
    char * name;
    @@ -1697,7 +1738,7 @@ can either be a name or an id. If the
    -

    §3.4.31: GUI_Scroll_Vars

    +

    §3.4.32: GUI_Scroll_Vars

    struct GUI_Scroll_Vars {
    float scroll_y;
    @@ -1735,7 +1776,7 @@ int32_t prev_target_x;

    -

    §3.4.32: Full_Cursor

    +

    §3.4.33: Full_Cursor

    struct Full_Cursor {
    int32_t pos;
    @@ -1779,7 +1820,7 @@ coordinate system supported by 4coder.
    See Also

    -

    §3.4.33: Buffer_Seek

    +

    §3.4.34: Buffer_Seek

    struct Buffer_Seek {
    Buffer_Seek_Type type;
    @@ -1843,8 +1884,38 @@ for concisely creating Buffer_Seek structs. They can be found in 4coder_buffer_
    The character number of a line-character type seek.
    See Also

    +
    +

    §3.4.35: 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.34: Buffer_Summary

    +

    §3.4.36: Buffer_Summary

    struct Buffer_Summary {
    bool32 exists;
    @@ -1852,6 +1923,7 @@ 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;
    @@ -1885,6 +1957,10 @@ bool32 unwrapped_lines;
    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.
    @@ -1914,7 +1990,7 @@ bool32 unwrapped_lines;
    See Also

    -

    §3.4.35: View_Summary

    +

    §3.4.37: View_Summary

    struct View_Summary {
    bool32 exists;
    @@ -1984,7 +2060,7 @@ GUI_Scroll_Vars scroll_vars;
    See Also

    -

    §3.4.36: User_Input

    +

    §3.4.38: User_Input

    struct User_Input {
    User_Input_Type_ID type;
    @@ -2021,7 +2097,7 @@ Generic_Command command;
    See Also

    -

    §3.4.37: Query_Bar

    +

    §3.4.39: Query_Bar

    struct Query_Bar {
    String prompt;
    @@ -2040,7 +2116,7 @@ that will be displayed as a drop down bar durring an interactive command.
    <

    -

    §3.4.38: Event_Message

    +

    §3.4.40: Event_Message

    struct Event_Message {
    int type;
    @@ -2053,7 +2129,7 @@ int type;

    -

    §3.4.39: Theme_Color

    +

    §3.4.41: Theme_Color

    struct Theme_Color {
    Style_Tag tag;
    diff --git a/4coder_custom_api.h b/4coder_custom_api.h index 45c7282e..2086c39e 100644 --- a/4coder_custom_api.h +++ b/4coder_custom_api.h @@ -10,6 +10,7 @@ #define BUFFER_BOUNDARY_SEEK_SIG(n) int32_t n(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, bool32 seek_forward, Seek_Boundary_Flag flags) #define BUFFER_READ_RANGE_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, int32_t start, int32_t end, char *out) #define BUFFER_REPLACE_RANGE_SIG(n) bool32 n(Application_Links *app, Buffer_Summary *buffer, int32_t start, int32_t end, char *str, int32_t len) +#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 CREATE_BUFFER_SIG(n) Buffer_Summary n(Application_Links *app, char *filename, int32_t filename_len, Buffer_Create_Flag flags) @@ -60,6 +61,7 @@ extern "C"{ typedef BUFFER_BOUNDARY_SEEK_SIG(Buffer_Boundary_Seek_Function); typedef BUFFER_READ_RANGE_SIG(Buffer_Read_Range_Function); typedef BUFFER_REPLACE_RANGE_SIG(Buffer_Replace_Range_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 CREATE_BUFFER_SIG(Create_Buffer_Function); @@ -113,6 +115,7 @@ struct Application_Links{ Buffer_Boundary_Seek_Function *buffer_boundary_seek; Buffer_Read_Range_Function *buffer_read_range; Buffer_Replace_Range_Function *buffer_replace_range; + Buffer_Batch_Edit_Function *buffer_batch_edit; Buffer_Set_Setting_Function *buffer_set_setting; Buffer_Auto_Indent_Function *buffer_auto_indent; Create_Buffer_Function *create_buffer; @@ -168,6 +171,7 @@ app_links->get_buffer_by_name = Get_Buffer_By_Name;\ app_links->buffer_boundary_seek = Buffer_Boundary_Seek;\ app_links->buffer_read_range = Buffer_Read_Range;\ app_links->buffer_replace_range = Buffer_Replace_Range;\ +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->create_buffer = Create_Buffer;\ diff --git a/4coder_default_include.cpp b/4coder_default_include.cpp index 17953034..c1e6e670 100644 --- a/4coder_default_include.cpp +++ b/4coder_default_include.cpp @@ -1405,6 +1405,10 @@ CUSTOM_COMMAND_SIG(open_in_other_regular){ # define open_in_other open_in_other_regular #endif +// +// Auto Indenting and Whitespace +// + CUSTOM_COMMAND_SIG(auto_tab_line_at_cursor){ unsigned int access = AccessOpen; View_Summary view = app->get_active_view(app, access); @@ -1446,6 +1450,66 @@ CUSTOM_COMMAND_SIG(write_and_auto_tab){ exec_command(app, auto_tab_line_at_cursor); } +CUSTOM_COMMAND_SIG(clean_all_lines){ + View_Summary view = app->get_active_view(app, AccessOpen); + Buffer_Summary buffer = app->get_buffer(app, view.buffer_id, AccessOpen); + + int line_count = buffer.line_count; + int edit_max = line_count; + + if (edit_max*sizeof(Buffer_Edit) < app->memory_size){ + Buffer_Edit *edits = (Buffer_Edit*)app->memory; + + char data[1024]; + Stream_Chunk chunk = {0}; + + int i = 0; + if (init_stream_chunk(&chunk, app, &buffer, + 0, data, sizeof(data))){ + Buffer_Edit *edit = edits; + + int buffer_size = buffer.size; + int still_looping = true; + int need_stopper = true; + int last_hard = buffer_size; + do{ + if (need_stopper && !still_looping){ + chunk.end = i+1; + chunk.data[0] = '\n'; + need_stopper = false; + } + + for (; i < chunk.end; ++i){ + char at_pos = chunk.data[i]; + if (at_pos == '\n'){ + if (last_hard+1 < i){ + edit->str_start = 0; + edit->len = 0; + edit->start = last_hard+1; + edit->end = i; + ++edit; + i = buffer_size; + } + } + else if (char_is_whitespace(at_pos)){ + // NOTE(allen): do nothing + } + else{ + last_hard = i; + } + } + + if (still_looping){ + still_looping = forward_stream_chunk(&chunk); + } + }while(still_looping && need_stopper); + + int edit_count = (int)(edit - edits); + app->buffer_batch_edit(app, &buffer, 0, edits, edit_count, BatchEdit_PreserveTokens); + } + } +} + // // Default Building Stuff // @@ -1455,7 +1519,7 @@ CUSTOM_COMMAND_SIG(write_and_auto_tab){ // directory of the given buffer, it cannot it get's the 4coder hot directory. // This behavior is a little different than previous versions of 4coder. // -// There is requirement that a custom build system in 4coder actually use the +// There is no requirement that a custom build system in 4coder actually use the // directory given by this function. enum Get_Build_Directory_Result{ BuildDir_None, diff --git a/4coder_types.h b/4coder_types.h index 3cd11926..8f853701 100644 --- a/4coder_types.h +++ b/4coder_types.h @@ -122,6 +122,15 @@ ENUM(int32_t, Event_Message_Type_ID){ EventMessage_CloseView }; +/* DOC(A Buffer_Batch_Edit_Type is a type of batch operation.) */ +ENUM(int32_t, Buffer_Batch_Edit_Type){ + /* DOC(The BatchEdit_Normal operation is always correct but does the most work.) */ + BatchEdit_Normal, + /* DOC(The BatchEdit_PreserveTokens operation is one in which none of the edits add, delete, or change any tokens. + This usually applies when whitespace is being replaced with whitespace.) */ + BatchEdit_PreserveTokens +} + /* DOC(A Buffer_Setting_ID names a setting in a buffer.) */ ENUM(int32_t, Buffer_Setting_ID){ /* DOC(BufferSetting_Null is not a valid setting, it is reserved to detect errors.) */ @@ -521,6 +530,20 @@ struct Buffer_Seek{ }; }; +/* DOC(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.) */ +struct Buffer_Edit{ + /* DOC(The str_start field specifies the first character in the accompanying string that corresponds with this edit.) */ + int32_t str_start; + /* DOC(The len field specifies the length of the string being written into the buffer.) */ + int32_t len; + /* DOC(The start field specifies the start of the range in the buffer to replace in absolute position.) */ + int32_t start; + /* DOC(The end field specifies one past the end of the range in the buffer to replace in absolute position.) */ + int32_t end; +}; + /* DOC(Buffer_Summary acts as a handle to a buffer and describes the state of the buffer.) DOC_SEE(Access_Flag)*/ struct Buffer_Summary{ @@ -543,6 +566,8 @@ struct Buffer_Summary{ /* DOC(If this is not a null summary, this field specifies the size of the text in the buffer.) */ int32_t size; + /* DOC(If this is not a null summary, this field specifies the number of lines in the buffer.) */ + int32_t line_count; /* DOC(If this is not a null summary, this field specifies the file name associated to this buffer.) */ char *file_name; diff --git a/4ed.cpp b/4ed.cpp index 7b050b75..aceb3272 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -744,7 +744,64 @@ COMMAND_DECL(clean_all_lines){ REQ_OPEN_VIEW(view); REQ_FILE(file, view); - view_clean_whitespace(system, models, view); + Mem_Options *mem = &models->mem; + Editing_File *file = view->file_data.file; + + Partition *part = &mem->part; + i32 line_count = file->state.buffer.line_count; + i32 edit_max = line_count * 2; + i32 edit_count = 0; + + Assert(file && !file->is_dummy); + Assert(view->edit_pos); + + Temp_Memory temp = begin_temp_memory(part); + Buffer_Edit *edits = push_array(part, Buffer_Edit, edit_max); + + char *str_base = (char*)part->base + part->pos; + i32 str_size = 0; + for (i32 line_i = 0; line_i < line_count; ++line_i){ + i32 start = file->state.buffer.line_starts[line_i]; + Hard_Start_Result hard_start = + buffer_find_hard_start(&file->state.buffer, start, 4); + + if (hard_start.all_whitespace){ + hard_start.indent_pos = 0; + } + + if ((hard_start.all_whitespace && hard_start.char_pos > start) || !hard_start.all_space){ + Buffer_Edit new_edit; + new_edit.str_start = str_size; + str_size += hard_start.indent_pos; + char *str = push_array(part, char, hard_start.indent_pos); + for (i32 j = 0; j < hard_start.indent_pos; ++j) str[j] = ' '; + new_edit.len = hard_start.indent_pos; + new_edit.start = start; + new_edit.end = hard_start.char_pos; + edits[edit_count++] = new_edit; + } + Assert(edit_count <= edit_max); + } + + if (edit_count > 0){ + Assert(buffer_batch_debug_sort_check(edits, edit_count)); + + // NOTE(allen): computing edit spec, doing batch edit + Buffer_Edit *inverse_array = push_array(part, Buffer_Edit, edit_count); + Assert(inverse_array); + + char *inv_str = (char*)part->base + part->pos; + Edit_Spec spec = + file_compute_whitespace_edit(mem, file, + view->edit_pos->cursor.pos, + edits, str_base, str_size, + inverse_array, inv_str, + part->max - part->pos, edit_count); + + file_do_white_batch_edit(system, models, view->file_data.file, spec, hist_normal); + } + + end_temp_memory(temp); } COMMAND_DECL(open_panel_vsplit){ diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp index 990927e3..e0dd4df7 100644 --- a/4ed_api_implementation.cpp +++ b/4ed_api_implementation.cpp @@ -24,6 +24,7 @@ fill_buffer_summary(Buffer_Summary *buffer, Editing_File *file, Working_Set *wor buffer->buffer_id = file->id.id; buffer->size = file->state.buffer.size; + buffer->line_count = file->state.buffer.line_count; buffer->file_name_len = file->name.source_path.size; buffer->buffer_name_len = file->name.live_name.size; @@ -701,6 +702,56 @@ DOC_SEE(4coder_Buffer_Positioning_System) return(result); } +API_EXPORT bool32 +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)/* +DOC_PARAM(str, This parameter provides all of the source string for the edits in the batch.) +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() +DOC_SEE(Buffer_Edit) +DOC_SEE(Buffer_Batch_Edit_Type) +*/{ + Command_Data *cmd = (Command_Data*)app->cmd_context; + Mem_Options *mem = cmd->models; + Partition *part = &models->mem.part; + Editing_File *file = imp_get_file(cmd, buffer); + + bool32 result = false; + + if (file){ + Temp_Memory temp = begin_temp_memory(part); + Buffer_Edit *inverse_edits = push_array(part, Buffer_Edit, edit_count); + char *inv_str = (char*)part->base + part->pos; + int inv_str_max = part->max - part->pos; + Assert(inverse_edits); + + switch (type){ + case BatchEdit_Normal: + { + // TODO(allen): + }break; + + case BatchEdit_PreserveTokens: + { + Edit_Spec spec = + file_compute_whitespace_edit(mem, file, + edits, str, str_len, + inverse_edits, inv_str, inv_str_max, + edit_count); + + file_do_white_batch_edit(system, models, file, spec, hist_normal); + }break; + } + + end_temp_memory(part); + } + + return(result); +} + API_EXPORT bool32 Buffer_Set_Setting(Application_Links *app, Buffer_Summary *buffer, Buffer_Setting_ID setting, int32_t value)/* DOC_PARAM(buffer, The buffer parameter specifies the buffer on which to set a setting.) diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index a871fb81..0f8a7818 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -2532,7 +2532,7 @@ clipboard_copy(System_Functions *system, General_Memory *general, Working_Set *w } internal Edit_Spec -file_compute_whitespace_edit(Mem_Options *mem, Editing_File *file, i32 cursor_pos, +file_compute_whitespace_edit(Mem_Options *mem, Editing_File *file, Buffer_Edit *edits, char *str_base, i32 str_size, Buffer_Edit *inverse_array, char *inv_str, i32 inv_max, i32 edit_count){ @@ -2563,66 +2563,6 @@ file_compute_whitespace_edit(Mem_Options *mem, Editing_File *file, i32 cursor_po return(spec); } -internal void -view_clean_whitespace(System_Functions *system, Models *models, View *view){ - Mem_Options *mem = &models->mem; - Editing_File *file = view->file_data.file; - - Partition *part = &mem->part; - i32 line_count = file->state.buffer.line_count; - i32 edit_max = line_count * 2; - i32 edit_count = 0; - - Assert(file && !file->is_dummy); - Assert(view->edit_pos); - - Temp_Memory temp = begin_temp_memory(part); - Buffer_Edit *edits = push_array(part, Buffer_Edit, edit_max); - - char *str_base = (char*)part->base + part->pos; - i32 str_size = 0; - for (i32 line_i = 0; line_i < line_count; ++line_i){ - i32 start = file->state.buffer.line_starts[line_i]; - Hard_Start_Result hard_start = - buffer_find_hard_start(&file->state.buffer, start, 4); - - if (hard_start.all_whitespace) hard_start.indent_pos = 0; - - if ((hard_start.all_whitespace && hard_start.char_pos > start) || !hard_start.all_space){ - Buffer_Edit new_edit; - new_edit.str_start = str_size; - str_size += hard_start.indent_pos; - char *str = push_array(part, char, hard_start.indent_pos); - for (i32 j = 0; j < hard_start.indent_pos; ++j) str[j] = ' '; - new_edit.len = hard_start.indent_pos; - new_edit.start = start; - new_edit.end = hard_start.char_pos; - edits[edit_count++] = new_edit; - } - Assert(edit_count <= edit_max); - } - - if (edit_count > 0){ - Assert(buffer_batch_debug_sort_check(edits, edit_count)); - - // NOTE(allen): computing edit spec, doing batch edit - Buffer_Edit *inverse_array = push_array(part, Buffer_Edit, edit_count); - Assert(inverse_array); - - char *inv_str = (char*)part->base + part->pos; - Edit_Spec spec = - file_compute_whitespace_edit(mem, file, - view->edit_pos->cursor.pos, - edits, str_base, str_size, - inverse_array, inv_str, - part->max - part->pos, edit_count); - - file_do_white_batch_edit(system, models, view->file_data.file, spec, hist_normal); - } - - end_temp_memory(temp); -} - struct Indent_Options{ b32 empty_blank_lines; b32 use_tabs; diff --git a/4tech_table.cpp b/4tech_table.cpp index fc4257c4..c1e47932 100644 --- a/4tech_table.cpp +++ b/4tech_table.cpp @@ -20,7 +20,6 @@ struct Table{ u32 *hash_array; u8 *data_array; i32 count, max; - i32 item_size; }; diff --git a/buffer/4coder_shared.cpp b/buffer/4coder_shared.cpp index cb1ee47b..ccd8b886 100644 --- a/buffer/4coder_shared.cpp +++ b/buffer/4coder_shared.cpp @@ -78,11 +78,6 @@ lroundup_(int x, int granularity){ #define measure_character(a,c) ((a)[c]) -typedef struct Buffer_Edit{ - int str_start, len; - int start, end; -} Buffer_Edit; - typedef struct Buffer_Batch_State{ int i; int shift_total;