package edit

import (
	
	
	
	
	
)

//elvdoc:fn insert-at-dot
//
// ```elvish
// edit:insert-at-dot $text
// ```
//
// Inserts the given text at the dot, moving the dot after the newly
// inserted text.

func ( cli.App,  string) {
	.CodeArea().MutateState(func( *tk.CodeAreaState) {
		.Buffer.InsertAtDot()
	})
}

//elvdoc:fn replace-input
//
// ```elvish
// edit:replace-input $text
// ```
//
// Equivalent to assigning `$text` to `$edit:current-command`.

func ( cli.App,  string) {
	.CodeArea().MutateState(func( *tk.CodeAreaState) {
		.Buffer = tk.CodeBuffer{Content: , Dot: len()}
	})
}

//elvdoc:var -dot
//
// Contains the current position of the cursor, as a byte position within
// `$edit:current-command`.

//elvdoc:var current-command
//
// Contains the content of the current input. Setting the variable will
// cause the cursor to move to the very end, as if `edit-dot = (count
// $edit:current-command)` has been invoked.
//
// This API is subject to change.

func ( cli.App,  eval.NsBuilder) {
	.AddGoFns("<edit>", map[string]interface{}{
		"insert-at-dot": func( string) { insertAtDot(, ) },
		"replace-input": func( string) { replaceInput(, ) },
	})

	 := func( interface{}) error {
		var  int
		 := vals.ScanToGo(, &)
		if  != nil {
			return 
		}
		.CodeArea().MutateState(func( *tk.CodeAreaState) {
			.Buffer.Dot = 
		})
		return nil
	}
	 := func() interface{} {
		return vals.FromGo(.CodeArea().CopyState().Buffer.Dot)
	}
	.Add("-dot", vars.FromSetGet(, ))

	 := func( interface{}) error {
		var  string
		 := vals.ScanToGo(, &)
		if  != nil {
			return 
		}
		replaceInput(, )
		return nil
	}
	 := func() interface{} {
		return vals.FromGo(.CodeArea().CopyState().Buffer.Content)
	}
	.Add("current-command", vars.FromSetGet(, ))
}